def __init__(self, prefix, windowName, width, height, icon, shelfCommand, annotation=' ', dockable=False, menuBar=False, mnb=False, mxb=False, s=False, rtf=False, startArea='right', allowedAreas='all', floating=False, *args, **kwargs): """ Initialize class and variables """ self.kwargs = kwargs self.windowName = windowName self.dockName = windowName + 'Dock' self.width = width self.height = height self.icon = icon self.prefix = prefix self.shelfCommand = shelfCommand self.annotation = annotation self.dockable = dockable self.menuBar = menuBar self.mnb = mnb self.mxb = mxb self.sizeable = s self.rtf = rtf self.startArea = startArea self.allowedAreas = allowedAreas self.floating = floating # store for use outside self.toolName = windowName self.mainWindow = '' self.menuBarLayout = '' self.prinipalMenus = None self.global_cfg = lcConfiguration.GlobalSettingsDictionary() self.lct_cfg = lcConfiguration.ConfigurationNode(lcPath.Path.get_tools_settings_file(), self.global_cfg) self.srcPath = lcPath.Path.getSrcPath()
def update_unpack_files(cls, scriptPath, updatePath, updateWindow='lct_update', *args, **kwargs): ''' unpack zip files and copy to script path ''' # settings global_cfg = lcConfiguration.GlobalSettingsDictionary(verbose=False) if pm.control(updateWindow, exists=True): pm.deleteUI(updateWindow) try: folderName = 'lct' fileDownload = urllib.urlretrieve( updatePath, os.path.join(scriptPath, 'lct_update.zip'))[0] # upgrade lct files if os.path.exists(os.path.join( scriptPath, folderName)): # if the original exists if os.path.exists( os.path.join(scriptPath, folderName + '_backup')): # if the backup exists shutil.rmtree( os.path.join(scriptPath, folderName + '_backup')) # remove the backup # make a new backup os.renames(os.path.join(scriptPath, folderName), os.path.join(scriptPath, folderName + '_backup')) # unzip new files with zipfile.ZipFile(fileDownload) as zf: zf.extractall(scriptPath) os.remove(fileDownload) global_cfg.set('g_first_launch', True) lcUtility.Utility.relaunch_all_open_tools() msg = 'Update Succeeded' log = "{}\n\n{}".format(lcUtility.SystemInfo().get_text(), msg) logger = lcUtility.LogManager('lct updated', log) logger.SendLog() except: lcUtility.Utility.lc_print_exception(message='Update Failed')
def update_periodic_check(cls, timeDifference=604800, *args, **kwargs): ''' if enough time has elapsed since last check show the update window ''' # settings global_cfg = lcConfiguration.GlobalSettingsDictionary(verbose=False) update_check = global_cfg.get('g_update_check') if update_check: currentLocation = os.path.dirname(__file__) scriptPath = os.path.normpath( os.path.join(currentLocation, os.pardir, os.pardir, os.pardir)) conf_file = os.path.normpath( os.path.join(scriptPath, 'lct', 'settings', 'lct.conf')) # find the version string for the current installed lct toolset if it exists if os.path.exists(conf_file): conf = lcConfiguration.Conf.load_conf_file(conf_file) # get the conf values release = conf['release'] version = conf['version'] timestamp = conf['timestamp'] # gather the times now = datetime.datetime.now() # 2015-04-12 15:35:34.183000 then = datetime.datetime.strptime(timestamp, "%Y-%m-%d %H:%M:%S.%f") tdelta = now - then seconds = tdelta.total_seconds() # if enough time has passed if seconds > timeDifference: # write new timestamp f = open(conf_file, 'w') f.write("release = '{0}'".format(release)) f.write('\n') f.write("version = '{0}'".format(version)) f.write('\n') f.write("timestamp = '{0}'".format(now)) f.close() # open the update window cls.lct_auto_update(confirmDiag=True)
#set conf values conf = lcConfiguration.Conf.load_conf_file(os.path.join(os.path.abspath(os.path.dirname(__file__)), "{}.conf".format(os.path.basename(__file__).split('.')[0]) ) ) publish = conf['publish'] annotation = conf['annotation'] prefix = conf['prefix'] height = conf['height'] #set paths srcPath = lcPath.Path.getSrcPath() basePath = os.path.abspath(os.path.dirname(__file__)) iconPath = os.path.normpath(os.path.join(basePath, 'icons')) defaultPath = 'Export Path . . .' # #setup configuration node and add necessary attributes global_cfg = lcConfiguration.GlobalSettingsDictionary() lct_cfg = lcConfiguration.ConfigurationNode(lcPath.Path.get_tools_settings_file(), global_cfg) lct_cfg.add('lcObjToolsPop', False) lct_cfg.add('lcObjToolsPath', defaultPath) lct_cfg.add('lcObjToolsPrefix', '') lct_cfg.add('lcObjToolsExportIndividual', True) lct_cfg.add('lcObjToolsUseSmoothPreview', True) def lcObjToolsUI(dockable=False, asChildLayout=False, *args, **kwargs): ''' ''' global lct_cfg global prefix ci = 0 #color index iterator windowName = 'lcObjTools' shelfCommand = 'import lct.src.{0}.{0} as {1}\nreload({1})\n{1}.{0}UI()'.format(windowName, prefix)
def update_confirm_window(cls, release, version, scriptPath, updatePath, *args, **kwargs): ''' show a window with update info and user confirm button ''' # settings global_cfg = lcConfiguration.GlobalSettingsDictionary(verbose=False) # format scriptPath to fit scriptPathNice = scriptPath if len(scriptPath) > 36: scriptPathNice = '....' + scriptPath[-32:] # updateURLNice = updatePath.replace('http://', '') updateURLNice = updatePath[-24:] windowName = 'lct_update' if pm.control(windowName, exists=True): pm.deleteUI(windowName) w = 300 wB = (w - 200) / 3 wC = (w - 100) / 2 h = 280 updateWindow = pm.window(windowName, t="LCToolbox - Update", widthHeight=[w, h], rtf=False, mnb=False, mxb=False, s=False, toolbox=True) pm.columnLayout() pm.text(l='', al='center', w=w) pm.text('update_heading', l='*****', al='center', w=w) pm.text(l='', al='center', w=w) pm.text(l='Release: {}'.format(release), al='center', w=w) pm.text(l='', al='center', w=w) pm.text(l='Current Version: {}'.format(version), al='center', w=w) if updatePath: pm.text('update_heading', edit=True, l='UPDATE AVAILABLE', font='boldLabelFont') pm.text(l='Update Version: {}'.format( updatePath.split('lct_')[1].split('.zip')[0]), al='center', w=w) pm.text(l='', al='center', w=w) pm.text(l='Install Path:\n{}'.format( os.path.join(scriptPathNice, 'lct')), al='center', w=w) pm.text(l='', al='center', w=w) pm.text(l='Update File:\n{}'.format(updateURLNice), al='center', w=w) pm.text(l='', al='center', w=w) pm.rowColumnLayout(nc=3, cw=([1, 100], [2, 100], [3, 100])) pm.text(l='', al='center', w=w) pm.button(l='Release Notes', w=100, h=25, command=lambda *args: webbrowser.open( 'http://lct.leocov.com/release_notes', new=2)) # pm.text(l='http://lct.leocov.com/release_notes', al='center', hyperlink=True) pm.text(l='', al='center', w=w) pm.setParent('..') pm.text(l='', al='center', w=w) pm.rowColumnLayout(nc=5, cw=([1, wB], [2, 100], [3, wB], [4, 100], [5, wB])) pm.text(l='', al='center', w=wB) pm.button(l='Update', w=100, h=25, command=lambda *args: cls.update_unpack_files( scriptPath, updatePath)) pm.text(l='', al='center', w=wB) pm.button(l='Cancel', w=100, h=25, command=lambda *args: pm.deleteUI(updateWindow)) pm.text(l='', al='center', w=wB) else: h = 135 pm.text('update_heading', edit=True, l='NO UPDATE AVAILABLE', font='boldLabelFont') pm.text(l='', al='center', w=w) pm.rowColumnLayout(nc=3, cw=([1, wC], [2, 100], [3, wC])) pm.text(l='', al='center', w=wC) pm.button(l='Close', w=100, h=25, command=lambda *args: pm.deleteUI(updateWindow)) pm.text(l='', al='center', w=wC) pm.setParent('..') pm.rowColumnLayout(nc=3, cw=([1, 40], [2, 200])) pm.text(l='', w=40) pm.checkBox( 'checkBox_periodic', l='Periodically check for updates?', w=w, h=25, al='center', v=global_cfg.get('g_update_check'), annotation= "Periodic update will check for a new version about every 7 days and prompt you to install it.", changeCommand=lambda *args: global_cfg.set( 'g_update_check', pm.checkBox('checkBox_periodic', query=True, v=True))) updateWindow.show() pm.window(updateWindow, edit=True, h=h, w=(w + 2))
def lcToolbox_first_launch_window(cls, force_show=False, *args, **kwargs): ''' show a window with first lauch settings ''' # settings global_cfg = lcConfiguration.GlobalSettingsDictionary(verbose=False) windowName = 'lct_first_launch' if pm.control(windowName, exists=True): pm.deleteUI(windowName) show_window = global_cfg.get('g_first_launch') if force_show: show_window = True if show_window: w = 300 h = 262 margins = 8 middle = w - (margins * 2) updateWindow = pm.window(windowName, t="LCToolbox - Welcome", widthHeight=[w, h], rtf=False, mnb=False, mxb=False, s=False, toolbox=True) pm.rowColumnLayout(nc=3, cw=([1, margins], [2, middle], [3, margins + 2])) # first column pm.text(l='', w=margins) # middle column pm.columnLayout() pm.text(l='Welcome to LCToolbox', al='center', w=middle, h=50, font='boldLabelFont') pm.text(l='Please read the License and Privacy Policy', al='center', w=middle, h=25) pm.button(l='License', al='center', w=middle, command=lambda *args: webbrowser.open('http://lct.leocov.com/license', new=2)) pm.text(l='', w=middle, h=8) pm.button(l='Privacy Policy', al='center', w=middle, command=lambda *args: webbrowser.open('http://lct.leocov.com/privacy', new=2)) pm.text(l='', w=middle, h=8) pm.button(l='Release Notes', w=middle, bgc=(0.5, 0.3, 0.3), command=lambda *args: webbrowser.open('http://lct.leocov.com/release_notes', new=2)) pm.text(l='', w=middle, h=8) pm.checkBox('checkBox_errors', l='Do you consent to automatically send error logs?', w=middle, h=25, al='center', v=global_cfg.get('g_send_errors'), annotation="Send error logs for critical excepton to the developer, some personal information is logged. See Privacy Policy for details.", bgc=(0.5, 0.3, 0.3), changeCommand=lambda *args: global_cfg.set('g_send_errors', pm.checkBox('checkBox_errors', query=True, v=True))) # pm.checkBox('checkBox_scene_settings', l='Save tool settings in Maya scene node?', w=middle, h=25, al='center', v=global_cfg.get('g_scene_settings'), annotation="Settings can be saved globally or as unique to each scene file in a script node.", changeCommand=lambda *args: global_cfg.set('g_scene_settings', pm.checkBox('checkBox_scene_settings', query=True, v=True))) pm.text(l='', w=middle, h=15) pm.checkBox('checkBox_first_launch', l='Show this window at launch?', w=middle, h=25, al='center', v=global_cfg.get('g_first_launch'), annotation="Hide this window until after an update.", bgc=(0.3, 0.5, 0.3), changeCommand=lambda *args: global_cfg.set('g_first_launch', pm.checkBox( 'checkBox_first_launch', query=True, v=True))) pm.setParent('..') # last column pm.text(l='', w=margins) updateWindow.show() pm.window(updateWindow, edit=True, h=h, w=(w + 2))