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 / ZOOMHEIGHT.PY < prev   
Encoding:
Python Source  |  2000-09-28  |  1.1 KB  |  47 lines

  1. # Sample extension: zoom a window to maximum height
  2.  
  3. import re
  4. import sys
  5.  
  6. class ZoomHeight:
  7.  
  8.     menudefs = [
  9.         ('windows', [
  10.             ('_Zoom Height', '<<zoom-height>>'),
  11.          ])
  12.     ]
  13.  
  14.     windows_keydefs = {
  15.         '<<zoom-height>>': ['<Alt-F2>'],
  16.     }
  17.     unix_keydefs = {
  18.         '<<zoom-height>>': ['<Control-x><Control-z>'],
  19.     }
  20.  
  21.     def __init__(self, editwin):
  22.         self.editwin = editwin
  23.  
  24.     def zoom_height_event(self, event):
  25.         top = self.editwin.top
  26.         zoom_height(top)
  27.  
  28. def zoom_height(top):
  29.     geom = top.wm_geometry()
  30.     m = re.match(r"(\d+)x(\d+)\+(-?\d+)\+(-?\d+)", geom)
  31.     if not m:
  32.         top.bell()
  33.         return
  34.     width, height, x, y = map(int, m.groups())
  35.     newheight = top.winfo_screenheight()
  36.     if sys.platform == 'win32':
  37.         newy = 0
  38.         newheight = newheight - 72
  39.     else:
  40.         newy = 24
  41.         newheight = newheight - 96
  42.     if height >= newheight:
  43.         newgeom = ""
  44.     else:
  45.         newgeom = "%dx%d+%d+%d" % (width, newheight, x, newy)
  46.     top.wm_geometry(newgeom)
  47.