1 | n/a | # Sample extension: zoom a window to maximum height |
---|
2 | n/a | |
---|
3 | n/a | import re |
---|
4 | n/a | import sys |
---|
5 | n/a | |
---|
6 | n/a | from idlelib import macosx |
---|
7 | n/a | |
---|
8 | n/a | |
---|
9 | n/a | class ZoomHeight: |
---|
10 | n/a | |
---|
11 | n/a | menudefs = [ |
---|
12 | n/a | ('windows', [ |
---|
13 | n/a | ('_Zoom Height', '<<zoom-height>>'), |
---|
14 | n/a | ]) |
---|
15 | n/a | ] |
---|
16 | n/a | |
---|
17 | n/a | def __init__(self, editwin): |
---|
18 | n/a | self.editwin = editwin |
---|
19 | n/a | |
---|
20 | n/a | def zoom_height_event(self, event): |
---|
21 | n/a | top = self.editwin.top |
---|
22 | n/a | zoom_height(top) |
---|
23 | n/a | |
---|
24 | n/a | |
---|
25 | n/a | def zoom_height(top): |
---|
26 | n/a | geom = top.wm_geometry() |
---|
27 | n/a | m = re.match(r"(\d+)x(\d+)\+(-?\d+)\+(-?\d+)", geom) |
---|
28 | n/a | if not m: |
---|
29 | n/a | top.bell() |
---|
30 | n/a | return |
---|
31 | n/a | width, height, x, y = map(int, m.groups()) |
---|
32 | n/a | newheight = top.winfo_screenheight() |
---|
33 | n/a | if sys.platform == 'win32': |
---|
34 | n/a | newy = 0 |
---|
35 | n/a | newheight = newheight - 72 |
---|
36 | n/a | |
---|
37 | n/a | elif macosx.isAquaTk(): |
---|
38 | n/a | # The '88' below is a magic number that avoids placing the bottom |
---|
39 | n/a | # of the window below the panel on my machine. I don't know how |
---|
40 | n/a | # to calculate the correct value for this with tkinter. |
---|
41 | n/a | newy = 22 |
---|
42 | n/a | newheight = newheight - newy - 88 |
---|
43 | n/a | |
---|
44 | n/a | else: |
---|
45 | n/a | #newy = 24 |
---|
46 | n/a | newy = 0 |
---|
47 | n/a | #newheight = newheight - 96 |
---|
48 | n/a | newheight = newheight - 88 |
---|
49 | n/a | if height >= newheight: |
---|
50 | n/a | newgeom = "" |
---|
51 | n/a | else: |
---|
52 | n/a | newgeom = "%dx%d+%d+%d" % (width, newheight, x, newy) |
---|
53 | n/a | top.wm_geometry(newgeom) |
---|