blob: d01c9e964aa60f6d9418103208ce3e9131a13c3a [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)
Serhiy Storchaka213ce122017-06-27 07:02:32 +030023 return "break"
David Scherer7aced172000-08-15 01:13:23 +000024
Terry Jan Reedybfbaa6b2016-08-31 00:50:55 -040025
David Scherer7aced172000-08-15 01:13:23 +000026def zoom_height(top):
27 geom = top.wm_geometry()
28 m = re.match(r"(\d+)x(\d+)\+(-?\d+)\+(-?\d+)", geom)
29 if not m:
30 top.bell()
31 return
32 width, height, x, y = map(int, m.groups())
33 newheight = top.winfo_screenheight()
34 if sys.platform == 'win32':
35 newy = 0
36 newheight = newheight - 72
Thomas Wouters0e3f5912006-08-11 14:57:12 +000037
Terry Jan Reedy6fa5bdc2016-05-28 13:22:31 -040038 elif macosx.isAquaTk():
Thomas Wouters0e3f5912006-08-11 14:57:12 +000039 # The '88' below is a magic number that avoids placing the bottom
40 # of the window below the panel on my machine. I don't know how
41 # to calculate the correct value for this with tkinter.
42 newy = 22
43 newheight = newheight - newy - 88
44
David Scherer7aced172000-08-15 01:13:23 +000045 else:
Kurt B. Kaiserd0e29262002-12-20 01:22:01 +000046 #newy = 24
47 newy = 0
48 #newheight = newheight - 96
Kurt B. Kaiser6655e4b2002-12-31 16:03:23 +000049 newheight = newheight - 88
David Scherer7aced172000-08-15 01:13:23 +000050 if height >= newheight:
51 newgeom = ""
52 else:
53 newgeom = "%dx%d+%d+%d" % (width, newheight, x, newy)
54 top.wm_geometry(newgeom)