PyXR

c:\python24\lib \ idlelib \ SearchDialog.py



0001 from Tkinter import *
0002 import SearchEngine
0003 from SearchDialogBase import SearchDialogBase
0004 
0005 
0006 def _setup(text):
0007     root = text._root()
0008     engine = SearchEngine.get(root)
0009     if not hasattr(engine, "_searchdialog"):
0010         engine._searchdialog = SearchDialog(root, engine)
0011     return engine._searchdialog
0012 
0013 def find(text):
0014     pat = text.get("sel.first", "sel.last")
0015     return _setup(text).open(text,pat)
0016 
0017 def find_again(text):
0018     return _setup(text).find_again(text)
0019 
0020 def find_selection(text):
0021     return _setup(text).find_selection(text)
0022 
0023 class SearchDialog(SearchDialogBase):
0024 
0025     def create_widgets(self):
0026         f = SearchDialogBase.create_widgets(self)
0027         self.make_button("Find", self.default_command, 1)
0028 
0029     def default_command(self, event=None):
0030         if not self.engine.getprog():
0031             return
0032         if self.find_again(self.text):
0033             self.close()
0034 
0035     def find_again(self, text):
0036         if not self.engine.getpat():
0037             self.open(text)
0038             return False
0039         if not self.engine.getprog():
0040             return False
0041         res = self.engine.search_text(text)
0042         if res:
0043             line, m = res
0044             i, j = m.span()
0045             first = "%d.%d" % (line, i)
0046             last = "%d.%d" % (line, j)
0047             try:
0048                 selfirst = text.index("sel.first")
0049                 sellast = text.index("sel.last")
0050                 if selfirst == first and sellast == last:
0051                     text.bell()
0052                     return False
0053             except TclError:
0054                 pass
0055             text.tag_remove("sel", "1.0", "end")
0056             text.tag_add("sel", first, last)
0057             text.mark_set("insert", self.engine.isback() and first or last)
0058             text.see("insert")
0059             return True
0060         else:
0061             text.bell()
0062             return False
0063 
0064     def find_selection(self, text):
0065         pat = text.get("sel.first", "sel.last")
0066         if pat:
0067             self.engine.setcookedpat(pat)
0068         return self.find_again(text)
0069 

Generated by PyXR 0.9.4
SourceForge.net Logo