Mercurial > libervia-backend
annotate frontends/sortilege_old/window.py @ 541:8b116fa42a31
core, bridge: waiting confirmation management (new getWaitingConf method)
author | Goffi <goffi@goffi.org> |
---|---|
date | Wed, 14 Nov 2012 20:24:28 +0100 |
parents | 2a072735e459 |
children | 952322b1d490 |
rev | line source |
---|---|
0 | 1 #!/usr/bin/python |
2 # -*- coding: utf-8 -*- | |
3 | |
4 """ | |
5 sortilege: a SAT frontend | |
228 | 6 Copyright (C) 2009, 2010, 2011 Jérôme Poisson (goffi@goffi.org) |
0 | 7 |
8 This program is free software: you can redistribute it and/or modify | |
480
2a072735e459
Licence modification: the full project is now under AGPL v3+ instead of GPL v3+
Goffi <goffi@goffi.org>
parents:
228
diff
changeset
|
9 it under the terms of the GNU Affero General Public License as published by |
0 | 10 the Free Software Foundation, either version 3 of the License, or |
11 (at your option) any later version. | |
12 | |
13 This program is distributed in the hope that it will be useful, | |
14 but WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
480
2a072735e459
Licence modification: the full project is now under AGPL v3+ instead of GPL v3+
Goffi <goffi@goffi.org>
parents:
228
diff
changeset
|
16 GNU Affero General Public License for more details. |
0 | 17 |
480
2a072735e459
Licence modification: the full project is now under AGPL v3+ instead of GPL v3+
Goffi <goffi@goffi.org>
parents:
228
diff
changeset
|
18 You should have received a copy of the GNU Affero General Public License |
0 | 19 along with this program. If not, see <http://www.gnu.org/licenses/>. |
20 """ | |
21 | |
22 | |
23 import curses | |
24 import os | |
25 import pdb | |
26 | |
27 | |
28 class Window(): | |
29 def __init__(self, parent, height, width, y, x, border=False, title="", code="utf-8"): | |
30 self.__border=border | |
31 self.__title=title | |
32 self.__active=False | |
33 self.__parent=parent | |
34 self.__code=code | |
35 self.__hide=False | |
36 | |
37 self.resize(height, width, y, x) | |
38 self.oriCoords=self.__coords #FIXME: tres moche, a faire en mieux | |
39 | |
40 def hide(self, hide=True): | |
41 self.__hide=hide | |
42 | |
43 def show(self): | |
44 self.__hide=False | |
45 | |
46 def isHidden(self): | |
47 return self.__hide | |
48 | |
49 def getY(self): | |
50 return self.__coords[2] | |
51 | |
52 def getX(self): | |
53 return self.__coords[3] | |
54 | |
55 def getHeight(self): | |
56 return self.__coords[0] | |
57 | |
58 def getWidth(self): | |
59 return self.__coords[1] | |
60 | |
61 | |
62 #FIXME: tres moche, a faire en plus joli | |
63 def getOriY(self): | |
64 return self.oriCoords[2] | |
65 | |
66 def getOriX(self): | |
67 return self.oriCoords[3] | |
68 | |
69 def getOriHeight(self): | |
70 return self.oriCoords[0] | |
71 | |
72 def getOriWidth(self): | |
73 return self.oriCoords[1] | |
74 | |
75 def defInsideCoord(self): | |
76 """define the inside coordinates (win coordinates minus decorations)""" | |
77 height,width,y,x=self.__coords | |
78 self.oriX = x if not self.__border else x+1 | |
79 self.oriY = y if not self.__border else y+1 | |
80 self.endX = x+width if not self.__border else x+width-2 | |
81 self.endY = y+height if not self.__border else y+height-2 | |
82 self.rWidth = width if not self.__border else width-2 | |
83 self.rHeight = height if not self.__border else height-2 | |
84 | |
85 def resize(self, height, width, y, x): | |
86 self.__coords=[height, width, y, x] | |
87 | |
88 # we check that coordinates are under limits | |
89 self.__coordAdjust(self.__coords) | |
90 height,width,y,x=self.__coords | |
91 | |
92 self.window = self.__parent.subwin(height, width, y, x) | |
93 self.defInsideCoord() | |
94 | |
95 def __coordAdjust(self, coords): | |
96 """Check that coordinates are under limits, adjust them else otherwise""" | |
97 height,width,y,x=coords | |
98 parentY, parentX = self.__parent.getbegyx() | |
99 parentHeight, parentWidth = self.__parent.getmaxyx() | |
100 | |
101 if y < parentY: | |
102 y = parentY | |
103 if x < parentX: | |
104 x = parentX | |
105 if height > parentHeight - y: | |
106 height = parentHeight - y | |
107 if width > parentWidth - x: | |
108 width = parentWidth - x | |
109 coords[0], coords[1], coords[2], coords[3] = [height, width, y, x] | |
110 | |
111 | |
112 def activate(self,state=True): | |
113 """Declare this window as current active one""" | |
114 self.__active=state | |
115 self.update() | |
116 | |
117 def isActive(self): | |
118 return self.__active | |
119 | |
120 def addYXStr(self, y, x, text, attr = 0, limit=0): | |
121 if self.__border: | |
122 x=x+1 | |
123 y=y+1 | |
124 n = self.rWidth-x if not limit else limit | |
125 encoded = text.encode(self.__code) | |
126 adjust = len(encoded) - len(text) # hack because addnstr doesn't manage unicode | |
127 try: | |
128 self.window.addnstr(y, x, encoded, n + adjust, attr) | |
129 except: | |
130 #We have to catch error to write on last line last col FIXME: is there a better way ? | |
131 pass | |
132 | |
133 def move(self, y, x): | |
134 self.window.move(y,x) | |
135 | |
136 def noutrefresh(self): | |
137 self.window.noutrefresh() | |
138 | |
139 def update(self): | |
140 """redraw all the window""" | |
141 if self.__hide: | |
142 return | |
143 self.clear() | |
144 | |
145 def border(self): | |
146 """redraw the border and title""" | |
147 y,x = self.window.getbegyx() | |
148 width = self.window.getmaxyx()[1] | |
149 if self.__border: | |
150 self.window.border() | |
151 if self.__title: | |
152 if len(self.__title)>width: | |
153 self.__title="" | |
154 else: | |
155 self.window.addstr(y,x+(width-len(self.__title))/2, self.__title) | |
156 | |
157 def clear(self): | |
158 self.window.clear() | |
159 self.border() |