blob: 523f5d51e02fd227ee67410458190f38fcf9e475 [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()
Thomas Wouters0e3f5912006-08-11 14:57:12 +000031
Terry Jan Reedydf9b0322019-05-27 19:16:46 -040032 # The constants below for Windows and Mac Aqua are visually determined
33 # to avoid taskbar or menubar and app icons.
34 newy, bot_y = ((0, 72) if sys.platform == 'win32' else
35 (22, 88) if macosx.isAquaTk() else
36 (0, 88) ) # Guess for anything else.
37 newheight = newheight - newy - bot_y
38 newgeom = '' if height >= newheight else f"{width}x{newheight}+{x}+{newy}"
David Scherer7aced172000-08-15 01:13:23 +000039 top.wm_geometry(newgeom)
Cheryl Sabellac1b4b0f2018-12-22 01:25:45 -050040 return newgeom != ""
Terry Jan Reedy4d921582018-06-19 19:12:52 -040041
42
43if __name__ == "__main__":
44 from unittest import main
45 main('idlelib.idle_test.test_zoomheight', verbosity=2, exit=False)
46
47 # Add htest?