def revertIvars(self): c = self.c # Revert the fonts themselves in the various panes. font = self.revertBodyFont c.frame.body.configure(font=font) font = self.revertLogFont c.frame.log.configureFont(font) font = self.revertTreeFont c.frame.tree.setFont(font=font) # Revert the setting of the items in the font panel self.last_selected_font = None # Use the font for the selected panes. font = self.getImpliedFont() self.selectFont(font) try: name, size, slant, weight = self.getFontSettings(font) size = int(size) except: pass self.sizeVar.set(size) self.boldVar.set(g.choose(weight == "bold", 1, 0)) self.italVar.set(g.choose(slant == "italic", 1, 0)) e = self.size_entry e.delete(0, "end") e.insert(0, str(size))
def update_ivars (self): """Called just before doing a find to update ivars from the find panel.""" for key in self.intKeys: val = self.dict[key].get() setattr(self, key, val) # No more _flag hack. # g.trace(key,val) # Set ivars from radio buttons. Convert these to 1 or 0. if 0: ### find_type = self.dict["radio-find-type"].get() self.pattern_match = g.choose(find_type == "pattern-search",1,0) self.script_search = g.choose(find_type == "script-search",1,0) search_scope = self.dict["radio-search-scope"].get() self.suboutline_only = g.choose(search_scope == "suboutline-only",1,0) self.node_only = g.choose(search_scope == "node-only",1,0) self.selection = g.choose(search_scope == "selection-only",1,0) # 11/9/03 # New in 4.3: The caller is responsible for removing most trailing cruft. # Among other things, this allows Leo to search for a single trailing space. s = self.find_ctrl.get("1.0","end") s = g.toUnicode(s,g.app.tkEncoding) # g.trace(repr(s)) if s and s[-1] in ('\r','\n'): s = s[:-1] self.find_text = s s = self.change_ctrl.get("1.0","end") if s and s[-1] in ('\r','\n'): s = s[:-1] s = g.toUnicode(s,g.app.tkEncoding) self.change_text = s
def showSuccess(self,pos,newpos): """Displays the final result. Returns self.dummy_vnode, v.edit_text() or c.frame.bodyCtrl with "insert" and "sel" points set properly.""" c = self.c ; v = self.v ; gui = g.app.gui # g.trace() c.frame.bringToFront() # Needed on the Mac c.beginUpdate() if 1: # range of update... c.selectVnode(v) c.frame.tree.redraw_now() # Redraw now so selections are not destroyed. # Select the found vnode again after redraw. if self.in_headline: c.editPosition(v) c.frame.tree.setNormalLabelState(v) assert(v.edit_text()) else: c.selectVnode(v) c.endUpdate(False) # Do not draw again! t = g.choose(self.in_headline,v.edit_text(),c.frame.bodyCtrl) insert = g.choose(self.reverse,pos,newpos) # g.trace(pos,newpos,t) gui.setInsertPoint(t,insert) gui.setSelectionRange(t,pos,newpos) gui.makeIndexVisible(t,insert) gui.set_focus(c,t) if self.wrap and not self.wrapVnode: self.wrapVnode = self.v
def onIdle(self,tag,keywords): c = keywords.get('c') if c != self.c: return # This should not be necessary, and it is. if g.app.killed: return if not hasattr(c,"hoistStack"): return on_widget = self.hoistOn.get(c) off_widget = self.hoistOff.get(c) if not on_widget or not off_widget: return # This can happen during unit tests. state = g.choose(c.canHoist(),"normal","disabled") on_widget.config(state=state) state = g.choose(c.canDehoist(),"normal","disabled") off_widget.config(state=state) if len(c.hoistStack) > 0: on_widget.config(bg=activeHoistColor, activebackground=activeHoistColor, text="Hoist %s" % len(c.hoistStack)) else: on_widget.config(bg=self.bgColor, activebackground=self.activeBgColor, text="Hoist")
def update_ivars(self): """Called just before doing a find to update ivars from the find panel.""" for key in self.intKeys: val = self.dict[key].get() setattr(self, key, val) # No more _flag hack. # g.trace(key,val) # Set ivars from radio buttons. Convert these to 1 or 0. find_type = self.dict["radio-find-type"].get() self.pattern_match = g.choose(find_type == "pattern-search", 1, 0) self.script_search = g.choose(find_type == "script-search", 1, 0) search_scope = self.dict["radio-search-scope"].get() self.suboutline_only = g.choose(search_scope == "suboutline-only", 1, 0) self.node_only = g.choose(search_scope == "node-only", 1, 0) self.selection = g.choose(search_scope == "selection-only", 1, 0) # 11/9/03 s = self.find_ctrl.get("1.0", "end - 1c") # Remove trailing newline s = g.toUnicode(s, g.app.tkEncoding) self.find_text = s s = self.change_ctrl.get("1.0", "end - 1c") # Remove trailing newline s = g.toUnicode(s, g.app.tkEncoding) self.change_text = s
def onIdle(self,tag,keywords): c = self.c # This should not be necessary, and it is. if g.app.killed: return if not hasattr(c,"hoistStack"): return on_widget = self.hoistOn.get(c) off_widget = self.hoistOff.get(c) if not on_widget or not off_widget: return # This can happen during unit tests. state = g.choose(c.canHoist(),"normal","disabled") on_widget.config(state=state) state = g.choose(c.canDehoist(),"normal","disabled") off_widget.config(state=state) if len(c.hoistStack) > 0: on_widget.config(bg=activeHoistColor, activebackground=activeHoistColor, text="Hoist %s" % len(c.hoistStack)) else: on_widget.config(bg=self.bgColor, activebackground=self.activeBgColor, text="Hoist")
def update_ivars2 (self ): #was called set_ivars # N.B.: separate c.ivars are much more convenient than a dict. c = self.c for key in self.intKeys: val = self.dict[key].get() setattr(c, key + "_flag", val) # g.trace(key,val) # Set ivars from radio buttons. 10/2/01: convert these to 1 or 0. find_type = self.dict["radio-find-type"].get() c.pattern_match_flag = g.choose(find_type == "pattern-search",1,0) c.script_search_flag = g.choose(find_type == "script-search",1,0) search_scope = self.dict["radio-search-scope"].get() c.suboutline_only_flag = g.choose(search_scope == "suboutline-only",1,0) c.node_only_flag = g.choose(search_scope == "node-only",1,0) c.selection_only_flag = g.choose(search_scope == "selection-only",1,0) # 11/9/03 #s = self.find_text.get("1.0","end - 1c") # Remove trailing newline #s = g.toUnicode(s,g.app.tkEncoding) # 2/25/03 #c.find_text = s s = self.findPanel.getText() c.find_text = s #s = self.change_text.get("1.0","end - 1c") # Remove trailing newline #s = g.toUnicode(s,g.app.tkEncoding) # 2/25/03 #c.change_text = s s = self.changePanel.getText() c.change_text = s
def update_ivars (self): """Called just before doing a find to update ivars from the find panel.""" for key in self.intKeys: val = self.dict[key].get() setattr(self, key, val) # No more _flag hack. # g.trace(key,val) # Set ivars from radio buttons. Convert these to 1 or 0. find_type = self.dict["radio-find-type"].get() self.pattern_match = g.choose(find_type == "pattern-search",1,0) self.script_search = g.choose(find_type == "script-search",1,0) search_scope = self.dict["radio-search-scope"].get() self.suboutline_only = g.choose(search_scope == "suboutline-only",1,0) self.node_only = g.choose(search_scope == "node-only",1,0) self.selection = g.choose(search_scope == "selection-only",1,0) # 11/9/03 s = self.find_ctrl.get("1.0","end - 1c") # Remove trailing newline s = g.toUnicode(s,g.app.tkEncoding) self.find_text = s s = self.change_ctrl.get("1.0","end - 1c") # Remove trailing newline s = g.toUnicode(s,g.app.tkEncoding) self.change_text = s
def showSuccess(self,pos,newpos): """Displays the final result. Returns self.dummy_vnode, p.edit_widget() or c.frame.bodyCtrl with "insert" and "sel" points set properly.""" c = self.c ; p = self.p ; gui = g.app.gui c.frame.bringToFront() # Needed on the Mac c.beginUpdate() try: c.selectPosition(p) finally: c.endUpdate(scroll=True) if self.in_headline: c.editPosition(p) # Set the focus and selection after the redraw. t = g.choose(self.in_headline,p.edit_widget(),c.frame.bodyCtrl) insert = g.choose(self.reverse,pos,newpos) # New in 4.4a3: a much better way to ensure progress in backward searches. # g.trace(id(t),pos,newpos) c.widgetWantsFocusNow(t) gui.setSelectionRange(t,pos,newpos,insert=insert) # c.widgetWantsFocusNow(t) gui.makeIndexVisible(t,insert) if self.wrap and not self.wrapPosition: self.wrapPosition = self.p
def doOp (self): val = self.val outer = self.lineParenLevel <= 0 or (self.parenLevel == 0 and self.squareBracketLevel == 0) # New in Python 2.4: '@' is an operator, not an error token. if self.val == '@': self.array.append(self.val) # Preserve whitespace after @. i = g.skip_ws(self.s,self.scol+1) ws = self.s[self.scol+1:i] if ws: self.array.append(ws) elif val == '(': # Nothing added; strip leading blank before function calls but not before Python keywords. strip = self.lastName=='name' and not keyword.iskeyword(self.prevName) self.put('(',strip=strip) self.parenLevel += 1 ; self.lineParenLevel += 1 elif val in ('=','==','+=','-=','!=','<=','>=','<','>','<>','*','**','+','&','|','/','//'): # Add leading and trailing blank in outer mode. s = g.choose(outer,' %s ','%s') self.put(s % val) elif val in ('^','~','{','['): # Add leading blank in outer mode. s = g.choose(outer,' %s','%s') self.put(s % val) if val == '[': self.squareBracketLevel += 1 elif val in (',',':','}',']',')'): # Add trailing blank in outer mode. s = g.choose(outer,'%s ','%s') self.put(s % val) if val == ']': self.squareBracketLevel -= 1 if val == ')': self.parenLevel -= 1 ; self.lineParenLevel -= 1 # ----- no difference between outer and inner modes --- elif val in (';','%'): # Add leading and trailing blank. self.put(' %s ' % val) elif val == '>>': # Add leading blank. self.put(' %s' % val) elif val == '<<': # Add trailing blank. self.put('%s ' % val) elif val in ('-'): # Could be binary or unary. Or could be a hyphen in a section name. # Add preceding blank only for non-id's. if outer: if self.array: prev = self.array[-1].rstrip() if prev and prev[-1] not in string.digits + string.letters: self.put(' %s' % val) else: self.put(val) else: self.put(val) # Try to leave whitespace unchanged. else: self.put(val) else: self.put(val)
def showPlugin(self, plugin): """Show a plugin""" self.name.setentry(plugin.name) self.version.setentry(plugin.version) self.filename.setentry(g.os_path_abspath(plugin.filename)) # EKR self.status.setentry(plugin.enabled) self.has_ini.setentry(g.choose(plugin.has_config, "Yes", "No")) self.has_toplevel.setentry(g.choose(plugin.has_toplevel, "Yes", "No")) if USE_PRIORITY: self.priority.setentry(plugin.priority) self.description.settext(plugin.description.strip()) self.commands.setlist(plugin.commands) self.handlers.setlist(plugin.handlers) self.requires.setlist(plugin.requires)
def init_s_ctrl (self,s): t = self.s_ctrl t.delete("1.0","end") t.insert("end",s) t.mark_set("insert",g.choose(self.reverse,"end","1.0")) return t
def createButtons (self,buttons): """Create a row of buttons. buttons is a list of dictionaries containing the properties of each button.""" assert(self.frame) self.buttonsFrame = f = gtk.Frame(self.top) f.pack(side="top",padx=30) # Buttons is a list of dictionaries, with an empty dictionary at the end if there is only one entry. buttonList = [] for d in buttons: text = d.get("text","<missing button name>") isDefault = d.get("default",False) underline = d.get("underline",0) command = d.get("command",None) bd = g.choose(isDefault,4,2) b = gtk.Button(f,width=6,text=text,bd=bd,underline=underline,command=command) b.pack(side="left",padx=5,pady=10) buttonList.append(b) if isDefault and command: self.defaultButtonCommand = command return buttonList
def showPlugin(self, plugin): """Show a plugin""" self.name.setentry(plugin.name) self.version.setentry(plugin.version) self.filename.setentry(g.os_path_abspath(plugin.filename)) # EKR self.status.setentry(plugin.enabled) self.has_ini.setentry( g.choose(plugin.has_config,"Yes","No")) self.has_toplevel.setentry( g.choose(plugin.has_toplevel,"Yes","No")) if USE_PRIORITY: self.priority.setentry(plugin.priority) self.description.settext(plugin.description.strip()) self.commands.setlist(plugin.commands) self.handlers.setlist(plugin.handlers) self.requires.setlist(plugin.requires)
def init_s_ctrl(self, s): c = self.c t = self.s_ctrl t.delete("1.0", "end") t.insert("end", s) t.mark_set("insert", g.choose(self.reverse, "end", "1.0")) return t
def compare_files(self, name1, name2): if name1 == name2: self.show("File names are identical.\nPlease pick distinct files.") return f1 = f2 = None try: f1 = self.doOpen(name1) f2 = self.doOpen(name2) if self.outputFileName: self.openOutputFile() ok = self.outputFileName == None or self.outputFile ok = g.choose(ok and ok != 0, 1, 0) if f1 and f2 and ok: # Don't compare if there is an error opening the output file. self.compare_open_files(f1, f2, name1, name2) except: self.show("exception comparing files") g.es_exception() try: if f1: f1.close() if f2: f2.close() if self.outputFile: self.outputFile.close() self.outputFile = None except: self.show("exception closing files") g.es_exception()
def createButtons(self, buttons): """Create a row of buttons. buttons is a list of dictionaries containing the properties of each button.""" assert (self.frame) self.buttonsFrame = f = Tk.Frame(self.top) f.pack(side="top", padx=30) # Buttons is a list of dictionaries, with an empty dictionary at the end if there is only one entry. buttonList = [] for d in buttons: text = d.get("text", "<missing button name>") isDefault = d.get("default", False) underline = d.get("underline", 0) command = d.get("command", None) bd = g.choose(isDefault, 4, 2) b = Tk.Button(f, width=6, text=text, bd=bd, underline=underline, command=command) b.pack(side="left", padx=5, pady=10) buttonList.append(b) if isDefault and command: self.defaultButtonCommand = command return buttonList
def computeLoadDir(): """Returns the directory containing leo.py.""" import leoGlobals as g # g.trace(g.app.tkEncoding) try: import leo path = g.os_path_abspath(leo.__file__) if sys.platform == "win32": # "mbcs" exists only on Windows. path = g.toUnicode(path, "mbcs") elif sys.platform == "dawwin": path = g.toUnicode(path, "utf-8") else: path = g.toUnicode(path, g.app.tkEncoding) if path: loadDir = g.os_path_dirname(path) else: loadDir = None if not loadDir: loadDir = g.os_path_abspath(os.getcwd()) print "Using emergency loadDir:", repr(loadDir) encoding = g.choose(sys.platform == "dawwin", "utf-8", g.app.tkEncoding) # 11/18/03 loadDir = g.toUnicode(loadDir, encoding) # 10/20/03 return loadDir except: print "Exception getting load directory" import traceback traceback.print_exc() return None
def setWidgets (self): """Set the values of checkbox & other widgets from the commander's ivars.""" c = self.c # Global options self.replace_tabs_var.set(g.choose(c.tab_width<0,1,0)) self.tangle_batch_var.set(c.tangle_batch_flag) self.untangle_batch_var.set(c.untangle_batch_flag) self.pageWidthText.delete("1.0","end") self.pageWidthText.insert("end",str(c.page_width)) self.tabWidthText.delete("1.0","end") self.tabWidthText.insert("end",str(abs(c.tab_width))) # Default Tangle Options self.tangleDirectoryText.delete("1.0","end") self.tangleDirectoryText.insert("end",c.tangle_directory) self.output_doc_var.set(c.output_doc_flag) self.use_header_var.set(c.use_header_flag) # Default Target Language if c.target_language == None: c.target_language = "python" self.lang_var.set(c.target_language)
def changeSelection(self): c = self.c ; v = self.v ; gui = g.app.gui # g.trace(self.in_headline) t = g.choose(self.in_headline,v.edit_text(),c.frame.bodyCtrl) oldSel = sel = gui.getTextSelection(t) if sel and len(sel) == 2: start,end = sel if start == end: sel = None if not sel or len(sel) != 2: g.es("No text selected") return False # Replace the selection in _both_ controls. start,end = oldSel gui.replaceSelectionRangeWithText(t, start,end,self.change_text) gui.replaceSelectionRangeWithText(self.s_ctrl,start,end,self.change_text) # Update the selection for the next match. gui.setSelectionRangeWithLength(t,start,len(self.change_text)) newSel = gui.getTextSelection(t) gui.set_focus(c,t) c.beginUpdate() if self.mark_changes: v.setMarked() # update node, undo status, dirty flag, changed mark & recolor if self.in_headline: c.frame.tree.idle_head_key(v) # 1/7/04 else: c.frame.body.onBodyChanged(v,"Change",oldSel=oldSel,newSel=newSel) c.frame.tree.drawIcon(v) # redraw only the icon. c.endUpdate(False) # No redraws here: they would destroy the headline selection. return True
def createFrame (self): c = self.c ; gui = g.app.gui self.top = top = Tk.Toplevel(g.app.root) top.title("Syntax colors for " + c.frame.shortFileName()) # DS, 10/28/03 top.protocol("WM_DELETE_WINDOW", self.onOk) gui.attachLeoIcon(top) #@ << create color panel >> #@+node:ekr.20031218072017.1876:<< create color panel >> outer = Tk.Frame(top,bd=2,relief="groove") outer.pack(anchor="n",pady=2,ipady=1,expand=1,fill="x") # Create all the rows. for name,option_name,default_color in self.colorPanelData: # Get the color. option_color = c.config.getColor(option_name) color = g.choose(option_color,option_color,default_color) # Create the row. f = Tk.Frame(outer,bd=2) f.pack() lab=Tk.Label(f,text=name,width=17,anchor="e") b1 = Tk.Button(f,text="",state="disabled",bg=color,width=4) self.buttons[name]=b1 # For callback. self.option_names[name]=option_name # For callback. b2 = Tk.Button(f,width=12,text=option_color) self.nameButtons[name]=b2 # 9/15/02: Added self=self to remove Python 2.1 warning. callback = lambda name=name,self=self:self.showColorPicker(name) b3 = Tk.Button(f,text="Color Picker...",command=callback) # 9/15/02: Added self=self to remove Python 2.1 warning. callback = lambda name=name,color=color,self=self:self.showColorName(name,color) b4 = Tk.Button(f,text="Color Name...",command=callback) lab.pack(side="left",padx=3) b1.pack (side="left",padx=3) b2.pack (side="left",padx=3) b3.pack (side="left",padx=3) b4.pack (side="left",padx=3) # Create the Ok, Cancel & Revert buttons f = Tk.Frame(outer,bd=2) f.pack() b = Tk.Button(f,width=6,text="OK",command=self.onOk) b.pack(side="left",padx=4) b = Tk.Button(f,width=6,text="Cancel",command=self.onCancel) b.pack(side="left",padx=4,expand=1,fill="x") b = Tk.Button(f,width=6,text="Revert",command=self.onRevert) b.pack(side="right",padx=4) #@nonl #@-node:ekr.20031218072017.1876:<< create color panel >> #@nl gui.center_dialog(top) # Do this _after_ building the dialog! top.resizable(0,0)
def compare_files (self, name1, name2): if name1 == name2: self.show("File names are identical.\nPlease pick distinct files.") return f1 = f2 = None try: f1 = self.doOpen(name1) f2 = self.doOpen(name2) if self.outputFileName: self.openOutputFile() ok = self.outputFileName == None or self.outputFile ok = g.choose(ok and ok != 0,1,0) if f1 and f2 and ok: # Don't compare if there is an error opening the output file. self.compare_open_files(f1,f2,name1,name2) except: self.show("exception comparing files") g.es_exception() try: if f1: f1.close() if f2: f2.close() if self.outputFile: self.outputFile.close() ; self.outputFile = None except: self.show("exception closing files") g.es_exception()
def callZenity(title, multiple=False, save=False, test=False): command = [ 'zenity', '--file-selection', '--title=%s'%title] if save: command.append('--save') if multiple: command.append('--multiple') o = Popen(command, stdout=PIPE) o.wait() filename = o.communicate()[0].rstrip() ret = o.returncode if trace: g.trace('\n\tfiles', repr(filename)) print '\treturncode', ret if ret: trace and g.trace(g.choose(save,'save','open'), 'cancelled') return '' if multiple: return filename.split('|') return filename
def batchChange (self,pos1,pos2,count): c = self.c ; v = self.v ; st = self.s_ctrl ; gui = g.app.gui # Replace the selection with self.change_text if gui.compareIndices(st,pos1, ">", pos2): pos1,pos2=pos2,pos1 gui.replaceSelectionRangeWithText(st,pos1,pos2,self.change_text) s = gui.getAllText(st) # Update the selection. insert=g.choose(self.reverse,pos1,pos1+'+'+str(len(self.change_text))+'c') gui.setSelectionRange(st,insert,insert) gui.setInsertPoint(st,insert) # Update the node if self.in_headline: #@ << set the undo head params >> #@+node:ekr.20031218072017.2294:<< set the undo head params >> sel = None if len(s) > 0 and s[-1]=='\n': s = s[:-1] if s != v.headString(): if count == 1: c.undoer.setUndoParams("Change All",v) # Tag the start of the Change all. # 11/23/03 c.undoer.setUndoParams("Change Headline",v, oldText=v.headString(), newText=s, oldSel=sel, newSel=sel) #@nonl #@-node:ekr.20031218072017.2294:<< set the undo head params >> #@nl v.initHeadString(s) else: #@ << set the undo body typing params >> #@+node:ekr.20031218072017.2295:<< set the undo body typing params >> sel = c.frame.body.getInsertionPoint() if len(s) > 0 and s[-1]=='\n': s = s[:-1] if s != v.bodyString(): if count == 1: c.undoer.setUndoParams("Change All",v) # Tag the start of the Change all. # 11/5/03: use setUndoParams to avoid incremental undo. c.undoer.setUndoParams("Change",v, oldText=v.bodyString(), newText=s, oldSel=sel, newSel=sel) #@nonl #@-node:ekr.20031218072017.2295:<< set the undo body typing params >> #@nl v.setBodyStringOrPane(s) # Set mark, changed and dirty bits. if c.mark_changes: v.setMarked() if not c.isChanged(): c.setChanged(True) v.setDirty()
def draw_tree_helper (self,p,indent): for p in p.self_and_siblings_iter(): if p.hasChildren(): box = g.choose(p.isExpanded(),'+','-') else: box = ' ' icons = '%s%s%s%s' % ( g.choose(p.v.t.hasBody(),'b',' '), g.choose(p.isMarked(),'m',' '), g.choose(p.isCloned(),'@',' '), g.choose(p.isDirty(),'*',' ')) print " " * indent * 2, icons, box, p.headString() if p.isExpanded() and p.hasChildren(): self.draw_tree_helper(p.firstChild(),indent+1)
def update(self, event=None): """Update the body text to show the present settings.""" c = self.c size = self.sizeVar.get() #@ << insert the new text in the size box >> #@+node:ekr.20031218072017.3937:<< insert the new text in the size box >> e = self.size_entry e.delete(0, "end") e.insert(0, str(size)) #@nonl #@-node:ekr.20031218072017.3937:<< insert the new text in the size box >> #@nl activeFont = self.getActiveFont() bodyChecked = self.bodyVar.get() logChecked = self.logVar.get() treeChecked = self.treeVar.get() if not bodyChecked and not logChecked and not treeChecked: g.es("no pane selected") return # c.frame.body.configure(setgrid=0) # Disable body resizes. c.beginUpdate() #@ << set the fonts in all panes >> #@+node:ekr.20031218072017.3938:<< set the fonts in all panes >> font = g.choose(bodyChecked, activeFont, self.revertBodyFont) c.frame.body.configure(font=font) font = g.choose(logChecked, activeFont, self.revertLogFont) c.frame.log.configureFont(font) font = g.choose(treeChecked, activeFont, self.revertTreeFont) c.frame.tree.setFont(font=font) #@nonl #@-node:ekr.20031218072017.3938:<< set the fonts in all panes >> #@nl c.endUpdate() # c.frame.body.configure(setgrid=1) # Enable body resizes. self.top.deiconify() self.top.lift()
def save (self): c = self.c ; p = self.p ; gui = g.app.gui t = g.choose(self.in_headline,p.edit_widget(),c.frame.bodyCtrl) insert = gui.getInsertPoint(t) sel = gui.getSelectionRange(t) if len(sel) == 2: start,end = sel else: start,end = None,None return (self.in_headline,p,t,insert,start,end)
def getActiveFont(self): box = self.family_list_box family = font = None # Get the family name if possible, or font otherwise. items = box.curselection() if len(items) == 0: # Nothing selected. if self.last_selected_font: font = self.last_selected_font else: font = self.getImpliedFont() else: try: # This shouldn't fail now. items = map(int, items) family = box.get(items[0]) except: g.es("unexpected exception") g.es_exception() font = self.getImpliedFont() # At this point we either have family or font. assert (font or family) if not family: # Extract the family from the computed font. family, junk, junk, junk = self.getFontSettings(font) # At last we have a valid family name! # Get all other font settings from the font panel. bold = self.boldVar.get() ital = self.italVar.get() size = self.sizeVar.get() # g.trace(size) slant = g.choose(ital, "italic", "roman") weight = g.choose(bold, "bold", "normal") # Compute the font from all the settings. font = tkFont.Font(family=family, size=size, slant=slant, weight=weight) self.selectFont(font) return font
def init (self,c): # g.trace('tkFindTab',g.callers()) # N.B.: separate c.ivars are much more convenient than a dict. for key in self.intKeys: # New in 4.3: get ivars from @settings. val = c.config.getBool(key) setattr(self,key,val) val = g.choose(val,1,0) # Work around major Tk problem. self.svarDict[key].set(val) # g.trace(key,val) #@ << set find/change widgets >> #@+node:ekr.20070212091209.1:<< set find/change widgets >> self.find_ctrl.delete(0,"end") self.change_ctrl.delete(0,"end") # New in 4.3: Get setting from @settings. for w,setting,defaultText in ( (self.find_ctrl,"find_text",'<find pattern here>'), (self.change_ctrl,"change_text",''), ): s = c.config.getString(setting) if not s: s = defaultText w.insert("end",s) #@-node:ekr.20070212091209.1:<< set find/change widgets >> #@nl #@ << set radio buttons from ivars >> #@+node:ekr.20070212091209.2:<< set radio buttons from ivars >> found = False for var,setting in ( ("pattern_match","pattern-search"), ("script_search","script-search")): val = self.svarDict[var].get() if val: self.svarDict["radio-find-type"].set(setting) found = True ; break if not found: self.svarDict["radio-find-type"].set("plain-search") found = False for var,setting in ( ("suboutline_only","suboutline-only"), ("node_only","node-only"), # ("selection_only","selection-only"), ): val = self.svarDict[var].get() if val: self.svarDict["radio-search-scope"].set(setting) found = True ; break if not found: self.svarDict["radio-search-scope"].set("entire-outline")
def enableMenu (self,menu,name,val): state = g.choose(val,"normal","disabled") try: menu.entryconfig(name,state=state) except: try: realName = self.getRealMenuName(name) realName = realName.replace("&","") menu.entryconfig(realName,state=state) except: print "enableMenu menu,name,val:",menu,name,val g.es_exception()
def save(self): c = self.c v = self.v gui = g.app.gui t = g.choose(self.in_headline, v.edit_text(), c.frame.bodyCtrl) insert = gui.getInsertPoint(t) sel = gui.getSelectionRange(t) if len(sel) == 2: start, end = sel else: start, end = None, None return (self.in_headline, v, t, insert, start, end)
def init (self,c): # N.B.: separate c.ivars are much more convenient than a dict. for key in self.intKeys: # New in 4.3: get ivars from @settings. val = c.config.getBool(key) setattr(self,key,val) val = g.choose(val,1,0) # Work around major Tk problem. self.dict[key].set(val) # g.trace(key,val) #@ << set find/change widgets >> #@+node:ekr.20031218072017.2060:<< set find/change widgets >> self.find_ctrl.delete("1.0","end") self.change_ctrl.delete("1.0","end") # New in 4.3: Get setting from @settings. for w,setting in ( (self.find_ctrl,"find_text"), (self.change_ctrl,"change_text"), ): s = c.config.getString(setting) if s is None: s = "" w.insert("end",s) #@nonl #@-node:ekr.20031218072017.2060:<< set find/change widgets >> #@nl #@ << set radio buttons from ivars >> #@+node:ekr.20031218072017.2061:<< set radio buttons from ivars >> found = False for var,setting in ( ("pattern_match","pattern-search"), ("script_search","script-search")): val = self.dict[var].get() if val: self.dict["radio-find-type"].set(setting) found = True ; break if not found: self.dict["radio-find-type"].set("plain-search") found = False for var,setting in ( ("suboutline_only","suboutline-only"), ("node_only","node-only"), ("selection_only","selection-only")): # 11/9/03 val = self.dict[var].get() if val: self.dict["radio-search-scope"].set(setting) found = True ; break if not found: self.dict["radio-search-scope"].set("entire-outine")
def batchChange (self,pos1,pos2): c = self.c ; u = c.undoer p = self.p ; st = self.s_ctrl ; gui = g.app.gui # Replace the selection with self.change_text if gui.compareIndices(st,pos1, ">", pos2): pos1,pos2=pos2,pos1 gui.replaceSelectionRangeWithText(st,pos1,pos2,self.change_text) s = gui.getAllText(st) # Update the selection. insert=g.choose(self.reverse,pos1,pos1+'+'+str(len(self.change_text))+'c') gui.setSelectionRange(st,insert,insert) gui.setInsertPoint(st,insert) # Update the node if self.in_headline: #@ << change headline >> #@+node:ekr.20031218072017.2294:<< change headline >> if len(s) > 0 and s[-1]=='\n': s = s[:-1] if s != p.headString(): undoData = u.beforeChangeNodeContents(p) p.initHeadString(s) if self.mark_changes: p.setMarked() p.setDirty() if not c.isChanged(): c.setChanged(True) u.afterChangeNodeContents(p,'Change Headline',undoData) #@nonl #@-node:ekr.20031218072017.2294:<< change headline >> #@nl else: #@ << change body >> #@+node:ekr.20031218072017.2295:<< change body >> if len(s) > 0 and s[-1]=='\n': s = s[:-1] if s != p.bodyString(): undoData = u.beforeChangeNodeContents(p) p.setBodyStringOrPane(s) if self.mark_changes: p.setMarked() p.setDirty() if not c.isChanged(): c.setChanged(True) u.afterChangeNodeContents(p,'Change Body',undoData)
def init(self, c): # N.B.: separate c.ivars are much more convenient than a dict. for key in self.intKeys: # New in 4.3: get ivars from @settings. val = c.config.getBool(key) setattr(self, key, val) val = g.choose(val, 1, 0) # Work around major Tk problem. self.dict[key].set(val) # g.trace(key,val) #@ << set find/change widgets >> #@+node:ekr.20031218072017.2060:<< set find/change widgets >> self.find_ctrl.delete("1.0", "end") self.change_ctrl.delete("1.0", "end") # New in 4.3: Get setting from @settings. for w, setting in ( (self.find_ctrl, "find_text"), (self.change_ctrl, "change_text"), ): s = c.config.getString(setting) if s is None: s = "" w.insert("end", s) #@nonl #@-node:ekr.20031218072017.2060:<< set find/change widgets >> #@nl #@ << set radio buttons from ivars >> #@+node:ekr.20031218072017.2061:<< set radio buttons from ivars >> found = False for var, setting in (("pattern_match", "pattern-search"), ("script_search", "script-search")): val = self.dict[var].get() if val: self.dict["radio-find-type"].set(setting) found = True break if not found: self.dict["radio-find-type"].set("plain-search") found = False for var, setting in (("suboutline_only", "suboutline-only"), ("node_only", "node-only"), ("selection_only", "selection-only")): # 11/9/03 val = self.dict[var].get() if val: self.dict["radio-search-scope"].set(setting) found = True break if not found: self.dict["radio-search-scope"].set("entire-outine")
def enableMenu(self, menu, name, val): state = g.choose(val, "normal", "disabled") try: menu.entryconfig(name, state=state) except: try: realName = self.getRealMenuName(name) realName = realName.replace("&", "") menu.entryconfig(realName, state=state) except: print "enableMenu menu,name,val:", menu, name, val g.es_exception() pass
def showSuccess(self, pos, newpos): """Displays the final result. Returns self.dummy_vnode, v.edit_text() or c.frame.bodyCtrl with "insert" and "sel" points set properly.""" c = self.c v = self.v gui = g.app.gui # g.trace() c.frame.bringToFront() # Needed on the Mac c.beginUpdate() if 1: # range of update... c.selectVnode(v) c.frame.tree.redraw_now( ) # Redraw now so selections are not destroyed. # Select the found vnode again after redraw. if self.in_headline: c.editPosition(v) c.frame.tree.setNormalLabelState(v) assert (v.edit_text()) else: c.selectVnode(v) c.endUpdate(False) # Do not draw again! t = g.choose(self.in_headline, v.edit_text(), c.frame.bodyCtrl) insert = g.choose(self.reverse, pos, newpos) # g.trace(pos,newpos,t) gui.setInsertPoint(t, insert) gui.setSelectionRange(t, pos, newpos) gui.makeIndexVisible(t, insert) gui.set_focus(c, t) if self.wrap and not self.wrapVnode: self.wrapVnode = self.v
def nextSlide (self,event=None): c = self.c ; p = c.currentPosition() if p == self.slide: p = self.slide.threadNext() oldSlide = self.slide else: oldSlide = None while p: h = p.headString().strip() if self.ignored(p): p = p.threadNext() elif h.startswith('@slideshow'): self.select(p) return g.es('At %s of slide show' % g.choose(oldSlide,'end','start')) elif g.match_word(h,0,'@ignore'): p = p.nodeAfterTree() elif h.startswith('@slide'): return self.select(p) else: p = p.threadNext() else: return g.es(g.choose(self.slideShowRoot, 'At end of slide show', 'Not in any slide show'))
def newMoreHead (self,firstLevel,useVerticalBar=True): useVerticalBar = True # Force the vertical bar v = self level = self.level() - firstLevel if level > 0: if useVerticalBar: s = " |\t" * level else: s = "\t" else: s = "" s += g.choose(v.hasChildren(), "+ ", "- ") s += v.headString() return s
def addButton (self,first): '''Add a button that creates a target for future moves.''' c = self.c ; p = c.currentPosition() sc = scriptingController(c) mb = quickMoveButton(self,p.copy(),first) b = sc.createIconButton( text = 'to-' + p.headString(), # createButton truncates text. command = mb.moveCurrentNodeToTarget, shortcut = None, statusLine = 'Move current node to %s child of %s' % (g.choose(first,'first','last'),p.headString()), bg = "LightBlue" )
def setUndoType (self,theType): u = self ; frame = u.c.frame menu = frame.menu.getMenu("Edit") name = u.undoMenuName(theType) if name != u.undoMenuLabel: # Update menu using old name. realLabel = frame.menu.getRealMenuName(name) if realLabel == name: underline=g.choose(g.match(name,0,"Can't"),-1,0) else: underline = realLabel.find("&") realLabel = realLabel.replace("&","") frame.menu.setMenuLabel(menu,u.realUndoMenuLabel,realLabel,underline=underline) u.undoType = theType u.undoMenuLabel = name u.realUndoMenuLabel = realLabel
def printLine (self,line,allFlag=False): both = self.search_body and self.search_headline context = self.batch # "batch" now indicates context if allFlag and both and context: g.es('-' * 20,self.p.headString()) theType = g.choose(self.in_headline,"head: ","body: ") g.es(theType + line) elif allFlag and context and not self.p.isVisited(): # We only need to print the context once. g.es('-' * 20,self.p.headString()) g.es(line) self.p.setVisited() else: g.es(line)
def printLine(self, line, allFlag=False): c = self.c both = self.search_body and self.search_headline context = self.batch # "batch" now indicates context if allFlag and both and context: g.es(self.v) theType = g.choose(self.in_headline, "head: ", "body: ") g.es(theType + line) elif allFlag and context and not self.v.isVisited(): # We only need to print the context once. g.es(self.v) g.es(line) self.v.setVisited() else: g.es(line)
def updateButtons (self): c = self.c for b,b2,enabled_image,disabled_image,cond in ( ( self.lt_nav_button,self.lt_nav_iconFrame_button, self.lt_nav_enabled_image,self.lt_nav_disabled_image, c.nodeHistory.canGoToPrevVisited()), ( self.rt_nav_button,self.rt_nav_iconFrame_button, self.rt_nav_enabled_image,self.rt_nav_disabled_image, c.nodeHistory.canGoToNextVisited()), ): # Disabled state makes the icon look bad. image = g.choose(cond,enabled_image,disabled_image) b.configure(image=image,state='normal') b2.configure(image=image,state='normal')
def updateButtons (self): c = self.c for b,b2,enabled_image,disabled_image,cond in ( ( self.lt_nav_button,self.lt_nav_iconFrame_button, self.lt_nav_enabled_image,self.lt_nav_disabled_image, c.beadPointer > 1), ( self.rt_nav_button,self.rt_nav_iconFrame_button, self.rt_nav_enabled_image,self.rt_nav_disabled_image, c.beadPointer + 1 < len(c.beadList)), ): # Disabled state makes the icon look bad. image = g.choose(cond,enabled_image,disabled_image) b.configure(image=image,state='normal') b2.configure(image=image,state='normal')
def enableMenu (self,menu,name,val): g.trace('not implemented') return ### if not menu: g.trace("no menu",name,val) return realName = self.getRealMenuName(name) realName = realName.replace("&","") id = menu.FindItem(realName) if id: item = menu.FindItemById(id) val = g.choose(val,1,0) item.Enable(val) else: g.trace("no item",name,val)
def changeSelection(self): c = self.c v = self.v gui = g.app.gui # g.trace(self.in_headline) t = g.choose(self.in_headline, v.edit_text(), c.frame.bodyCtrl) oldSel = sel = gui.getTextSelection(t) if sel and len(sel) == 2: start, end = sel if start == end: sel = None if not sel or len(sel) != 2: g.es("No text selected") return False # Replace the selection in _both_ controls. start, end = oldSel gui.replaceSelectionRangeWithText(t, start, end, self.change_text) gui.replaceSelectionRangeWithText(self.s_ctrl, start, end, self.change_text) # Update the selection for the next match. gui.setSelectionRangeWithLength(t, start, len(self.change_text)) newSel = gui.getTextSelection(t) gui.set_focus(c, t) c.beginUpdate() if self.mark_changes: v.setMarked() # update node, undo status, dirty flag, changed mark & recolor if self.in_headline: c.frame.tree.idle_head_key(v) # 1/7/04 else: c.frame.body.onBodyChanged(v, "Change", oldSel=oldSel, newSel=newSel) c.frame.tree.drawIcon(v) # redraw only the icon. c.endUpdate( False ) # No redraws here: they would destroy the headline selection. return True
def init (self,c): # N.B.: separate c.ivars are much more convenient than a dict. for key in self.intKeys: val = getattr(c, key + "_flag") val = g.choose(val,1,0) # 2/1/04: work around major Tk problem. self.dict[key].set(val) # g.trace(key,val) #@ << set find/change widgets >> #@+node:mork.20050127121143.10:<< set find/change widgets >> self.find_text.delete("1.0","end") self.find_text.insert("end",c.find_text) self.change_text.delete("1.0","end") self.change_text.insert("end",c.change_text) #@nonl #@-node:mork.20050127121143.10:<< set find/change widgets >> #@nl #@ << set radio buttons from ivars >> #@+node:mork.20050127121143.11:<< set radio buttons from ivars >> found = False for var,setting in ( ("pattern_match","pattern-search"), ("script_search","script-search")): val = self.dict[var].get() if val: self.dict["radio-find-type"].set(setting) found = True ; break if not found: self.dict["radio-find-type"].set("plain-search") found = False for var,setting in ( ("suboutline_only","suboutline-only"), ("node_only","node-only"), ("selection_only","selection-only")): # 11/9/03 val = self.dict[var].get() if val: self.dict["radio-search-scope"].set(setting) found = True ; break if not found: self.dict["radio-search-scope"].set("entire-outine")
def getDetails(self, text): """Get the details of the plugin We look for __version__ hooks config commands """ self.is_plugin = self.hasImport(text, "leoPlugins") self.version = self.getPattern(text, r'__version__\s*=\s*"(.*?)"', "-") # Allow both single and double triple-quoted strings. match1 = self.getMatch(text, r'"""(.*?)"""') match2 = self.getMatch(text, r"'''(.*?)'''") pat1 = match1 and match1.group(1) pat2 = match2 and match2.group(1) if pat1 and pat2: # Take the first pattern that appears. self.description = g.choose(match1.start() < match2.start(), pat1, pat2) else: # Take whatever. self.description = pat1 or pat2 or 'Unknown' # g.trace('%4d %s' % (len(self.description),self.name)) self.commands = sets.Set(self.getPatterns(text, "def cmd_(\w*?)\(")) self.handlers = sets.Set( self.getPatterns(text, r'registerHandler\("(.*?)"')) # Look for the matching .ini file. ini_file_name = g.os_path_join(g.app.loadDir, "..", "plugins", self.getName(self.filename) + ".ini") ini_file_name = g.os_path_abspath(ini_file_name) self.has_config = g.os_path_exists(ini_file_name) self.hash = sha.sha(text).hexdigest() self.can_read = True if USE_PRIORITY: self.priority = self.getPattern( text, r'__plugin_priority__\s*=\s*(.*?)$', "-") self.has_toplevel = self.hasPattern(text, "def topLevelMenu")
def setWidgets(self): """Set the values of checkbox & other widgets from the commander's ivars.""" c = self.c # Global options self.replace_tabs_var.set(g.choose(c.tab_width < 0, 1, 0)) self.tangle_batch_var.set(c.tangle_batch_flag) self.untangle_batch_var.set(c.untangle_batch_flag) self.pageWidthText.delete("1.0", "end") self.pageWidthText.insert("end", str(c.page_width)) self.tabWidthText.delete("1.0", "end") self.tabWidthText.insert("end", str(abs(c.tab_width))) # Default Tangle Options self.tangleDirectoryText.delete("1.0", "end") self.tangleDirectoryText.insert("end", c.tangle_directory) self.output_doc_var.set(c.output_doc_flag) self.use_header_var.set(c.use_header_flag) # Default Target Language if c.target_language == None: c.target_language = "python" self.lang_var.set(c.target_language)
def initBatchText(self): v = self.v self.wrapping = False # Only interactive commands allow wrapping. s = g.choose(self.in_headline, v.headString(), v.bodyString()) return self.init_s_ctrl(s)
def moveIndexForward(self, t, index, n): newpos = t.index("%s+%dc" % (index, n)) return g.choose(t.compare(newpos, "==", "end"), None, newpos)
def moveIndexToNextLine(self, t, index): newpos = t.index("%s linestart + 1lines" % (index)) return g.choose(t.compare(newpos, "==", "end"), None, newpos)
def batchChange(self, pos1, pos2, count): c = self.c v = self.v st = self.s_ctrl gui = g.app.gui # Replace the selection with self.change_text if gui.compareIndices(st, pos1, ">", pos2): pos1, pos2 = pos2, pos1 gui.replaceSelectionRangeWithText(st, pos1, pos2, self.change_text) s = gui.getAllText(st) # Update the selection. insert = g.choose(self.reverse, pos1, pos1 + '+' + str(len(self.change_text)) + 'c') gui.setSelectionRange(st, insert, insert) gui.setInsertPoint(st, insert) # Update the node if self.in_headline: #@ << set the undo head params >> #@+node:ekr.20031218072017.2294:<< set the undo head params >> sel = None if len(s) > 0 and s[-1] == '\n': s = s[:-1] if s != v.headString(): if count == 1: c.undoer.setUndoParams( "Change All", v) # Tag the start of the Change all. # 11/23/03 c.undoer.setUndoParams("Change Headline", v, oldText=v.headString(), newText=s, oldSel=sel, newSel=sel) #@nonl #@-node:ekr.20031218072017.2294:<< set the undo head params >> #@nl v.initHeadString(s) else: #@ << set the undo body typing params >> #@+node:ekr.20031218072017.2295:<< set the undo body typing params >> sel = c.frame.body.getInsertionPoint() if len(s) > 0 and s[-1] == '\n': s = s[:-1] if s != v.bodyString(): if count == 1: c.undoer.setUndoParams( "Change All", v) # Tag the start of the Change all. # 11/5/03: use setUndoParams to avoid incremental undo. c.undoer.setUndoParams("Change", v, oldText=v.bodyString(), newText=s, oldSel=sel, newSel=sel) #@nonl #@-node:ekr.20031218072017.2295:<< set the undo body typing params >> #@nl v.setBodyStringOrPane(s) # Set mark, changed and dirty bits. if c.mark_changes: v.setMarked() if not c.isChanged(): c.setChanged(True) v.setDirty()
def search(self): """Searches the present headline or body text for self.find_text and returns True if found. self.whole_word, self.ignore_case, and self.pattern_match control the search.""" __pychecker__ = '--no-implicitreturns' # Suppress bad warning. c = self.c v = self.v t = self.s_ctrl gui = g.app.gui assert (c and t and v) if self.selection_only: index, stopindex = self.selStart, self.selEnd # g.trace(index,stopindex,v) if index == stopindex: return None, None else: index = gui.getInsertPoint(t) stopindex = g.choose(self.reverse, gui.firstIndex(), gui.lastIndex()) while 1: try: pos = self.gui_search(t, self.find_text, index, stopindex=stopindex, backwards=self.reverse, regexp=self.pattern_match, nocase=self.ignore_case) except: g.es_exception(full=False) self.errors += 1 return None, None if not pos: return None, None if self.find_text == '\n': # 2/3/04: A hack. Time to get rid of gui indices! newpos = gui.moveIndexToNextLine(t, pos) # g.trace(pos,t.index(newpos)) else: newpos = gui.moveIndexForward(t, pos, len(self.find_text)) if newpos is None: return None, None if self.reverse and gui.compareIndices(t, newpos, "==", index): #@ << search again after getting stuck going backward >> #@+node:ekr.20031218072017.3078:<< search again after getting stuck going backward >> index = gui.moveIndexBackward(newpos, len(self.find_text)) pos = self.gui_search(t, self.find_text, index, stopindex=stopindex, backwards=self.reverse, regexp=self.pattern_match, nocase=self.ignore_case) if not pos: return None, None newpos = gui.moveIndexForward(t, pos, len(self.find_text)) #@nonl #@-node:ekr.20031218072017.3078:<< search again after getting stuck going backward >> #@nl #@ << return if we are passed the wrap point >> #@+node:ekr.20031218072017.3079:<< return if we are passed the wrap point >> if self.wrapping and self.wrapPos and self.wrapVnode and self.v == self.wrapVnode: if self.reverse and gui.compareIndices(t, pos, "<", self.wrapPos): # g.trace("wrap done") return None, None if not self.reverse and gui.compareIndices( t, newpos, ">", self.wrapPos): return None, None #@nonl #@-node:ekr.20031218072017.3079:<< return if we are passed the wrap point >> #@nl if self.whole_word: index = t.index(g.choose(self.reverse, pos, newpos)) #@ << continue if not whole word match >> #@+node:ekr.20031218072017.3080:<< continue if not whole word match >> # Set pos to None if word characters preceed or follow the selection. before = gui.getCharBeforeIndex(t, pos) first = gui.getCharAtIndex(t, pos) last = gui.getCharBeforeIndex(t, newpos) after = gui.getCharAtIndex(t, newpos) #g.trace("before,first",before,first,g.is_c_id(before),g.is_c_id(first)) #g.trace("after,last", after,last, g.is_c_id(after), g.is_c_id(last)) if g.is_c_id(before) and g.is_c_id(first): continue if g.is_c_id(after) and g.is_c_id(last): continue #@nonl #@-node:ekr.20031218072017.3080:<< continue if not whole word match >> #@nl #g.trace("found:",pos,newpos,v) gui.setTextSelection(t, pos, newpos) return pos, newpos
def initNextText(self): v = self.v s = g.choose(self.in_headline, v.headString(), v.bodyString()) return self.init_s_ctrl(s)
def createFrame(self): c = self.c gui = g.app.gui self.top = top = Tk.Toplevel(g.app.root) top.title("Syntax colors for " + c.frame.shortFileName()) # DS, 10/28/03 top.protocol("WM_DELETE_WINDOW", self.onOk) gui.attachLeoIcon(top) #@ << create color panel >> #@+node:ekr.20031218072017.1876:<< create color panel >> outer = Tk.Frame(top, bd=2, relief="groove") outer.pack(anchor="n", pady=2, ipady=1, expand=1, fill="x") # Create all the rows. for name, option_name, default_color in self.colorPanelData: # Get the color. option_color = c.config.getColor(option_name) color = g.choose(option_color, option_color, default_color) # Create the row. f = Tk.Frame(outer, bd=2) f.pack() lab = Tk.Label(f, text=name, width=17, anchor="e") b1 = Tk.Button(f, text="", state="disabled", bg=color, width=4) self.buttons[name] = b1 # For callback. self.option_names[name] = option_name # For callback. b2 = Tk.Button(f, width=12, text=option_color) self.nameButtons[name] = b2 # 9/15/02: Added self=self to remove Python 2.1 warning. callback = lambda name=name, self=self: self.showColorPicker(name) b3 = Tk.Button(f, text="Color Picker...", command=callback) # 9/15/02: Added self=self to remove Python 2.1 warning. callback = lambda name=name, color=color, self=self: self.showColorName( name, color) b4 = Tk.Button(f, text="Color Name...", command=callback) lab.pack(side="left", padx=3) b1.pack(side="left", padx=3) b2.pack(side="left", padx=3) b3.pack(side="left", padx=3) b4.pack(side="left", padx=3) # Create the Ok, Cancel & Revert buttons f = Tk.Frame(outer, bd=2) f.pack() b = Tk.Button(f, width=6, text="OK", command=self.onOk) b.pack(side="left", padx=4) b = Tk.Button(f, width=6, text="Cancel", command=self.onCancel) b.pack(side="left", padx=4, expand=1, fill="x") b = Tk.Button(f, width=6, text="Revert", command=self.onRevert) b.pack(side="right", padx=4) #@nonl #@-node:ekr.20031218072017.1876:<< create color panel >> #@nl gui.center_dialog(top) # Do this _after_ building the dialog! top.resizable(0, 0)
def finishCreate(self): c = self.c # File names. for i, option in ((0, "compare_file_1"), (1, "compare_file_2"), (2, "output_file")): name = c.config.getString(option) if name and len(name) > 0: e = self.browseEntries[i] e.delete(0, "end") e.insert(0, name) name = c.config.getString("output_file") b = g.choose(name and len(name) > 0, 1, 0) self.useOutputFileVar.set(b) # File options. b = c.config.getBool("ignore_first_line_of_file_1") if b == None: b = 0 self.ignoreFirstLine1Var.set(b) b = c.config.getBool("ignore_first_line_of_file_2") if b == None: b = 0 self.ignoreFirstLine2Var.set(b) b = c.config.getBool("append_output_to_output_file") if b == None: b = 0 self.appendOutputVar.set(b) ext = c.config.getString("limit_directory_search_extension") b = ext and len(ext) > 0 b = g.choose(b and b != 0, 1, 0) self.limitToExtensionVar.set(b) if b: e = self.extensionEntry #e.delete(0,"end") e.setText(ext) #e.insert(0,ext) # Print options. b = c.config.getBool("print_both_lines_for_matches") if b == None: b = 0 self.printBothMatchesVar.set(b) b = c.config.getBool("print_matching_lines") if b == None: b = 0 self.printMatchesVar.set(b) b = c.config.getBool("print_mismatching_lines") if b == None: b = 0 self.printMismatchesVar.set(b) b = c.config.getBool("print_trailing_lines") if b == None: b = 0 self.printTrailingMismatchesVar.set(b) n = c.config.getInt("limit_count") b = n and n > 0 b = g.choose(b and b != 0, 1, 0) self.stopAfterMismatchVar.set(b) if b: e = self.countEntry e.setText(str(n)) #e.delete(0,"end") #e.insert(0,str(n)) # bool options... for option, var, default in ( # Whitespace options. ("ignore_blank_lines", self.ignoreBlankLinesVar, 1), ("ignore_interior_whitespace", self.ignoreInteriorWhitespaceVar, 0), ("ignore_leading_whitespace", self.ignoreLeadingWhitespaceVar, 0), ("ignore_sentinel_lines", self.ignoreSentinelLinesVar, 0), ("make_whitespace_visible", self.makeWhitespaceVisibleVar, 0), ): b = c.config.getBool(option) if b is None: b = default var.set(b) if 0: # old code b = c.config.getBool("ignore_blank_lines") if b == None: b = 1 # unusual default. self.ignoreBlankLinesVar.set(b) b = c.config.getBool("ignore_interior_whitespace") if b == None: b = 0 self.ignoreInteriorWhitespaceVar.set(b) b = c.config.getBool("ignore_leading_whitespace") if b == None: b = 0 self.ignoreLeadingWhitespaceVar.set(b) b = c.config.getBool("ignore_sentinel_lines") if b == None: b = 0 self.ignoreSentinelLinesVar.set(b) b = c.config.getBool("make_whitespace_visible") if b == None: b = 0 self.makeWhitespaceVisibleVar.set(b)
def onPrintMatchedLines(self): v = self.printMatchesVar.get() b = self.printButtons[1] state = g.choose(v, "normal", "disabled") b.configure(state=state)