annotate frontends/primitivus/custom_widgets.py @ 124:961e0898271f

primitivus chat window - management of one 2 one / group chat - timestamp displayed - added shortcuts for showing/hiding panels - color used - fixed vcard bug (contact displayed even if not from current profile if vcard changed/not in cache) - added VerticalSeparator widget - *List widgets can now use an other widget than SelectableText - new UnselectableText widget
author Goffi <goffi@goffi.org>
date Thu, 08 Jul 2010 19:47:54 +0800
parents 03d8bcc67182
children 8d611eb9ae48
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
113
e5ca22113280 Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
1 #!/usr/bin/python
e5ca22113280 Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
2 # -*- coding: utf-8 -*-
e5ca22113280 Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
3
e5ca22113280 Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
4 """
e5ca22113280 Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
5 Primitivus: a SAT frontend
e5ca22113280 Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
6 Copyright (C) 2009, 2010 Jérôme Poisson (goffi@goffi.org)
e5ca22113280 Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
7
e5ca22113280 Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
8 This program is free software: you can redistribute it and/or modify
e5ca22113280 Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
9 it under the terms of the GNU General Public License as published by
e5ca22113280 Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
10 the Free Software Foundation, either version 3 of the License, or
e5ca22113280 Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
11 (at your option) any later version.
e5ca22113280 Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
12
e5ca22113280 Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
13 This program is distributed in the hope that it will be useful,
e5ca22113280 Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
e5ca22113280 Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
e5ca22113280 Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
16 GNU General Public License for more details.
e5ca22113280 Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
17
e5ca22113280 Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
18 You should have received a copy of the GNU General Public License
e5ca22113280 Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
19 along with this program. If not, see <http://www.gnu.org/licenses/>.
e5ca22113280 Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
20 """
e5ca22113280 Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
21
e5ca22113280 Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
22 import urwid
120
1ca5f254ce41 primitivus group chat & misc
Goffi <goffi@goffi.org>
parents: 119
diff changeset
23 from urwid.escape import utf8decode
113
e5ca22113280 Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
24
e5ca22113280 Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
25 class Password(urwid.Edit):
121
03d8bcc67182 misc documentation
Goffi <goffi@goffi.org>
parents: 120
diff changeset
26 """Edit box which doesn't show what is entered (show '*' or other char instead)"""
113
e5ca22113280 Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
27
e5ca22113280 Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
28 def __init__(self, *args, **kwargs):
121
03d8bcc67182 misc documentation
Goffi <goffi@goffi.org>
parents: 120
diff changeset
29 """Same args than Edit.__init__ with an additional keyword arg 'hidden_char'
03d8bcc67182 misc documentation
Goffi <goffi@goffi.org>
parents: 120
diff changeset
30 @param hidden_char: char to show instead of what is actually entered: default '*'
03d8bcc67182 misc documentation
Goffi <goffi@goffi.org>
parents: 120
diff changeset
31 """
113
e5ca22113280 Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
32 self.hidden_char=kwargs['hidden_char'] if kwargs.has_key('hidden_char') else '*'
e5ca22113280 Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
33 self.__real_text=''
e5ca22113280 Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
34 super(Password, self).__init__(*args, **kwargs)
e5ca22113280 Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
35
e5ca22113280 Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
36 def set_edit_text(self, text):
e5ca22113280 Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
37 self.__real_text = text
e5ca22113280 Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
38 hidden_txt = len(text)*'*'
e5ca22113280 Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
39 super(Password, self).set_edit_text(hidden_txt)
e5ca22113280 Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
40
e5ca22113280 Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
41 def get_edit_text(self):
e5ca22113280 Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
42 return self.__real_text
e5ca22113280 Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
43
118
76055a209ed9 primitivus: added edition zone at the bottom
Goffi <goffi@goffi.org>
parents: 117
diff changeset
44 class AdvancedEdit(urwid.Edit):
121
03d8bcc67182 misc documentation
Goffi <goffi@goffi.org>
parents: 120
diff changeset
45 """Edit box with some custom improvments
03d8bcc67182 misc documentation
Goffi <goffi@goffi.org>
parents: 120
diff changeset
46 new chars:
03d8bcc67182 misc documentation
Goffi <goffi@goffi.org>
parents: 120
diff changeset
47 - C-a: like 'home'
03d8bcc67182 misc documentation
Goffi <goffi@goffi.org>
parents: 120
diff changeset
48 - C-e: like 'end'
03d8bcc67182 misc documentation
Goffi <goffi@goffi.org>
parents: 120
diff changeset
49 - C-k: remove everything on the right of the cursor
03d8bcc67182 misc documentation
Goffi <goffi@goffi.org>
parents: 120
diff changeset
50 - C-w: remove the word on the back
03d8bcc67182 misc documentation
Goffi <goffi@goffi.org>
parents: 120
diff changeset
51 new behaviour: emit a 'click' signal when enter is pressed"""
119
ded2431cea5a Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 118
diff changeset
52 signals = urwid.Edit.signals + ['click']
118
76055a209ed9 primitivus: added edition zone at the bottom
Goffi <goffi@goffi.org>
parents: 117
diff changeset
53
76055a209ed9 primitivus: added edition zone at the bottom
Goffi <goffi@goffi.org>
parents: 117
diff changeset
54 def keypress(self, size, key):
76055a209ed9 primitivus: added edition zone at the bottom
Goffi <goffi@goffi.org>
parents: 117
diff changeset
55 #TODO: insert mode is not managed yet
76055a209ed9 primitivus: added edition zone at the bottom
Goffi <goffi@goffi.org>
parents: 117
diff changeset
56 if key == 'ctrl a':
76055a209ed9 primitivus: added edition zone at the bottom
Goffi <goffi@goffi.org>
parents: 117
diff changeset
57 key = 'home'
76055a209ed9 primitivus: added edition zone at the bottom
Goffi <goffi@goffi.org>
parents: 117
diff changeset
58 elif key == 'ctrl e':
76055a209ed9 primitivus: added edition zone at the bottom
Goffi <goffi@goffi.org>
parents: 117
diff changeset
59 key = 'end'
76055a209ed9 primitivus: added edition zone at the bottom
Goffi <goffi@goffi.org>
parents: 117
diff changeset
60 elif key == 'ctrl k':
76055a209ed9 primitivus: added edition zone at the bottom
Goffi <goffi@goffi.org>
parents: 117
diff changeset
61 self._delete_highlighted()
76055a209ed9 primitivus: added edition zone at the bottom
Goffi <goffi@goffi.org>
parents: 117
diff changeset
62 self.set_edit_text(self.edit_text[:self.edit_pos])
76055a209ed9 primitivus: added edition zone at the bottom
Goffi <goffi@goffi.org>
parents: 117
diff changeset
63 elif key == 'ctrl w':
76055a209ed9 primitivus: added edition zone at the bottom
Goffi <goffi@goffi.org>
parents: 117
diff changeset
64 before = self.edit_text[:self.edit_pos]
76055a209ed9 primitivus: added edition zone at the bottom
Goffi <goffi@goffi.org>
parents: 117
diff changeset
65 pos = before.rstrip().rfind(" ")+1
76055a209ed9 primitivus: added edition zone at the bottom
Goffi <goffi@goffi.org>
parents: 117
diff changeset
66 self.set_edit_text(before[:pos] + self.edit_text[self.edit_pos:])
76055a209ed9 primitivus: added edition zone at the bottom
Goffi <goffi@goffi.org>
parents: 117
diff changeset
67 self.set_edit_pos(pos)
119
ded2431cea5a Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 118
diff changeset
68 elif key == 'enter':
ded2431cea5a Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 118
diff changeset
69 self._emit('click')
118
76055a209ed9 primitivus: added edition zone at the bottom
Goffi <goffi@goffi.org>
parents: 117
diff changeset
70 return super(AdvancedEdit, self).keypress(size, key)
76055a209ed9 primitivus: added edition zone at the bottom
Goffi <goffi@goffi.org>
parents: 117
diff changeset
71
76055a209ed9 primitivus: added edition zone at the bottom
Goffi <goffi@goffi.org>
parents: 117
diff changeset
72
120
1ca5f254ce41 primitivus group chat & misc
Goffi <goffi@goffi.org>
parents: 119
diff changeset
73 class SurroundedText(urwid.FlowWidget):
121
03d8bcc67182 misc documentation
Goffi <goffi@goffi.org>
parents: 120
diff changeset
74 """Text centered on a repeated character (like a Divider, but with a text in the center)"""
120
1ca5f254ce41 primitivus group chat & misc
Goffi <goffi@goffi.org>
parents: 119
diff changeset
75
1ca5f254ce41 primitivus group chat & misc
Goffi <goffi@goffi.org>
parents: 119
diff changeset
76 def __init__(self,text,car=utf8decode('─')):
1ca5f254ce41 primitivus group chat & misc
Goffi <goffi@goffi.org>
parents: 119
diff changeset
77 self.text=text
1ca5f254ce41 primitivus group chat & misc
Goffi <goffi@goffi.org>
parents: 119
diff changeset
78 self.car=car
1ca5f254ce41 primitivus group chat & misc
Goffi <goffi@goffi.org>
parents: 119
diff changeset
79
1ca5f254ce41 primitivus group chat & misc
Goffi <goffi@goffi.org>
parents: 119
diff changeset
80 def rows(self,size,focus=False):
1ca5f254ce41 primitivus group chat & misc
Goffi <goffi@goffi.org>
parents: 119
diff changeset
81 return self.display_widget(size, focus).rows(size, focus)
1ca5f254ce41 primitivus group chat & misc
Goffi <goffi@goffi.org>
parents: 119
diff changeset
82
1ca5f254ce41 primitivus group chat & misc
Goffi <goffi@goffi.org>
parents: 119
diff changeset
83 def render(self, size, focus=False):
1ca5f254ce41 primitivus group chat & misc
Goffi <goffi@goffi.org>
parents: 119
diff changeset
84 return self.display_widget(size, focus).render(size, focus)
1ca5f254ce41 primitivus group chat & misc
Goffi <goffi@goffi.org>
parents: 119
diff changeset
85
1ca5f254ce41 primitivus group chat & misc
Goffi <goffi@goffi.org>
parents: 119
diff changeset
86 def display_widget(self, size, focus):
1ca5f254ce41 primitivus group chat & misc
Goffi <goffi@goffi.org>
parents: 119
diff changeset
87 (maxcol,) = size
1ca5f254ce41 primitivus group chat & misc
Goffi <goffi@goffi.org>
parents: 119
diff changeset
88 middle = (maxcol-len(self.text))/2
1ca5f254ce41 primitivus group chat & misc
Goffi <goffi@goffi.org>
parents: 119
diff changeset
89 render_text = middle * self.car + self.text + (maxcol - len(self.text) - middle) * self.car
1ca5f254ce41 primitivus group chat & misc
Goffi <goffi@goffi.org>
parents: 119
diff changeset
90 return urwid.Text(render_text)
1ca5f254ce41 primitivus group chat & misc
Goffi <goffi@goffi.org>
parents: 119
diff changeset
91
1ca5f254ce41 primitivus group chat & misc
Goffi <goffi@goffi.org>
parents: 119
diff changeset
92
1ca5f254ce41 primitivus group chat & misc
Goffi <goffi@goffi.org>
parents: 119
diff changeset
93
113
e5ca22113280 Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
94 class SelectableText(urwid.FlowWidget):
120
1ca5f254ce41 primitivus group chat & misc
Goffi <goffi@goffi.org>
parents: 119
diff changeset
95 """Text which can be selected with space"""
113
e5ca22113280 Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
96 signals = ['change']
e5ca22113280 Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
97
e5ca22113280 Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
98 def __init__(self, text, align='left'):
e5ca22113280 Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
99 self.text=unicode(text)
e5ca22113280 Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
100 self.align = align
e5ca22113280 Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
101 self.__selected=False
e5ca22113280 Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
102
e5ca22113280 Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
103 def getValue(self):
e5ca22113280 Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
104 return self.text
e5ca22113280 Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
105
e5ca22113280 Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
106 def setState(self, selected, invisible=False):
e5ca22113280 Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
107 """Change state
e5ca22113280 Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
108 @param selected: boolean state value
e5ca22113280 Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
109 @param invisible: don't emit change signal if True"""
e5ca22113280 Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
110 assert(type(selected)==bool)
e5ca22113280 Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
111 self.__selected=selected
119
ded2431cea5a Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 118
diff changeset
112 self._invalidate()
113
e5ca22113280 Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
113 if not invisible:
e5ca22113280 Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
114 self._emit("change", self.__selected)
e5ca22113280 Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
115
e5ca22113280 Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
116 def getState(self):
e5ca22113280 Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
117 return self.__selected
e5ca22113280 Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
118
e5ca22113280 Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
119 def selectable(self):
e5ca22113280 Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
120 return True
e5ca22113280 Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
121
e5ca22113280 Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
122 def keypress(self, size, key):
e5ca22113280 Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
123 if key==' ' or key=='enter':
e5ca22113280 Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
124 self.setState(not self.__selected)
e5ca22113280 Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
125 else:
e5ca22113280 Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
126 return key
e5ca22113280 Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
127
e5ca22113280 Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
128 def rows(self,size,focus=False):
e5ca22113280 Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
129 return self.display_widget(size, focus).rows(size, focus)
e5ca22113280 Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
130
e5ca22113280 Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
131 def render(self, size, focus=False):
e5ca22113280 Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
132 return self.display_widget(size, focus).render(size, focus)
e5ca22113280 Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
133
e5ca22113280 Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
134 def display_widget(self, size, focus):
e5ca22113280 Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
135 attr = 'selected' if self.__selected else 'default'
e5ca22113280 Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
136 if focus:
e5ca22113280 Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
137 attr+="_focus"
e5ca22113280 Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
138 return urwid.Text((attr,self.text), align=self.align)
e5ca22113280 Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
139
124
961e0898271f primitivus chat window
Goffi <goffi@goffi.org>
parents: 121
diff changeset
140 class UnselectableText(SelectableText):
961e0898271f primitivus chat window
Goffi <goffi@goffi.org>
parents: 121
diff changeset
141
961e0898271f primitivus chat window
Goffi <goffi@goffi.org>
parents: 121
diff changeset
142 def setState(self, selected, invisible=False):
961e0898271f primitivus chat window
Goffi <goffi@goffi.org>
parents: 121
diff changeset
143 pass
961e0898271f primitivus chat window
Goffi <goffi@goffi.org>
parents: 121
diff changeset
144
119
ded2431cea5a Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 118
diff changeset
145 class GenericList(urwid.WidgetWrap):
ded2431cea5a Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 118
diff changeset
146 signals = ['click','change']
113
e5ca22113280 Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
147
124
961e0898271f primitivus chat window
Goffi <goffi@goffi.org>
parents: 121
diff changeset
148 def __init__(self, options, style=[], align='left', option_type = SelectableText, on_click=None, on_change=None, user_data=None):
119
ded2431cea5a Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 118
diff changeset
149 """
ded2431cea5a Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 118
diff changeset
150 Widget managing list of string and their selection
ded2431cea5a Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 118
diff changeset
151 @param options: list of strings used for options
ded2431cea5a Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 118
diff changeset
152 @param style: list of string:
ded2431cea5a Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 118
diff changeset
153 - 'single' if only one must be selected
ded2431cea5a Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 118
diff changeset
154 - 'no_first_select' nothing selected when list is first displayed
ded2431cea5a Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 118
diff changeset
155 - 'can_select_none' if we can select nothing
ded2431cea5a Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 118
diff changeset
156 @param align: alignement of text inside the list
ded2431cea5a Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 118
diff changeset
157 @param on_click: method called when click signal is emited
ded2431cea5a Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 118
diff changeset
158 @param user_data: data sent to the callback for click signal
ded2431cea5a Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 118
diff changeset
159 """
113
e5ca22113280 Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
160 self.single = 'single' in style
119
ded2431cea5a Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 118
diff changeset
161 self.no_first_select = 'no_first_select' in style
ded2431cea5a Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 118
diff changeset
162 self.can_select_none = 'can_select_none' in style
113
e5ca22113280 Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
163 self.align = align
124
961e0898271f primitivus chat window
Goffi <goffi@goffi.org>
parents: 121
diff changeset
164 self.option_type = option_type
119
ded2431cea5a Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 118
diff changeset
165 self.first_display = True
113
e5ca22113280 Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
166
119
ded2431cea5a Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 118
diff changeset
167 if on_click:
ded2431cea5a Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 118
diff changeset
168 urwid.connect_signal(self, 'click', on_click, user_data)
ded2431cea5a Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 118
diff changeset
169
ded2431cea5a Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 118
diff changeset
170 if on_change:
ded2431cea5a Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 118
diff changeset
171 urwid.connect_signal(self, 'change', on_change, user_data)
113
e5ca22113280 Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
172
114
77f48939ad6e primitivus: added Alert widget
Goffi <goffi@goffi.org>
parents: 113
diff changeset
173 self.content = urwid.SimpleListWalker([])
113
e5ca22113280 Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
174 self.list_box = urwid.ListBox(self.content)
118
76055a209ed9 primitivus: added edition zone at the bottom
Goffi <goffi@goffi.org>
parents: 117
diff changeset
175 urwid.WidgetWrap.__init__(self, self.list_box)
114
77f48939ad6e primitivus: added Alert widget
Goffi <goffi@goffi.org>
parents: 113
diff changeset
176 self.changeValues(options)
113
e5ca22113280 Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
177
e5ca22113280 Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
178 def __onStateChange(self, widget, selected):
e5ca22113280 Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
179 if self.single:
119
ded2431cea5a Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 118
diff changeset
180 if not selected and not self.can_select_none:
113
e5ca22113280 Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
181 #if in single mode, it's forbidden to unselect a value
e5ca22113280 Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
182 widget.setState(True, invisible=True)
e5ca22113280 Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
183 return
119
ded2431cea5a Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 118
diff changeset
184 if selected:
113
e5ca22113280 Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
185 self.unselectAll(invisible=True)
e5ca22113280 Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
186 widget.setState(True, invisible=True)
119
ded2431cea5a Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 118
diff changeset
187 self._emit("click")
113
e5ca22113280 Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
188
e5ca22113280 Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
189
e5ca22113280 Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
190 def unselectAll(self, invisible=False):
e5ca22113280 Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
191 for widget in self.content:
e5ca22113280 Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
192 if widget.getState():
e5ca22113280 Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
193 widget.setState(False, invisible)
e5ca22113280 Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
194 widget._invalidate()
e5ca22113280 Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
195
116
7c482ecac0ff primitivus: basic contact list, connexion now work \o/
Goffi <goffi@goffi.org>
parents: 114
diff changeset
196 def deleteValue(self, value):
7c482ecac0ff primitivus: basic contact list, connexion now work \o/
Goffi <goffi@goffi.org>
parents: 114
diff changeset
197 """Delete the first value equal to the param given"""
119
ded2431cea5a Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 118
diff changeset
198 for widget in self.content:
ded2431cea5a Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 118
diff changeset
199 if widget.getValue() == value:
ded2431cea5a Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 118
diff changeset
200 self.content.remove(widget)
ded2431cea5a Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 118
diff changeset
201 self._emit('change')
ded2431cea5a Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 118
diff changeset
202 return
ded2431cea5a Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 118
diff changeset
203 raise ValueError("%s ==> %s" % (str(value),str(self.content)))
116
7c482ecac0ff primitivus: basic contact list, connexion now work \o/
Goffi <goffi@goffi.org>
parents: 114
diff changeset
204
119
ded2431cea5a Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 118
diff changeset
205 def getSelectedValue(self):
114
77f48939ad6e primitivus: added Alert widget
Goffi <goffi@goffi.org>
parents: 113
diff changeset
206 """Convenience method to get the value selected as a string in single mode, or None"""
119
ded2431cea5a Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 118
diff changeset
207 values = self.getSelectedValues()
114
77f48939ad6e primitivus: added Alert widget
Goffi <goffi@goffi.org>
parents: 113
diff changeset
208 return values[0] if values else None
77f48939ad6e primitivus: added Alert widget
Goffi <goffi@goffi.org>
parents: 113
diff changeset
209
119
ded2431cea5a Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 118
diff changeset
210 def getAllValues(self):
ded2431cea5a Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 118
diff changeset
211 """Return values of all items"""
ded2431cea5a Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 118
diff changeset
212 return [widget.getValue() for widget in self.content]
ded2431cea5a Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 118
diff changeset
213
ded2431cea5a Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 118
diff changeset
214 def getSelectedValues(self):
ded2431cea5a Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 118
diff changeset
215 """Return values of selected items"""
113
e5ca22113280 Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
216 result = []
e5ca22113280 Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
217 for widget in self.content:
e5ca22113280 Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
218 if widget.getState():
e5ca22113280 Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
219 result.append(widget.getValue())
e5ca22113280 Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
220 return result
e5ca22113280 Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
221
119
ded2431cea5a Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 118
diff changeset
222 def getDisplayWidget(self):
ded2431cea5a Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 118
diff changeset
223 return self.list_box
ded2431cea5a Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 118
diff changeset
224
113
e5ca22113280 Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
225 def changeValues(self, new_values):
116
7c482ecac0ff primitivus: basic contact list, connexion now work \o/
Goffi <goffi@goffi.org>
parents: 114
diff changeset
226 """Change all value in one shot"""
119
ded2431cea5a Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 118
diff changeset
227 if not self.first_display:
ded2431cea5a Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 118
diff changeset
228 old_selected = self.getSelectedValues()
ded2431cea5a Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 118
diff changeset
229 widgets = []
ded2431cea5a Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 118
diff changeset
230 for option in new_values:
124
961e0898271f primitivus chat window
Goffi <goffi@goffi.org>
parents: 121
diff changeset
231 widget = self.option_type(option, self.align)
119
ded2431cea5a Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 118
diff changeset
232 if not self.first_display and option in old_selected:
ded2431cea5a Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 118
diff changeset
233 widget.setState(True)
ded2431cea5a Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 118
diff changeset
234 widgets.append(widget)
124
961e0898271f primitivus chat window
Goffi <goffi@goffi.org>
parents: 121
diff changeset
235 try:
961e0898271f primitivus chat window
Goffi <goffi@goffi.org>
parents: 121
diff changeset
236 urwid.connect_signal(widget, 'change', self.__onStateChange)
961e0898271f primitivus chat window
Goffi <goffi@goffi.org>
parents: 121
diff changeset
237 except NameError:
961e0898271f primitivus chat window
Goffi <goffi@goffi.org>
parents: 121
diff changeset
238 pass #the widget given doesn't support 'change' signal
113
e5ca22113280 Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
239 self.content[:] = widgets
119
ded2431cea5a Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 118
diff changeset
240 if self.first_display and self.single and new_values and not self.no_first_select:
114
77f48939ad6e primitivus: added Alert widget
Goffi <goffi@goffi.org>
parents: 113
diff changeset
241 self.content[0].setState(True)
119
ded2431cea5a Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 118
diff changeset
242 display_widget = self.getDisplayWidget()
118
76055a209ed9 primitivus: added edition zone at the bottom
Goffi <goffi@goffi.org>
parents: 117
diff changeset
243 self._set_w(display_widget)
119
ded2431cea5a Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 118
diff changeset
244 self._emit('change')
ded2431cea5a Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 118
diff changeset
245 self.first_display = False
ded2431cea5a Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 118
diff changeset
246
113
e5ca22113280 Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
247 def selectValue(self, value):
e5ca22113280 Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
248 self.unselectAll()
e5ca22113280 Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
249 idx = 0
e5ca22113280 Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
250 for widget in self.content:
119
ded2431cea5a Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 118
diff changeset
251 if widget.getSelectedValue() == value:
113
e5ca22113280 Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
252 widget.setState(True)
e5ca22113280 Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
253 self.list_box.set_focus(idx)
e5ca22113280 Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
254 return
e5ca22113280 Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
255 idx+=1
e5ca22113280 Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
256
119
ded2431cea5a Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 118
diff changeset
257 class List(urwid.FlowWidget):
ded2431cea5a Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 118
diff changeset
258 """FlowWidget list, same arguments as GenericList, with an additional one 'max_height'"""
ded2431cea5a Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 118
diff changeset
259 signals = ['click','change']
ded2431cea5a Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 118
diff changeset
260
124
961e0898271f primitivus chat window
Goffi <goffi@goffi.org>
parents: 121
diff changeset
261 def __init__(self, options, style=[], max_height=5, align='left', option_type = SelectableText, on_click=None, on_change=None, user_data=None):
961e0898271f primitivus chat window
Goffi <goffi@goffi.org>
parents: 121
diff changeset
262 self.genericList = GenericList(options, style, align, option_type, on_click, on_change, user_data)
119
ded2431cea5a Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 118
diff changeset
263 self.max_height = max_height
ded2431cea5a Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 118
diff changeset
264
ded2431cea5a Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 118
diff changeset
265 def selectable(self):
ded2431cea5a Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 118
diff changeset
266 return True
ded2431cea5a Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 118
diff changeset
267
ded2431cea5a Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 118
diff changeset
268 def keypress(self, size, key):
ded2431cea5a Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 118
diff changeset
269 return self.displayWidget(size,True).keypress(size, key)
ded2431cea5a Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 118
diff changeset
270
ded2431cea5a Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 118
diff changeset
271 def unselectAll(self, invisible=False):
ded2431cea5a Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 118
diff changeset
272 return self.genericList.unselectAll(invisible)
ded2431cea5a Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 118
diff changeset
273
ded2431cea5a Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 118
diff changeset
274 def deleteValue(self, value):
ded2431cea5a Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 118
diff changeset
275 return self.genericList.deleteValue(value)
ded2431cea5a Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 118
diff changeset
276
ded2431cea5a Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 118
diff changeset
277 def getSelectedValue(self):
ded2431cea5a Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 118
diff changeset
278 return self.genericList.getSelectedValue()
ded2431cea5a Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 118
diff changeset
279
ded2431cea5a Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 118
diff changeset
280 def getAllValues(self):
ded2431cea5a Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 118
diff changeset
281 return self.genericList.getAllValues()
ded2431cea5a Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 118
diff changeset
282
ded2431cea5a Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 118
diff changeset
283 def getSelectedValues(self):
ded2431cea5a Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 118
diff changeset
284 return self.genericList.getSelectedValues()
ded2431cea5a Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 118
diff changeset
285
ded2431cea5a Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 118
diff changeset
286 def changeValues(self, new_values):
ded2431cea5a Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 118
diff changeset
287 return self.genericList.changeValues(new_values)
ded2431cea5a Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 118
diff changeset
288
ded2431cea5a Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 118
diff changeset
289 def selectValue(self, value):
ded2431cea5a Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 118
diff changeset
290 return self.genericList.selectValue(value)
ded2431cea5a Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 118
diff changeset
291
ded2431cea5a Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 118
diff changeset
292 def render(self, size, focus=False):
ded2431cea5a Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 118
diff changeset
293 return self.displayWidget(size, focus).render(size, focus)
ded2431cea5a Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 118
diff changeset
294
ded2431cea5a Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 118
diff changeset
295 def rows(self, size, focus=False):
ded2431cea5a Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 118
diff changeset
296 return self.displayWidget(size, focus).rows(size, focus)
ded2431cea5a Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 118
diff changeset
297
ded2431cea5a Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 118
diff changeset
298 def displayWidget(self, size, focus):
ded2431cea5a Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 118
diff changeset
299 list_size = sum([wid.rows(size, focus) for wid in self.genericList.content])
120
1ca5f254ce41 primitivus group chat & misc
Goffi <goffi@goffi.org>
parents: 119
diff changeset
300 height = min(list_size,self.max_height) or 1
119
ded2431cea5a Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 118
diff changeset
301 return urwid.BoxAdapter(self.genericList, height)
ded2431cea5a Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 118
diff changeset
302
120
1ca5f254ce41 primitivus group chat & misc
Goffi <goffi@goffi.org>
parents: 119
diff changeset
303 ## DIALOGS ##
1ca5f254ce41 primitivus group chat & misc
Goffi <goffi@goffi.org>
parents: 119
diff changeset
304
119
ded2431cea5a Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 118
diff changeset
305 class GenericDialog(urwid.WidgetWrap):
113
e5ca22113280 Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
306
e5ca22113280 Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
307 def __init__(self, widgets_lst, title, style=[], **kwargs):
e5ca22113280 Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
308 frame_header = urwid.AttrMap(urwid.Text(title,'center'),'title')
e5ca22113280 Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
309
e5ca22113280 Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
310 buttons = None
e5ca22113280 Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
311
e5ca22113280 Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
312 if "OK/CANCEL" in style:
e5ca22113280 Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
313 buttons = [urwid.Button(_("Cancel"), kwargs['cancel_cb']),
e5ca22113280 Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
314 urwid.Button(_("Ok"), kwargs['ok_cb'], kwargs['ok_value'])]
e5ca22113280 Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
315 elif "YES/NO" in style:
e5ca22113280 Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
316 buttons = [urwid.Button(_("Yes"), kwargs['yes_cb']),
e5ca22113280 Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
317 urwid.Button(_("No"), kwargs['no_cb'], kwargs['yes_value'])]
114
77f48939ad6e primitivus: added Alert widget
Goffi <goffi@goffi.org>
parents: 113
diff changeset
318 if "OK" in style:
77f48939ad6e primitivus: added Alert widget
Goffi <goffi@goffi.org>
parents: 113
diff changeset
319 buttons = [urwid.Button(_("Ok"), kwargs['ok_cb'], kwargs['ok_value'])]
113
e5ca22113280 Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
320 if buttons:
e5ca22113280 Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
321 buttons_flow = urwid.GridFlow(buttons, max([len(button.get_label()) for button in buttons])+4, 1, 1, 'center')
e5ca22113280 Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
322 widgets_lst.append(buttons_flow)
e5ca22113280 Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
323 body_content = urwid.SimpleListWalker(widgets_lst)
e5ca22113280 Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
324 frame_body = urwid.ListBox(body_content)
e5ca22113280 Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
325 frame = urwid.Frame(frame_body, frame_header)
e5ca22113280 Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
326 decorated_frame = urwid.LineBox(frame)
e5ca22113280 Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
327 urwid.WidgetWrap.__init__(self, decorated_frame)
e5ca22113280 Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
328
e5ca22113280 Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
329
e5ca22113280 Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
330
119
ded2431cea5a Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 118
diff changeset
331 class InputDialog(GenericDialog):
121
03d8bcc67182 misc documentation
Goffi <goffi@goffi.org>
parents: 120
diff changeset
332 """Dialog with an edit box"""
113
e5ca22113280 Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
333
120
1ca5f254ce41 primitivus group chat & misc
Goffi <goffi@goffi.org>
parents: 119
diff changeset
334 def __init__(self, title, instrucions, style=['OK/CANCEL'], default_txt = '', **kwargs):
113
e5ca22113280 Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
335 instr_wid = urwid.Text(instrucions+':')
120
1ca5f254ce41 primitivus group chat & misc
Goffi <goffi@goffi.org>
parents: 119
diff changeset
336 edit_box = urwid.Edit(edit_text=default_txt)
119
ded2431cea5a Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 118
diff changeset
337 GenericDialog.__init__(self, [instr_wid,edit_box], title, style, ok_value=edit_box, **kwargs)
113
e5ca22113280 Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
338
119
ded2431cea5a Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 118
diff changeset
339 class ConfirmDialog(GenericDialog):
121
03d8bcc67182 misc documentation
Goffi <goffi@goffi.org>
parents: 120
diff changeset
340 """Dialog with buttons for confirm or cancel an action"""
113
e5ca22113280 Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
341
e5ca22113280 Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
342 def __init__(self, title, style=['YES/NO'], **kwargs):
119
ded2431cea5a Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 118
diff changeset
343 GenericDialog.__init__(self, [], title, style, yes_value=None, **kwargs)
114
77f48939ad6e primitivus: added Alert widget
Goffi <goffi@goffi.org>
parents: 113
diff changeset
344
119
ded2431cea5a Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 118
diff changeset
345 class Alert(GenericDialog):
121
03d8bcc67182 misc documentation
Goffi <goffi@goffi.org>
parents: 120
diff changeset
346 """Dialog with just a message and a OK button"""
114
77f48939ad6e primitivus: added Alert widget
Goffi <goffi@goffi.org>
parents: 113
diff changeset
347
77f48939ad6e primitivus: added Alert widget
Goffi <goffi@goffi.org>
parents: 113
diff changeset
348 def __init__(self, title, message, style=['OK'], **kwargs):
119
ded2431cea5a Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 118
diff changeset
349 GenericDialog.__init__(self, [urwid.Text(message, 'center')], title, style, ok_value=None, **kwargs)
ded2431cea5a Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 118
diff changeset
350
120
1ca5f254ce41 primitivus group chat & misc
Goffi <goffi@goffi.org>
parents: 119
diff changeset
351 ## CONTAINERS ##
1ca5f254ce41 primitivus group chat & misc
Goffi <goffi@goffi.org>
parents: 119
diff changeset
352
119
ded2431cea5a Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 118
diff changeset
353 class FocusFrame(urwid.Frame):
121
03d8bcc67182 misc documentation
Goffi <goffi@goffi.org>
parents: 120
diff changeset
354 """Frame which manage 'tab' key"""
119
ded2431cea5a Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 118
diff changeset
355
ded2431cea5a Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 118
diff changeset
356 def keypress(self, size, key):
ded2431cea5a Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 118
diff changeset
357 if key == 'tab':
ded2431cea5a Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 118
diff changeset
358 focus_list = ('header','body','footer')
ded2431cea5a Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 118
diff changeset
359 focus_idx = focus_list.index(self.focus_part)
ded2431cea5a Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 118
diff changeset
360 for i in range(2):
ded2431cea5a Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 118
diff changeset
361 focus_idx = (focus_idx + 1) % len(focus_list)
ded2431cea5a Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 118
diff changeset
362 focus_name = focus_list[focus_idx]
ded2431cea5a Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 118
diff changeset
363 widget = getattr(self,'_'+focus_name)
ded2431cea5a Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 118
diff changeset
364 if widget!=None and widget.selectable():
ded2431cea5a Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 118
diff changeset
365 self.set_focus(focus_name)
ded2431cea5a Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 118
diff changeset
366
ded2431cea5a Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 118
diff changeset
367 return urwid.Frame.keypress(self, size, key)
120
1ca5f254ce41 primitivus group chat & misc
Goffi <goffi@goffi.org>
parents: 119
diff changeset
368
1ca5f254ce41 primitivus group chat & misc
Goffi <goffi@goffi.org>
parents: 119
diff changeset
369 ## DECORATORS ##
1ca5f254ce41 primitivus group chat & misc
Goffi <goffi@goffi.org>
parents: 119
diff changeset
370 class LabelLine(urwid.LineBox):
121
03d8bcc67182 misc documentation
Goffi <goffi@goffi.org>
parents: 120
diff changeset
371 """Like LineBox, but with a Label centered in the top line"""
120
1ca5f254ce41 primitivus group chat & misc
Goffi <goffi@goffi.org>
parents: 119
diff changeset
372
1ca5f254ce41 primitivus group chat & misc
Goffi <goffi@goffi.org>
parents: 119
diff changeset
373 def __init__(self, original_widget, label_widget):
1ca5f254ce41 primitivus group chat & misc
Goffi <goffi@goffi.org>
parents: 119
diff changeset
374 urwid.LineBox.__init__(self, original_widget)
1ca5f254ce41 primitivus group chat & misc
Goffi <goffi@goffi.org>
parents: 119
diff changeset
375 top_columns = self._w.widget_list[0]
1ca5f254ce41 primitivus group chat & misc
Goffi <goffi@goffi.org>
parents: 119
diff changeset
376 top_columns.widget_list[1] = label_widget
124
961e0898271f primitivus chat window
Goffi <goffi@goffi.org>
parents: 121
diff changeset
377
961e0898271f primitivus chat window
Goffi <goffi@goffi.org>
parents: 121
diff changeset
378 class VerticalSeparator(urwid.WidgetDecoration, urwid.WidgetWrap):
961e0898271f primitivus chat window
Goffi <goffi@goffi.org>
parents: 121
diff changeset
379 def __init__(self, original_widget, left_char = utf8decode("│"), right_char = ''):
961e0898271f primitivus chat window
Goffi <goffi@goffi.org>
parents: 121
diff changeset
380 """Draw a separator on left and/or of original_widget."""
120
1ca5f254ce41 primitivus group chat & misc
Goffi <goffi@goffi.org>
parents: 119
diff changeset
381
124
961e0898271f primitivus chat window
Goffi <goffi@goffi.org>
parents: 121
diff changeset
382 widgets = [original_widget]
961e0898271f primitivus chat window
Goffi <goffi@goffi.org>
parents: 121
diff changeset
383 if left_char:
961e0898271f primitivus chat window
Goffi <goffi@goffi.org>
parents: 121
diff changeset
384 widgets.insert(0, ('fixed', 1, urwid.SolidFill(left_char)))
961e0898271f primitivus chat window
Goffi <goffi@goffi.org>
parents: 121
diff changeset
385 if right_char:
961e0898271f primitivus chat window
Goffi <goffi@goffi.org>
parents: 121
diff changeset
386 widgets.append(('fixed', 1, urwid.SolidFill(right_char)))
961e0898271f primitivus chat window
Goffi <goffi@goffi.org>
parents: 121
diff changeset
387 columns = urwid.Columns(widgets, box_columns = [0,2], focus_column = 1)
961e0898271f primitivus chat window
Goffi <goffi@goffi.org>
parents: 121
diff changeset
388 urwid.WidgetDecoration.__init__(self, original_widget)
961e0898271f primitivus chat window
Goffi <goffi@goffi.org>
parents: 121
diff changeset
389 urwid.WidgetWrap.__init__(self, columns)
961e0898271f primitivus chat window
Goffi <goffi@goffi.org>
parents: 121
diff changeset
390
961e0898271f primitivus chat window
Goffi <goffi@goffi.org>
parents: 121
diff changeset
391