-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgrid.py~
79 lines (66 loc) · 2.22 KB
/
grid.py~
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
class Pane():
def __init__(self, x, y, width, height, windows):
self.x =x
self.y = y
self.width = width
self.height = height
self.windows = windows
def reconfigure(self):
win_num = len(self.windows)
w = self.width/win_num
print w
h = self.height
x = self.x
y = self.y
for win in self.windows:
win.configure(x=x, y=y, width=w, height=h, border_width=1)
if x < self.width:
x = x + w
class Grid():
def __init__(self, root):
self.windows = []
self.panes = []
self.screen = root.get_geometry()
def remove_window(self, window):
if window in self.windows:
self.windows.remove(window)
print self.panes
self.update_panes()
def insert_window(self, window, pos=0):
self.windows.insert(0, window)
self.update_panes()
def update_panes(self):
self.panes =[]
win_num = len(self.windows)
print "we have this many windows: ", win_num
x = 0
y = 0
w = self.screen.width
h = self.screen.height
if win_num == 1:
pane = Pane(x, y, w, h, self.windows)
self.panes.append(pane)
elif win_num == 2:
w = w/2
for win in self.windows:
pane = Pane(x, y, w, h, [win])
self.panes.append(pane)
x = x + w
elif win_num > 2:
print "more than 2 windows"
pane = 0
for win in self.windows:
if win == self.windows[0]:
h=h - (h/3)
print "main pane has y and h:", y, h
pane = Pane(x,y, w, h, [win])
self.panes.append(pane)
y = h
h = h/2
elif len(self.panes) == 1 :
pane = Pane(x, y, w, h, [win])
self.panes.append(pane)
else:
pane.windows.append(win)
for pane in self.panes:
pane.reconfigure()