home *** CD-ROM | disk | FTP | other *** search
/ PC World 2001 April / PCWorld_2001-04_cd.bin / Software / TemaCD / webclean / !!!python!!! / BeOpen-Python-2.0.exe / SEARCHBINDING.PY < prev    next >
Encoding:
Python Source  |  2000-09-28  |  2.7 KB  |  98 lines

  1. import tkSimpleDialog
  2.  
  3. ###$ event <<find>>
  4. ###$ win <Control-f>
  5. ###$ unix <Control-u><Control-u><Control-s>
  6.  
  7. ###$ event <<find-again>>
  8. ###$ win <Control-g>
  9. ###$ win <F3>
  10. ###$ unix <Control-u><Control-s>
  11.  
  12. ###$ event <<find-selection>>
  13. ###$ win <Control-F3>
  14. ###$ unix <Control-s>
  15.  
  16. ###$ event <<find-in-files>>
  17. ###$ win <Alt-F3>
  18.  
  19. ###$ event <<replace>>
  20. ###$ win <Control-h>
  21.  
  22. ###$ event <<goto-line>>
  23. ###$ win <Alt-g>
  24. ###$ unix <Alt-g>
  25.  
  26. class SearchBinding:
  27.  
  28.     windows_keydefs = {
  29.         '<<find-again>>': ['<Control-g>', '<F3>'],
  30.         '<<find-in-files>>': ['<Alt-F3>'],
  31.         '<<find-selection>>': ['<Control-F3>'],
  32.         '<<find>>': ['<Control-f>'],
  33.         '<<replace>>': ['<Control-h>'],
  34.         '<<goto-line>>': ['<Alt-g>'],
  35.     }
  36.  
  37.     unix_keydefs = {
  38.         '<<find-again>>': ['<Control-u><Control-s>'],
  39.         '<<find-in-files>>': ['<Alt-s>', '<Meta-s>'],
  40.         '<<find-selection>>': ['<Control-s>'],
  41.         '<<find>>': ['<Control-u><Control-u><Control-s>'],
  42.         '<<replace>>': ['<Control-r>'],
  43.         '<<goto-line>>': ['<Alt-g>', '<Meta-g>'],
  44.     }
  45.  
  46.     menudefs = [
  47.         ('edit', [
  48.             None,
  49.             ('_Find...', '<<find>>'),
  50.             ('Find a_gain', '<<find-again>>'),
  51.             ('Find _selection', '<<find-selection>>'),
  52.             ('Find in Files...', '<<find-in-files>>'),
  53.             ('R_eplace...', '<<replace>>'),
  54.             ('Go to _line', '<<goto-line>>'),
  55.          ]),
  56.     ]
  57.  
  58.     def __init__(self, editwin):
  59.         self.editwin = editwin
  60.  
  61.     def find_event(self, event):
  62.         import SearchDialog
  63.         SearchDialog.find(self.editwin.text)
  64.         return "break"
  65.  
  66.     def find_again_event(self, event):
  67.         import SearchDialog
  68.         SearchDialog.find_again(self.editwin.text)
  69.         return "break"
  70.  
  71.     def find_selection_event(self, event):
  72.         import SearchDialog
  73.         SearchDialog.find_selection(self.editwin.text)
  74.         return "break"
  75.  
  76.     def find_in_files_event(self, event):
  77.         import GrepDialog
  78.         GrepDialog.grep(self.editwin.text, self.editwin.io, self.editwin.flist)
  79.         return "break"
  80.  
  81.     def replace_event(self, event):
  82.         import ReplaceDialog
  83.         ReplaceDialog.replace(self.editwin.text)
  84.         return "break"
  85.  
  86.     def goto_line_event(self, event):
  87.         text = self.editwin.text
  88.         lineno = tkSimpleDialog.askinteger("Goto",
  89.                                            "Go to line number:",
  90.                                            parent=text)
  91.         if lineno is None:
  92.             return "break"
  93.         if lineno <= 0:
  94.             text.bell()
  95.             return "break"
  96.         text.mark_set("insert", "%d.0" % lineno)
  97.         text.see("insert")
  98.