ZoomHeight.py 1.3 KB

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