ยปCore Development>Code coverage>Lib/idlelib/SearchDialog.py

Python code coverage for Lib/idlelib/SearchDialog.py

#countcontent
1n/afrom tkinter import *
2n/a
3n/afrom idlelib import SearchEngine
4n/afrom idlelib.SearchDialogBase import SearchDialogBase
5n/a
6n/adef _setup(text):
7n/a root = text._root()
8n/a engine = SearchEngine.get(root)
9n/a if not hasattr(engine, "_searchdialog"):
10n/a engine._searchdialog = SearchDialog(root, engine)
11n/a return engine._searchdialog
12n/a
13n/adef find(text):
14n/a pat = text.get("sel.first", "sel.last")
15n/a return _setup(text).open(text,pat)
16n/a
17n/adef find_again(text):
18n/a return _setup(text).find_again(text)
19n/a
20n/adef find_selection(text):
21n/a return _setup(text).find_selection(text)
22n/a
23n/aclass SearchDialog(SearchDialogBase):
24n/a
25n/a def create_widgets(self):
26n/a f = SearchDialogBase.create_widgets(self)
27n/a self.make_button("Find Next", self.default_command, 1)
28n/a
29n/a def default_command(self, event=None):
30n/a if not self.engine.getprog():
31n/a return
32n/a self.find_again(self.text)
33n/a
34n/a def find_again(self, text):
35n/a if not self.engine.getpat():
36n/a self.open(text)
37n/a return False
38n/a if not self.engine.getprog():
39n/a return False
40n/a res = self.engine.search_text(text)
41n/a if res:
42n/a line, m = res
43n/a i, j = m.span()
44n/a first = "%d.%d" % (line, i)
45n/a last = "%d.%d" % (line, j)
46n/a try:
47n/a selfirst = text.index("sel.first")
48n/a sellast = text.index("sel.last")
49n/a if selfirst == first and sellast == last:
50n/a text.bell()
51n/a return False
52n/a except TclError:
53n/a pass
54n/a text.tag_remove("sel", "1.0", "end")
55n/a text.tag_add("sel", first, last)
56n/a text.mark_set("insert", self.engine.isback() and first or last)
57n/a text.see("insert")
58n/a return True
59n/a else:
60n/a text.bell()
61n/a return False
62n/a
63n/a def find_selection(self, text):
64n/a pat = text.get("sel.first", "sel.last")
65n/a if pat:
66n/a self.engine.setcookedpat(pat)
67n/a return self.find_again(text)