blob: aa4a427eab737ffac6340059e002b105ac4866c8 [file] [log] [blame]
David Scherer7aced172000-08-15 01:13:23 +00001# Sample extension: zoom a window to maximum height
2
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
11 menudefs = [
12 ('windows', [
13 ('_Zoom Height', '<<zoom-height>>'),
14 ])
15 ]
Kurt B. Kaiser6655e4b2002-12-31 16:03:23 +000016
David Scherer7aced172000-08-15 01:13:23 +000017 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
Terry Jan Reedybfbaa6b2016-08-31 00:50:55 -040024
David Scherer7aced172000-08-15 01:13:23 +000025def 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
Thomas Wouters0e3f5912006-08-11 14:57:12 +000036
Terry Jan Reedy6fa5bdc2016-05-28 13:22:31 -040037 elif macosx.isAquaTk():
Thomas Wouters0e3f5912006-08-11 14:57:12 +000038 # 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
David Scherer7aced172000-08-15 01:13:23 +000044 else:
Kurt B. Kaiserd0e29262002-12-20 01:22:01 +000045 #newy = 24
46 newy = 0
47 #newheight = newheight - 96
Kurt B. Kaiser6655e4b2002-12-31 16:03:23 +000048 newheight = newheight - 88
David Scherer7aced172000-08-15 01:13:23 +000049 if height >= newheight:
50 newgeom = ""
51 else:
52 newgeom = "%dx%d+%d+%d" % (width, newheight, x, newy)
53 top.wm_geometry(newgeom)