annotate frontends/sortilege_old/window.py @ 749:192b804ee446

plugin XEP-0033: bug fix for sending messages with the addressing feature to several servers
author souliane <souliane@mailoo.org>
date Mon, 16 Dec 2013 14:48:28 +0100
parents 84a6e83157c2
children
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
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
goffi@necton2
parents:
diff changeset
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
goffi@necton2
parents:
diff changeset
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
goffi@necton2
parents:
diff changeset
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
goffi@necton2
parents:
diff changeset
19
goffi@necton2
parents:
diff changeset
20
goffi@necton2
parents:
diff changeset
21 import curses
goffi@necton2
parents:
diff changeset
22 import os
goffi@necton2
parents:
diff changeset
23 import pdb
goffi@necton2
parents:
diff changeset
24
goffi@necton2
parents:
diff changeset
25
588
beaf6bec2fcd Remove every old-style class.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 587
diff changeset
26 class Window(object):
0
goffi@necton2
parents:
diff changeset
27 def __init__(self, parent, height, width, y, x, border=False, title="", code="utf-8"):
goffi@necton2
parents:
diff changeset
28 self.__border=border
goffi@necton2
parents:
diff changeset
29 self.__title=title
goffi@necton2
parents:
diff changeset
30 self.__active=False
goffi@necton2
parents:
diff changeset
31 self.__parent=parent
goffi@necton2
parents:
diff changeset
32 self.__code=code
goffi@necton2
parents:
diff changeset
33 self.__hide=False
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 480
diff changeset
34
0
goffi@necton2
parents:
diff changeset
35 self.resize(height, width, y, x)
goffi@necton2
parents:
diff changeset
36 self.oriCoords=self.__coords #FIXME: tres moche, a faire en mieux
goffi@necton2
parents:
diff changeset
37
goffi@necton2
parents:
diff changeset
38 def hide(self, hide=True):
goffi@necton2
parents:
diff changeset
39 self.__hide=hide
goffi@necton2
parents:
diff changeset
40
goffi@necton2
parents:
diff changeset
41 def show(self):
goffi@necton2
parents:
diff changeset
42 self.__hide=False
goffi@necton2
parents:
diff changeset
43
goffi@necton2
parents:
diff changeset
44 def isHidden(self):
goffi@necton2
parents:
diff changeset
45 return self.__hide
goffi@necton2
parents:
diff changeset
46
goffi@necton2
parents:
diff changeset
47 def getY(self):
goffi@necton2
parents:
diff changeset
48 return self.__coords[2]
goffi@necton2
parents:
diff changeset
49
goffi@necton2
parents:
diff changeset
50 def getX(self):
goffi@necton2
parents:
diff changeset
51 return self.__coords[3]
goffi@necton2
parents:
diff changeset
52
goffi@necton2
parents:
diff changeset
53 def getHeight(self):
goffi@necton2
parents:
diff changeset
54 return self.__coords[0]
goffi@necton2
parents:
diff changeset
55
goffi@necton2
parents:
diff changeset
56 def getWidth(self):
goffi@necton2
parents:
diff changeset
57 return self.__coords[1]
goffi@necton2
parents:
diff changeset
58
goffi@necton2
parents:
diff changeset
59
goffi@necton2
parents:
diff changeset
60 #FIXME: tres moche, a faire en plus joli
goffi@necton2
parents:
diff changeset
61 def getOriY(self):
goffi@necton2
parents:
diff changeset
62 return self.oriCoords[2]
goffi@necton2
parents:
diff changeset
63
goffi@necton2
parents:
diff changeset
64 def getOriX(self):
goffi@necton2
parents:
diff changeset
65 return self.oriCoords[3]
goffi@necton2
parents:
diff changeset
66
goffi@necton2
parents:
diff changeset
67 def getOriHeight(self):
goffi@necton2
parents:
diff changeset
68 return self.oriCoords[0]
goffi@necton2
parents:
diff changeset
69
goffi@necton2
parents:
diff changeset
70 def getOriWidth(self):
goffi@necton2
parents:
diff changeset
71 return self.oriCoords[1]
goffi@necton2
parents:
diff changeset
72
goffi@necton2
parents:
diff changeset
73 def defInsideCoord(self):
goffi@necton2
parents:
diff changeset
74 """define the inside coordinates (win coordinates minus decorations)"""
goffi@necton2
parents:
diff changeset
75 height,width,y,x=self.__coords
goffi@necton2
parents:
diff changeset
76 self.oriX = x if not self.__border else x+1
goffi@necton2
parents:
diff changeset
77 self.oriY = y if not self.__border else y+1
goffi@necton2
parents:
diff changeset
78 self.endX = x+width if not self.__border else x+width-2
goffi@necton2
parents:
diff changeset
79 self.endY = y+height if not self.__border else y+height-2
goffi@necton2
parents:
diff changeset
80 self.rWidth = width if not self.__border else width-2
goffi@necton2
parents:
diff changeset
81 self.rHeight = height if not self.__border else height-2
goffi@necton2
parents:
diff changeset
82
goffi@necton2
parents:
diff changeset
83 def resize(self, height, width, y, x):
goffi@necton2
parents:
diff changeset
84 self.__coords=[height, width, y, x]
goffi@necton2
parents:
diff changeset
85
goffi@necton2
parents:
diff changeset
86 # we check that coordinates are under limits
goffi@necton2
parents:
diff changeset
87 self.__coordAdjust(self.__coords)
goffi@necton2
parents:
diff changeset
88 height,width,y,x=self.__coords
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 480
diff changeset
89
0
goffi@necton2
parents:
diff changeset
90 self.window = self.__parent.subwin(height, width, y, x)
goffi@necton2
parents:
diff changeset
91 self.defInsideCoord()
goffi@necton2
parents:
diff changeset
92
goffi@necton2
parents:
diff changeset
93 def __coordAdjust(self, coords):
goffi@necton2
parents:
diff changeset
94 """Check that coordinates are under limits, adjust them else otherwise"""
goffi@necton2
parents:
diff changeset
95 height,width,y,x=coords
goffi@necton2
parents:
diff changeset
96 parentY, parentX = self.__parent.getbegyx()
goffi@necton2
parents:
diff changeset
97 parentHeight, parentWidth = self.__parent.getmaxyx()
goffi@necton2
parents:
diff changeset
98
goffi@necton2
parents:
diff changeset
99 if y < parentY:
goffi@necton2
parents:
diff changeset
100 y = parentY
goffi@necton2
parents:
diff changeset
101 if x < parentX:
goffi@necton2
parents:
diff changeset
102 x = parentX
goffi@necton2
parents:
diff changeset
103 if height > parentHeight - y:
goffi@necton2
parents:
diff changeset
104 height = parentHeight - y
goffi@necton2
parents:
diff changeset
105 if width > parentWidth - x:
goffi@necton2
parents:
diff changeset
106 width = parentWidth - x
goffi@necton2
parents:
diff changeset
107 coords[0], coords[1], coords[2], coords[3] = [height, width, y, x]
goffi@necton2
parents:
diff changeset
108
goffi@necton2
parents:
diff changeset
109
goffi@necton2
parents:
diff changeset
110 def activate(self,state=True):
goffi@necton2
parents:
diff changeset
111 """Declare this window as current active one"""
goffi@necton2
parents:
diff changeset
112 self.__active=state
goffi@necton2
parents:
diff changeset
113 self.update()
goffi@necton2
parents:
diff changeset
114
goffi@necton2
parents:
diff changeset
115 def isActive(self):
goffi@necton2
parents:
diff changeset
116 return self.__active
goffi@necton2
parents:
diff changeset
117
goffi@necton2
parents:
diff changeset
118 def addYXStr(self, y, x, text, attr = 0, limit=0):
goffi@necton2
parents:
diff changeset
119 if self.__border:
goffi@necton2
parents:
diff changeset
120 x=x+1
goffi@necton2
parents:
diff changeset
121 y=y+1
goffi@necton2
parents:
diff changeset
122 n = self.rWidth-x if not limit else limit
goffi@necton2
parents:
diff changeset
123 encoded = text.encode(self.__code)
goffi@necton2
parents:
diff changeset
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
goffi@necton2
parents:
diff changeset
127 except:
goffi@necton2
parents:
diff changeset
128 #We have to catch error to write on last line last col FIXME: is there a better way ?
goffi@necton2
parents:
diff changeset
129 pass
goffi@necton2
parents:
diff changeset
130
goffi@necton2
parents:
diff changeset
131 def move(self, y, x):
goffi@necton2
parents:
diff changeset
132 self.window.move(y,x)
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 480
diff changeset
133
0
goffi@necton2
parents:
diff changeset
134 def noutrefresh(self):
goffi@necton2
parents:
diff changeset
135 self.window.noutrefresh()
goffi@necton2
parents:
diff changeset
136
goffi@necton2
parents:
diff changeset
137 def update(self):
goffi@necton2
parents:
diff changeset
138 """redraw all the window"""
goffi@necton2
parents:
diff changeset
139 if self.__hide:
goffi@necton2
parents:
diff changeset
140 return
goffi@necton2
parents:
diff changeset
141 self.clear()
goffi@necton2
parents:
diff changeset
142
goffi@necton2
parents:
diff changeset
143 def border(self):
goffi@necton2
parents:
diff changeset
144 """redraw the border and title"""
goffi@necton2
parents:
diff changeset
145 y,x = self.window.getbegyx()
goffi@necton2
parents:
diff changeset
146 width = self.window.getmaxyx()[1]
goffi@necton2
parents:
diff changeset
147 if self.__border:
goffi@necton2
parents:
diff changeset
148 self.window.border()
goffi@necton2
parents:
diff changeset
149 if self.__title:
goffi@necton2
parents:
diff changeset
150 if len(self.__title)>width:
goffi@necton2
parents:
diff changeset
151 self.__title=""
goffi@necton2
parents:
diff changeset
152 else:
goffi@necton2
parents:
diff changeset
153 self.window.addstr(y,x+(width-len(self.__title))/2, self.__title)
goffi@necton2
parents:
diff changeset
154
goffi@necton2
parents:
diff changeset
155 def clear(self):
goffi@necton2
parents:
diff changeset
156 self.window.clear()
goffi@necton2
parents:
diff changeset
157 self.border()