annotate frontends/primitivus/custom_widgets.py @ 7:94868f58850b

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