blob: 0aefea63375f0f426e9261b01b8422cfe31631dc [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
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())
Guido van Rossum38a5a3b1999-01-29 20:44:45 +000032 newheight = top.winfo_screenheight()
Guido van Rossum0c65e251999-01-03 00:47:07 +000033 if sys.platform == 'win32':
Guido van Rossum38a5a3b1999-01-29 20:44:45 +000034 newy = 0
35 newheight = newheight - 72
Guido van Rossum0c65e251999-01-03 00:47:07 +000036 else:
Guido van Rossum38a5a3b1999-01-29 20:44:45 +000037 newy = 24
38 newheight = newheight - 96
39 if height >= newheight:
Guido van Rossum504b0bf1999-01-02 21:28:54 +000040 newgeom = ""
Guido van Rossum38a5a3b1999-01-29 20:44:45 +000041 else:
42 newgeom = "%dx%d+%d+%d" % (width, newheight, x, newy)
Guido van Rossum504b0bf1999-01-02 21:28:54 +000043 top.wm_geometry(newgeom)