blob: 73f1df071bf3bf6aa9e4b43eaed6d2627702f941 [file] [log] [blame]
wohlganger58fc71c2017-09-10 16:19:47 -05001"Zoom a window to maximum height."
David Scherer7aced172000-08-15 01:13:23 +00002
3import re
4import sys
Guido van Rossum36e0a922007-07-20 04:05:57 +00005
Terry Jan Reedy6fa5bdc2016-05-28 13:22:31 -04006from idlelib import macosx
David Scherer7aced172000-08-15 01:13:23 +00007
Terry Jan Reedybfbaa6b2016-08-31 00:50:55 -04008
David Scherer7aced172000-08-15 01:13:23 +00009class ZoomHeight:
10
David Scherer7aced172000-08-15 01:13:23 +000011 def __init__(self, editwin):
12 self.editwin = editwin
13
Terry Jan Reedy4d921582018-06-19 19:12:52 -040014 def zoom_height_event(self, event=None):
David Scherer7aced172000-08-15 01:13:23 +000015 top = self.editwin.top
16 zoom_height(top)
Serhiy Storchaka213ce122017-06-27 07:02:32 +030017 return "break"
David Scherer7aced172000-08-15 01:13:23 +000018
Terry Jan Reedybfbaa6b2016-08-31 00:50:55 -040019
David Scherer7aced172000-08-15 01:13:23 +000020def zoom_height(top):
21 geom = top.wm_geometry()
22 m = re.match(r"(\d+)x(\d+)\+(-?\d+)\+(-?\d+)", geom)
23 if not m:
24 top.bell()
25 return
26 width, height, x, y = map(int, m.groups())
27 newheight = top.winfo_screenheight()
28 if sys.platform == 'win32':
29 newy = 0
30 newheight = newheight - 72
Thomas Wouters0e3f5912006-08-11 14:57:12 +000031
Terry Jan Reedy6fa5bdc2016-05-28 13:22:31 -040032 elif macosx.isAquaTk():
Thomas Wouters0e3f5912006-08-11 14:57:12 +000033 # The '88' below is a magic number that avoids placing the bottom
34 # of the window below the panel on my machine. I don't know how
35 # to calculate the correct value for this with tkinter.
36 newy = 22
37 newheight = newheight - newy - 88
38
David Scherer7aced172000-08-15 01:13:23 +000039 else:
Kurt B. Kaiserd0e29262002-12-20 01:22:01 +000040 #newy = 24
41 newy = 0
42 #newheight = newheight - 96
Kurt B. Kaiser6655e4b2002-12-31 16:03:23 +000043 newheight = newheight - 88
David Scherer7aced172000-08-15 01:13:23 +000044 if height >= newheight:
45 newgeom = ""
46 else:
47 newgeom = "%dx%d+%d+%d" % (width, newheight, x, newy)
48 top.wm_geometry(newgeom)
Terry Jan Reedy4d921582018-06-19 19:12:52 -040049
50
51if __name__ == "__main__":
52 from unittest import main
53 main('idlelib.idle_test.test_zoomheight', verbosity=2, exit=False)
54
55 # Add htest?