blob: 35e285f0ba414bed91f4ef056f2484f697f2ffd0 [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
Cheryl Sabellac1b4b0f2018-12-22 01:25:45 -050016 zoomed = zoom_height(top)
17 menu_status = 'Restore' if zoomed else 'Zoom'
18 self.editwin.update_menu_label(menu='options', index='* Height',
19 label=f'{menu_status} Height')
Serhiy Storchaka213ce122017-06-27 07:02:32 +030020 return "break"
David Scherer7aced172000-08-15 01:13:23 +000021
Terry Jan Reedybfbaa6b2016-08-31 00:50:55 -040022
David Scherer7aced172000-08-15 01:13:23 +000023def zoom_height(top):
24 geom = top.wm_geometry()
25 m = re.match(r"(\d+)x(\d+)\+(-?\d+)\+(-?\d+)", geom)
26 if not m:
27 top.bell()
28 return
29 width, height, x, y = map(int, m.groups())
30 newheight = top.winfo_screenheight()
31 if sys.platform == 'win32':
32 newy = 0
33 newheight = newheight - 72
Thomas Wouters0e3f5912006-08-11 14:57:12 +000034
Terry Jan Reedy6fa5bdc2016-05-28 13:22:31 -040035 elif macosx.isAquaTk():
Thomas Wouters0e3f5912006-08-11 14:57:12 +000036 # The '88' below is a magic number that avoids placing the bottom
37 # of the window below the panel on my machine. I don't know how
38 # to calculate the correct value for this with tkinter.
39 newy = 22
40 newheight = newheight - newy - 88
41
David Scherer7aced172000-08-15 01:13:23 +000042 else:
Kurt B. Kaiserd0e29262002-12-20 01:22:01 +000043 #newy = 24
44 newy = 0
45 #newheight = newheight - 96
Kurt B. Kaiser6655e4b2002-12-31 16:03:23 +000046 newheight = newheight - 88
David Scherer7aced172000-08-15 01:13:23 +000047 if height >= newheight:
48 newgeom = ""
49 else:
50 newgeom = "%dx%d+%d+%d" % (width, newheight, x, newy)
51 top.wm_geometry(newgeom)
Cheryl Sabellac1b4b0f2018-12-22 01:25:45 -050052 return newgeom != ""
Terry Jan Reedy4d921582018-06-19 19:12:52 -040053
54
55if __name__ == "__main__":
56 from unittest import main
57 main('idlelib.idle_test.test_zoomheight', verbosity=2, exit=False)
58
59 # Add htest?