diff -r 58674a027d10 Lib/idlelib/GrepDialog.py --- a/Lib/idlelib/GrepDialog.py Wed Jan 07 23:49:06 2015 -0500 +++ b/Lib/idlelib/GrepDialog.py Sat Jan 10 20:12:42 2015 +1100 @@ -11,6 +11,10 @@ # EditorWindow -> GrepDialop -> OutputWindow -> EditorWindow def grep(text, io=None, flist=None): + """Opens the Find in Files dialog. + + This global function handles getting the SearchEngine singleton object to + perform this operation.""" root = text._root() engine = SearchEngine.get(root) if not hasattr(engine, "_grepdialog"): @@ -20,6 +24,7 @@ dialog.open(text, searchphrase, io) class GrepDialog(SearchDialogBase): + """Creates the modal search dialog for the Find in Files dialog.""" title = "Find in Files Dialog" icon = "Grep" @@ -32,6 +37,13 @@ self.recvar = BooleanVar(root) def open(self, text, searchphrase, io=None): + """Opens the Find in Files search dialog. + + Arguments: + text -- a MultiCall object containing the text information + searchphrase -- the search text to populate the search field with + io -- an IOBinding object containing the file information (default None) + """ SearchDialogBase.open(self, text, searchphrase) if io: path = io.filename or "" @@ -44,10 +56,12 @@ self.globvar.set(os.path.join(dir, "*" + tail)) def create_entries(self): + """Creates the text field UI elements, including the "In files" text field.""" SearchDialogBase.create_entries(self) self.globent = self.make_entry("In files:", self.globvar)[0] def create_other_buttons(self): + """Creates the "Recursive" checkbox.""" f = self.make_frame()[0] btn = Checkbutton(f, anchor="w", @@ -57,10 +71,15 @@ btn.select() def create_command_buttons(self): + """Creates the "Search Files" button.""" SearchDialogBase.create_command_buttons(self) self.make_button("Search Files", self.default_command, 1) def default_command(self, event=None): + """Creates the output window for the results and begins the grepping. + + Arguments: + event -- Not used. (default None)""" prog = self.engine.getprog() if not prog: return @@ -77,6 +96,11 @@ sys.stdout = save def grep_it(self, prog, path): + """Performs the grepping. + + Arguments: + prog -- The regex object to use for grepping. + path -- The parent folder to search.""" dir, base = os.path.split(path) list = self.findfiles(dir, base, self.recvar.get()) list.sort() diff -r 58674a027d10 Lib/idlelib/ReplaceDialog.py --- a/Lib/idlelib/ReplaceDialog.py Wed Jan 07 23:49:06 2015 -0500 +++ b/Lib/idlelib/ReplaceDialog.py Sat Jan 10 20:12:42 2015 +1100 @@ -6,6 +6,10 @@ def replace(text): + """Opens the Replace dialog. + + This global function handles getting the SearchEngine singleton object to + perform this operation.""" root = text._root() engine = SearchEngine.get(root) if not hasattr(engine, "_replacedialog"): @@ -15,6 +19,7 @@ class ReplaceDialog(SearchDialogBase): + """Creates the modal search dialog for the Replace dialog.""" title = "Replace Dialog" icon = "Replace" @@ -24,6 +29,13 @@ self.replvar = StringVar(root) def open(self, text): + """Opens the Replace dialog as a modal window. + + This method is overriden by subclasses to customize the UI elements. + + Arguments: + text -- a MultiCall object containing the text information + """ SearchDialogBase.open(self, text) try: first = text.index("sel.first") @@ -39,10 +51,12 @@ self.ok = 1 def create_entries(self): + """Create the main text fields for the Replace dialog.""" SearchDialogBase.create_entries(self) self.replent = self.make_entry("Replace with:", self.replvar)[0] def create_command_buttons(self): + """Create the Find, Replace, and Replace All buttons.""" SearchDialogBase.create_command_buttons(self) self.make_button("Find", self.find_it) self.make_button("Replace", self.replace_it) @@ -50,6 +64,7 @@ self.make_button("Replace All", self.replace_all) def find_it(self, event=None): + """The Find button's handler function. Performs a Find operation.""" self.do_find(0) def replace_it(self, event=None): @@ -57,14 +72,16 @@ self.do_replace() def default_command(self, event=None): + """The Replace button's handler function. Performs a Find and + Replace operation, then Find the next instance of the Find text.""" if self.do_find(self.ok): if self.do_replace(): # Only find next match if replace succeeded. # A bad re can cause a it to fail. self.do_find(0) def _replace_expand(self, m, repl): - """ Helper function for expanding a regular expression - in the replace field, if needed. """ + """Helper function for expanding a regular expression in the replace + field, if needed.""" if self.engine.isre(): try: new = m.expand(repl) @@ -77,6 +94,8 @@ return new def replace_all(self, event=None): + """The Replace All button's handler function. Performs a Replace + operation for all instances of the text.""" prog = self.engine.getprog() if not prog: return @@ -126,6 +145,7 @@ self.close() def do_find(self, ok=0): + """Performs a Find operation.""" if not self.engine.getprog(): return False text = self.text @@ -142,6 +162,7 @@ return True def do_replace(self): + """Performs a Replace operation.""" prog = self.engine.getprog() if not prog: return False diff -r 58674a027d10 Lib/idlelib/SearchDialog.py --- a/Lib/idlelib/SearchDialog.py Wed Jan 07 23:49:06 2015 -0500 +++ b/Lib/idlelib/SearchDialog.py Sat Jan 10 20:12:42 2015 +1100 @@ -4,6 +4,7 @@ from idlelib.SearchDialogBase import SearchDialogBase def _setup(text): + """Creates and returns the singleton SearchEngine object.""" root = text._root() engine = SearchEngine.get(root) if not hasattr(engine, "_searchdialog"): @@ -11,27 +12,52 @@ return engine._searchdialog def find(text): + """Opens the Find dialog. + + This global function handles getting the SearchEngine singleton object to + perform this operation.""" pat = text.get("sel.first", "sel.last") return _setup(text).open(text,pat) def find_again(text): + """Performs the previous Find operation again. If there was no previous + Find, then opens the Find dialog. + + This global function handles getting the SearchEngine singleton object to + perform this operation.""" return _setup(text).find_again(text) def find_selection(text): + """Opens the Find dialog, prepopulating the search phrase with the + currently selected text. + + This global function handles getting the SearchEngine singleton object to + perform this operation.""" return _setup(text).find_selection(text) class SearchDialog(SearchDialogBase): + """Creates the modal search dialog for the Find dialog.""" def create_widgets(self): + """Creates all of the initial set of base UI elements and binds the + Enter/Esc keys. For SearchDialog, additionally creates the Find Next + button.""" f = SearchDialogBase.create_widgets(self) self.make_button("Find Next", self.default_command, 1) def default_command(self, event=None): + """The default command is run when Enter is pressed. For SearchDialog, + it is the Find operation. + + Arguments: + event -- Not used. (default None)""" if not self.engine.getprog(): return self.find_again(self.text) def find_again(self, text): + """Performs the previous Find operation again. If there was no previous + Find, then opens the Find dialog.""" if not self.engine.getpat(): self.open(text) return False @@ -61,6 +87,8 @@ return False def find_selection(self, text): + """Performs a Find based on the currently selected text and previously + set Find options.""" pat = text.get("sel.first", "sel.last") if pat: self.engine.setcookedpat(pat) diff -r 58674a027d10 Lib/idlelib/SearchDialogBase.py --- a/Lib/idlelib/SearchDialogBase.py Wed Jan 07 23:49:06 2015 -0500 +++ b/Lib/idlelib/SearchDialogBase.py Sat Jan 10 20:12:42 2015 +1100 @@ -45,7 +45,15 @@ self.top = None def open(self, text, searchphrase=None): - "Make dialog visible on top of others and ready to use." + """Opens the search dialog as a modal window. + + This method is overriden by subclasses to customize the UI elements. + + Arguments: + text -- a MultiCall object containing the text information + searchphrase -- The text to populate the search field with. If None, + the previous search phrase is reused + """ self.text = text if not self.top: self.create_widgets() @@ -53,21 +61,23 @@ self.top.deiconify() self.top.tkraise() if searchphrase: + # populate the Find field self.ent.delete(0,"end") self.ent.insert("end",searchphrase) self.ent.focus_set() self.ent.selection_range(0, "end") self.ent.icursor(0) - self.top.grab_set() + self.top.grab_set() # make this dialog window modal def close(self, event=None): - "Put dialog away for later use." + """Closes the modal search dialog.""" if self.top: - self.top.grab_release() + self.top.grab_release() # un-modal this dialog window self.top.withdraw() def create_widgets(self): - '''Create basic 3 row x 3 col search (find) dialog. + '''Create basic 3 row x 3 col search (find) dialog and binds the + Enter/Esc keys. Other dialogs override subsidiary create_x methods as needed. Replace and Find-in-Files add another entry row. diff -r 58674a027d10 Lib/idlelib/SearchEngine.py --- a/Lib/idlelib/SearchEngine.py Wed Jan 07 23:49:06 2015 -0500 +++ b/Lib/idlelib/SearchEngine.py Sat Jan 10 20:12:42 2015 +1100 @@ -91,6 +91,7 @@ return prog def report_error(self, pat, msg, col=-1): + """Display a dialog box reporting an error with the Find regex.""" # Derived class could override this with something fancier msg = "Error: " + str(msg) if pat: @@ -141,6 +142,15 @@ return res def search_forward(self, text, prog, line, col, wrap, ok=0): + """Highlight the text for the next match. + + Arguments: + text -- a MultiCall object containing the text information + prog -- A regex pattern object. + line -- The line number to start searching from. + col -- The column number to start searching from. + wrap -- If True, continue search past the end. + ok -- See search_text()""" wrapped = 0 startline = line chars = text.get("%d.0" % line, "%d.0" % (line+1)) @@ -163,6 +173,15 @@ return None def search_backward(self, text, prog, line, col, wrap, ok=0): + """Highlight the text for the previous match. + + Arguments: + text -- a MultiCall object containing the text information + prog -- A regex pattern object. + line -- The line number to start searching from. + col -- The column number to start searching from. + wrap -- If True, continue search past the end. + ok -- See search_text()""" wrapped = 0 startline = line chars = text.get("%d.0" % line, "%d.0" % (line+1)) @@ -210,8 +229,7 @@ return found def get_selection(text): - '''Return tuple of 'line.col' indexes from selection or insert mark. - ''' + '''Return tuple of 'line.col' indexes from selection or insert mark.''' try: first = text.index("sel.first") last = text.index("sel.last")