annotate frontends/sortilege/boxsizer.py @ 36:6491b7956c80

wix: Form submitting, first draft
author Goffi <goffi@goffi.org>
date Mon, 14 Dec 2009 02:11:05 +1100
parents c4bc297b82f0
children a5b5fb5fc9fd
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
goffi@necton2
parents:
diff changeset
1 #!/usr/bin/python
goffi@necton2
parents:
diff changeset
2 # -*- coding: utf-8 -*-
goffi@necton2
parents:
diff changeset
3
goffi@necton2
parents:
diff changeset
4 """
goffi@necton2
parents:
diff changeset
5 sortilege: a SAT frontend
goffi@necton2
parents:
diff changeset
6 Copyright (C) 2009 Jérôme Poisson (goffi@goffi.org)
goffi@necton2
parents:
diff changeset
7
goffi@necton2
parents:
diff changeset
8 This program is free software: you can redistribute it and/or modify
goffi@necton2
parents:
diff changeset
9 it under the terms of the GNU General Public License as published by
goffi@necton2
parents:
diff changeset
10 the Free Software Foundation, either version 3 of the License, or
goffi@necton2
parents:
diff changeset
11 (at your option) any later version.
goffi@necton2
parents:
diff changeset
12
goffi@necton2
parents:
diff changeset
13 This program is distributed in the hope that it will be useful,
goffi@necton2
parents:
diff changeset
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
goffi@necton2
parents:
diff changeset
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
goffi@necton2
parents:
diff changeset
16 GNU General Public License for more details.
goffi@necton2
parents:
diff changeset
17
goffi@necton2
parents:
diff changeset
18 You should have received a copy of the GNU General Public License
goffi@necton2
parents:
diff changeset
19 along with this program. If not, see <http://www.gnu.org/licenses/>.
goffi@necton2
parents:
diff changeset
20 """
goffi@necton2
parents:
diff changeset
21
goffi@necton2
parents:
diff changeset
22
goffi@necton2
parents:
diff changeset
23 from window import Window
goffi@necton2
parents:
diff changeset
24 import os,pdb
goffi@necton2
parents:
diff changeset
25
goffi@necton2
parents:
diff changeset
26
goffi@necton2
parents:
diff changeset
27 def echo(message):
goffi@necton2
parents:
diff changeset
28 return
goffi@necton2
parents:
diff changeset
29 os.system('echo "'+str(message)+'" >> /tmp/toto')
goffi@necton2
parents:
diff changeset
30
goffi@necton2
parents:
diff changeset
31
goffi@necton2
parents:
diff changeset
32 class BoxSizer:
goffi@necton2
parents:
diff changeset
33 """This class manage the position of the window like boxes."""
goffi@necton2
parents:
diff changeset
34
goffi@necton2
parents:
diff changeset
35
goffi@necton2
parents:
diff changeset
36
goffi@necton2
parents:
diff changeset
37 def __init__(self, parent):
goffi@necton2
parents:
diff changeset
38 self.__parent=parent
goffi@necton2
parents:
diff changeset
39 self.boxes=[]
goffi@necton2
parents:
diff changeset
40
goffi@necton2
parents:
diff changeset
41
goffi@necton2
parents:
diff changeset
42
goffi@necton2
parents:
diff changeset
43 def appendRow(self, win):
goffi@necton2
parents:
diff changeset
44 self.boxes.append([win])
goffi@necton2
parents:
diff changeset
45
goffi@necton2
parents:
diff changeset
46 def appendColum(self, index, win):
goffi@necton2
parents:
diff changeset
47 if len(self.boxes)<=index:
goffi@necton2
parents:
diff changeset
48 #TODO: throw an error here
goffi@necton2
parents:
diff changeset
49 return
goffi@necton2
parents:
diff changeset
50 self.boxes[index].append(win)
goffi@necton2
parents:
diff changeset
51
goffi@necton2
parents:
diff changeset
52 def update(self):
goffi@necton2
parents:
diff changeset
53 """Resize boxes"""
goffi@necton2
parents:
diff changeset
54 oriY=0
goffi@necton2
parents:
diff changeset
55 visible_row=[]
goffi@necton2
parents:
diff changeset
56 for row in self.boxes:
goffi@necton2
parents:
diff changeset
57 current_row=[]
goffi@necton2
parents:
diff changeset
58 oriX=0
goffi@necton2
parents:
diff changeset
59 for win in row:
goffi@necton2
parents:
diff changeset
60 x=win.getOriX()
goffi@necton2
parents:
diff changeset
61 y=win.getOriY()
goffi@necton2
parents:
diff changeset
62 w=win.getOriWidth()
goffi@necton2
parents:
diff changeset
63 h=win.getOriHeight()
goffi@necton2
parents:
diff changeset
64 if win.isHidden():
goffi@necton2
parents:
diff changeset
65 if len(current_row)>1 and win is row[-1]:
goffi@necton2
parents:
diff changeset
66 #if the last win is hidden, we expand previous visible one
goffi@necton2
parents:
diff changeset
67 current_row[-1][2] = current_row[-1][2] + (win.getX() - oriX)+win.getWidth()
goffi@necton2
parents:
diff changeset
68 else:
goffi@necton2
parents:
diff changeset
69 echo ("ajout de %s à current row" % (win.__class__.__name__))
goffi@necton2
parents:
diff changeset
70 current_row.append([win, h+y-oriY, w+x-oriX, oriY, oriX])
goffi@necton2
parents:
diff changeset
71 oriX=oriX+w
goffi@necton2
parents:
diff changeset
72
goffi@necton2
parents:
diff changeset
73 if oriX!=0:
goffi@necton2
parents:
diff changeset
74 echo ("ligne visible (dernier: %s)" % win.__class__.__name__)
goffi@necton2
parents:
diff changeset
75 oriY=oriY+h
goffi@necton2
parents:
diff changeset
76 visible_row.append(current_row)
goffi@necton2
parents:
diff changeset
77 elif visible_row:
goffi@necton2
parents:
diff changeset
78 #if all the row is empty, we take the space
goffi@necton2
parents:
diff changeset
79 for box in visible_row[-1]:
goffi@necton2
parents:
diff changeset
80 echo ("on augmente %s de %d" % (box[0].__class__.__name__, h))
goffi@necton2
parents:
diff changeset
81 box[1]=box[1]+h
goffi@necton2
parents:
diff changeset
82 oriY=oriY+h #this only happen if it's not the first visible row
goffi@necton2
parents:
diff changeset
83 else:
goffi@necton2
parents:
diff changeset
84 echo ("ligne invisible")
goffi@necton2
parents:
diff changeset
85
goffi@necton2
parents:
diff changeset
86 for row in visible_row:
goffi@necton2
parents:
diff changeset
87 for win in row:
goffi@necton2
parents:
diff changeset
88 win[0].resize(win[1], win[2], win[3], win[4])