Mercurial > cpython-lru_cache-weakref
annotate Lib/idlelib/SearchDialog.py @ 58925:eecf1bef052d 2.6
Merged revisions 78207 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r78207 | ezio.melotti | 2010-02-17 01:26:09 +0200 (Wed, 17 Feb 2010) | 1 line
#7930: fix stripid
........
| author | Ezio Melotti <ezio.melotti@gmail.com> |
|---|---|
| date | Tue, 16 Feb 2010 23:29:44 +0000 |
| parents | b53604fad54b |
| children | eab361617f6a |
| rev | line source |
|---|---|
|
47183
b53604fad54b
Tkinter rename reversal: remove tkinter package, adapt imports and docs.
Georg Brandl <georg@python.org>
parents:
47101
diff
changeset
|
1 from Tkinter import * |
| 13975 | 2 import SearchEngine |
| 3 from SearchDialogBase import SearchDialogBase | |
| 4 | |
| 5 | |
| 6 def _setup(text): | |
| 7 root = text._root() | |
| 8 engine = SearchEngine.get(root) | |
| 9 if not hasattr(engine, "_searchdialog"): | |
| 10 engine._searchdialog = SearchDialog(root, engine) | |
| 11 return engine._searchdialog | |
| 12 | |
| 13 def find(text): | |
|
26068
868ff0dfabd2
By default when getting the search menu, the currently highligted
Chui Tey <chui.tey@advdata.com.au>
parents:
25313
diff
changeset
|
14 pat = text.get("sel.first", "sel.last") |
|
868ff0dfabd2
By default when getting the search menu, the currently highligted
Chui Tey <chui.tey@advdata.com.au>
parents:
25313
diff
changeset
|
15 return _setup(text).open(text,pat) |
| 13975 | 16 |
| 17 def find_again(text): | |
| 18 return _setup(text).find_again(text) | |
| 19 | |
| 20 def find_selection(text): | |
| 21 return _setup(text).find_selection(text) | |
| 22 | |
| 23 class SearchDialog(SearchDialogBase): | |
| 24 | |
| 25 def create_widgets(self): | |
| 26 f = SearchDialogBase.create_widgets(self) | |
| 27 self.make_button("Find", self.default_command, 1) | |
| 28 | |
| 29 def default_command(self, event=None): | |
| 30 if not self.engine.getprog(): | |
| 31 return | |
| 32 if self.find_again(self.text): | |
| 33 self.close() | |
| 34 | |
| 35 def find_again(self, text): | |
| 36 if not self.engine.getpat(): | |
| 37 self.open(text) | |
| 25313 | 38 return False |
| 13975 | 39 if not self.engine.getprog(): |
| 25313 | 40 return False |
| 13975 | 41 res = self.engine.search_text(text) |
| 42 if res: | |
| 43 line, m = res | |
| 44 i, j = m.span() | |
| 45 first = "%d.%d" % (line, i) | |
| 46 last = "%d.%d" % (line, j) | |
| 47 try: | |
| 48 selfirst = text.index("sel.first") | |
| 49 sellast = text.index("sel.last") | |
| 50 if selfirst == first and sellast == last: | |
| 51 text.bell() | |
| 25313 | 52 return False |
| 13975 | 53 except TclError: |
| 54 pass | |
| 55 text.tag_remove("sel", "1.0", "end") | |
| 56 text.tag_add("sel", first, last) | |
| 57 text.mark_set("insert", self.engine.isback() and first or last) | |
| 58 text.see("insert") | |
| 25313 | 59 return True |
| 13975 | 60 else: |
| 61 text.bell() | |
| 25313 | 62 return False |
| 13975 | 63 |
| 64 def find_selection(self, text): | |
| 65 pat = text.get("sel.first", "sel.last") | |
| 66 if pat: | |
| 67 self.engine.setcookedpat(pat) | |
| 68 return self.find_again(text) |
