Dialog for finding and replacing a pattern in text.
| 30 | |
| 31 | |
| 32 | class ReplaceDialog(SearchDialogBase): |
| 33 | "Dialog for finding and replacing a pattern in text." |
| 34 | |
| 35 | title = "Replace Dialog" |
| 36 | icon = "Replace" |
| 37 | |
| 38 | def __init__(self, root, engine): |
| 39 | """Create search dialog for finding and replacing text. |
| 40 | |
| 41 | Uses SearchDialogBase as the basis for the GUI and a |
| 42 | searchengine instance to prepare the search. |
| 43 | |
| 44 | Attributes: |
| 45 | replvar: StringVar containing 'Replace with:' value. |
| 46 | replent: Entry widget for replvar. Created in |
| 47 | create_entries(). |
| 48 | ok: Boolean used in searchengine.search_text to indicate |
| 49 | whether the search includes the selection. |
| 50 | """ |
| 51 | super().__init__(root, engine) |
| 52 | self.replvar = StringVar(root) |
| 53 | self.insert_tags = None |
| 54 | |
| 55 | def open(self, text, searchphrase=None, *, insert_tags=None): |
| 56 | """Make dialog visible on top of others and ready to use. |
| 57 | |
| 58 | Also, set the search to include the current selection |
| 59 | (self.ok). |
| 60 | |
| 61 | Args: |
| 62 | text: Text widget being searched. |
| 63 | searchphrase: String phrase to search. |
| 64 | """ |
| 65 | SearchDialogBase.open(self, text, searchphrase) |
| 66 | self.ok = True |
| 67 | self.insert_tags = insert_tags |
| 68 | |
| 69 | def create_entries(self): |
| 70 | "Create base and additional label and text entry widgets." |
| 71 | SearchDialogBase.create_entries(self) |
| 72 | self.replent = self.make_entry("Replace with:", self.replvar)[0] |
| 73 | |
| 74 | def create_command_buttons(self): |
| 75 | """Create base and additional command buttons. |
| 76 | |
| 77 | The additional buttons are for Find, Replace, |
| 78 | Replace+Find, and Replace All. |
| 79 | """ |
| 80 | SearchDialogBase.create_command_buttons(self) |
| 81 | self.make_button("Find", self.find_it) |
| 82 | self.make_button("Replace", self.replace_it) |
| 83 | self.make_button("Replace+Find", self.default_command, isdef=True) |
| 84 | self.make_button("Replace All", self.replace_all) |
| 85 | |
| 86 | def find_it(self, event=None): |
| 87 | "Handle the Find button." |
| 88 | self.do_find(False) |
| 89 |
no outgoing calls
searching dependent graphs…