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