def menuResourceFromList(menuList): #desc = " 'menubar': {'type':'MenuBar',\n" desc = "{'type':'MenuBar',\n" desc += " 'menus': [\n" inMenu = 0 for m in menuList: if m['type'] == 'Menu': if inMenu: # close Menu desc += " ]\n" desc += " },\n" desc += menuAttributes(m) inMenu = 1 else: desc += menuItemAttributes(m) # close Menu desc += " ]\n" desc += " },\n" # close MenuBar desc += " ]\n" desc += "}\n" d = eval(desc) return resource.Resource(d)
def buildChooserResource(self, title, caption, options, defOption): """This builds a string containing a resource description as you find in a .rsrc files""" # dynamically build each of the list choices optionsStr = "[" for opt in options: txt = opt.replace("'", "\\'") # optionsStr = optionsStr + "'" + opt.replace("'", "\\'") + "'," optionsStr = optionsStr + "'" + txt + "'," optionsStr = optionsStr + "]" # construct the resource string. dlgRSRC = "{'type':'CustomDialog','name':'dlgChooser'," + \ " 'title':'" + title + "','position':(100,50),'size':(445, 330),\n\n'components': [" dlgRSRC = dlgRSRC + " {'type':'StaticText', 'name':'labelCaption', 'position':(10,10)," + \ "'text':'" + caption.replace("'", "\\'") + "'}," dlgRSRC = dlgRSRC + " {'type':'List', 'name':'options', 'position':(10,30),'size':(415,200)," + \ "'items':" + optionsStr + ",'stringSelection':'" + defOption.replace("'", "\\'") + "'}," dlgRSRC = dlgRSRC + \ "{'type':'Button', 'name':'btnOK', 'position':(10, 260), " + \ "'label':'OK', 'id':5100, 'default':1, 'toolTip':'Update Preferences'}," + \ "{'type':'Button', 'name':'btnCancel', 'position':(110, 260)," + \ "'label':'Cancel', 'id':5101, 'toolTip':'Discard Preferences Changes' } " + \ " ] } " # eval the resource string, pass it to Resource() and return it. return resource.Resource( eval(dlgRSRC) )
def stringResourceFromList(stringList): desc = " {\n" for s in stringList: desc += """ %s:%s,\n""" % (repr(s), repr(stringList[s])) # close strings desc += " }\n" d = eval(desc) return resource.Resource(d)
def buildAboutResource(self, title, description, links): """This builds a string containing a resource description as you find in a .rsrc files""" description = description.replace("\n", "\\n") description = description.replace("'", "\\'") # build the body of the About dialog resourece string. done first so we know the # total height of the whole window when we write out the main string at the end. bodyRSRC = " {'type':'StaticText', 'name':'labelDesc', 'position':(10,10)," + \ "'alignment':'center','size':(360,30),'text':'" + title + "'}," bodyRSRC = bodyRSRC + " {'type':'TextArea', 'name':'labelDesc', 'position':(10,40)," + \ "'size':(360,80),'text':'" + description + "'}," vert = 140 for i in range(len(links)): link = links[i] bodyRSRC = bodyRSRC + " {'type':'StaticText', 'name':'labelLinkDesc%d', " % i + \ "'position':(10,%d)," % (vert) + \ "'text':'" + link[0] + "'}," vert += 20 bodyRSRC = bodyRSRC + " {'type':'StaticText', 'name':'labelLink%d', " % i + \ "'position':(10,%d)," % (vert) + \ "'foregroundColor':'blue', 'text':'" + link[1] + "'}," vert += 30 bodyRSRC = bodyRSRC + \ "{'type':'Button', 'name':'btnOK', 'position':(10, %d), " % vert + \ "'label':'OK', 'id':5100 }" + \ " ] } " vert += 60 # construct the final resource string. dlgRSRC = "{'type':'CustomDialog','name':'dlgAbout'," + \ " 'title':'About " + title + "...','position':(-1,-1),'size':(390, %d),\n\n'components': [" % vert dlgRSRC += bodyRSRC # eval the resource string, pass it to Resource() and return it. return resource.Resource( eval(dlgRSRC) )
def buildSpeedReaderResource(self, title, prefs): """This builds a string containing a resource description as you find in a .rsrc files""" # main StaticText whcih holds each word bodyRSRC = " {'type':'StaticText', 'name':'theWords', 'position':(10,100)," + \ "'alignment':'center','font':" + self.font + ",'size':(520,110),'text':'-'}," # the buttons bodyRSRC = bodyRSRC + \ "{'type':'Button', 'name':'btnStart', 'position':(10, 260)," + \ "'label':'Start', 'toolTip':'Starts Speed Reading' }, " + \ "{'type':'Button', 'name':'btnPause', 'position':(110, 260)," + \ "'label':'Pause', 'toolTip':'Pauses Speed Reading' }, " + \ "{'type':'Button', 'name':'btnClose', 'position':(210, 260), " + \ "'label':'Close', 'id':5100 }," + \ " ] } " # construct the final resource string. dlgRSRC = "{'type':'CustomDialog','name':'dlgAutoTextScroller'," + \ " 'title':'" + title + "','position':(100,100),'size':(540, 320),\n\n'components': [" dlgRSRC += bodyRSRC # eval the resource string, pass it to Resource() and return it. return resource.Resource( eval(dlgRSRC) )
def loadConfig(self): try: if not os.path.exists(self.configPath): os.mkdir(self.configPath) path = os.path.join(self.configPath, USERCONFIG) self.config = util.readAndEvalFile(path) if self.config != {}: if 'position' in self.config: self.position = self.config['position'] if 'size' in self.config: self.size = self.config['size'] if 'history' in self.config: history = self.config['history'] history.reverse() for h in history: self.fileHistory.AddFileToHistory(h) if 'view_white_space' in self.config: self.components.document.SetViewWhiteSpace( self.config['view_white_space']) self.menuBar.setChecked('menuViewWhitespace', self.config['view_white_space']) if 'indentation_guides' in self.config: self.components.document.SetIndentationGuides( self.config['indentation_guides']) self.menuBar.setChecked('menuViewIndentationGuides', self.config['indentation_guides']) if 'right_edge_guide' in self.config: self.components.document.SetEdgeMode( self.config['right_edge_guide']) self.menuBar.setChecked('menuViewRightEdgeIndicator', self.config['right_edge_guide']) if 'view_EOL' in self.config: self.components.document.SetViewEOL( self.config['view_EOL']) self.menuBar.setChecked('menuViewEndOfLineMarkers', self.config['view_EOL']) if 'line_numbers' in self.config: self.components.document.lineNumbersVisible = self.config[ 'line_numbers'] self.menuBar.setChecked('menuViewLineNumbers', self.config['line_numbers']) if 'folding' in self.config: self.components.document.codeFoldingVisible = self.config[ 'folding'] self.menuBar.setChecked('menuViewCodeFolding', self.config['folding']) if 'macros' in self.config: self.macros = self.config['macros'] # should match based on name instead m = self.menuBar.menus[4] rsrc = resource.Resource({ 'type': 'MenuItem', 'name': 'scriptletSep2', 'label': '-' }) mi = menu.MenuItem(self, m, rsrc) m.appendMenuItem(mi) for macro in self.macros: #print 'm', macro if macro['key'] == '': key = '' else: key = '\t' + macro['key'] rsrc = resource.Resource({ 'type': 'MenuItem', 'name': 'menuScriptlet' + macro['label'], 'label': macro['label'] + key, 'command': 'runMacro' }) mi = menu.MenuItem(self, m, rsrc) m.appendMenuItem(mi) except: self.config = {}
def buildPrefsResource(self, title, preferences): """This builds a string containing a resource description as you find in a .rsrc files""" location = 15 height = 80 prefsResString = "" # dynamically build each of the preference choices. for preference in preferences: escapedDefaultPref = preference[3] if preference[4] != 2 and preference[4] != 6 and preference[4] != 7: escapedDefaultPref = escapedDefaultPref.replace("'", "\\'") prefsResString = prefsResString + \ "{'type':'StaticText', 'name':'lab" + preference[0] + "', " + \ "'position':(45, %d), " % (location) + \ "'text':'" + preference[1].replace("'", "\\'") + "'}," + \ "{'type':'Button', 'name':'btn" + preference[0] + "', " + \ "'position':(15, %d), 'size':(18,-1)," % (location-3) + \ "'label':'?','command':'printHelpString'}," # prefernce needs a text box for normal string. if preference[4] == 1: # 1 prefsResString = prefsResString + \ "{'type':'TextField', 'name':'" + preference[0] + "', " + \ "'size':(200,-1), 'position':(220, %d), " % (location-3) + \ "'text':'" + escapedDefaultPref + "'}," # text box, but for a number elif preference[4] == 2 or preference[4] == 6: # was 4 prefsResString = prefsResString + \ "{'type':'TextField', 'name':'" + preference[0] + "', " + \ "'size':(200,-1), 'position':(220, %d), " % (location-3) + \ "'text':'%s'}," % escapedDefaultPref # password field elif preference[4] == 3: # 3 prefsResString = prefsResString + \ "{'type':'PasswordField', 'name':'" + preference[0] + "', " + \ "'size':(200,-1), 'position':(220, %d), " % (location-3) + \ "'text':'" + preference[3] + "'}," # "Yes"/"No" choice box elif preference[4] == 4: # was 2 - I changed the order so it made more sense. prefsResString = prefsResString + \ "{'type':'Choice', 'name':'" + preference[0] + "', " + \ "'size':(80,-1), 'position':(220, %d), " % (location-3) + \ "'items':['Yes','No'],'stringSelection':'" + escapedDefaultPref + "'}," # Custom choice box elif preference[4] == 5: # prefsResString = prefsResString + \ "{'type':'Choice', 'name':'" + preference[0] + "', " + \ "'size':(80,-1), 'position':(220, %d), " % (location-3) + \ "'items':[" for item in preference[5]: prefsResString = prefsResString + "'%s'," % item prefsResString = prefsResString + "], 'stringSelection':'" + escapedDefaultPref + "'}," # Font preference elif preference[4] == 7: prefsResString = prefsResString + \ "{'type':'Button', 'name':'" + preference[0] + "', " + \ "'size':(60,-1), 'label':'Choose','position':(220, %d), " % (location-3) + \ "'command':'fontChoose'}," location = location + 35 height = height + 35 # construct the resource string. dlgRSRC = "{'type':'CustomDialog','name':'dlgPrefs'," + \ " 'title':'" + title + "','position':(100,50),'size':(440, %d),\n\n'components': [" % height dlgRSRC = dlgRSRC + prefsResString dlgRSRC = dlgRSRC + \ "{'type':'Button', 'name':'btnOK', 'position':(15, %d), " % (height - 55) + \ "'label':'OK', 'id':5100, 'default':1, 'toolTip':'Update Preferences'}," + \ "{'type':'Button', 'name':'btnCancel', 'position':(115, %d)," % (height - 55) + \ "'label':'Cancel', 'id':5101, 'toolTip':'Discard Preferences Changes' } " + \ " ] } " # eval the resource string, pass it to Resource() and return it. return resource.Resource( eval(dlgRSRC) )