MCPcopy Index your code
hub / github.com/python/cpython / SearchDialog

Class SearchDialog

Lib/idlelib/search.py:62–132  ·  view source on GitHub ↗

Dialog for finding a pattern in text.

Source from the content-addressed store, hash-verified

60
61
62class SearchDialog(SearchDialogBase):
63 "Dialog for finding a pattern in text."
64
65 def create_widgets(self):
66 "Create the base search dialog and add a button for Find Next."
67 SearchDialogBase.create_widgets(self)
68 # TODO - why is this here and not in a create_command_buttons?
69 self.make_button("Find Next", self.default_command, isdef=True)
70
71 def default_command(self, event=None):
72 "Handle the Find Next button as the default command."
73 if not self.engine.getprog():
74 return
75 self.find_again(self.text)
76
77 def find_again(self, text):
78 """Repeat the last search.
79
80 If no search was previously run, open a new search dialog. In
81 this case, no search is done.
82
83 If a search was previously run, the search dialog won't be
84 shown and the options from the previous search (including the
85 search pattern) will be used to find the next occurrence
86 of the pattern. Next is relative based on direction.
87
88 Position the window to display the located occurrence in the
89 text.
90
91 Return True if the search was successful and False otherwise.
92 """
93 if not self.engine.getpat():
94 self.open(text)
95 return False
96 if not self.engine.getprog():
97 return False
98 res = self.engine.search_text(text)
99 if res:
100 line, m = res
101 i, j = m.span()
102 first = "%d.%d" % (line, i)
103 last = "%d.%d" % (line, j)
104 try:
105 selfirst = text.index("sel.first")
106 sellast = text.index("sel.last")
107 if selfirst == first and sellast == last:
108 self.bell()
109 return False
110 except TclError:
111 pass
112 text.tag_remove("sel", "1.0", "end")
113 text.tag_add("sel", first, last)
114 text.mark_set("insert", self.engine.isback() and first or last)
115 text.see("insert")
116 return True
117 else:
118 self.bell()
119 return False

Callers 1

_setupFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…