blob: ecc306a73392b00b18a70cf6ba3fb01965666a6c [file] [log] [blame]
Guido van Rossum504b0bf1999-01-02 21:28:54 +00001# Sample extension: zoom a window to maximum height
2
3import re
Guido van Rossum0c65e251999-01-03 00:47:07 +00004import sys
Guido van Rossum504b0bf1999-01-02 21:28:54 +00005
6class ZoomHeight:
7
8 menudefs = [
9 ('windows', [
10 ('_Zoom Height', '<<zoom-height>>'),
11 ])
12 ]
13
14 windows_keydefs = {
15 '<<zoom-height>>': ['<Alt-F2>'],
16 }
17 unix_keydefs = {
Guido van Rossum0c65e251999-01-03 00:47:07 +000018 '<<zoom-height>>': ['<Control-x><Control-z>'],
Guido van Rossum504b0bf1999-01-02 21:28:54 +000019 }
20
21 def __init__(self, editwin):
22 self.editwin = editwin
23
24 def zoom_height_event(self, event):
25 top = self.editwin.top
Guido van Rossum96cf2711999-06-01 18:17:02 +000026 zoom_height(top)
27
28def zoom_height(top):
29 geom = top.wm_geometry()
30 m = re.match(r"(\d+)x(\d+)\+(-?\d+)\+(-?\d+)", geom)
31 if not m:
32 top.bell()
33 return
34 width, height, x, y = map(int, m.groups())
35 newheight = top.winfo_screenheight()
36 if sys.platform == 'win32':
37 newy = 0
38 newheight = newheight - 72
39 else:
40 newy = 24
41 newheight = newheight - 96
42 if height >= newheight:
43 newgeom = ""
44 else:
45 newgeom = "%dx%d+%d+%d" % (width, newheight, x, newy)
46 top.wm_geometry(newgeom)