Home | History | Annotate | Download | only in idlelib
      1 # Sample extension: zoom a window to maximum height
      2 
      3 import re
      4 import sys
      5 
      6 from idlelib import macosx
      7 
      8 
      9 class ZoomHeight:
     10 
     11     menudefs = [
     12         ('windows', [
     13             ('_Zoom Height', '<<zoom-height>>'),
     14          ])
     15     ]
     16 
     17     def __init__(self, editwin):
     18         self.editwin = editwin
     19 
     20     def zoom_height_event(self, event):
     21         top = self.editwin.top
     22         zoom_height(top)
     23 
     24 
     25 def zoom_height(top):
     26     geom = top.wm_geometry()
     27     m = re.match(r"(\d+)x(\d+)\+(-?\d+)\+(-?\d+)", geom)
     28     if not m:
     29         top.bell()
     30         return
     31     width, height, x, y = map(int, m.groups())
     32     newheight = top.winfo_screenheight()
     33     if sys.platform == 'win32':
     34         newy = 0
     35         newheight = newheight - 72
     36 
     37     elif macosx.isAquaTk():
     38         # The '88' below is a magic number that avoids placing the bottom
     39         # of the window below the panel on my machine. I don't know how
     40         # to calculate the correct value for this with tkinter.
     41         newy = 22
     42         newheight = newheight - newy - 88
     43 
     44     else:
     45         #newy = 24
     46         newy = 0
     47         #newheight = newheight - 96
     48         newheight = newheight - 88
     49     if height >= newheight:
     50         newgeom = ""
     51     else:
     52         newgeom = "%dx%d+%d+%d" % (width, newheight, x, newy)
     53     top.wm_geometry(newgeom)
     54