annotate frontends/primitivus/custom_widgets.py @ 11:983840425a55

Primitivus: menu is now working /!\ tooltips not managed yet, doesn't manage properly menu when it's displayed on several rows /!\ still need to manage other menus (chat menu)
author Goffi <goffi@goffi.org>
date Wed, 14 Jul 2010 19:36:40 +0800
parents 024b79b61a31
children 7e63429cc929
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):
10
024b79b61a31 Primitivus: misc fixes + menubar first draft
Goffi <goffi@goffi.org>
parents: 9
diff changeset
26 toto=0
7
94868f58850b misc documentation
Goffi <goffi@goffi.org>
parents: 6
diff changeset
27 """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
28
cb72fb2bfa0d Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
29 def __init__(self, *args, **kwargs):
7
94868f58850b misc documentation
Goffi <goffi@goffi.org>
parents: 6
diff changeset
30 """Same args than Edit.__init__ with an additional keyword arg 'hidden_char'
94868f58850b misc documentation
Goffi <goffi@goffi.org>
parents: 6
diff changeset
31 @param hidden_char: char to show instead of what is actually entered: default '*'
94868f58850b misc documentation
Goffi <goffi@goffi.org>
parents: 6
diff changeset
32 """
0
cb72fb2bfa0d Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
33 self.hidden_char=kwargs['hidden_char'] if kwargs.has_key('hidden_char') else '*'
cb72fb2bfa0d Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
34 self.__real_text=''
cb72fb2bfa0d Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
35 super(Password, self).__init__(*args, **kwargs)
cb72fb2bfa0d Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
36
cb72fb2bfa0d Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
37 def set_edit_text(self, text):
cb72fb2bfa0d Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
38 self.__real_text = text
cb72fb2bfa0d Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
39 hidden_txt = len(text)*'*'
cb72fb2bfa0d Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
40 super(Password, self).set_edit_text(hidden_txt)
cb72fb2bfa0d Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
41
cb72fb2bfa0d Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
42 def get_edit_text(self):
cb72fb2bfa0d Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
43 return self.__real_text
cb72fb2bfa0d Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
44
10
024b79b61a31 Primitivus: misc fixes + menubar first draft
Goffi <goffi@goffi.org>
parents: 9
diff changeset
45 def insert_text(self, text):
024b79b61a31 Primitivus: misc fixes + menubar first draft
Goffi <goffi@goffi.org>
parents: 9
diff changeset
46 self._edit_text = self.__real_text
024b79b61a31 Primitivus: misc fixes + menubar first draft
Goffi <goffi@goffi.org>
parents: 9
diff changeset
47 super(Password,self).insert_text(text)
024b79b61a31 Primitivus: misc fixes + menubar first draft
Goffi <goffi@goffi.org>
parents: 9
diff changeset
48
024b79b61a31 Primitivus: misc fixes + menubar first draft
Goffi <goffi@goffi.org>
parents: 9
diff changeset
49 def render(self, size, focus=False):
024b79b61a31 Primitivus: misc fixes + menubar first draft
Goffi <goffi@goffi.org>
parents: 9
diff changeset
50 Password.toto+=1
024b79b61a31 Primitivus: misc fixes + menubar first draft
Goffi <goffi@goffi.org>
parents: 9
diff changeset
51 if Password.toto==30:
024b79b61a31 Primitivus: misc fixes + menubar first draft
Goffi <goffi@goffi.org>
parents: 9
diff changeset
52 import os,pdb
024b79b61a31 Primitivus: misc fixes + menubar first draft
Goffi <goffi@goffi.org>
parents: 9
diff changeset
53 os.system('reset')
024b79b61a31 Primitivus: misc fixes + menubar first draft
Goffi <goffi@goffi.org>
parents: 9
diff changeset
54 pdb.set_trace()
024b79b61a31 Primitivus: misc fixes + menubar first draft
Goffi <goffi@goffi.org>
parents: 9
diff changeset
55 return super(Password, self).render(size, focus)
024b79b61a31 Primitivus: misc fixes + menubar first draft
Goffi <goffi@goffi.org>
parents: 9
diff changeset
56
4
c94cdbfdf3e8 primitivus: added edition zone at the bottom
Goffi <goffi@goffi.org>
parents: 3
diff changeset
57 class AdvancedEdit(urwid.Edit):
7
94868f58850b misc documentation
Goffi <goffi@goffi.org>
parents: 6
diff changeset
58 """Edit box with some custom improvments
94868f58850b misc documentation
Goffi <goffi@goffi.org>
parents: 6
diff changeset
59 new chars:
94868f58850b misc documentation
Goffi <goffi@goffi.org>
parents: 6
diff changeset
60 - C-a: like 'home'
94868f58850b misc documentation
Goffi <goffi@goffi.org>
parents: 6
diff changeset
61 - C-e: like 'end'
94868f58850b misc documentation
Goffi <goffi@goffi.org>
parents: 6
diff changeset
62 - C-k: remove everything on the right of the cursor
94868f58850b misc documentation
Goffi <goffi@goffi.org>
parents: 6
diff changeset
63 - C-w: remove the word on the back
94868f58850b misc documentation
Goffi <goffi@goffi.org>
parents: 6
diff changeset
64 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
65 signals = urwid.Edit.signals + ['click']
4
c94cdbfdf3e8 primitivus: added edition zone at the bottom
Goffi <goffi@goffi.org>
parents: 3
diff changeset
66
c94cdbfdf3e8 primitivus: added edition zone at the bottom
Goffi <goffi@goffi.org>
parents: 3
diff changeset
67 def keypress(self, size, key):
c94cdbfdf3e8 primitivus: added edition zone at the bottom
Goffi <goffi@goffi.org>
parents: 3
diff changeset
68 #TODO: insert mode is not managed yet
c94cdbfdf3e8 primitivus: added edition zone at the bottom
Goffi <goffi@goffi.org>
parents: 3
diff changeset
69 if key == 'ctrl a':
c94cdbfdf3e8 primitivus: added edition zone at the bottom
Goffi <goffi@goffi.org>
parents: 3
diff changeset
70 key = 'home'
c94cdbfdf3e8 primitivus: added edition zone at the bottom
Goffi <goffi@goffi.org>
parents: 3
diff changeset
71 elif key == 'ctrl e':
c94cdbfdf3e8 primitivus: added edition zone at the bottom
Goffi <goffi@goffi.org>
parents: 3
diff changeset
72 key = 'end'
c94cdbfdf3e8 primitivus: added edition zone at the bottom
Goffi <goffi@goffi.org>
parents: 3
diff changeset
73 elif key == 'ctrl k':
c94cdbfdf3e8 primitivus: added edition zone at the bottom
Goffi <goffi@goffi.org>
parents: 3
diff changeset
74 self._delete_highlighted()
c94cdbfdf3e8 primitivus: added edition zone at the bottom
Goffi <goffi@goffi.org>
parents: 3
diff changeset
75 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
76 elif key == 'ctrl w':
c94cdbfdf3e8 primitivus: added edition zone at the bottom
Goffi <goffi@goffi.org>
parents: 3
diff changeset
77 before = self.edit_text[:self.edit_pos]
c94cdbfdf3e8 primitivus: added edition zone at the bottom
Goffi <goffi@goffi.org>
parents: 3
diff changeset
78 pos = before.rstrip().rfind(" ")+1
c94cdbfdf3e8 primitivus: added edition zone at the bottom
Goffi <goffi@goffi.org>
parents: 3
diff changeset
79 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
80 self.set_edit_pos(pos)
5
592cd64933dd Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 4
diff changeset
81 elif key == 'enter':
592cd64933dd Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 4
diff changeset
82 self._emit('click')
4
c94cdbfdf3e8 primitivus: added edition zone at the bottom
Goffi <goffi@goffi.org>
parents: 3
diff changeset
83 return super(AdvancedEdit, self).keypress(size, key)
c94cdbfdf3e8 primitivus: added edition zone at the bottom
Goffi <goffi@goffi.org>
parents: 3
diff changeset
84
c94cdbfdf3e8 primitivus: added edition zone at the bottom
Goffi <goffi@goffi.org>
parents: 3
diff changeset
85
6
d586d06a9d8f primitivus group chat & misc
Goffi <goffi@goffi.org>
parents: 5
diff changeset
86 class SurroundedText(urwid.FlowWidget):
7
94868f58850b misc documentation
Goffi <goffi@goffi.org>
parents: 6
diff changeset
87 """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
88
d586d06a9d8f primitivus group chat & misc
Goffi <goffi@goffi.org>
parents: 5
diff changeset
89 def __init__(self,text,car=utf8decode('─')):
d586d06a9d8f primitivus group chat & misc
Goffi <goffi@goffi.org>
parents: 5
diff changeset
90 self.text=text
d586d06a9d8f primitivus group chat & misc
Goffi <goffi@goffi.org>
parents: 5
diff changeset
91 self.car=car
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 def rows(self,size,focus=False):
d586d06a9d8f primitivus group chat & misc
Goffi <goffi@goffi.org>
parents: 5
diff changeset
94 return self.display_widget(size, focus).rows(size, focus)
d586d06a9d8f primitivus group chat & misc
Goffi <goffi@goffi.org>
parents: 5
diff changeset
95
d586d06a9d8f primitivus group chat & misc
Goffi <goffi@goffi.org>
parents: 5
diff changeset
96 def render(self, size, focus=False):
d586d06a9d8f primitivus group chat & misc
Goffi <goffi@goffi.org>
parents: 5
diff changeset
97 return self.display_widget(size, focus).render(size, focus)
d586d06a9d8f primitivus group chat & misc
Goffi <goffi@goffi.org>
parents: 5
diff changeset
98
d586d06a9d8f primitivus group chat & misc
Goffi <goffi@goffi.org>
parents: 5
diff changeset
99 def display_widget(self, size, focus):
d586d06a9d8f primitivus group chat & misc
Goffi <goffi@goffi.org>
parents: 5
diff changeset
100 (maxcol,) = size
d586d06a9d8f primitivus group chat & misc
Goffi <goffi@goffi.org>
parents: 5
diff changeset
101 middle = (maxcol-len(self.text))/2
d586d06a9d8f primitivus group chat & misc
Goffi <goffi@goffi.org>
parents: 5
diff changeset
102 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
103 return urwid.Text(render_text)
d586d06a9d8f primitivus group chat & misc
Goffi <goffi@goffi.org>
parents: 5
diff changeset
104
d586d06a9d8f primitivus group chat & misc
Goffi <goffi@goffi.org>
parents: 5
diff changeset
105
d586d06a9d8f primitivus group chat & misc
Goffi <goffi@goffi.org>
parents: 5
diff changeset
106
0
cb72fb2bfa0d Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
107 class SelectableText(urwid.FlowWidget):
6
d586d06a9d8f primitivus group chat & misc
Goffi <goffi@goffi.org>
parents: 5
diff changeset
108 """Text which can be selected with space"""
0
cb72fb2bfa0d Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
109 signals = ['change']
cb72fb2bfa0d Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
110
9
6650747dfdcb primitivus: contact list enhancement
Goffi <goffi@goffi.org>
parents: 8
diff changeset
111 def __init__(self, text, align='left', header='', select_attr=None, default_attr=None, selected = False, data=None):
0
cb72fb2bfa0d Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
112 self.text=unicode(text)
9
6650747dfdcb primitivus: contact list enhancement
Goffi <goffi@goffi.org>
parents: 8
diff changeset
113 self.header=header
6650747dfdcb primitivus: contact list enhancement
Goffi <goffi@goffi.org>
parents: 8
diff changeset
114 if data:
6650747dfdcb primitivus: contact list enhancement
Goffi <goffi@goffi.org>
parents: 8
diff changeset
115 self.data=data
6650747dfdcb primitivus: contact list enhancement
Goffi <goffi@goffi.org>
parents: 8
diff changeset
116 if select_attr:
6650747dfdcb primitivus: contact list enhancement
Goffi <goffi@goffi.org>
parents: 8
diff changeset
117 self.selected = select_attr
6650747dfdcb primitivus: contact list enhancement
Goffi <goffi@goffi.org>
parents: 8
diff changeset
118 if default_attr:
6650747dfdcb primitivus: contact list enhancement
Goffi <goffi@goffi.org>
parents: 8
diff changeset
119 self.default = default_attr
0
cb72fb2bfa0d Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
120 self.align = align
9
6650747dfdcb primitivus: contact list enhancement
Goffi <goffi@goffi.org>
parents: 8
diff changeset
121 self.__selected=selected
0
cb72fb2bfa0d Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
122
cb72fb2bfa0d Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
123 def getValue(self):
cb72fb2bfa0d Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
124 return self.text
9
6650747dfdcb primitivus: contact list enhancement
Goffi <goffi@goffi.org>
parents: 8
diff changeset
125
6650747dfdcb primitivus: contact list enhancement
Goffi <goffi@goffi.org>
parents: 8
diff changeset
126 def setAttribute(self, name, value):
6650747dfdcb primitivus: contact list enhancement
Goffi <goffi@goffi.org>
parents: 8
diff changeset
127 """Change attribut used for rendering widget
6650747dfdcb primitivus: contact list enhancement
Goffi <goffi@goffi.org>
parents: 8
diff changeset
128 @param name: one of
6650747dfdcb primitivus: contact list enhancement
Goffi <goffi@goffi.org>
parents: 8
diff changeset
129 -default: when not selected
6650747dfdcb primitivus: contact list enhancement
Goffi <goffi@goffi.org>
parents: 8
diff changeset
130 -selected: when selected
6650747dfdcb primitivus: contact list enhancement
Goffi <goffi@goffi.org>
parents: 8
diff changeset
131 @param value: name of the attribute
6650747dfdcb primitivus: contact list enhancement
Goffi <goffi@goffi.org>
parents: 8
diff changeset
132 /!\ the attribute name followed by _focus is used when widget has focus"""
6650747dfdcb primitivus: contact list enhancement
Goffi <goffi@goffi.org>
parents: 8
diff changeset
133 assert name in ['default', 'selected']
6650747dfdcb primitivus: contact list enhancement
Goffi <goffi@goffi.org>
parents: 8
diff changeset
134 self.__setattr__(name,value)
6650747dfdcb primitivus: contact list enhancement
Goffi <goffi@goffi.org>
parents: 8
diff changeset
135 self._invalidate()
0
cb72fb2bfa0d Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
136
cb72fb2bfa0d Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
137 def setState(self, selected, invisible=False):
cb72fb2bfa0d Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
138 """Change state
cb72fb2bfa0d Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
139 @param selected: boolean state value
cb72fb2bfa0d Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
140 @param invisible: don't emit change signal if True"""
cb72fb2bfa0d Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
141 assert(type(selected)==bool)
cb72fb2bfa0d Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
142 self.__selected=selected
5
592cd64933dd Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 4
diff changeset
143 self._invalidate()
0
cb72fb2bfa0d Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
144 if not invisible:
cb72fb2bfa0d Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
145 self._emit("change", self.__selected)
cb72fb2bfa0d Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
146
cb72fb2bfa0d Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
147 def getState(self):
cb72fb2bfa0d Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
148 return self.__selected
cb72fb2bfa0d Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
149
cb72fb2bfa0d Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
150 def selectable(self):
cb72fb2bfa0d Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
151 return True
cb72fb2bfa0d Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
152
cb72fb2bfa0d Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
153 def keypress(self, size, key):
cb72fb2bfa0d Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
154 if key==' ' or key=='enter':
cb72fb2bfa0d Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
155 self.setState(not self.__selected)
cb72fb2bfa0d Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
156 else:
cb72fb2bfa0d Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
157 return key
cb72fb2bfa0d Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
158
cb72fb2bfa0d Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
159 def rows(self,size,focus=False):
cb72fb2bfa0d Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
160 return self.display_widget(size, focus).rows(size, focus)
cb72fb2bfa0d Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
161
cb72fb2bfa0d Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
162 def render(self, size, focus=False):
cb72fb2bfa0d Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
163 return self.display_widget(size, focus).render(size, focus)
cb72fb2bfa0d Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
164
cb72fb2bfa0d Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
165 def display_widget(self, size, focus):
9
6650747dfdcb primitivus: contact list enhancement
Goffi <goffi@goffi.org>
parents: 8
diff changeset
166 try:
6650747dfdcb primitivus: contact list enhancement
Goffi <goffi@goffi.org>
parents: 8
diff changeset
167 select_attr = self.selected
6650747dfdcb primitivus: contact list enhancement
Goffi <goffi@goffi.org>
parents: 8
diff changeset
168 except AttributeError:
6650747dfdcb primitivus: contact list enhancement
Goffi <goffi@goffi.org>
parents: 8
diff changeset
169 select_attr = 'selected'
6650747dfdcb primitivus: contact list enhancement
Goffi <goffi@goffi.org>
parents: 8
diff changeset
170 try:
6650747dfdcb primitivus: contact list enhancement
Goffi <goffi@goffi.org>
parents: 8
diff changeset
171 default_attr = self.default
6650747dfdcb primitivus: contact list enhancement
Goffi <goffi@goffi.org>
parents: 8
diff changeset
172 except AttributeError:
6650747dfdcb primitivus: contact list enhancement
Goffi <goffi@goffi.org>
parents: 8
diff changeset
173 default_attr = 'default'
6650747dfdcb primitivus: contact list enhancement
Goffi <goffi@goffi.org>
parents: 8
diff changeset
174 attr = select_attr if self.__selected else default_attr
0
cb72fb2bfa0d Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
175 if focus:
cb72fb2bfa0d Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
176 attr+="_focus"
9
6650747dfdcb primitivus: contact list enhancement
Goffi <goffi@goffi.org>
parents: 8
diff changeset
177 return urwid.Text((attr,self.header+self.text), align=self.align)
0
cb72fb2bfa0d Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
178
9
6650747dfdcb primitivus: contact list enhancement
Goffi <goffi@goffi.org>
parents: 8
diff changeset
179 class ClickableText(SelectableText):
6650747dfdcb primitivus: contact list enhancement
Goffi <goffi@goffi.org>
parents: 8
diff changeset
180 signals = SelectableText.signals + ['click']
8
ec01505ec109 primitivus chat window
Goffi <goffi@goffi.org>
parents: 7
diff changeset
181
ec01505ec109 primitivus chat window
Goffi <goffi@goffi.org>
parents: 7
diff changeset
182 def setState(self, selected, invisible=False):
9
6650747dfdcb primitivus: contact list enhancement
Goffi <goffi@goffi.org>
parents: 8
diff changeset
183 self._emit('click')
8
ec01505ec109 primitivus chat window
Goffi <goffi@goffi.org>
parents: 7
diff changeset
184
5
592cd64933dd Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 4
diff changeset
185 class GenericList(urwid.WidgetWrap):
592cd64933dd Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 4
diff changeset
186 signals = ['click','change']
0
cb72fb2bfa0d Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
187
8
ec01505ec109 primitivus chat window
Goffi <goffi@goffi.org>
parents: 7
diff changeset
188 def __init__(self, options, style=[], align='left', option_type = SelectableText, on_click=None, on_change=None, user_data=None):
5
592cd64933dd Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 4
diff changeset
189 """
592cd64933dd Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 4
diff changeset
190 Widget managing list of string and their selection
592cd64933dd Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 4
diff changeset
191 @param options: list of strings used for options
592cd64933dd Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 4
diff changeset
192 @param style: list of string:
592cd64933dd Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 4
diff changeset
193 - 'single' if only one must be selected
592cd64933dd Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 4
diff changeset
194 - 'no_first_select' nothing selected when list is first displayed
592cd64933dd Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 4
diff changeset
195 - 'can_select_none' if we can select nothing
592cd64933dd Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 4
diff changeset
196 @param align: alignement of text inside the list
592cd64933dd Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 4
diff changeset
197 @param on_click: method called when click signal is emited
592cd64933dd Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 4
diff changeset
198 @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
199 """
0
cb72fb2bfa0d Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
200 self.single = 'single' in style
5
592cd64933dd Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 4
diff changeset
201 self.no_first_select = 'no_first_select' in style
592cd64933dd Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 4
diff changeset
202 self.can_select_none = 'can_select_none' in style
0
cb72fb2bfa0d Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
203 self.align = align
8
ec01505ec109 primitivus chat window
Goffi <goffi@goffi.org>
parents: 7
diff changeset
204 self.option_type = option_type
5
592cd64933dd Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 4
diff changeset
205 self.first_display = True
0
cb72fb2bfa0d Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
206
5
592cd64933dd Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 4
diff changeset
207 if on_click:
592cd64933dd Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 4
diff changeset
208 urwid.connect_signal(self, 'click', on_click, user_data)
592cd64933dd Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 4
diff changeset
209
592cd64933dd Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 4
diff changeset
210 if on_change:
592cd64933dd Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 4
diff changeset
211 urwid.connect_signal(self, 'change', on_change, user_data)
0
cb72fb2bfa0d Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
212
1
a5c9603dac37 primitivus: added Alert widget
Goffi <goffi@goffi.org>
parents: 0
diff changeset
213 self.content = urwid.SimpleListWalker([])
0
cb72fb2bfa0d Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
214 self.list_box = urwid.ListBox(self.content)
4
c94cdbfdf3e8 primitivus: added edition zone at the bottom
Goffi <goffi@goffi.org>
parents: 3
diff changeset
215 urwid.WidgetWrap.__init__(self, self.list_box)
1
a5c9603dac37 primitivus: added Alert widget
Goffi <goffi@goffi.org>
parents: 0
diff changeset
216 self.changeValues(options)
0
cb72fb2bfa0d Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
217
cb72fb2bfa0d Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
218 def __onStateChange(self, widget, selected):
cb72fb2bfa0d Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
219 if self.single:
5
592cd64933dd Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 4
diff changeset
220 if not selected and not self.can_select_none:
0
cb72fb2bfa0d Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
221 #if in single mode, it's forbidden to unselect a value
cb72fb2bfa0d Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
222 widget.setState(True, invisible=True)
cb72fb2bfa0d Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
223 return
5
592cd64933dd Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 4
diff changeset
224 if selected:
0
cb72fb2bfa0d Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
225 self.unselectAll(invisible=True)
cb72fb2bfa0d Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
226 widget.setState(True, invisible=True)
5
592cd64933dd Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 4
diff changeset
227 self._emit("click")
0
cb72fb2bfa0d Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
228
cb72fb2bfa0d Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
229
cb72fb2bfa0d Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
230 def unselectAll(self, invisible=False):
cb72fb2bfa0d Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
231 for widget in self.content:
cb72fb2bfa0d Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
232 if widget.getState():
cb72fb2bfa0d Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
233 widget.setState(False, invisible)
cb72fb2bfa0d Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
234 widget._invalidate()
cb72fb2bfa0d Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
235
2
07b7dcd314ff primitivus: basic contact list, connexion now work \o/
Goffi <goffi@goffi.org>
parents: 1
diff changeset
236 def deleteValue(self, value):
07b7dcd314ff primitivus: basic contact list, connexion now work \o/
Goffi <goffi@goffi.org>
parents: 1
diff changeset
237 """Delete the first value equal to the param given"""
5
592cd64933dd Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 4
diff changeset
238 for widget in self.content:
592cd64933dd Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 4
diff changeset
239 if widget.getValue() == value:
592cd64933dd Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 4
diff changeset
240 self.content.remove(widget)
592cd64933dd Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 4
diff changeset
241 self._emit('change')
592cd64933dd Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 4
diff changeset
242 return
592cd64933dd Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 4
diff changeset
243 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
244
5
592cd64933dd Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 4
diff changeset
245 def getSelectedValue(self):
1
a5c9603dac37 primitivus: added Alert widget
Goffi <goffi@goffi.org>
parents: 0
diff changeset
246 """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
247 values = self.getSelectedValues()
1
a5c9603dac37 primitivus: added Alert widget
Goffi <goffi@goffi.org>
parents: 0
diff changeset
248 return values[0] if values else None
a5c9603dac37 primitivus: added Alert widget
Goffi <goffi@goffi.org>
parents: 0
diff changeset
249
5
592cd64933dd Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 4
diff changeset
250 def getAllValues(self):
592cd64933dd Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 4
diff changeset
251 """Return values of all items"""
592cd64933dd Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 4
diff changeset
252 return [widget.getValue() for widget in self.content]
592cd64933dd Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 4
diff changeset
253
592cd64933dd Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 4
diff changeset
254 def getSelectedValues(self):
592cd64933dd Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 4
diff changeset
255 """Return values of selected items"""
0
cb72fb2bfa0d Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
256 result = []
cb72fb2bfa0d Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
257 for widget in self.content:
cb72fb2bfa0d Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
258 if widget.getState():
cb72fb2bfa0d Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
259 result.append(widget.getValue())
cb72fb2bfa0d Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
260 return result
cb72fb2bfa0d Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
261
5
592cd64933dd Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 4
diff changeset
262 def getDisplayWidget(self):
592cd64933dd Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 4
diff changeset
263 return self.list_box
592cd64933dd Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 4
diff changeset
264
0
cb72fb2bfa0d Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
265 def changeValues(self, new_values):
2
07b7dcd314ff primitivus: basic contact list, connexion now work \o/
Goffi <goffi@goffi.org>
parents: 1
diff changeset
266 """Change all value in one shot"""
5
592cd64933dd Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 4
diff changeset
267 if not self.first_display:
592cd64933dd Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 4
diff changeset
268 old_selected = self.getSelectedValues()
592cd64933dd Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 4
diff changeset
269 widgets = []
592cd64933dd Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 4
diff changeset
270 for option in new_values:
8
ec01505ec109 primitivus chat window
Goffi <goffi@goffi.org>
parents: 7
diff changeset
271 widget = self.option_type(option, self.align)
5
592cd64933dd Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 4
diff changeset
272 if not self.first_display and option in old_selected:
592cd64933dd Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 4
diff changeset
273 widget.setState(True)
592cd64933dd Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 4
diff changeset
274 widgets.append(widget)
8
ec01505ec109 primitivus chat window
Goffi <goffi@goffi.org>
parents: 7
diff changeset
275 try:
ec01505ec109 primitivus chat window
Goffi <goffi@goffi.org>
parents: 7
diff changeset
276 urwid.connect_signal(widget, 'change', self.__onStateChange)
ec01505ec109 primitivus chat window
Goffi <goffi@goffi.org>
parents: 7
diff changeset
277 except NameError:
ec01505ec109 primitivus chat window
Goffi <goffi@goffi.org>
parents: 7
diff changeset
278 pass #the widget given doesn't support 'change' signal
0
cb72fb2bfa0d Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
279 self.content[:] = widgets
5
592cd64933dd Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 4
diff changeset
280 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
281 self.content[0].setState(True)
5
592cd64933dd Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 4
diff changeset
282 display_widget = self.getDisplayWidget()
4
c94cdbfdf3e8 primitivus: added edition zone at the bottom
Goffi <goffi@goffi.org>
parents: 3
diff changeset
283 self._set_w(display_widget)
5
592cd64933dd Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 4
diff changeset
284 self._emit('change')
592cd64933dd Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 4
diff changeset
285 self.first_display = False
592cd64933dd Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 4
diff changeset
286
0
cb72fb2bfa0d Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
287 def selectValue(self, value):
cb72fb2bfa0d Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
288 self.unselectAll()
cb72fb2bfa0d Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
289 idx = 0
cb72fb2bfa0d Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
290 for widget in self.content:
5
592cd64933dd Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 4
diff changeset
291 if widget.getSelectedValue() == value:
0
cb72fb2bfa0d Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
292 widget.setState(True)
cb72fb2bfa0d Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
293 self.list_box.set_focus(idx)
cb72fb2bfa0d Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
294 return
cb72fb2bfa0d Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
295 idx+=1
cb72fb2bfa0d Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
296
5
592cd64933dd Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 4
diff changeset
297 class List(urwid.FlowWidget):
592cd64933dd Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 4
diff changeset
298 """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
299 signals = ['click','change']
592cd64933dd Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 4
diff changeset
300
8
ec01505ec109 primitivus chat window
Goffi <goffi@goffi.org>
parents: 7
diff changeset
301 def __init__(self, options, style=[], max_height=5, align='left', option_type = SelectableText, on_click=None, on_change=None, user_data=None):
ec01505ec109 primitivus chat window
Goffi <goffi@goffi.org>
parents: 7
diff changeset
302 self.genericList = GenericList(options, style, align, option_type, on_click, on_change, user_data)
5
592cd64933dd Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 4
diff changeset
303 self.max_height = max_height
592cd64933dd Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 4
diff changeset
304
592cd64933dd Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 4
diff changeset
305 def selectable(self):
592cd64933dd Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 4
diff changeset
306 return True
592cd64933dd Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 4
diff changeset
307
592cd64933dd Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 4
diff changeset
308 def keypress(self, size, key):
592cd64933dd Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 4
diff changeset
309 return self.displayWidget(size,True).keypress(size, key)
592cd64933dd Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 4
diff changeset
310
592cd64933dd Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 4
diff changeset
311 def unselectAll(self, invisible=False):
592cd64933dd Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 4
diff changeset
312 return self.genericList.unselectAll(invisible)
592cd64933dd Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 4
diff changeset
313
592cd64933dd Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 4
diff changeset
314 def deleteValue(self, value):
592cd64933dd Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 4
diff changeset
315 return self.genericList.deleteValue(value)
592cd64933dd Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 4
diff changeset
316
592cd64933dd Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 4
diff changeset
317 def getSelectedValue(self):
592cd64933dd Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 4
diff changeset
318 return self.genericList.getSelectedValue()
592cd64933dd Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 4
diff changeset
319
592cd64933dd Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 4
diff changeset
320 def getAllValues(self):
592cd64933dd Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 4
diff changeset
321 return self.genericList.getAllValues()
592cd64933dd Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 4
diff changeset
322
592cd64933dd Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 4
diff changeset
323 def getSelectedValues(self):
592cd64933dd Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 4
diff changeset
324 return self.genericList.getSelectedValues()
592cd64933dd Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 4
diff changeset
325
592cd64933dd Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 4
diff changeset
326 def changeValues(self, new_values):
592cd64933dd Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 4
diff changeset
327 return self.genericList.changeValues(new_values)
592cd64933dd Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 4
diff changeset
328
592cd64933dd Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 4
diff changeset
329 def selectValue(self, value):
592cd64933dd Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 4
diff changeset
330 return self.genericList.selectValue(value)
592cd64933dd Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 4
diff changeset
331
592cd64933dd Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 4
diff changeset
332 def render(self, size, focus=False):
592cd64933dd Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 4
diff changeset
333 return self.displayWidget(size, focus).render(size, focus)
592cd64933dd Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 4
diff changeset
334
592cd64933dd Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 4
diff changeset
335 def rows(self, size, focus=False):
592cd64933dd Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 4
diff changeset
336 return self.displayWidget(size, focus).rows(size, focus)
592cd64933dd Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 4
diff changeset
337
592cd64933dd Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 4
diff changeset
338 def displayWidget(self, size, focus):
592cd64933dd Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 4
diff changeset
339 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
340 height = min(list_size,self.max_height) or 1
5
592cd64933dd Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 4
diff changeset
341 return urwid.BoxAdapter(self.genericList, height)
592cd64933dd Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 4
diff changeset
342
10
024b79b61a31 Primitivus: misc fixes + menubar first draft
Goffi <goffi@goffi.org>
parents: 9
diff changeset
343 ## MISC ##
024b79b61a31 Primitivus: misc fixes + menubar first draft
Goffi <goffi@goffi.org>
parents: 9
diff changeset
344
11
983840425a55 Primitivus: menu is now working
Goffi <goffi@goffi.org>
parents: 10
diff changeset
345 class MenuBox(urwid.WidgetWrap):
983840425a55 Primitivus: menu is now working
Goffi <goffi@goffi.org>
parents: 10
diff changeset
346 signals = ['click']
983840425a55 Primitivus: menu is now working
Goffi <goffi@goffi.org>
parents: 10
diff changeset
347
983840425a55 Primitivus: menu is now working
Goffi <goffi@goffi.org>
parents: 10
diff changeset
348 def __init__(self,parent,items):
983840425a55 Primitivus: menu is now working
Goffi <goffi@goffi.org>
parents: 10
diff changeset
349 self.parent = parent
983840425a55 Primitivus: menu is now working
Goffi <goffi@goffi.org>
parents: 10
diff changeset
350 self.selected = None
983840425a55 Primitivus: menu is now working
Goffi <goffi@goffi.org>
parents: 10
diff changeset
351 content = urwid.SimpleListWalker([ClickableText(text,default_attr='menuitem') for text in items])
983840425a55 Primitivus: menu is now working
Goffi <goffi@goffi.org>
parents: 10
diff changeset
352 for wid in content:
983840425a55 Primitivus: menu is now working
Goffi <goffi@goffi.org>
parents: 10
diff changeset
353 urwid.connect_signal(wid, 'click', self.onClick)
983840425a55 Primitivus: menu is now working
Goffi <goffi@goffi.org>
parents: 10
diff changeset
354
983840425a55 Primitivus: menu is now working
Goffi <goffi@goffi.org>
parents: 10
diff changeset
355 self.listBox = urwid.ListBox(content)
983840425a55 Primitivus: menu is now working
Goffi <goffi@goffi.org>
parents: 10
diff changeset
356 menubox = urwid.LineBox(urwid.BoxAdapter(self.listBox,len(items)))
983840425a55 Primitivus: menu is now working
Goffi <goffi@goffi.org>
parents: 10
diff changeset
357 urwid.WidgetWrap.__init__(self,menubox)
983840425a55 Primitivus: menu is now working
Goffi <goffi@goffi.org>
parents: 10
diff changeset
358
983840425a55 Primitivus: menu is now working
Goffi <goffi@goffi.org>
parents: 10
diff changeset
359 def getValue(self):
983840425a55 Primitivus: menu is now working
Goffi <goffi@goffi.org>
parents: 10
diff changeset
360 return self.selected
983840425a55 Primitivus: menu is now working
Goffi <goffi@goffi.org>
parents: 10
diff changeset
361
983840425a55 Primitivus: menu is now working
Goffi <goffi@goffi.org>
parents: 10
diff changeset
362 def keypress(self, size, key):
983840425a55 Primitivus: menu is now working
Goffi <goffi@goffi.org>
parents: 10
diff changeset
363 if key=='up':
983840425a55 Primitivus: menu is now working
Goffi <goffi@goffi.org>
parents: 10
diff changeset
364 if self.listBox.get_focus()[1] == 0:
983840425a55 Primitivus: menu is now working
Goffi <goffi@goffi.org>
parents: 10
diff changeset
365 self.parent.keypress(size, key)
983840425a55 Primitivus: menu is now working
Goffi <goffi@goffi.org>
parents: 10
diff changeset
366 elif key=='left' or key=='right':
983840425a55 Primitivus: menu is now working
Goffi <goffi@goffi.org>
parents: 10
diff changeset
367 self.parent.keypress(size,'up')
983840425a55 Primitivus: menu is now working
Goffi <goffi@goffi.org>
parents: 10
diff changeset
368 self.parent.keypress(size,key)
983840425a55 Primitivus: menu is now working
Goffi <goffi@goffi.org>
parents: 10
diff changeset
369 return super(MenuBox,self).keypress(size,key)
983840425a55 Primitivus: menu is now working
Goffi <goffi@goffi.org>
parents: 10
diff changeset
370
983840425a55 Primitivus: menu is now working
Goffi <goffi@goffi.org>
parents: 10
diff changeset
371 def onClick(self, wid):
983840425a55 Primitivus: menu is now working
Goffi <goffi@goffi.org>
parents: 10
diff changeset
372 self.selected = wid.getValue()
983840425a55 Primitivus: menu is now working
Goffi <goffi@goffi.org>
parents: 10
diff changeset
373 self._emit('click')
983840425a55 Primitivus: menu is now working
Goffi <goffi@goffi.org>
parents: 10
diff changeset
374
10
024b79b61a31 Primitivus: misc fixes + menubar first draft
Goffi <goffi@goffi.org>
parents: 9
diff changeset
375 class Menu(urwid.FlowWidget):
024b79b61a31 Primitivus: misc fixes + menubar first draft
Goffi <goffi@goffi.org>
parents: 9
diff changeset
376
11
983840425a55 Primitivus: menu is now working
Goffi <goffi@goffi.org>
parents: 10
diff changeset
377 def __init__(self,loop):
10
024b79b61a31 Primitivus: misc fixes + menubar first draft
Goffi <goffi@goffi.org>
parents: 9
diff changeset
378 super(Menu, self).__init__()
11
983840425a55 Primitivus: menu is now working
Goffi <goffi@goffi.org>
parents: 10
diff changeset
379 self.loop = loop
983840425a55 Primitivus: menu is now working
Goffi <goffi@goffi.org>
parents: 10
diff changeset
380 self.menu_keys = []
983840425a55 Primitivus: menu is now working
Goffi <goffi@goffi.org>
parents: 10
diff changeset
381 self.menu = {}
10
024b79b61a31 Primitivus: misc fixes + menubar first draft
Goffi <goffi@goffi.org>
parents: 9
diff changeset
382 self.shortcuts = {} #keyboard shortcuts
11
983840425a55 Primitivus: menu is now working
Goffi <goffi@goffi.org>
parents: 10
diff changeset
383 self.focus_menu = 0
983840425a55 Primitivus: menu is now working
Goffi <goffi@goffi.org>
parents: 10
diff changeset
384 self.save_bottom = None
983840425a55 Primitivus: menu is now working
Goffi <goffi@goffi.org>
parents: 10
diff changeset
385
983840425a55 Primitivus: menu is now working
Goffi <goffi@goffi.org>
parents: 10
diff changeset
386 def selectable(self):
983840425a55 Primitivus: menu is now working
Goffi <goffi@goffi.org>
parents: 10
diff changeset
387 return True
983840425a55 Primitivus: menu is now working
Goffi <goffi@goffi.org>
parents: 10
diff changeset
388
983840425a55 Primitivus: menu is now working
Goffi <goffi@goffi.org>
parents: 10
diff changeset
389 def __buildOverlay(self,menu_key,columns):
983840425a55 Primitivus: menu is now working
Goffi <goffi@goffi.org>
parents: 10
diff changeset
390 """Build the overlay menu which show menuitems
983840425a55 Primitivus: menu is now working
Goffi <goffi@goffi.org>
parents: 10
diff changeset
391 @param menu_key: name of the category
983840425a55 Primitivus: menu is now working
Goffi <goffi@goffi.org>
parents: 10
diff changeset
392 @colums: column number where the menubox must be displayed"""
983840425a55 Primitivus: menu is now working
Goffi <goffi@goffi.org>
parents: 10
diff changeset
393 max_len = 0
983840425a55 Primitivus: menu is now working
Goffi <goffi@goffi.org>
parents: 10
diff changeset
394 for item in self.menu[menu_key]:
983840425a55 Primitivus: menu is now working
Goffi <goffi@goffi.org>
parents: 10
diff changeset
395 if len(item[0]) > max_len:
983840425a55 Primitivus: menu is now working
Goffi <goffi@goffi.org>
parents: 10
diff changeset
396 max_len = len(item[0])
983840425a55 Primitivus: menu is now working
Goffi <goffi@goffi.org>
parents: 10
diff changeset
397
983840425a55 Primitivus: menu is now working
Goffi <goffi@goffi.org>
parents: 10
diff changeset
398 self.save_bottom = self.loop.widget
983840425a55 Primitivus: menu is now working
Goffi <goffi@goffi.org>
parents: 10
diff changeset
399 menu_box = MenuBox(self,[item[0] for item in self.menu[menu_key]])
983840425a55 Primitivus: menu is now working
Goffi <goffi@goffi.org>
parents: 10
diff changeset
400 urwid.connect_signal(menu_box, 'click', self.onClick)
983840425a55 Primitivus: menu is now working
Goffi <goffi@goffi.org>
parents: 10
diff changeset
401
983840425a55 Primitivus: menu is now working
Goffi <goffi@goffi.org>
parents: 10
diff changeset
402 self.loop.widget = urwid.Overlay(urwid.AttrMap(menu_box,'menubar'),self.save_bottom,('fixed left', columns),max_len+2,('fixed top',1),None)
983840425a55 Primitivus: menu is now working
Goffi <goffi@goffi.org>
parents: 10
diff changeset
403
983840425a55 Primitivus: menu is now working
Goffi <goffi@goffi.org>
parents: 10
diff changeset
404 def keypress(self, size, key):
983840425a55 Primitivus: menu is now working
Goffi <goffi@goffi.org>
parents: 10
diff changeset
405 if key == 'right' and self.focus_menu < len(self.menu)-1:
983840425a55 Primitivus: menu is now working
Goffi <goffi@goffi.org>
parents: 10
diff changeset
406 self.focus_menu += 1
983840425a55 Primitivus: menu is now working
Goffi <goffi@goffi.org>
parents: 10
diff changeset
407 self._invalidate()
983840425a55 Primitivus: menu is now working
Goffi <goffi@goffi.org>
parents: 10
diff changeset
408 elif key == 'left' and self.focus_menu > 0:
983840425a55 Primitivus: menu is now working
Goffi <goffi@goffi.org>
parents: 10
diff changeset
409 self.focus_menu -= 1
983840425a55 Primitivus: menu is now working
Goffi <goffi@goffi.org>
parents: 10
diff changeset
410 self._invalidate()
983840425a55 Primitivus: menu is now working
Goffi <goffi@goffi.org>
parents: 10
diff changeset
411 elif key == 'down':
983840425a55 Primitivus: menu is now working
Goffi <goffi@goffi.org>
parents: 10
diff changeset
412 if not self.save_bottom:
983840425a55 Primitivus: menu is now working
Goffi <goffi@goffi.org>
parents: 10
diff changeset
413 column = sum([len(menu)+4 for menu in self.menu_keys[0:self.focus_menu]],self.focus_menu+1)
983840425a55 Primitivus: menu is now working
Goffi <goffi@goffi.org>
parents: 10
diff changeset
414 self.__buildOverlay(self.menu_keys[self.focus_menu],column)
983840425a55 Primitivus: menu is now working
Goffi <goffi@goffi.org>
parents: 10
diff changeset
415 elif key == 'up':
983840425a55 Primitivus: menu is now working
Goffi <goffi@goffi.org>
parents: 10
diff changeset
416 if self.save_bottom:
983840425a55 Primitivus: menu is now working
Goffi <goffi@goffi.org>
parents: 10
diff changeset
417 self.loop.widget = self.save_bottom
983840425a55 Primitivus: menu is now working
Goffi <goffi@goffi.org>
parents: 10
diff changeset
418 self.save_bottom = None
983840425a55 Primitivus: menu is now working
Goffi <goffi@goffi.org>
parents: 10
diff changeset
419
983840425a55 Primitivus: menu is now working
Goffi <goffi@goffi.org>
parents: 10
diff changeset
420 return key
10
024b79b61a31 Primitivus: misc fixes + menubar first draft
Goffi <goffi@goffi.org>
parents: 9
diff changeset
421
024b79b61a31 Primitivus: misc fixes + menubar first draft
Goffi <goffi@goffi.org>
parents: 9
diff changeset
422 def checkShortcuts(self, key):
024b79b61a31 Primitivus: misc fixes + menubar first draft
Goffi <goffi@goffi.org>
parents: 9
diff changeset
423 for shortcut in self.shortcuts.keys():
024b79b61a31 Primitivus: misc fixes + menubar first draft
Goffi <goffi@goffi.org>
parents: 9
diff changeset
424 if key == shortcut:
11
983840425a55 Primitivus: menu is now working
Goffi <goffi@goffi.org>
parents: 10
diff changeset
425 category, item, callback = self.shortcuts[shortcut]
10
024b79b61a31 Primitivus: misc fixes + menubar first draft
Goffi <goffi@goffi.org>
parents: 9
diff changeset
426 callback((category, item))
024b79b61a31 Primitivus: misc fixes + menubar first draft
Goffi <goffi@goffi.org>
parents: 9
diff changeset
427 return key
024b79b61a31 Primitivus: misc fixes + menubar first draft
Goffi <goffi@goffi.org>
parents: 9
diff changeset
428
024b79b61a31 Primitivus: misc fixes + menubar first draft
Goffi <goffi@goffi.org>
parents: 9
diff changeset
429 def addMenu(self, category, item, callback, shortcut=None):
024b79b61a31 Primitivus: misc fixes + menubar first draft
Goffi <goffi@goffi.org>
parents: 9
diff changeset
430 """Add a menu item, create the category if new
024b79b61a31 Primitivus: misc fixes + menubar first draft
Goffi <goffi@goffi.org>
parents: 9
diff changeset
431 @param category: category of the menu (e.g. File/Edit)
024b79b61a31 Primitivus: misc fixes + menubar first draft
Goffi <goffi@goffi.org>
parents: 9
diff changeset
432 @param item: menu item (e.g. new/close/about)
024b79b61a31 Primitivus: misc fixes + menubar first draft
Goffi <goffi@goffi.org>
parents: 9
diff changeset
433 @callback: method to call when item is selected"""
024b79b61a31 Primitivus: misc fixes + menubar first draft
Goffi <goffi@goffi.org>
parents: 9
diff changeset
434 if not category in self.menu.keys():
024b79b61a31 Primitivus: misc fixes + menubar first draft
Goffi <goffi@goffi.org>
parents: 9
diff changeset
435 self.menu_keys.append(category)
024b79b61a31 Primitivus: misc fixes + menubar first draft
Goffi <goffi@goffi.org>
parents: 9
diff changeset
436 self.menu[category] = []
11
983840425a55 Primitivus: menu is now working
Goffi <goffi@goffi.org>
parents: 10
diff changeset
437 self.menu[category].append((item, callback))
10
024b79b61a31 Primitivus: misc fixes + menubar first draft
Goffi <goffi@goffi.org>
parents: 9
diff changeset
438 if shortcut:
024b79b61a31 Primitivus: misc fixes + menubar first draft
Goffi <goffi@goffi.org>
parents: 9
diff changeset
439 assert(shortcut not in self.shortcuts.keys())
024b79b61a31 Primitivus: misc fixes + menubar first draft
Goffi <goffi@goffi.org>
parents: 9
diff changeset
440 self.shortcuts[shortcut] = (category, item, callback)
024b79b61a31 Primitivus: misc fixes + menubar first draft
Goffi <goffi@goffi.org>
parents: 9
diff changeset
441
024b79b61a31 Primitivus: misc fixes + menubar first draft
Goffi <goffi@goffi.org>
parents: 9
diff changeset
442 def rows(self,size,focus=False):
024b79b61a31 Primitivus: misc fixes + menubar first draft
Goffi <goffi@goffi.org>
parents: 9
diff changeset
443 return self.display_widget(size, focus).rows(size, focus)
024b79b61a31 Primitivus: misc fixes + menubar first draft
Goffi <goffi@goffi.org>
parents: 9
diff changeset
444
024b79b61a31 Primitivus: misc fixes + menubar first draft
Goffi <goffi@goffi.org>
parents: 9
diff changeset
445 def render(self, size, focus=False):
024b79b61a31 Primitivus: misc fixes + menubar first draft
Goffi <goffi@goffi.org>
parents: 9
diff changeset
446 return self.display_widget(size, focus).render(size, focus)
024b79b61a31 Primitivus: misc fixes + menubar first draft
Goffi <goffi@goffi.org>
parents: 9
diff changeset
447
024b79b61a31 Primitivus: misc fixes + menubar first draft
Goffi <goffi@goffi.org>
parents: 9
diff changeset
448 def display_widget(self, size, focus):
024b79b61a31 Primitivus: misc fixes + menubar first draft
Goffi <goffi@goffi.org>
parents: 9
diff changeset
449 render_txt = []
11
983840425a55 Primitivus: menu is now working
Goffi <goffi@goffi.org>
parents: 10
diff changeset
450 idx = 0
10
024b79b61a31 Primitivus: misc fixes + menubar first draft
Goffi <goffi@goffi.org>
parents: 9
diff changeset
451 for menu in self.menu_keys:
11
983840425a55 Primitivus: menu is now working
Goffi <goffi@goffi.org>
parents: 10
diff changeset
452 if focus and idx == self.focus_menu:
983840425a55 Primitivus: menu is now working
Goffi <goffi@goffi.org>
parents: 10
diff changeset
453 render_txt.append(('selected_menu', '[ %s ]' % menu))
983840425a55 Primitivus: menu is now working
Goffi <goffi@goffi.org>
parents: 10
diff changeset
454 render_txt.append(' ')
983840425a55 Primitivus: menu is now working
Goffi <goffi@goffi.org>
parents: 10
diff changeset
455 else:
983840425a55 Primitivus: menu is now working
Goffi <goffi@goffi.org>
parents: 10
diff changeset
456 render_txt.append('[ %s ] ' % menu)
983840425a55 Primitivus: menu is now working
Goffi <goffi@goffi.org>
parents: 10
diff changeset
457 idx += 1
10
024b79b61a31 Primitivus: misc fixes + menubar first draft
Goffi <goffi@goffi.org>
parents: 9
diff changeset
458 return urwid.AttrMap(urwid.Text(render_txt), 'menubar')
024b79b61a31 Primitivus: misc fixes + menubar first draft
Goffi <goffi@goffi.org>
parents: 9
diff changeset
459
11
983840425a55 Primitivus: menu is now working
Goffi <goffi@goffi.org>
parents: 10
diff changeset
460 def onClick(self, widget):
983840425a55 Primitivus: menu is now working
Goffi <goffi@goffi.org>
parents: 10
diff changeset
461 category = self.menu_keys[self.focus_menu]
983840425a55 Primitivus: menu is now working
Goffi <goffi@goffi.org>
parents: 10
diff changeset
462 item = widget.getValue()
983840425a55 Primitivus: menu is now working
Goffi <goffi@goffi.org>
parents: 10
diff changeset
463 for menu_item in self.menu[category]:
983840425a55 Primitivus: menu is now working
Goffi <goffi@goffi.org>
parents: 10
diff changeset
464 if item == menu_item[0]:
983840425a55 Primitivus: menu is now working
Goffi <goffi@goffi.org>
parents: 10
diff changeset
465 callback = menu_item[1]
983840425a55 Primitivus: menu is now working
Goffi <goffi@goffi.org>
parents: 10
diff changeset
466 break
983840425a55 Primitivus: menu is now working
Goffi <goffi@goffi.org>
parents: 10
diff changeset
467 if callback:
983840425a55 Primitivus: menu is now working
Goffi <goffi@goffi.org>
parents: 10
diff changeset
468 self.keypress(None,'up')
983840425a55 Primitivus: menu is now working
Goffi <goffi@goffi.org>
parents: 10
diff changeset
469 callback((category, item))
983840425a55 Primitivus: menu is now working
Goffi <goffi@goffi.org>
parents: 10
diff changeset
470
10
024b79b61a31 Primitivus: misc fixes + menubar first draft
Goffi <goffi@goffi.org>
parents: 9
diff changeset
471
6
d586d06a9d8f primitivus group chat & misc
Goffi <goffi@goffi.org>
parents: 5
diff changeset
472 ## DIALOGS ##
d586d06a9d8f primitivus group chat & misc
Goffi <goffi@goffi.org>
parents: 5
diff changeset
473
5
592cd64933dd Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 4
diff changeset
474 class GenericDialog(urwid.WidgetWrap):
0
cb72fb2bfa0d Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
475
cb72fb2bfa0d Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
476 def __init__(self, widgets_lst, title, style=[], **kwargs):
cb72fb2bfa0d Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
477 frame_header = urwid.AttrMap(urwid.Text(title,'center'),'title')
cb72fb2bfa0d Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
478
cb72fb2bfa0d Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
479 buttons = None
cb72fb2bfa0d Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
480
cb72fb2bfa0d Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
481 if "OK/CANCEL" in style:
cb72fb2bfa0d Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
482 buttons = [urwid.Button(_("Cancel"), kwargs['cancel_cb']),
cb72fb2bfa0d Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
483 urwid.Button(_("Ok"), kwargs['ok_cb'], kwargs['ok_value'])]
cb72fb2bfa0d Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
484 elif "YES/NO" in style:
cb72fb2bfa0d Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
485 buttons = [urwid.Button(_("Yes"), kwargs['yes_cb']),
cb72fb2bfa0d Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
486 urwid.Button(_("No"), kwargs['no_cb'], kwargs['yes_value'])]
1
a5c9603dac37 primitivus: added Alert widget
Goffi <goffi@goffi.org>
parents: 0
diff changeset
487 if "OK" in style:
a5c9603dac37 primitivus: added Alert widget
Goffi <goffi@goffi.org>
parents: 0
diff changeset
488 buttons = [urwid.Button(_("Ok"), kwargs['ok_cb'], kwargs['ok_value'])]
0
cb72fb2bfa0d Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
489 if buttons:
cb72fb2bfa0d Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
490 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
491 widgets_lst.append(buttons_flow)
cb72fb2bfa0d Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
492 body_content = urwid.SimpleListWalker(widgets_lst)
cb72fb2bfa0d Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
493 frame_body = urwid.ListBox(body_content)
cb72fb2bfa0d Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
494 frame = urwid.Frame(frame_body, frame_header)
cb72fb2bfa0d Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
495 decorated_frame = urwid.LineBox(frame)
cb72fb2bfa0d Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
496 urwid.WidgetWrap.__init__(self, decorated_frame)
cb72fb2bfa0d Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
497
cb72fb2bfa0d Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
498
cb72fb2bfa0d Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
499
5
592cd64933dd Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 4
diff changeset
500 class InputDialog(GenericDialog):
7
94868f58850b misc documentation
Goffi <goffi@goffi.org>
parents: 6
diff changeset
501 """Dialog with an edit box"""
0
cb72fb2bfa0d Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
502
6
d586d06a9d8f primitivus group chat & misc
Goffi <goffi@goffi.org>
parents: 5
diff changeset
503 def __init__(self, title, instrucions, style=['OK/CANCEL'], default_txt = '', **kwargs):
0
cb72fb2bfa0d Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
504 instr_wid = urwid.Text(instrucions+':')
6
d586d06a9d8f primitivus group chat & misc
Goffi <goffi@goffi.org>
parents: 5
diff changeset
505 edit_box = urwid.Edit(edit_text=default_txt)
5
592cd64933dd Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 4
diff changeset
506 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
507
5
592cd64933dd Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 4
diff changeset
508 class ConfirmDialog(GenericDialog):
7
94868f58850b misc documentation
Goffi <goffi@goffi.org>
parents: 6
diff changeset
509 """Dialog with buttons for confirm or cancel an action"""
0
cb72fb2bfa0d Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
510
cb72fb2bfa0d Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
511 def __init__(self, title, style=['YES/NO'], **kwargs):
5
592cd64933dd Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 4
diff changeset
512 GenericDialog.__init__(self, [], title, style, yes_value=None, **kwargs)
1
a5c9603dac37 primitivus: added Alert widget
Goffi <goffi@goffi.org>
parents: 0
diff changeset
513
5
592cd64933dd Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 4
diff changeset
514 class Alert(GenericDialog):
7
94868f58850b misc documentation
Goffi <goffi@goffi.org>
parents: 6
diff changeset
515 """Dialog with just a message and a OK button"""
1
a5c9603dac37 primitivus: added Alert widget
Goffi <goffi@goffi.org>
parents: 0
diff changeset
516
a5c9603dac37 primitivus: added Alert widget
Goffi <goffi@goffi.org>
parents: 0
diff changeset
517 def __init__(self, title, message, style=['OK'], **kwargs):
5
592cd64933dd Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 4
diff changeset
518 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
519
6
d586d06a9d8f primitivus group chat & misc
Goffi <goffi@goffi.org>
parents: 5
diff changeset
520 ## CONTAINERS ##
d586d06a9d8f primitivus group chat & misc
Goffi <goffi@goffi.org>
parents: 5
diff changeset
521
5
592cd64933dd Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 4
diff changeset
522 class FocusFrame(urwid.Frame):
7
94868f58850b misc documentation
Goffi <goffi@goffi.org>
parents: 6
diff changeset
523 """Frame which manage 'tab' key"""
5
592cd64933dd Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 4
diff changeset
524
592cd64933dd Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 4
diff changeset
525 def keypress(self, size, key):
592cd64933dd Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 4
diff changeset
526 if key == 'tab':
592cd64933dd Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 4
diff changeset
527 focus_list = ('header','body','footer')
592cd64933dd Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 4
diff changeset
528 focus_idx = focus_list.index(self.focus_part)
592cd64933dd Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 4
diff changeset
529 for i in range(2):
592cd64933dd Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 4
diff changeset
530 focus_idx = (focus_idx + 1) % len(focus_list)
592cd64933dd Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 4
diff changeset
531 focus_name = focus_list[focus_idx]
592cd64933dd Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 4
diff changeset
532 widget = getattr(self,'_'+focus_name)
592cd64933dd Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 4
diff changeset
533 if widget!=None and widget.selectable():
592cd64933dd Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 4
diff changeset
534 self.set_focus(focus_name)
592cd64933dd Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 4
diff changeset
535
592cd64933dd Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 4
diff changeset
536 return urwid.Frame.keypress(self, size, key)
6
d586d06a9d8f primitivus group chat & misc
Goffi <goffi@goffi.org>
parents: 5
diff changeset
537
d586d06a9d8f primitivus group chat & misc
Goffi <goffi@goffi.org>
parents: 5
diff changeset
538 ## DECORATORS ##
d586d06a9d8f primitivus group chat & misc
Goffi <goffi@goffi.org>
parents: 5
diff changeset
539 class LabelLine(urwid.LineBox):
7
94868f58850b misc documentation
Goffi <goffi@goffi.org>
parents: 6
diff changeset
540 """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
541
d586d06a9d8f primitivus group chat & misc
Goffi <goffi@goffi.org>
parents: 5
diff changeset
542 def __init__(self, original_widget, label_widget):
d586d06a9d8f primitivus group chat & misc
Goffi <goffi@goffi.org>
parents: 5
diff changeset
543 urwid.LineBox.__init__(self, original_widget)
d586d06a9d8f primitivus group chat & misc
Goffi <goffi@goffi.org>
parents: 5
diff changeset
544 top_columns = self._w.widget_list[0]
d586d06a9d8f primitivus group chat & misc
Goffi <goffi@goffi.org>
parents: 5
diff changeset
545 top_columns.widget_list[1] = label_widget
8
ec01505ec109 primitivus chat window
Goffi <goffi@goffi.org>
parents: 7
diff changeset
546
ec01505ec109 primitivus chat window
Goffi <goffi@goffi.org>
parents: 7
diff changeset
547 class VerticalSeparator(urwid.WidgetDecoration, urwid.WidgetWrap):
ec01505ec109 primitivus chat window
Goffi <goffi@goffi.org>
parents: 7
diff changeset
548 def __init__(self, original_widget, left_char = utf8decode("│"), right_char = ''):
ec01505ec109 primitivus chat window
Goffi <goffi@goffi.org>
parents: 7
diff changeset
549 """Draw a separator on left and/or of original_widget."""
6
d586d06a9d8f primitivus group chat & misc
Goffi <goffi@goffi.org>
parents: 5
diff changeset
550
8
ec01505ec109 primitivus chat window
Goffi <goffi@goffi.org>
parents: 7
diff changeset
551 widgets = [original_widget]
ec01505ec109 primitivus chat window
Goffi <goffi@goffi.org>
parents: 7
diff changeset
552 if left_char:
ec01505ec109 primitivus chat window
Goffi <goffi@goffi.org>
parents: 7
diff changeset
553 widgets.insert(0, ('fixed', 1, urwid.SolidFill(left_char)))
ec01505ec109 primitivus chat window
Goffi <goffi@goffi.org>
parents: 7
diff changeset
554 if right_char:
ec01505ec109 primitivus chat window
Goffi <goffi@goffi.org>
parents: 7
diff changeset
555 widgets.append(('fixed', 1, urwid.SolidFill(right_char)))
ec01505ec109 primitivus chat window
Goffi <goffi@goffi.org>
parents: 7
diff changeset
556 columns = urwid.Columns(widgets, box_columns = [0,2], focus_column = 1)
ec01505ec109 primitivus chat window
Goffi <goffi@goffi.org>
parents: 7
diff changeset
557 urwid.WidgetDecoration.__init__(self, original_widget)
ec01505ec109 primitivus chat window
Goffi <goffi@goffi.org>
parents: 7
diff changeset
558 urwid.WidgetWrap.__init__(self, columns)
ec01505ec109 primitivus chat window
Goffi <goffi@goffi.org>
parents: 7
diff changeset
559
ec01505ec109 primitivus chat window
Goffi <goffi@goffi.org>
parents: 7
diff changeset
560