Mercurial > urwid-satext
annotate urwid_satext/sat_widgets.py @ 66:287ff3e1edd1
removed trailing spaces
author | Goffi <goffi@goffi.org> |
---|---|
date | Sat, 21 Dec 2013 16:51:14 +0100 |
parents | 090f3e0754d3 |
children | c270867a80f9 |
rev | line source |
---|---|
0 | 1 #!/usr/bin/python |
2 # -*- coding: utf-8 -*- | |
3 | |
64 | 4 # Urwid SàT extensions |
5 # Copyright (C) 2009, 2010, 2011, 2012, 2013 Jérôme Poisson (goffi@goffi.org) | |
6 # | |
7 # This program is free software: you can redistribute it and/or modify | |
8 # it under the terms of the GNU Lesser General Public License as published by | |
9 # the Free Software Foundation, either version 3 of the License, or | |
10 # (at your option) any later version. | |
11 # | |
12 # This program is distributed in the hope that it will be useful, | |
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 # GNU Lesser General Public License for more details. | |
16 # | |
17 # You should have received a copy of the GNU Lesser General Public License | |
18 # along with this program. If not, see <http://www.gnu.org/licenses/>. | |
0 | 19 |
20 import urwid | |
26
fcc20ac7b68a
Primitivus: major changes in SelectableText, menu can now be used with mouse, TabsContainer show wich tab is selected
Goffi <goffi@goffi.org>
parents:
25
diff
changeset
|
21 from logging import debug, info, warning, error |
44 | 22 import encodings |
23 utf8decode = lambda s: encodings.codecs.utf_8_decode(s)[0] | |
0 | 24 |
59
a99951c9ce2a
Password now use AdvancedEdit to take advantage of shortcuts
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
25 from urwid.util import is_mouse_press #XXX: is_mouse_press is not included in urwid in 1.0.0 |
0 | 26 |
10
024b79b61a31
Primitivus: misc fixes + menubar first draft
Goffi <goffi@goffi.org>
parents:
9
diff
changeset
|
27 |
4
c94cdbfdf3e8
primitivus: added edition zone at the bottom
Goffi <goffi@goffi.org>
parents:
3
diff
changeset
|
28 class AdvancedEdit(urwid.Edit): |
7 | 29 """Edit box with some custom improvments |
30 new chars: | |
31 - C-a: like 'home' | |
32 - C-e: like 'end' | |
33 - C-k: remove everything on the right of the cursor | |
34 - C-w: remove the word on the back | |
35 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
|
36 signals = urwid.Edit.signals + ['click'] |
4
c94cdbfdf3e8
primitivus: added edition zone at the bottom
Goffi <goffi@goffi.org>
parents:
3
diff
changeset
|
37 |
22
dfabea6f73b5
Primitivus: AdvancedEdit and Notification bar improved
Goffi <goffi@goffi.org>
parents:
21
diff
changeset
|
38 def setCompletionMethod(self, callback): |
dfabea6f73b5
Primitivus: AdvancedEdit and Notification bar improved
Goffi <goffi@goffi.org>
parents:
21
diff
changeset
|
39 """Define method called when completion is asked |
dfabea6f73b5
Primitivus: AdvancedEdit and Notification bar improved
Goffi <goffi@goffi.org>
parents:
21
diff
changeset
|
40 @callback: method with 2 arguments: |
dfabea6f73b5
Primitivus: AdvancedEdit and Notification bar improved
Goffi <goffi@goffi.org>
parents:
21
diff
changeset
|
41 - the text to complete |
dfabea6f73b5
Primitivus: AdvancedEdit and Notification bar improved
Goffi <goffi@goffi.org>
parents:
21
diff
changeset
|
42 - if there was already a completion, a dict with |
dfabea6f73b5
Primitivus: AdvancedEdit and Notification bar improved
Goffi <goffi@goffi.org>
parents:
21
diff
changeset
|
43 - 'completed':last completion |
66 | 44 - 'completion_pos': cursor position where the completion starts |
22
dfabea6f73b5
Primitivus: AdvancedEdit and Notification bar improved
Goffi <goffi@goffi.org>
parents:
21
diff
changeset
|
45 - 'position': last completion cursor position |
dfabea6f73b5
Primitivus: AdvancedEdit and Notification bar improved
Goffi <goffi@goffi.org>
parents:
21
diff
changeset
|
46 this dict must be used (and can be filled) to find next completion) |
dfabea6f73b5
Primitivus: AdvancedEdit and Notification bar improved
Goffi <goffi@goffi.org>
parents:
21
diff
changeset
|
47 and which return the full text completed""" |
dfabea6f73b5
Primitivus: AdvancedEdit and Notification bar improved
Goffi <goffi@goffi.org>
parents:
21
diff
changeset
|
48 self.completion_cb = callback |
dfabea6f73b5
Primitivus: AdvancedEdit and Notification bar improved
Goffi <goffi@goffi.org>
parents:
21
diff
changeset
|
49 self.completion_data = {} |
dfabea6f73b5
Primitivus: AdvancedEdit and Notification bar improved
Goffi <goffi@goffi.org>
parents:
21
diff
changeset
|
50 |
4
c94cdbfdf3e8
primitivus: added edition zone at the bottom
Goffi <goffi@goffi.org>
parents:
3
diff
changeset
|
51 def keypress(self, size, key): |
c94cdbfdf3e8
primitivus: added edition zone at the bottom
Goffi <goffi@goffi.org>
parents:
3
diff
changeset
|
52 #TODO: insert mode is not managed yet |
c94cdbfdf3e8
primitivus: added edition zone at the bottom
Goffi <goffi@goffi.org>
parents:
3
diff
changeset
|
53 if key == 'ctrl a': |
c94cdbfdf3e8
primitivus: added edition zone at the bottom
Goffi <goffi@goffi.org>
parents:
3
diff
changeset
|
54 key = 'home' |
c94cdbfdf3e8
primitivus: added edition zone at the bottom
Goffi <goffi@goffi.org>
parents:
3
diff
changeset
|
55 elif key == 'ctrl e': |
c94cdbfdf3e8
primitivus: added edition zone at the bottom
Goffi <goffi@goffi.org>
parents:
3
diff
changeset
|
56 key = 'end' |
c94cdbfdf3e8
primitivus: added edition zone at the bottom
Goffi <goffi@goffi.org>
parents:
3
diff
changeset
|
57 elif key == 'ctrl k': |
c94cdbfdf3e8
primitivus: added edition zone at the bottom
Goffi <goffi@goffi.org>
parents:
3
diff
changeset
|
58 self._delete_highlighted() |
c94cdbfdf3e8
primitivus: added edition zone at the bottom
Goffi <goffi@goffi.org>
parents:
3
diff
changeset
|
59 self.set_edit_text(self.edit_text[:self.edit_pos]) |
66 | 60 elif key == 'ctrl w': |
4
c94cdbfdf3e8
primitivus: added edition zone at the bottom
Goffi <goffi@goffi.org>
parents:
3
diff
changeset
|
61 before = self.edit_text[:self.edit_pos] |
c94cdbfdf3e8
primitivus: added edition zone at the bottom
Goffi <goffi@goffi.org>
parents:
3
diff
changeset
|
62 pos = before.rstrip().rfind(" ")+1 |
c94cdbfdf3e8
primitivus: added edition zone at the bottom
Goffi <goffi@goffi.org>
parents:
3
diff
changeset
|
63 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
|
64 self.set_edit_pos(pos) |
5
592cd64933dd
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
4
diff
changeset
|
65 elif key == 'enter': |
592cd64933dd
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
4
diff
changeset
|
66 self._emit('click') |
22
dfabea6f73b5
Primitivus: AdvancedEdit and Notification bar improved
Goffi <goffi@goffi.org>
parents:
21
diff
changeset
|
67 elif key == 'shift tab': |
dfabea6f73b5
Primitivus: AdvancedEdit and Notification bar improved
Goffi <goffi@goffi.org>
parents:
21
diff
changeset
|
68 try: |
dfabea6f73b5
Primitivus: AdvancedEdit and Notification bar improved
Goffi <goffi@goffi.org>
parents:
21
diff
changeset
|
69 before = self.edit_text[:self.edit_pos] |
dfabea6f73b5
Primitivus: AdvancedEdit and Notification bar improved
Goffi <goffi@goffi.org>
parents:
21
diff
changeset
|
70 if self.completion_data: |
dfabea6f73b5
Primitivus: AdvancedEdit and Notification bar improved
Goffi <goffi@goffi.org>
parents:
21
diff
changeset
|
71 if (not self.completion_data['completed'] |
dfabea6f73b5
Primitivus: AdvancedEdit and Notification bar improved
Goffi <goffi@goffi.org>
parents:
21
diff
changeset
|
72 or self.completion_data['position'] != self.edit_pos |
dfabea6f73b5
Primitivus: AdvancedEdit and Notification bar improved
Goffi <goffi@goffi.org>
parents:
21
diff
changeset
|
73 or not before.endswith(self.completion_data['completed'])): |
dfabea6f73b5
Primitivus: AdvancedEdit and Notification bar improved
Goffi <goffi@goffi.org>
parents:
21
diff
changeset
|
74 self.completion_data.clear() |
dfabea6f73b5
Primitivus: AdvancedEdit and Notification bar improved
Goffi <goffi@goffi.org>
parents:
21
diff
changeset
|
75 else: |
dfabea6f73b5
Primitivus: AdvancedEdit and Notification bar improved
Goffi <goffi@goffi.org>
parents:
21
diff
changeset
|
76 before = before[:-len(self.completion_data['completed'])] |
dfabea6f73b5
Primitivus: AdvancedEdit and Notification bar improved
Goffi <goffi@goffi.org>
parents:
21
diff
changeset
|
77 complet = self.completion_cb(before, self.completion_data) |
dfabea6f73b5
Primitivus: AdvancedEdit and Notification bar improved
Goffi <goffi@goffi.org>
parents:
21
diff
changeset
|
78 self.completion_data['completed'] = complet[len(before):] |
dfabea6f73b5
Primitivus: AdvancedEdit and Notification bar improved
Goffi <goffi@goffi.org>
parents:
21
diff
changeset
|
79 self.set_edit_text(complet+self.edit_text[self.edit_pos:]) |
dfabea6f73b5
Primitivus: AdvancedEdit and Notification bar improved
Goffi <goffi@goffi.org>
parents:
21
diff
changeset
|
80 self.set_edit_pos(len(complet)) |
dfabea6f73b5
Primitivus: AdvancedEdit and Notification bar improved
Goffi <goffi@goffi.org>
parents:
21
diff
changeset
|
81 self.completion_data['position'] = self.edit_pos |
dfabea6f73b5
Primitivus: AdvancedEdit and Notification bar improved
Goffi <goffi@goffi.org>
parents:
21
diff
changeset
|
82 return |
dfabea6f73b5
Primitivus: AdvancedEdit and Notification bar improved
Goffi <goffi@goffi.org>
parents:
21
diff
changeset
|
83 except AttributeError: |
dfabea6f73b5
Primitivus: AdvancedEdit and Notification bar improved
Goffi <goffi@goffi.org>
parents:
21
diff
changeset
|
84 #No completion method defined |
dfabea6f73b5
Primitivus: AdvancedEdit and Notification bar improved
Goffi <goffi@goffi.org>
parents:
21
diff
changeset
|
85 pass |
66 | 86 return super(AdvancedEdit, self).keypress(size, key) |
59
a99951c9ce2a
Password now use AdvancedEdit to take advantage of shortcuts
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
87 |
a99951c9ce2a
Password now use AdvancedEdit to take advantage of shortcuts
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
88 class Password(AdvancedEdit): |
a99951c9ce2a
Password now use AdvancedEdit to take advantage of shortcuts
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
89 """Edit box which doesn't show what is entered (show '*' or other char instead)""" |
a99951c9ce2a
Password now use AdvancedEdit to take advantage of shortcuts
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
90 |
a99951c9ce2a
Password now use AdvancedEdit to take advantage of shortcuts
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
91 def __init__(self, *args, **kwargs): |
a99951c9ce2a
Password now use AdvancedEdit to take advantage of shortcuts
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
92 """Same args than Edit.__init__ with an additional keyword arg 'hidden_char' |
a99951c9ce2a
Password now use AdvancedEdit to take advantage of shortcuts
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
93 @param hidden_char: char to show instead of what is actually entered: default '*' |
a99951c9ce2a
Password now use AdvancedEdit to take advantage of shortcuts
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
94 """ |
a99951c9ce2a
Password now use AdvancedEdit to take advantage of shortcuts
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
95 self.hidden_char=kwargs['hidden_char'] if kwargs.has_key('hidden_char') else '*' |
a99951c9ce2a
Password now use AdvancedEdit to take advantage of shortcuts
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
96 self.__real_text='' |
a99951c9ce2a
Password now use AdvancedEdit to take advantage of shortcuts
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
97 super(Password, self).__init__(*args, **kwargs) |
a99951c9ce2a
Password now use AdvancedEdit to take advantage of shortcuts
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
98 |
a99951c9ce2a
Password now use AdvancedEdit to take advantage of shortcuts
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
99 def set_edit_text(self, text): |
a99951c9ce2a
Password now use AdvancedEdit to take advantage of shortcuts
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
100 self.__real_text = text |
a99951c9ce2a
Password now use AdvancedEdit to take advantage of shortcuts
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
101 hidden_txt = len(text)*'*' |
a99951c9ce2a
Password now use AdvancedEdit to take advantage of shortcuts
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
102 super(Password, self).set_edit_text(hidden_txt) |
a99951c9ce2a
Password now use AdvancedEdit to take advantage of shortcuts
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
103 |
a99951c9ce2a
Password now use AdvancedEdit to take advantage of shortcuts
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
104 def get_edit_text(self): |
a99951c9ce2a
Password now use AdvancedEdit to take advantage of shortcuts
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
105 return self.__real_text |
a99951c9ce2a
Password now use AdvancedEdit to take advantage of shortcuts
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
106 |
a99951c9ce2a
Password now use AdvancedEdit to take advantage of shortcuts
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
107 def insert_text(self, text): |
a99951c9ce2a
Password now use AdvancedEdit to take advantage of shortcuts
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
108 self._edit_text = self.__real_text |
a99951c9ce2a
Password now use AdvancedEdit to take advantage of shortcuts
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
109 super(Password,self).insert_text(text) |
a99951c9ce2a
Password now use AdvancedEdit to take advantage of shortcuts
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
110 |
a99951c9ce2a
Password now use AdvancedEdit to take advantage of shortcuts
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
111 def render(self, size, focus=False): |
a99951c9ce2a
Password now use AdvancedEdit to take advantage of shortcuts
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
112 return super(Password, self).render(size, focus) |
66 | 113 |
57 | 114 class ModalEdit(AdvancedEdit): |
115 """AdvancedEdit with vi-like mode management | |
116 - there is a new 'mode' property wich can be changed with properties | |
117 specified during init | |
118 - completion callback received a new 'mode' argument | |
119 """ | |
120 | |
121 def __init__(self, modes, *args, **kwargs): | |
122 """ first argument is "modes", others are the same paramaters as AdvancedEdit | |
123 @param modes: dictionnary in the form: | |
124 'key_to_change_mode': ('Mode', caption) | |
125 e.g.: 'i': ('INSERTION', '> ') | |
126 There *MUST* be a None key (for NORMAL mode)""" | |
127 assert(isinstance(modes, dict) and None in modes) | |
128 self._modes = modes | |
129 super(ModalEdit, self).__init__(*args, **kwargs) | |
130 self.mode = self._modes[None][0] | |
131 | |
132 @property | |
133 def mode(self): | |
134 return self._mode | |
135 | |
136 @mode.setter | |
137 def mode(self, value): | |
138 mode_key = None | |
139 for key in self._modes: | |
140 if self._modes[key][0] == value: | |
141 mode_key = key | |
142 break | |
66 | 143 |
57 | 144 mode, caption = self._modes[mode_key] |
145 self._mode = mode | |
146 self.set_caption(caption) | |
147 if not mode_key: #we are in NORMAL mode | |
148 self.set_edit_text('') | |
149 | |
150 def setCompletionMethod(self, callback): | |
151 """ Same as AdvancedEdit.setCompletionMethod, but with a third argument: current mode""" | |
152 super(ModalEdit, self).setCompletionMethod(lambda text,data: callback(text, data, self._mode)) | |
153 | |
154 def keypress(self, size, key): | |
155 if key == 'esc': | |
156 self.mode = "NORMAL" | |
157 return | |
158 if self._mode == 'NORMAL' and key in self._modes: | |
159 self.mode = self._modes[key][0] | |
160 return | |
66 | 161 return super(ModalEdit, self).keypress(size, key) |
4
c94cdbfdf3e8
primitivus: added edition zone at the bottom
Goffi <goffi@goffi.org>
parents:
3
diff
changeset
|
162 |
6 | 163 class SurroundedText(urwid.FlowWidget): |
7 | 164 """Text centered on a repeated character (like a Divider, but with a text in the center)""" |
6 | 165 |
166 def __init__(self,text,car=utf8decode('─')): | |
167 self.text=text | |
168 self.car=car | |
169 | |
170 def rows(self,size,focus=False): | |
171 return self.display_widget(size, focus).rows(size, focus) | |
172 | |
173 def render(self, size, focus=False): | |
174 return self.display_widget(size, focus).render(size, focus) | |
175 | |
176 def display_widget(self, size, focus): | |
177 (maxcol,) = size | |
178 middle = (maxcol-len(self.text))/2 | |
179 render_text = middle * self.car + self.text + (maxcol - len(self.text) - middle) * self.car | |
180 return urwid.Text(render_text) | |
181 | |
26
fcc20ac7b68a
Primitivus: major changes in SelectableText, menu can now be used with mouse, TabsContainer show wich tab is selected
Goffi <goffi@goffi.org>
parents:
25
diff
changeset
|
182 class SelectableText(urwid.WidgetWrap): |
6 | 183 """Text which can be selected with space""" |
0 | 184 signals = ['change'] |
66 | 185 |
26
fcc20ac7b68a
Primitivus: major changes in SelectableText, menu can now be used with mouse, TabsContainer show wich tab is selected
Goffi <goffi@goffi.org>
parents:
25
diff
changeset
|
186 def __init__(self, text, align='left', header='', focus_attr='default_focus', selected_text=None, selected=False, data=None): |
fcc20ac7b68a
Primitivus: major changes in SelectableText, menu can now be used with mouse, TabsContainer show wich tab is selected
Goffi <goffi@goffi.org>
parents:
25
diff
changeset
|
187 """@param text: same as urwid.Text's text parameter |
fcc20ac7b68a
Primitivus: major changes in SelectableText, menu can now be used with mouse, TabsContainer show wich tab is selected
Goffi <goffi@goffi.org>
parents:
25
diff
changeset
|
188 @param align: same as urwid.Text's align parameter |
fcc20ac7b68a
Primitivus: major changes in SelectableText, menu can now be used with mouse, TabsContainer show wich tab is selected
Goffi <goffi@goffi.org>
parents:
25
diff
changeset
|
189 @select_attr: attrbute to use when selected |
fcc20ac7b68a
Primitivus: major changes in SelectableText, menu can now be used with mouse, TabsContainer show wich tab is selected
Goffi <goffi@goffi.org>
parents:
25
diff
changeset
|
190 @param selected: is the text selected ?""" |
fcc20ac7b68a
Primitivus: major changes in SelectableText, menu can now be used with mouse, TabsContainer show wich tab is selected
Goffi <goffi@goffi.org>
parents:
25
diff
changeset
|
191 self.focus_attr = focus_attr |
fcc20ac7b68a
Primitivus: major changes in SelectableText, menu can now be used with mouse, TabsContainer show wich tab is selected
Goffi <goffi@goffi.org>
parents:
25
diff
changeset
|
192 self.__selected = False |
fcc20ac7b68a
Primitivus: major changes in SelectableText, menu can now be used with mouse, TabsContainer show wich tab is selected
Goffi <goffi@goffi.org>
parents:
25
diff
changeset
|
193 self.__was_focused = False |
fcc20ac7b68a
Primitivus: major changes in SelectableText, menu can now be used with mouse, TabsContainer show wich tab is selected
Goffi <goffi@goffi.org>
parents:
25
diff
changeset
|
194 self.header = self.__valid_text(header) |
fcc20ac7b68a
Primitivus: major changes in SelectableText, menu can now be used with mouse, TabsContainer show wich tab is selected
Goffi <goffi@goffi.org>
parents:
25
diff
changeset
|
195 self.default_txt = self.__valid_text(text) |
fcc20ac7b68a
Primitivus: major changes in SelectableText, menu can now be used with mouse, TabsContainer show wich tab is selected
Goffi <goffi@goffi.org>
parents:
25
diff
changeset
|
196 urwid.WidgetWrap.__init__(self, urwid.Text("",align=align)) |
fcc20ac7b68a
Primitivus: major changes in SelectableText, menu can now be used with mouse, TabsContainer show wich tab is selected
Goffi <goffi@goffi.org>
parents:
25
diff
changeset
|
197 self.setSelectedText(selected_text) |
fcc20ac7b68a
Primitivus: major changes in SelectableText, menu can now be used with mouse, TabsContainer show wich tab is selected
Goffi <goffi@goffi.org>
parents:
25
diff
changeset
|
198 self.setState(selected) |
fcc20ac7b68a
Primitivus: major changes in SelectableText, menu can now be used with mouse, TabsContainer show wich tab is selected
Goffi <goffi@goffi.org>
parents:
25
diff
changeset
|
199 |
fcc20ac7b68a
Primitivus: major changes in SelectableText, menu can now be used with mouse, TabsContainer show wich tab is selected
Goffi <goffi@goffi.org>
parents:
25
diff
changeset
|
200 def __valid_text(self, text): |
fcc20ac7b68a
Primitivus: major changes in SelectableText, menu can now be used with mouse, TabsContainer show wich tab is selected
Goffi <goffi@goffi.org>
parents:
25
diff
changeset
|
201 """Tmp method needed until dbus and urwid are more friends""" |
fcc20ac7b68a
Primitivus: major changes in SelectableText, menu can now be used with mouse, TabsContainer show wich tab is selected
Goffi <goffi@goffi.org>
parents:
25
diff
changeset
|
202 if isinstance(text,basestring): |
fcc20ac7b68a
Primitivus: major changes in SelectableText, menu can now be used with mouse, TabsContainer show wich tab is selected
Goffi <goffi@goffi.org>
parents:
25
diff
changeset
|
203 return unicode(text) |
fcc20ac7b68a
Primitivus: major changes in SelectableText, menu can now be used with mouse, TabsContainer show wich tab is selected
Goffi <goffi@goffi.org>
parents:
25
diff
changeset
|
204 elif isinstance(text,tuple): |
fcc20ac7b68a
Primitivus: major changes in SelectableText, menu can now be used with mouse, TabsContainer show wich tab is selected
Goffi <goffi@goffi.org>
parents:
25
diff
changeset
|
205 return (unicode(text[0]),text[1]) |
fcc20ac7b68a
Primitivus: major changes in SelectableText, menu can now be used with mouse, TabsContainer show wich tab is selected
Goffi <goffi@goffi.org>
parents:
25
diff
changeset
|
206 elif isinstance(text,list): |
fcc20ac7b68a
Primitivus: major changes in SelectableText, menu can now be used with mouse, TabsContainer show wich tab is selected
Goffi <goffi@goffi.org>
parents:
25
diff
changeset
|
207 for idx in range(len(text)): |
fcc20ac7b68a
Primitivus: major changes in SelectableText, menu can now be used with mouse, TabsContainer show wich tab is selected
Goffi <goffi@goffi.org>
parents:
25
diff
changeset
|
208 elem = text[idx] |
fcc20ac7b68a
Primitivus: major changes in SelectableText, menu can now be used with mouse, TabsContainer show wich tab is selected
Goffi <goffi@goffi.org>
parents:
25
diff
changeset
|
209 if isinstance(elem,basestring): |
fcc20ac7b68a
Primitivus: major changes in SelectableText, menu can now be used with mouse, TabsContainer show wich tab is selected
Goffi <goffi@goffi.org>
parents:
25
diff
changeset
|
210 text[idx] = unicode(elem) |
fcc20ac7b68a
Primitivus: major changes in SelectableText, menu can now be used with mouse, TabsContainer show wich tab is selected
Goffi <goffi@goffi.org>
parents:
25
diff
changeset
|
211 if isinstance(elem,tuple): |
fcc20ac7b68a
Primitivus: major changes in SelectableText, menu can now be used with mouse, TabsContainer show wich tab is selected
Goffi <goffi@goffi.org>
parents:
25
diff
changeset
|
212 text[idx] = (unicode(elem[0]),elem[1]) |
fcc20ac7b68a
Primitivus: major changes in SelectableText, menu can now be used with mouse, TabsContainer show wich tab is selected
Goffi <goffi@goffi.org>
parents:
25
diff
changeset
|
213 else: |
fcc20ac7b68a
Primitivus: major changes in SelectableText, menu can now be used with mouse, TabsContainer show wich tab is selected
Goffi <goffi@goffi.org>
parents:
25
diff
changeset
|
214 warning (_('WARNING: unknown text type')) |
fcc20ac7b68a
Primitivus: major changes in SelectableText, menu can now be used with mouse, TabsContainer show wich tab is selected
Goffi <goffi@goffi.org>
parents:
25
diff
changeset
|
215 return text |
0 | 216 |
217 def getValue(self): | |
26
fcc20ac7b68a
Primitivus: major changes in SelectableText, menu can now be used with mouse, TabsContainer show wich tab is selected
Goffi <goffi@goffi.org>
parents:
25
diff
changeset
|
218 if isinstance(self.default_txt,basestring): |
fcc20ac7b68a
Primitivus: major changes in SelectableText, menu can now be used with mouse, TabsContainer show wich tab is selected
Goffi <goffi@goffi.org>
parents:
25
diff
changeset
|
219 return self.default_txt |
fcc20ac7b68a
Primitivus: major changes in SelectableText, menu can now be used with mouse, TabsContainer show wich tab is selected
Goffi <goffi@goffi.org>
parents:
25
diff
changeset
|
220 list_attr = self.default_txt if isinstance(self.default_txt, list) else [self.default_txt] |
fcc20ac7b68a
Primitivus: major changes in SelectableText, menu can now be used with mouse, TabsContainer show wich tab is selected
Goffi <goffi@goffi.org>
parents:
25
diff
changeset
|
221 txt = "" |
fcc20ac7b68a
Primitivus: major changes in SelectableText, menu can now be used with mouse, TabsContainer show wich tab is selected
Goffi <goffi@goffi.org>
parents:
25
diff
changeset
|
222 for attr in list_attr: |
fcc20ac7b68a
Primitivus: major changes in SelectableText, menu can now be used with mouse, TabsContainer show wich tab is selected
Goffi <goffi@goffi.org>
parents:
25
diff
changeset
|
223 if isinstance(attr,tuple): |
fcc20ac7b68a
Primitivus: major changes in SelectableText, menu can now be used with mouse, TabsContainer show wich tab is selected
Goffi <goffi@goffi.org>
parents:
25
diff
changeset
|
224 txt+=attr[1] |
fcc20ac7b68a
Primitivus: major changes in SelectableText, menu can now be used with mouse, TabsContainer show wich tab is selected
Goffi <goffi@goffi.org>
parents:
25
diff
changeset
|
225 else: |
fcc20ac7b68a
Primitivus: major changes in SelectableText, menu can now be used with mouse, TabsContainer show wich tab is selected
Goffi <goffi@goffi.org>
parents:
25
diff
changeset
|
226 txt+=attr |
fcc20ac7b68a
Primitivus: major changes in SelectableText, menu can now be used with mouse, TabsContainer show wich tab is selected
Goffi <goffi@goffi.org>
parents:
25
diff
changeset
|
227 return txt |
9 | 228 |
16
263fe4d067ad
Primitivus: notification bar, first draft
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
229 def get_text(self): |
263fe4d067ad
Primitivus: notification bar, first draft
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
230 """for compatibility with urwid.Text""" |
263fe4d067ad
Primitivus: notification bar, first draft
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
231 return self.getValue() |
263fe4d067ad
Primitivus: notification bar, first draft
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
232 |
263fe4d067ad
Primitivus: notification bar, first draft
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
233 def set_text(self, text): |
26
fcc20ac7b68a
Primitivus: major changes in SelectableText, menu can now be used with mouse, TabsContainer show wich tab is selected
Goffi <goffi@goffi.org>
parents:
25
diff
changeset
|
234 """/!\ set_text doesn't change self.selected_txt !""" |
fcc20ac7b68a
Primitivus: major changes in SelectableText, menu can now be used with mouse, TabsContainer show wich tab is selected
Goffi <goffi@goffi.org>
parents:
25
diff
changeset
|
235 self.default_txt = self.__valid_text(text) |
fcc20ac7b68a
Primitivus: major changes in SelectableText, menu can now be used with mouse, TabsContainer show wich tab is selected
Goffi <goffi@goffi.org>
parents:
25
diff
changeset
|
236 self.setState(self.__selected,invisible=True) |
16
263fe4d067ad
Primitivus: notification bar, first draft
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
237 |
26
fcc20ac7b68a
Primitivus: major changes in SelectableText, menu can now be used with mouse, TabsContainer show wich tab is selected
Goffi <goffi@goffi.org>
parents:
25
diff
changeset
|
238 def setSelectedText(self, text=None): |
fcc20ac7b68a
Primitivus: major changes in SelectableText, menu can now be used with mouse, TabsContainer show wich tab is selected
Goffi <goffi@goffi.org>
parents:
25
diff
changeset
|
239 """Text to display when selected |
fcc20ac7b68a
Primitivus: major changes in SelectableText, menu can now be used with mouse, TabsContainer show wich tab is selected
Goffi <goffi@goffi.org>
parents:
25
diff
changeset
|
240 @text: text as in urwid.Text or None for default value""" |
fcc20ac7b68a
Primitivus: major changes in SelectableText, menu can now be used with mouse, TabsContainer show wich tab is selected
Goffi <goffi@goffi.org>
parents:
25
diff
changeset
|
241 if text == None: |
27 | 242 text = ('selected',self.getValue()) |
26
fcc20ac7b68a
Primitivus: major changes in SelectableText, menu can now be used with mouse, TabsContainer show wich tab is selected
Goffi <goffi@goffi.org>
parents:
25
diff
changeset
|
243 self.selected_txt = self.__valid_text(text) |
fcc20ac7b68a
Primitivus: major changes in SelectableText, menu can now be used with mouse, TabsContainer show wich tab is selected
Goffi <goffi@goffi.org>
parents:
25
diff
changeset
|
244 if self.__selected: |
fcc20ac7b68a
Primitivus: major changes in SelectableText, menu can now be used with mouse, TabsContainer show wich tab is selected
Goffi <goffi@goffi.org>
parents:
25
diff
changeset
|
245 self.setState(self.__selected) |
fcc20ac7b68a
Primitivus: major changes in SelectableText, menu can now be used with mouse, TabsContainer show wich tab is selected
Goffi <goffi@goffi.org>
parents:
25
diff
changeset
|
246 |
fcc20ac7b68a
Primitivus: major changes in SelectableText, menu can now be used with mouse, TabsContainer show wich tab is selected
Goffi <goffi@goffi.org>
parents:
25
diff
changeset
|
247 |
fcc20ac7b68a
Primitivus: major changes in SelectableText, menu can now be used with mouse, TabsContainer show wich tab is selected
Goffi <goffi@goffi.org>
parents:
25
diff
changeset
|
248 def __set_txt(self): |
fcc20ac7b68a
Primitivus: major changes in SelectableText, menu can now be used with mouse, TabsContainer show wich tab is selected
Goffi <goffi@goffi.org>
parents:
25
diff
changeset
|
249 txt_list = [self.header] |
fcc20ac7b68a
Primitivus: major changes in SelectableText, menu can now be used with mouse, TabsContainer show wich tab is selected
Goffi <goffi@goffi.org>
parents:
25
diff
changeset
|
250 txt = self.selected_txt if self.__selected else self.default_txt |
fcc20ac7b68a
Primitivus: major changes in SelectableText, menu can now be used with mouse, TabsContainer show wich tab is selected
Goffi <goffi@goffi.org>
parents:
25
diff
changeset
|
251 if isinstance(txt,list): |
fcc20ac7b68a
Primitivus: major changes in SelectableText, menu can now be used with mouse, TabsContainer show wich tab is selected
Goffi <goffi@goffi.org>
parents:
25
diff
changeset
|
252 txt_list.extend(txt) |
fcc20ac7b68a
Primitivus: major changes in SelectableText, menu can now be used with mouse, TabsContainer show wich tab is selected
Goffi <goffi@goffi.org>
parents:
25
diff
changeset
|
253 else: |
fcc20ac7b68a
Primitivus: major changes in SelectableText, menu can now be used with mouse, TabsContainer show wich tab is selected
Goffi <goffi@goffi.org>
parents:
25
diff
changeset
|
254 txt_list.append(txt) |
fcc20ac7b68a
Primitivus: major changes in SelectableText, menu can now be used with mouse, TabsContainer show wich tab is selected
Goffi <goffi@goffi.org>
parents:
25
diff
changeset
|
255 self._w.base_widget.set_text(txt_list) |
fcc20ac7b68a
Primitivus: major changes in SelectableText, menu can now be used with mouse, TabsContainer show wich tab is selected
Goffi <goffi@goffi.org>
parents:
25
diff
changeset
|
256 |
66 | 257 |
0 | 258 def setState(self, selected, invisible=False): |
259 """Change state | |
260 @param selected: boolean state value | |
261 @param invisible: don't emit change signal if True""" | |
262 assert(type(selected)==bool) | |
263 self.__selected=selected | |
26
fcc20ac7b68a
Primitivus: major changes in SelectableText, menu can now be used with mouse, TabsContainer show wich tab is selected
Goffi <goffi@goffi.org>
parents:
25
diff
changeset
|
264 self.__set_txt() |
fcc20ac7b68a
Primitivus: major changes in SelectableText, menu can now be used with mouse, TabsContainer show wich tab is selected
Goffi <goffi@goffi.org>
parents:
25
diff
changeset
|
265 self.__was_focused = False |
5
592cd64933dd
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
4
diff
changeset
|
266 self._invalidate() |
0 | 267 if not invisible: |
268 self._emit("change", self.__selected) | |
66 | 269 |
0 | 270 def getState(self): |
271 return self.__selected | |
272 | |
273 def selectable(self): | |
274 return True | |
275 | |
276 def keypress(self, size, key): | |
277 if key==' ' or key=='enter': | |
278 self.setState(not self.__selected) | |
279 else: | |
280 return key | |
281 | |
15
8241b3157699
Primitivus: custom_widgets imrpovments
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
282 def mouse_event(self, size, event, button, x, y, focus): |
53
d34f2b0f68d3
urwid 1.0.0 update: fixed missing is_mouse_press
Goffi <goffi@goffi.org>
parents:
44
diff
changeset
|
283 if is_mouse_press(event) and button == 1: |
15
8241b3157699
Primitivus: custom_widgets imrpovments
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
284 self.setState(not self.__selected) |
8241b3157699
Primitivus: custom_widgets imrpovments
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
285 return True |
66 | 286 |
15
8241b3157699
Primitivus: custom_widgets imrpovments
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
287 return False |
66 | 288 |
0 | 289 def render(self, size, focus=False): |
26
fcc20ac7b68a
Primitivus: major changes in SelectableText, menu can now be used with mouse, TabsContainer show wich tab is selected
Goffi <goffi@goffi.org>
parents:
25
diff
changeset
|
290 attr_list = self._w.base_widget._attrib |
fcc20ac7b68a
Primitivus: major changes in SelectableText, menu can now be used with mouse, TabsContainer show wich tab is selected
Goffi <goffi@goffi.org>
parents:
25
diff
changeset
|
291 if not focus: |
fcc20ac7b68a
Primitivus: major changes in SelectableText, menu can now be used with mouse, TabsContainer show wich tab is selected
Goffi <goffi@goffi.org>
parents:
25
diff
changeset
|
292 if self.__was_focused: |
fcc20ac7b68a
Primitivus: major changes in SelectableText, menu can now be used with mouse, TabsContainer show wich tab is selected
Goffi <goffi@goffi.org>
parents:
25
diff
changeset
|
293 self.__set_txt() |
fcc20ac7b68a
Primitivus: major changes in SelectableText, menu can now be used with mouse, TabsContainer show wich tab is selected
Goffi <goffi@goffi.org>
parents:
25
diff
changeset
|
294 self.__was_focused = False |
fcc20ac7b68a
Primitivus: major changes in SelectableText, menu can now be used with mouse, TabsContainer show wich tab is selected
Goffi <goffi@goffi.org>
parents:
25
diff
changeset
|
295 else: |
fcc20ac7b68a
Primitivus: major changes in SelectableText, menu can now be used with mouse, TabsContainer show wich tab is selected
Goffi <goffi@goffi.org>
parents:
25
diff
changeset
|
296 if not self.__was_focused: |
fcc20ac7b68a
Primitivus: major changes in SelectableText, menu can now be used with mouse, TabsContainer show wich tab is selected
Goffi <goffi@goffi.org>
parents:
25
diff
changeset
|
297 if not attr_list: |
fcc20ac7b68a
Primitivus: major changes in SelectableText, menu can now be used with mouse, TabsContainer show wich tab is selected
Goffi <goffi@goffi.org>
parents:
25
diff
changeset
|
298 attr_list.append((self.focus_attr,len(self._w.base_widget.text))) |
fcc20ac7b68a
Primitivus: major changes in SelectableText, menu can now be used with mouse, TabsContainer show wich tab is selected
Goffi <goffi@goffi.org>
parents:
25
diff
changeset
|
299 else: |
fcc20ac7b68a
Primitivus: major changes in SelectableText, menu can now be used with mouse, TabsContainer show wich tab is selected
Goffi <goffi@goffi.org>
parents:
25
diff
changeset
|
300 for idx in range(len(attr_list)): |
fcc20ac7b68a
Primitivus: major changes in SelectableText, menu can now be used with mouse, TabsContainer show wich tab is selected
Goffi <goffi@goffi.org>
parents:
25
diff
changeset
|
301 attr,attr_len = attr_list[idx] |
fcc20ac7b68a
Primitivus: major changes in SelectableText, menu can now be used with mouse, TabsContainer show wich tab is selected
Goffi <goffi@goffi.org>
parents:
25
diff
changeset
|
302 if attr == None: |
fcc20ac7b68a
Primitivus: major changes in SelectableText, menu can now be used with mouse, TabsContainer show wich tab is selected
Goffi <goffi@goffi.org>
parents:
25
diff
changeset
|
303 attr = self.focus_attr |
fcc20ac7b68a
Primitivus: major changes in SelectableText, menu can now be used with mouse, TabsContainer show wich tab is selected
Goffi <goffi@goffi.org>
parents:
25
diff
changeset
|
304 attr_list[idx] = (attr,attr_len) |
fcc20ac7b68a
Primitivus: major changes in SelectableText, menu can now be used with mouse, TabsContainer show wich tab is selected
Goffi <goffi@goffi.org>
parents:
25
diff
changeset
|
305 else: |
fcc20ac7b68a
Primitivus: major changes in SelectableText, menu can now be used with mouse, TabsContainer show wich tab is selected
Goffi <goffi@goffi.org>
parents:
25
diff
changeset
|
306 if not attr.endswith('_focus'): |
fcc20ac7b68a
Primitivus: major changes in SelectableText, menu can now be used with mouse, TabsContainer show wich tab is selected
Goffi <goffi@goffi.org>
parents:
25
diff
changeset
|
307 attr+="_focus" |
fcc20ac7b68a
Primitivus: major changes in SelectableText, menu can now be used with mouse, TabsContainer show wich tab is selected
Goffi <goffi@goffi.org>
parents:
25
diff
changeset
|
308 attr_list[idx] = (attr,attr_len) |
fcc20ac7b68a
Primitivus: major changes in SelectableText, menu can now be used with mouse, TabsContainer show wich tab is selected
Goffi <goffi@goffi.org>
parents:
25
diff
changeset
|
309 self._w.base_widget._invalidate() |
fcc20ac7b68a
Primitivus: major changes in SelectableText, menu can now be used with mouse, TabsContainer show wich tab is selected
Goffi <goffi@goffi.org>
parents:
25
diff
changeset
|
310 self.__was_focused = True #bloody ugly hack :) |
fcc20ac7b68a
Primitivus: major changes in SelectableText, menu can now be used with mouse, TabsContainer show wich tab is selected
Goffi <goffi@goffi.org>
parents:
25
diff
changeset
|
311 return self._w.render(size, focus) |
0 | 312 |
9 | 313 class ClickableText(SelectableText): |
314 signals = SelectableText.signals + ['click'] | |
66 | 315 |
8 | 316 def setState(self, selected, invisible=False): |
26
fcc20ac7b68a
Primitivus: major changes in SelectableText, menu can now be used with mouse, TabsContainer show wich tab is selected
Goffi <goffi@goffi.org>
parents:
25
diff
changeset
|
317 super(ClickableText,self).setState(False,True) |
fcc20ac7b68a
Primitivus: major changes in SelectableText, menu can now be used with mouse, TabsContainer show wich tab is selected
Goffi <goffi@goffi.org>
parents:
25
diff
changeset
|
318 if not invisible: |
fcc20ac7b68a
Primitivus: major changes in SelectableText, menu can now be used with mouse, TabsContainer show wich tab is selected
Goffi <goffi@goffi.org>
parents:
25
diff
changeset
|
319 self._emit('click') |
8 | 320 |
15
8241b3157699
Primitivus: custom_widgets imrpovments
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
321 class CustomButton(ClickableText): |
8241b3157699
Primitivus: custom_widgets imrpovments
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
322 |
8241b3157699
Primitivus: custom_widgets imrpovments
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
323 def __init__(self, label, on_press=None, user_data=None, left_border = "[ ", right_border = " ]"): |
8241b3157699
Primitivus: custom_widgets imrpovments
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
324 self.label = label |
26
fcc20ac7b68a
Primitivus: major changes in SelectableText, menu can now be used with mouse, TabsContainer show wich tab is selected
Goffi <goffi@goffi.org>
parents:
25
diff
changeset
|
325 self.left_border = left_border |
fcc20ac7b68a
Primitivus: major changes in SelectableText, menu can now be used with mouse, TabsContainer show wich tab is selected
Goffi <goffi@goffi.org>
parents:
25
diff
changeset
|
326 self.right_border = right_border |
66 | 327 super(CustomButton, self).__init__([left_border, label, right_border]) |
26
fcc20ac7b68a
Primitivus: major changes in SelectableText, menu can now be used with mouse, TabsContainer show wich tab is selected
Goffi <goffi@goffi.org>
parents:
25
diff
changeset
|
328 self.size = len(self.get_text()) |
15
8241b3157699
Primitivus: custom_widgets imrpovments
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
329 if on_press: |
8241b3157699
Primitivus: custom_widgets imrpovments
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
330 urwid.connect_signal(self, 'click', on_press, user_data) |
8241b3157699
Primitivus: custom_widgets imrpovments
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
331 |
8241b3157699
Primitivus: custom_widgets imrpovments
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
332 def getSize(self): |
8241b3157699
Primitivus: custom_widgets imrpovments
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
333 """Return representation size of the button""" |
8241b3157699
Primitivus: custom_widgets imrpovments
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
334 return self.size |
8241b3157699
Primitivus: custom_widgets imrpovments
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
335 |
8241b3157699
Primitivus: custom_widgets imrpovments
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
336 def get_label(self): |
26
fcc20ac7b68a
Primitivus: major changes in SelectableText, menu can now be used with mouse, TabsContainer show wich tab is selected
Goffi <goffi@goffi.org>
parents:
25
diff
changeset
|
337 return self.label[1] if isinstance(self.label,tuple) else self.label |
fcc20ac7b68a
Primitivus: major changes in SelectableText, menu can now be used with mouse, TabsContainer show wich tab is selected
Goffi <goffi@goffi.org>
parents:
25
diff
changeset
|
338 |
fcc20ac7b68a
Primitivus: major changes in SelectableText, menu can now be used with mouse, TabsContainer show wich tab is selected
Goffi <goffi@goffi.org>
parents:
25
diff
changeset
|
339 def set_label(self, label): |
fcc20ac7b68a
Primitivus: major changes in SelectableText, menu can now be used with mouse, TabsContainer show wich tab is selected
Goffi <goffi@goffi.org>
parents:
25
diff
changeset
|
340 self.label = label |
fcc20ac7b68a
Primitivus: major changes in SelectableText, menu can now be used with mouse, TabsContainer show wich tab is selected
Goffi <goffi@goffi.org>
parents:
25
diff
changeset
|
341 self.set_text([self.left_border, label, self.right_border]) |
15
8241b3157699
Primitivus: custom_widgets imrpovments
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
342 |
5
592cd64933dd
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
4
diff
changeset
|
343 class GenericList(urwid.WidgetWrap): |
592cd64933dd
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
4
diff
changeset
|
344 signals = ['click','change'] |
0 | 345 |
8 | 346 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
|
347 """ |
592cd64933dd
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
4
diff
changeset
|
348 Widget managing list of string and their selection |
592cd64933dd
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
4
diff
changeset
|
349 @param options: list of strings used for options |
592cd64933dd
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
4
diff
changeset
|
350 @param style: list of string: |
592cd64933dd
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
4
diff
changeset
|
351 - 'single' if only one must be selected |
66 | 352 - 'no_first_select' nothing selected when list is first displayed |
5
592cd64933dd
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
4
diff
changeset
|
353 - 'can_select_none' if we can select nothing |
592cd64933dd
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
4
diff
changeset
|
354 @param align: alignement of text inside the list |
592cd64933dd
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
4
diff
changeset
|
355 @param on_click: method called when click signal is emited |
592cd64933dd
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
4
diff
changeset
|
356 @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
|
357 """ |
0 | 358 self.single = 'single' in style |
5
592cd64933dd
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
4
diff
changeset
|
359 self.no_first_select = 'no_first_select' in style |
592cd64933dd
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
4
diff
changeset
|
360 self.can_select_none = 'can_select_none' in style |
0 | 361 self.align = align |
8 | 362 self.option_type = option_type |
5
592cd64933dd
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
4
diff
changeset
|
363 self.first_display = True |
66 | 364 |
5
592cd64933dd
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
4
diff
changeset
|
365 if on_click: |
592cd64933dd
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
4
diff
changeset
|
366 urwid.connect_signal(self, 'click', on_click, user_data) |
66 | 367 |
5
592cd64933dd
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
4
diff
changeset
|
368 if on_change: |
592cd64933dd
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
4
diff
changeset
|
369 urwid.connect_signal(self, 'change', on_change, user_data) |
66 | 370 |
1 | 371 self.content = urwid.SimpleListWalker([]) |
0 | 372 self.list_box = urwid.ListBox(self.content) |
4
c94cdbfdf3e8
primitivus: added edition zone at the bottom
Goffi <goffi@goffi.org>
parents:
3
diff
changeset
|
373 urwid.WidgetWrap.__init__(self, self.list_box) |
1 | 374 self.changeValues(options) |
0 | 375 |
376 def __onStateChange(self, widget, selected): | |
377 if self.single: | |
5
592cd64933dd
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
4
diff
changeset
|
378 if not selected and not self.can_select_none: |
0 | 379 #if in single mode, it's forbidden to unselect a value |
380 widget.setState(True, invisible=True) | |
381 return | |
5
592cd64933dd
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
4
diff
changeset
|
382 if selected: |
0 | 383 self.unselectAll(invisible=True) |
384 widget.setState(True, invisible=True) | |
56
22ab98a06492
GenericList: click/change signals fix
Goffi <goffi@goffi.org>
parents:
53
diff
changeset
|
385 self._emit("change") |
0 | 386 |
56
22ab98a06492
GenericList: click/change signals fix
Goffi <goffi@goffi.org>
parents:
53
diff
changeset
|
387 def __onClick(self, widget): |
22ab98a06492
GenericList: click/change signals fix
Goffi <goffi@goffi.org>
parents:
53
diff
changeset
|
388 self._emit("click", widget) |
0 | 389 |
390 def unselectAll(self, invisible=False): | |
391 for widget in self.content: | |
392 if widget.getState(): | |
393 widget.setState(False, invisible) | |
394 widget._invalidate() | |
395 | |
2
07b7dcd314ff
primitivus: basic contact list, connexion now work \o/
Goffi <goffi@goffi.org>
parents:
1
diff
changeset
|
396 def deleteValue(self, value): |
07b7dcd314ff
primitivus: basic contact list, connexion now work \o/
Goffi <goffi@goffi.org>
parents:
1
diff
changeset
|
397 """Delete the first value equal to the param given""" |
5
592cd64933dd
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
4
diff
changeset
|
398 for widget in self.content: |
592cd64933dd
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
4
diff
changeset
|
399 if widget.getValue() == value: |
592cd64933dd
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
4
diff
changeset
|
400 self.content.remove(widget) |
592cd64933dd
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
4
diff
changeset
|
401 self._emit('change') |
592cd64933dd
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
4
diff
changeset
|
402 return |
592cd64933dd
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
4
diff
changeset
|
403 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
|
404 |
5
592cd64933dd
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
4
diff
changeset
|
405 def getSelectedValue(self): |
1 | 406 """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
|
407 values = self.getSelectedValues() |
1 | 408 return values[0] if values else None |
409 | |
5
592cd64933dd
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
4
diff
changeset
|
410 def getAllValues(self): |
592cd64933dd
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
4
diff
changeset
|
411 """Return values of all items""" |
592cd64933dd
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
4
diff
changeset
|
412 return [widget.getValue() for widget in self.content] |
592cd64933dd
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
4
diff
changeset
|
413 |
592cd64933dd
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
4
diff
changeset
|
414 def getSelectedValues(self): |
592cd64933dd
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
4
diff
changeset
|
415 """Return values of selected items""" |
0 | 416 result = [] |
417 for widget in self.content: | |
418 if widget.getState(): | |
419 result.append(widget.getValue()) | |
420 return result | |
421 | |
5
592cd64933dd
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
4
diff
changeset
|
422 def getDisplayWidget(self): |
592cd64933dd
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
4
diff
changeset
|
423 return self.list_box |
592cd64933dd
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
4
diff
changeset
|
424 |
0 | 425 def changeValues(self, new_values): |
2
07b7dcd314ff
primitivus: basic contact list, connexion now work \o/
Goffi <goffi@goffi.org>
parents:
1
diff
changeset
|
426 """Change all value in one shot""" |
5
592cd64933dd
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
4
diff
changeset
|
427 if not self.first_display: |
592cd64933dd
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
4
diff
changeset
|
428 old_selected = self.getSelectedValues() |
592cd64933dd
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
4
diff
changeset
|
429 widgets = [] |
592cd64933dd
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
4
diff
changeset
|
430 for option in new_values: |
8 | 431 widget = self.option_type(option, self.align) |
5
592cd64933dd
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
4
diff
changeset
|
432 if not self.first_display and option in old_selected: |
592cd64933dd
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
4
diff
changeset
|
433 widget.setState(True) |
592cd64933dd
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
4
diff
changeset
|
434 widgets.append(widget) |
56
22ab98a06492
GenericList: click/change signals fix
Goffi <goffi@goffi.org>
parents:
53
diff
changeset
|
435 for signal, callback in (('change', self.__onStateChange), ('click', self.__onClick)): |
22ab98a06492
GenericList: click/change signals fix
Goffi <goffi@goffi.org>
parents:
53
diff
changeset
|
436 try: |
22ab98a06492
GenericList: click/change signals fix
Goffi <goffi@goffi.org>
parents:
53
diff
changeset
|
437 urwid.connect_signal(widget, signal, callback) |
22ab98a06492
GenericList: click/change signals fix
Goffi <goffi@goffi.org>
parents:
53
diff
changeset
|
438 except NameError: |
22ab98a06492
GenericList: click/change signals fix
Goffi <goffi@goffi.org>
parents:
53
diff
changeset
|
439 pass #the widget given doesn't support the signal |
0 | 440 self.content[:] = widgets |
5
592cd64933dd
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
4
diff
changeset
|
441 if self.first_display and self.single and new_values and not self.no_first_select: |
1 | 442 self.content[0].setState(True) |
5
592cd64933dd
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
4
diff
changeset
|
443 display_widget = self.getDisplayWidget() |
4
c94cdbfdf3e8
primitivus: added edition zone at the bottom
Goffi <goffi@goffi.org>
parents:
3
diff
changeset
|
444 self._set_w(display_widget) |
5
592cd64933dd
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
4
diff
changeset
|
445 self._emit('change') |
66 | 446 self.first_display = False |
5
592cd64933dd
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
4
diff
changeset
|
447 |
0 | 448 def selectValue(self, value): |
28
654d31983f19
primitivus: fixed misnamed method in custom widget
Goffi <goffi@goffi.org>
parents:
27
diff
changeset
|
449 """Select the first item which has the given value""" |
0 | 450 self.unselectAll() |
451 idx = 0 | |
452 for widget in self.content: | |
28
654d31983f19
primitivus: fixed misnamed method in custom widget
Goffi <goffi@goffi.org>
parents:
27
diff
changeset
|
453 if widget.getValue() == value: |
0 | 454 widget.setState(True) |
455 self.list_box.set_focus(idx) | |
456 return | |
457 idx+=1 | |
458 | |
5
592cd64933dd
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
4
diff
changeset
|
459 class List(urwid.FlowWidget): |
592cd64933dd
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
4
diff
changeset
|
460 """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
|
461 signals = ['click','change'] |
592cd64933dd
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
4
diff
changeset
|
462 |
8 | 463 def __init__(self, options, style=[], max_height=5, align='left', option_type = SelectableText, on_click=None, on_change=None, user_data=None): |
464 self.genericList = GenericList(options, style, align, option_type, on_click, on_change, user_data) | |
66 | 465 self.max_height = max_height |
5
592cd64933dd
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
4
diff
changeset
|
466 |
592cd64933dd
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
4
diff
changeset
|
467 def selectable(self): |
592cd64933dd
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
4
diff
changeset
|
468 return True |
592cd64933dd
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
4
diff
changeset
|
469 |
592cd64933dd
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
4
diff
changeset
|
470 def keypress(self, size, key): |
592cd64933dd
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
4
diff
changeset
|
471 return self.displayWidget(size,True).keypress(size, key) |
66 | 472 |
5
592cd64933dd
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
4
diff
changeset
|
473 def unselectAll(self, invisible=False): |
592cd64933dd
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
4
diff
changeset
|
474 return self.genericList.unselectAll(invisible) |
66 | 475 |
5
592cd64933dd
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
4
diff
changeset
|
476 def deleteValue(self, value): |
592cd64933dd
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
4
diff
changeset
|
477 return self.genericList.deleteValue(value) |
592cd64933dd
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
4
diff
changeset
|
478 |
592cd64933dd
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
4
diff
changeset
|
479 def getSelectedValue(self): |
592cd64933dd
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
4
diff
changeset
|
480 return self.genericList.getSelectedValue() |
592cd64933dd
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
4
diff
changeset
|
481 |
592cd64933dd
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
4
diff
changeset
|
482 def getAllValues(self): |
592cd64933dd
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
4
diff
changeset
|
483 return self.genericList.getAllValues() |
592cd64933dd
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
4
diff
changeset
|
484 |
592cd64933dd
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
4
diff
changeset
|
485 def getSelectedValues(self): |
592cd64933dd
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
4
diff
changeset
|
486 return self.genericList.getSelectedValues() |
592cd64933dd
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
4
diff
changeset
|
487 |
592cd64933dd
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
4
diff
changeset
|
488 def changeValues(self, new_values): |
592cd64933dd
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
4
diff
changeset
|
489 return self.genericList.changeValues(new_values) |
592cd64933dd
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
4
diff
changeset
|
490 |
592cd64933dd
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
4
diff
changeset
|
491 def selectValue(self, value): |
592cd64933dd
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
4
diff
changeset
|
492 return self.genericList.selectValue(value) |
592cd64933dd
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
4
diff
changeset
|
493 |
592cd64933dd
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
4
diff
changeset
|
494 def render(self, size, focus=False): |
592cd64933dd
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
4
diff
changeset
|
495 return self.displayWidget(size, focus).render(size, focus) |
66 | 496 |
5
592cd64933dd
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
4
diff
changeset
|
497 def rows(self, size, focus=False): |
592cd64933dd
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
4
diff
changeset
|
498 return self.displayWidget(size, focus).rows(size, focus) |
592cd64933dd
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
4
diff
changeset
|
499 |
592cd64933dd
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
4
diff
changeset
|
500 def displayWidget(self, size, focus): |
592cd64933dd
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
4
diff
changeset
|
501 list_size = sum([wid.rows(size, focus) for wid in self.genericList.content]) |
66 | 502 height = min(list_size,self.max_height) or 1 |
5
592cd64933dd
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
4
diff
changeset
|
503 return urwid.BoxAdapter(self.genericList, height) |
592cd64933dd
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
4
diff
changeset
|
504 |
10
024b79b61a31
Primitivus: misc fixes + menubar first draft
Goffi <goffi@goffi.org>
parents:
9
diff
changeset
|
505 ## MISC ## |
024b79b61a31
Primitivus: misc fixes + menubar first draft
Goffi <goffi@goffi.org>
parents:
9
diff
changeset
|
506 |
16
263fe4d067ad
Primitivus: notification bar, first draft
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
507 class NotificationBar(urwid.WidgetWrap): |
263fe4d067ad
Primitivus: notification bar, first draft
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
508 """Bar used to show misc information to user""" |
263fe4d067ad
Primitivus: notification bar, first draft
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
509 signals = ['change'] |
263fe4d067ad
Primitivus: notification bar, first draft
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
510 |
263fe4d067ad
Primitivus: notification bar, first draft
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
511 def __init__(self): |
263fe4d067ad
Primitivus: notification bar, first draft
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
512 self.waitNotifs = urwid.Text('') |
26
fcc20ac7b68a
Primitivus: major changes in SelectableText, menu can now be used with mouse, TabsContainer show wich tab is selected
Goffi <goffi@goffi.org>
parents:
25
diff
changeset
|
513 self.message = ClickableText('') |
16
263fe4d067ad
Primitivus: notification bar, first draft
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
514 urwid.connect_signal(self.message, 'click', lambda wid: self.showNext()) |
26
fcc20ac7b68a
Primitivus: major changes in SelectableText, menu can now be used with mouse, TabsContainer show wich tab is selected
Goffi <goffi@goffi.org>
parents:
25
diff
changeset
|
515 self.progress = ClickableText('') |
22
dfabea6f73b5
Primitivus: AdvancedEdit and Notification bar improved
Goffi <goffi@goffi.org>
parents:
21
diff
changeset
|
516 self.columns = urwid.Columns([('fixed',6,self.waitNotifs),self.message,('fixed',4,self.progress)]) |
16
263fe4d067ad
Primitivus: notification bar, first draft
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
517 urwid.WidgetWrap.__init__(self, urwid.AttrMap(self.columns,'notifs')) |
263fe4d067ad
Primitivus: notification bar, first draft
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
518 self.notifs = [] |
66 | 519 |
16
263fe4d067ad
Primitivus: notification bar, first draft
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
520 def __modQueue(self): |
263fe4d067ad
Primitivus: notification bar, first draft
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
521 """must be called each time the notifications queue is changed""" |
26
fcc20ac7b68a
Primitivus: major changes in SelectableText, menu can now be used with mouse, TabsContainer show wich tab is selected
Goffi <goffi@goffi.org>
parents:
25
diff
changeset
|
522 self.waitNotifs.set_text(('notifs',"(%i)" % len(self.notifs) if self.notifs else '')) |
16
263fe4d067ad
Primitivus: notification bar, first draft
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
523 self._emit('change') |
263fe4d067ad
Primitivus: notification bar, first draft
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
524 |
22
dfabea6f73b5
Primitivus: AdvancedEdit and Notification bar improved
Goffi <goffi@goffi.org>
parents:
21
diff
changeset
|
525 def setProgress(self,percentage): |
dfabea6f73b5
Primitivus: AdvancedEdit and Notification bar improved
Goffi <goffi@goffi.org>
parents:
21
diff
changeset
|
526 """Define the progression to show on the right side of the bar""" |
dfabea6f73b5
Primitivus: AdvancedEdit and Notification bar improved
Goffi <goffi@goffi.org>
parents:
21
diff
changeset
|
527 if percentage == None: |
dfabea6f73b5
Primitivus: AdvancedEdit and Notification bar improved
Goffi <goffi@goffi.org>
parents:
21
diff
changeset
|
528 self.progress.set_text('') |
dfabea6f73b5
Primitivus: AdvancedEdit and Notification bar improved
Goffi <goffi@goffi.org>
parents:
21
diff
changeset
|
529 else: |
26
fcc20ac7b68a
Primitivus: major changes in SelectableText, menu can now be used with mouse, TabsContainer show wich tab is selected
Goffi <goffi@goffi.org>
parents:
25
diff
changeset
|
530 self.progress.set_text(('notifs','%02i%%' % percentage)) |
22
dfabea6f73b5
Primitivus: AdvancedEdit and Notification bar improved
Goffi <goffi@goffi.org>
parents:
21
diff
changeset
|
531 self._emit('change') |
dfabea6f73b5
Primitivus: AdvancedEdit and Notification bar improved
Goffi <goffi@goffi.org>
parents:
21
diff
changeset
|
532 |
16
263fe4d067ad
Primitivus: notification bar, first draft
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
533 def addPopUp(self, pop_up_widget): |
263fe4d067ad
Primitivus: notification bar, first draft
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
534 """Add a popup to the waiting queue""" |
263fe4d067ad
Primitivus: notification bar, first draft
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
535 self.notifs.append(('popup',pop_up_widget)) |
263fe4d067ad
Primitivus: notification bar, first draft
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
536 self.__modQueue() |
263fe4d067ad
Primitivus: notification bar, first draft
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
537 |
263fe4d067ad
Primitivus: notification bar, first draft
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
538 def addMessage(self, message): |
263fe4d067ad
Primitivus: notification bar, first draft
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
539 "Add a message to the notificatio bar" |
263fe4d067ad
Primitivus: notification bar, first draft
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
540 if not self.message.get_text(): |
26
fcc20ac7b68a
Primitivus: major changes in SelectableText, menu can now be used with mouse, TabsContainer show wich tab is selected
Goffi <goffi@goffi.org>
parents:
25
diff
changeset
|
541 self.message.set_text(('notifs',message)) |
16
263fe4d067ad
Primitivus: notification bar, first draft
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
542 self._invalidate() |
263fe4d067ad
Primitivus: notification bar, first draft
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
543 self._emit('change') |
263fe4d067ad
Primitivus: notification bar, first draft
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
544 else: |
263fe4d067ad
Primitivus: notification bar, first draft
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
545 self.notifs.append(('message',message)) |
263fe4d067ad
Primitivus: notification bar, first draft
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
546 self.__modQueue() |
263fe4d067ad
Primitivus: notification bar, first draft
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
547 |
263fe4d067ad
Primitivus: notification bar, first draft
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
548 def showNext(self): |
263fe4d067ad
Primitivus: notification bar, first draft
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
549 """Show next message if any, else delete current message""" |
263fe4d067ad
Primitivus: notification bar, first draft
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
550 found = None |
263fe4d067ad
Primitivus: notification bar, first draft
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
551 for notif in self.notifs: |
263fe4d067ad
Primitivus: notification bar, first draft
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
552 if notif[0] == "message": |
263fe4d067ad
Primitivus: notification bar, first draft
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
553 found = notif |
263fe4d067ad
Primitivus: notification bar, first draft
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
554 break |
263fe4d067ad
Primitivus: notification bar, first draft
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
555 if found: |
263fe4d067ad
Primitivus: notification bar, first draft
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
556 self.notifs.remove(found) |
26
fcc20ac7b68a
Primitivus: major changes in SelectableText, menu can now be used with mouse, TabsContainer show wich tab is selected
Goffi <goffi@goffi.org>
parents:
25
diff
changeset
|
557 self.message.set_text(('notifs',found[1])) |
16
263fe4d067ad
Primitivus: notification bar, first draft
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
558 self.__modQueue() |
263fe4d067ad
Primitivus: notification bar, first draft
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
559 else: |
263fe4d067ad
Primitivus: notification bar, first draft
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
560 self.message.set_text('') |
263fe4d067ad
Primitivus: notification bar, first draft
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
561 self._emit('change') |
263fe4d067ad
Primitivus: notification bar, first draft
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
562 |
263fe4d067ad
Primitivus: notification bar, first draft
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
563 def getNextPopup(self): |
263fe4d067ad
Primitivus: notification bar, first draft
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
564 """Return next pop-up and remove it from the queue |
263fe4d067ad
Primitivus: notification bar, first draft
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
565 @return: pop-up or None if there is no more in the queue""" |
263fe4d067ad
Primitivus: notification bar, first draft
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
566 ret = None |
263fe4d067ad
Primitivus: notification bar, first draft
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
567 for notif in self.notifs: |
263fe4d067ad
Primitivus: notification bar, first draft
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
568 if notif[0] == 'popup': |
263fe4d067ad
Primitivus: notification bar, first draft
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
569 ret = notif[1] |
263fe4d067ad
Primitivus: notification bar, first draft
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
570 break |
263fe4d067ad
Primitivus: notification bar, first draft
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
571 if ret: |
263fe4d067ad
Primitivus: notification bar, first draft
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
572 self.notifs.remove(notif) |
263fe4d067ad
Primitivus: notification bar, first draft
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
573 self.__modQueue() |
263fe4d067ad
Primitivus: notification bar, first draft
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
574 return ret |
263fe4d067ad
Primitivus: notification bar, first draft
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
575 |
263fe4d067ad
Primitivus: notification bar, first draft
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
576 def isQueueEmpty(self): |
263fe4d067ad
Primitivus: notification bar, first draft
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
577 return not bool(self.notifs) |
263fe4d067ad
Primitivus: notification bar, first draft
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
578 |
263fe4d067ad
Primitivus: notification bar, first draft
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
579 def canHide(self): |
263fe4d067ad
Primitivus: notification bar, first draft
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
580 """Return True if there is now important information to show""" |
22
dfabea6f73b5
Primitivus: AdvancedEdit and Notification bar improved
Goffi <goffi@goffi.org>
parents:
21
diff
changeset
|
581 return self.isQueueEmpty() and not self.message.get_text() and not self.progress.get_text() |
16
263fe4d067ad
Primitivus: notification bar, first draft
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
582 |
263fe4d067ad
Primitivus: notification bar, first draft
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
583 |
11 | 584 class MenuBox(urwid.WidgetWrap): |
15
8241b3157699
Primitivus: custom_widgets imrpovments
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
585 """Show menu items of a category in a box""" |
11 | 586 signals = ['click'] |
66 | 587 |
11 | 588 def __init__(self,parent,items): |
589 self.parent = parent | |
590 self.selected = None | |
26
fcc20ac7b68a
Primitivus: major changes in SelectableText, menu can now be used with mouse, TabsContainer show wich tab is selected
Goffi <goffi@goffi.org>
parents:
25
diff
changeset
|
591 content = urwid.SimpleListWalker([ClickableText(('menuitem',text)) for text in items]) |
11 | 592 for wid in content: |
593 urwid.connect_signal(wid, 'click', self.onClick) | |
594 | |
595 self.listBox = urwid.ListBox(content) | |
596 menubox = urwid.LineBox(urwid.BoxAdapter(self.listBox,len(items))) | |
597 urwid.WidgetWrap.__init__(self,menubox) | |
598 | |
599 def getValue(self): | |
600 return self.selected | |
66 | 601 |
11 | 602 def keypress(self, size, key): |
603 if key=='up': | |
604 if self.listBox.get_focus()[1] == 0: | |
605 self.parent.keypress(size, key) | |
606 elif key=='left' or key=='right': | |
607 self.parent.keypress(size,'up') | |
608 self.parent.keypress(size,key) | |
609 return super(MenuBox,self).keypress(size,key) | |
66 | 610 |
26
fcc20ac7b68a
Primitivus: major changes in SelectableText, menu can now be used with mouse, TabsContainer show wich tab is selected
Goffi <goffi@goffi.org>
parents:
25
diff
changeset
|
611 def mouse_event(self, size, event, button, x, y, focus): |
fcc20ac7b68a
Primitivus: major changes in SelectableText, menu can now be used with mouse, TabsContainer show wich tab is selected
Goffi <goffi@goffi.org>
parents:
25
diff
changeset
|
612 if button == 3: |
fcc20ac7b68a
Primitivus: major changes in SelectableText, menu can now be used with mouse, TabsContainer show wich tab is selected
Goffi <goffi@goffi.org>
parents:
25
diff
changeset
|
613 self.parent.keypress(size,'up') |
fcc20ac7b68a
Primitivus: major changes in SelectableText, menu can now be used with mouse, TabsContainer show wich tab is selected
Goffi <goffi@goffi.org>
parents:
25
diff
changeset
|
614 return True |
fcc20ac7b68a
Primitivus: major changes in SelectableText, menu can now be used with mouse, TabsContainer show wich tab is selected
Goffi <goffi@goffi.org>
parents:
25
diff
changeset
|
615 return super(MenuBox,self).mouse_event(size, event, button, x, y, focus) |
11 | 616 |
617 def onClick(self, wid): | |
618 self.selected = wid.getValue() | |
619 self._emit('click') | |
620 | |
26
fcc20ac7b68a
Primitivus: major changes in SelectableText, menu can now be used with mouse, TabsContainer show wich tab is selected
Goffi <goffi@goffi.org>
parents:
25
diff
changeset
|
621 class Menu(urwid.WidgetWrap): |
10
024b79b61a31
Primitivus: misc fixes + menubar first draft
Goffi <goffi@goffi.org>
parents:
9
diff
changeset
|
622 |
12
7e63429cc929
Primitivus: menu are now managed and fully working
Goffi <goffi@goffi.org>
parents:
11
diff
changeset
|
623 def __init__(self,loop, x_orig=0): |
7e63429cc929
Primitivus: menu are now managed and fully working
Goffi <goffi@goffi.org>
parents:
11
diff
changeset
|
624 """Menu widget |
7e63429cc929
Primitivus: menu are now managed and fully working
Goffi <goffi@goffi.org>
parents:
11
diff
changeset
|
625 @param loop: main loop of urwid |
7e63429cc929
Primitivus: menu are now managed and fully working
Goffi <goffi@goffi.org>
parents:
11
diff
changeset
|
626 @param x_orig: absolute start of the abscissa |
7e63429cc929
Primitivus: menu are now managed and fully working
Goffi <goffi@goffi.org>
parents:
11
diff
changeset
|
627 """ |
11 | 628 self.loop = loop |
629 self.menu_keys = [] | |
630 self.menu = {} | |
12
7e63429cc929
Primitivus: menu are now managed and fully working
Goffi <goffi@goffi.org>
parents:
11
diff
changeset
|
631 self.x_orig = x_orig |
10
024b79b61a31
Primitivus: misc fixes + menubar first draft
Goffi <goffi@goffi.org>
parents:
9
diff
changeset
|
632 self.shortcuts = {} #keyboard shortcuts |
11 | 633 self.save_bottom = None |
26
fcc20ac7b68a
Primitivus: major changes in SelectableText, menu can now be used with mouse, TabsContainer show wich tab is selected
Goffi <goffi@goffi.org>
parents:
25
diff
changeset
|
634 col_rol = ColumnsRoller() |
fcc20ac7b68a
Primitivus: major changes in SelectableText, menu can now be used with mouse, TabsContainer show wich tab is selected
Goffi <goffi@goffi.org>
parents:
25
diff
changeset
|
635 urwid.WidgetWrap.__init__(self, urwid.AttrMap(col_rol,'menubar')) |
66 | 636 |
11 | 637 def selectable(self): |
638 return True | |
13
8cccbaadb9c5
Primitivus: menu roller doesn't go anymore on a menu if it's empty
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
639 |
8cccbaadb9c5
Primitivus: menu roller doesn't go anymore on a menu if it's empty
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
640 def getMenuSize(self): |
8cccbaadb9c5
Primitivus: menu roller doesn't go anymore on a menu if it's empty
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
641 """return the current number of categories in this menu""" |
8cccbaadb9c5
Primitivus: menu roller doesn't go anymore on a menu if it's empty
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
642 return len(self.menu_keys) |
66 | 643 |
12
7e63429cc929
Primitivus: menu are now managed and fully working
Goffi <goffi@goffi.org>
parents:
11
diff
changeset
|
644 def setOrigX(self, orig_x): |
7e63429cc929
Primitivus: menu are now managed and fully working
Goffi <goffi@goffi.org>
parents:
11
diff
changeset
|
645 self.x_orig = orig_x |
7e63429cc929
Primitivus: menu are now managed and fully working
Goffi <goffi@goffi.org>
parents:
11
diff
changeset
|
646 |
11 | 647 def __buildOverlay(self,menu_key,columns): |
648 """Build the overlay menu which show menuitems | |
649 @param menu_key: name of the category | |
650 @colums: column number where the menubox must be displayed""" | |
651 max_len = 0 | |
652 for item in self.menu[menu_key]: | |
653 if len(item[0]) > max_len: | |
654 max_len = len(item[0]) | |
655 | |
656 self.save_bottom = self.loop.widget | |
657 menu_box = MenuBox(self,[item[0] for item in self.menu[menu_key]]) | |
26
fcc20ac7b68a
Primitivus: major changes in SelectableText, menu can now be used with mouse, TabsContainer show wich tab is selected
Goffi <goffi@goffi.org>
parents:
25
diff
changeset
|
658 urwid.connect_signal(menu_box, 'click', self.onItemClick) |
66 | 659 |
660 self.loop.widget = urwid.Overlay(urwid.AttrMap(menu_box,'menubar'),self.save_bottom,('fixed left', columns),max_len+2,('fixed top',1),None) | |
11 | 661 |
662 def keypress(self, size, key): | |
26
fcc20ac7b68a
Primitivus: major changes in SelectableText, menu can now be used with mouse, TabsContainer show wich tab is selected
Goffi <goffi@goffi.org>
parents:
25
diff
changeset
|
663 if key == 'down': |
fcc20ac7b68a
Primitivus: major changes in SelectableText, menu can now be used with mouse, TabsContainer show wich tab is selected
Goffi <goffi@goffi.org>
parents:
25
diff
changeset
|
664 key = 'enter' |
11 | 665 elif key == 'up': |
666 if self.save_bottom: | |
667 self.loop.widget = self.save_bottom | |
668 self.save_bottom = None | |
66 | 669 |
26
fcc20ac7b68a
Primitivus: major changes in SelectableText, menu can now be used with mouse, TabsContainer show wich tab is selected
Goffi <goffi@goffi.org>
parents:
25
diff
changeset
|
670 return self._w.base_widget.keypress(size, key) |
66 | 671 |
10
024b79b61a31
Primitivus: misc fixes + menubar first draft
Goffi <goffi@goffi.org>
parents:
9
diff
changeset
|
672 def checkShortcuts(self, key): |
024b79b61a31
Primitivus: misc fixes + menubar first draft
Goffi <goffi@goffi.org>
parents:
9
diff
changeset
|
673 for shortcut in self.shortcuts.keys(): |
024b79b61a31
Primitivus: misc fixes + menubar first draft
Goffi <goffi@goffi.org>
parents:
9
diff
changeset
|
674 if key == shortcut: |
11 | 675 category, item, callback = self.shortcuts[shortcut] |
10
024b79b61a31
Primitivus: misc fixes + menubar first draft
Goffi <goffi@goffi.org>
parents:
9
diff
changeset
|
676 callback((category, item)) |
024b79b61a31
Primitivus: misc fixes + menubar first draft
Goffi <goffi@goffi.org>
parents:
9
diff
changeset
|
677 return key |
024b79b61a31
Primitivus: misc fixes + menubar first draft
Goffi <goffi@goffi.org>
parents:
9
diff
changeset
|
678 |
024b79b61a31
Primitivus: misc fixes + menubar first draft
Goffi <goffi@goffi.org>
parents:
9
diff
changeset
|
679 def addMenu(self, category, item, callback, shortcut=None): |
024b79b61a31
Primitivus: misc fixes + menubar first draft
Goffi <goffi@goffi.org>
parents:
9
diff
changeset
|
680 """Add a menu item, create the category if new |
024b79b61a31
Primitivus: misc fixes + menubar first draft
Goffi <goffi@goffi.org>
parents:
9
diff
changeset
|
681 @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
|
682 @param item: menu item (e.g. new/close/about) |
024b79b61a31
Primitivus: misc fixes + menubar first draft
Goffi <goffi@goffi.org>
parents:
9
diff
changeset
|
683 @callback: method to call when item is selected""" |
024b79b61a31
Primitivus: misc fixes + menubar first draft
Goffi <goffi@goffi.org>
parents:
9
diff
changeset
|
684 if not category in self.menu.keys(): |
024b79b61a31
Primitivus: misc fixes + menubar first draft
Goffi <goffi@goffi.org>
parents:
9
diff
changeset
|
685 self.menu_keys.append(category) |
024b79b61a31
Primitivus: misc fixes + menubar first draft
Goffi <goffi@goffi.org>
parents:
9
diff
changeset
|
686 self.menu[category] = [] |
26
fcc20ac7b68a
Primitivus: major changes in SelectableText, menu can now be used with mouse, TabsContainer show wich tab is selected
Goffi <goffi@goffi.org>
parents:
25
diff
changeset
|
687 button = CustomButton(('menubar',category), self.onCategoryClick, |
fcc20ac7b68a
Primitivus: major changes in SelectableText, menu can now be used with mouse, TabsContainer show wich tab is selected
Goffi <goffi@goffi.org>
parents:
25
diff
changeset
|
688 left_border = ('menubar',"[ "), |
fcc20ac7b68a
Primitivus: major changes in SelectableText, menu can now be used with mouse, TabsContainer show wich tab is selected
Goffi <goffi@goffi.org>
parents:
25
diff
changeset
|
689 right_border = ('menubar'," ]")) |
fcc20ac7b68a
Primitivus: major changes in SelectableText, menu can now be used with mouse, TabsContainer show wich tab is selected
Goffi <goffi@goffi.org>
parents:
25
diff
changeset
|
690 self._w.base_widget.addWidget(button,button.getSize()) |
11 | 691 self.menu[category].append((item, callback)) |
10
024b79b61a31
Primitivus: misc fixes + menubar first draft
Goffi <goffi@goffi.org>
parents:
9
diff
changeset
|
692 if shortcut: |
024b79b61a31
Primitivus: misc fixes + menubar first draft
Goffi <goffi@goffi.org>
parents:
9
diff
changeset
|
693 assert(shortcut not in self.shortcuts.keys()) |
024b79b61a31
Primitivus: misc fixes + menubar first draft
Goffi <goffi@goffi.org>
parents:
9
diff
changeset
|
694 self.shortcuts[shortcut] = (category, item, callback) |
024b79b61a31
Primitivus: misc fixes + menubar first draft
Goffi <goffi@goffi.org>
parents:
9
diff
changeset
|
695 |
26
fcc20ac7b68a
Primitivus: major changes in SelectableText, menu can now be used with mouse, TabsContainer show wich tab is selected
Goffi <goffi@goffi.org>
parents:
25
diff
changeset
|
696 def onItemClick(self, widget): |
fcc20ac7b68a
Primitivus: major changes in SelectableText, menu can now be used with mouse, TabsContainer show wich tab is selected
Goffi <goffi@goffi.org>
parents:
25
diff
changeset
|
697 category = self._w.base_widget.getSelected().get_label() |
11 | 698 item = widget.getValue() |
26
fcc20ac7b68a
Primitivus: major changes in SelectableText, menu can now be used with mouse, TabsContainer show wich tab is selected
Goffi <goffi@goffi.org>
parents:
25
diff
changeset
|
699 callback = None |
11 | 700 for menu_item in self.menu[category]: |
701 if item == menu_item[0]: | |
702 callback = menu_item[1] | |
703 break | |
704 if callback: | |
705 self.keypress(None,'up') | |
706 callback((category, item)) | |
66 | 707 |
26
fcc20ac7b68a
Primitivus: major changes in SelectableText, menu can now be used with mouse, TabsContainer show wich tab is selected
Goffi <goffi@goffi.org>
parents:
25
diff
changeset
|
708 def onCategoryClick(self, button): |
fcc20ac7b68a
Primitivus: major changes in SelectableText, menu can now be used with mouse, TabsContainer show wich tab is selected
Goffi <goffi@goffi.org>
parents:
25
diff
changeset
|
709 self.__buildOverlay(button.get_label(), |
66 | 710 self.x_orig + self._w.base_widget.getStartCol(button)) |
711 | |
11 | 712 |
12
7e63429cc929
Primitivus: menu are now managed and fully working
Goffi <goffi@goffi.org>
parents:
11
diff
changeset
|
713 class MenuRoller(urwid.WidgetWrap): |
7e63429cc929
Primitivus: menu are now managed and fully working
Goffi <goffi@goffi.org>
parents:
11
diff
changeset
|
714 |
7e63429cc929
Primitivus: menu are now managed and fully working
Goffi <goffi@goffi.org>
parents:
11
diff
changeset
|
715 def __init__(self,menus_list): |
7e63429cc929
Primitivus: menu are now managed and fully working
Goffi <goffi@goffi.org>
parents:
11
diff
changeset
|
716 """Create a MenuRoller |
7e63429cc929
Primitivus: menu are now managed and fully working
Goffi <goffi@goffi.org>
parents:
11
diff
changeset
|
717 @param menus_list: list of tuple with (name, Menu_instance), name can be None |
7e63429cc929
Primitivus: menu are now managed and fully working
Goffi <goffi@goffi.org>
parents:
11
diff
changeset
|
718 """ |
7e63429cc929
Primitivus: menu are now managed and fully working
Goffi <goffi@goffi.org>
parents:
11
diff
changeset
|
719 assert (menus_list) |
7e63429cc929
Primitivus: menu are now managed and fully working
Goffi <goffi@goffi.org>
parents:
11
diff
changeset
|
720 self.selected = 0 |
7e63429cc929
Primitivus: menu are now managed and fully working
Goffi <goffi@goffi.org>
parents:
11
diff
changeset
|
721 self.name_list = [] |
7e63429cc929
Primitivus: menu are now managed and fully working
Goffi <goffi@goffi.org>
parents:
11
diff
changeset
|
722 self.menus = {} |
66 | 723 |
724 self.columns = urwid.Columns([urwid.Text(''),urwid.Text('')]) | |
12
7e63429cc929
Primitivus: menu are now managed and fully working
Goffi <goffi@goffi.org>
parents:
11
diff
changeset
|
725 urwid.WidgetWrap.__init__(self, self.columns) |
66 | 726 |
12
7e63429cc929
Primitivus: menu are now managed and fully working
Goffi <goffi@goffi.org>
parents:
11
diff
changeset
|
727 for menu_tuple in menus_list: |
7e63429cc929
Primitivus: menu are now managed and fully working
Goffi <goffi@goffi.org>
parents:
11
diff
changeset
|
728 name,menu = menu_tuple |
7e63429cc929
Primitivus: menu are now managed and fully working
Goffi <goffi@goffi.org>
parents:
11
diff
changeset
|
729 self.addMenu(name, menu) |
7e63429cc929
Primitivus: menu are now managed and fully working
Goffi <goffi@goffi.org>
parents:
11
diff
changeset
|
730 |
7e63429cc929
Primitivus: menu are now managed and fully working
Goffi <goffi@goffi.org>
parents:
11
diff
changeset
|
731 def __showSelected(self): |
7e63429cc929
Primitivus: menu are now managed and fully working
Goffi <goffi@goffi.org>
parents:
11
diff
changeset
|
732 """show menu selected""" |
7e63429cc929
Primitivus: menu are now managed and fully working
Goffi <goffi@goffi.org>
parents:
11
diff
changeset
|
733 name_txt = u'\u21c9 '+self.name_list[self.selected]+u' \u21c7 ' |
66 | 734 current_name = ClickableText(name_txt) |
12
7e63429cc929
Primitivus: menu are now managed and fully working
Goffi <goffi@goffi.org>
parents:
11
diff
changeset
|
735 name_len = len(name_txt) |
7e63429cc929
Primitivus: menu are now managed and fully working
Goffi <goffi@goffi.org>
parents:
11
diff
changeset
|
736 current_menu = self.menus[self.name_list[self.selected]] |
7e63429cc929
Primitivus: menu are now managed and fully working
Goffi <goffi@goffi.org>
parents:
11
diff
changeset
|
737 current_menu.setOrigX(name_len) |
65
090f3e0754d3
fix for recent urwid versions (> 1.1.0)
Goffi <goffi@goffi.org>
parents:
64
diff
changeset
|
738 self.columns.contents[0] = (current_name, ('given', name_len, False)) |
090f3e0754d3
fix for recent urwid versions (> 1.1.0)
Goffi <goffi@goffi.org>
parents:
64
diff
changeset
|
739 self.columns.contents[1] = (current_menu, ('weight', 1, False)) |
12
7e63429cc929
Primitivus: menu are now managed and fully working
Goffi <goffi@goffi.org>
parents:
11
diff
changeset
|
740 |
7e63429cc929
Primitivus: menu are now managed and fully working
Goffi <goffi@goffi.org>
parents:
11
diff
changeset
|
741 def keypress(self, size, key): |
7e63429cc929
Primitivus: menu are now managed and fully working
Goffi <goffi@goffi.org>
parents:
11
diff
changeset
|
742 if key=='up': |
7e63429cc929
Primitivus: menu are now managed and fully working
Goffi <goffi@goffi.org>
parents:
11
diff
changeset
|
743 if self.columns.get_focus_column()==0 and self.selected > 0: |
7e63429cc929
Primitivus: menu are now managed and fully working
Goffi <goffi@goffi.org>
parents:
11
diff
changeset
|
744 self.selected -= 1 |
7e63429cc929
Primitivus: menu are now managed and fully working
Goffi <goffi@goffi.org>
parents:
11
diff
changeset
|
745 self.__showSelected() |
7e63429cc929
Primitivus: menu are now managed and fully working
Goffi <goffi@goffi.org>
parents:
11
diff
changeset
|
746 elif key=='down': |
7e63429cc929
Primitivus: menu are now managed and fully working
Goffi <goffi@goffi.org>
parents:
11
diff
changeset
|
747 if self.columns.get_focus_column()==0 and self.selected < len(self.name_list)-1: |
7e63429cc929
Primitivus: menu are now managed and fully working
Goffi <goffi@goffi.org>
parents:
11
diff
changeset
|
748 self.selected += 1 |
7e63429cc929
Primitivus: menu are now managed and fully working
Goffi <goffi@goffi.org>
parents:
11
diff
changeset
|
749 self.__showSelected() |
13
8cccbaadb9c5
Primitivus: menu roller doesn't go anymore on a menu if it's empty
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
750 elif key=='right': |
8cccbaadb9c5
Primitivus: menu roller doesn't go anymore on a menu if it's empty
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
751 if self.columns.get_focus_column()==0 and \ |
65
090f3e0754d3
fix for recent urwid versions (> 1.1.0)
Goffi <goffi@goffi.org>
parents:
64
diff
changeset
|
752 (isinstance(self.columns.contents[1][0], urwid.Text) or \ |
13
8cccbaadb9c5
Primitivus: menu roller doesn't go anymore on a menu if it's empty
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
753 self.menus[self.name_list[self.selected]].getMenuSize()==0): |
8cccbaadb9c5
Primitivus: menu roller doesn't go anymore on a menu if it's empty
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
754 return #if we have no menu or the menu is empty, we don't go the right column |
12
7e63429cc929
Primitivus: menu are now managed and fully working
Goffi <goffi@goffi.org>
parents:
11
diff
changeset
|
755 |
7e63429cc929
Primitivus: menu are now managed and fully working
Goffi <goffi@goffi.org>
parents:
11
diff
changeset
|
756 return super(MenuRoller, self).keypress(size, key) |
7e63429cc929
Primitivus: menu are now managed and fully working
Goffi <goffi@goffi.org>
parents:
11
diff
changeset
|
757 |
7e63429cc929
Primitivus: menu are now managed and fully working
Goffi <goffi@goffi.org>
parents:
11
diff
changeset
|
758 def addMenu(self, name_param, menu): |
7e63429cc929
Primitivus: menu are now managed and fully working
Goffi <goffi@goffi.org>
parents:
11
diff
changeset
|
759 name = name_param or '' |
7e63429cc929
Primitivus: menu are now managed and fully working
Goffi <goffi@goffi.org>
parents:
11
diff
changeset
|
760 if name not in self.name_list: |
7e63429cc929
Primitivus: menu are now managed and fully working
Goffi <goffi@goffi.org>
parents:
11
diff
changeset
|
761 self.name_list.append(name) |
7e63429cc929
Primitivus: menu are now managed and fully working
Goffi <goffi@goffi.org>
parents:
11
diff
changeset
|
762 self.menus[name] = menu |
7e63429cc929
Primitivus: menu are now managed and fully working
Goffi <goffi@goffi.org>
parents:
11
diff
changeset
|
763 if self.name_list[self.selected] == name: |
7e63429cc929
Primitivus: menu are now managed and fully working
Goffi <goffi@goffi.org>
parents:
11
diff
changeset
|
764 self.__showSelected() #if we are on the menu, we update it |
7e63429cc929
Primitivus: menu are now managed and fully working
Goffi <goffi@goffi.org>
parents:
11
diff
changeset
|
765 |
15
8241b3157699
Primitivus: custom_widgets imrpovments
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
766 def removeMenu(self, name): |
8241b3157699
Primitivus: custom_widgets imrpovments
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
767 if name in self.name_list: |
8241b3157699
Primitivus: custom_widgets imrpovments
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
768 self.name_list.remove(name) |
8241b3157699
Primitivus: custom_widgets imrpovments
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
769 if name in self.menus.keys(): |
8241b3157699
Primitivus: custom_widgets imrpovments
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
770 del self.menus[name] |
8241b3157699
Primitivus: custom_widgets imrpovments
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
771 self.selected = 0 |
8241b3157699
Primitivus: custom_widgets imrpovments
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
772 self.__showSelected() |
8241b3157699
Primitivus: custom_widgets imrpovments
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
773 |
12
7e63429cc929
Primitivus: menu are now managed and fully working
Goffi <goffi@goffi.org>
parents:
11
diff
changeset
|
774 def checkShortcuts(self, key): |
7e63429cc929
Primitivus: menu are now managed and fully working
Goffi <goffi@goffi.org>
parents:
11
diff
changeset
|
775 for menu in self.name_list: |
7e63429cc929
Primitivus: menu are now managed and fully working
Goffi <goffi@goffi.org>
parents:
11
diff
changeset
|
776 key = self.menus[menu].checkShortcuts(key) |
7e63429cc929
Primitivus: menu are now managed and fully working
Goffi <goffi@goffi.org>
parents:
11
diff
changeset
|
777 return key |
66 | 778 |
10
024b79b61a31
Primitivus: misc fixes + menubar first draft
Goffi <goffi@goffi.org>
parents:
9
diff
changeset
|
779 |
6 | 780 ## DIALOGS ## |
781 | |
5
592cd64933dd
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
4
diff
changeset
|
782 class GenericDialog(urwid.WidgetWrap): |
0 | 783 |
784 def __init__(self, widgets_lst, title, style=[], **kwargs): | |
785 frame_header = urwid.AttrMap(urwid.Text(title,'center'),'title') | |
66 | 786 |
0 | 787 buttons = None |
788 | |
789 if "OK/CANCEL" in style: | |
24
67a19cfeab8f
Primitivus now implement showDialog + new "newAlert" bridge method to show a dialog from core
Goffi <goffi@goffi.org>
parents:
22
diff
changeset
|
790 cancel_arg = [kwargs['cancel_value']] if kwargs.has_key('cancel_value') else [] |
67a19cfeab8f
Primitivus now implement showDialog + new "newAlert" bridge method to show a dialog from core
Goffi <goffi@goffi.org>
parents:
22
diff
changeset
|
791 ok_arg = [kwargs['ok_value']] if kwargs.has_key('ok_value') else [] |
67a19cfeab8f
Primitivus now implement showDialog + new "newAlert" bridge method to show a dialog from core
Goffi <goffi@goffi.org>
parents:
22
diff
changeset
|
792 buttons = [urwid.Button(_("Cancel"), kwargs['cancel_cb'], *cancel_arg), |
67a19cfeab8f
Primitivus now implement showDialog + new "newAlert" bridge method to show a dialog from core
Goffi <goffi@goffi.org>
parents:
22
diff
changeset
|
793 urwid.Button(_("Ok"), kwargs['ok_cb'], *ok_arg)] |
0 | 794 elif "YES/NO" in style: |
24
67a19cfeab8f
Primitivus now implement showDialog + new "newAlert" bridge method to show a dialog from core
Goffi <goffi@goffi.org>
parents:
22
diff
changeset
|
795 yes_arg = [kwargs['yes_value']] if kwargs.has_key('yes_value') else [] |
67a19cfeab8f
Primitivus now implement showDialog + new "newAlert" bridge method to show a dialog from core
Goffi <goffi@goffi.org>
parents:
22
diff
changeset
|
796 no_arg = [kwargs['no_value']] if kwargs.has_key('no_value') else [] |
67a19cfeab8f
Primitivus now implement showDialog + new "newAlert" bridge method to show a dialog from core
Goffi <goffi@goffi.org>
parents:
22
diff
changeset
|
797 buttons = [urwid.Button(_("Yes"), kwargs['yes_cb'], *yes_arg), |
67a19cfeab8f
Primitivus now implement showDialog + new "newAlert" bridge method to show a dialog from core
Goffi <goffi@goffi.org>
parents:
22
diff
changeset
|
798 urwid.Button(_("No"), kwargs['no_cb'], *no_arg)] |
1 | 799 if "OK" in style: |
24
67a19cfeab8f
Primitivus now implement showDialog + new "newAlert" bridge method to show a dialog from core
Goffi <goffi@goffi.org>
parents:
22
diff
changeset
|
800 ok_arg = [kwargs['ok_value']] if kwargs.has_key('ok_value') else [] |
67a19cfeab8f
Primitivus now implement showDialog + new "newAlert" bridge method to show a dialog from core
Goffi <goffi@goffi.org>
parents:
22
diff
changeset
|
801 buttons = [urwid.Button(_("Ok"), kwargs['ok_cb'], *ok_arg)] |
0 | 802 if buttons: |
803 buttons_flow = urwid.GridFlow(buttons, max([len(button.get_label()) for button in buttons])+4, 1, 1, 'center') | |
804 body_content = urwid.SimpleListWalker(widgets_lst) | |
805 frame_body = urwid.ListBox(body_content) | |
24
67a19cfeab8f
Primitivus now implement showDialog + new "newAlert" bridge method to show a dialog from core
Goffi <goffi@goffi.org>
parents:
22
diff
changeset
|
806 frame = FocusFrame(frame_body, frame_header, buttons_flow if buttons else None, 'footer' if buttons else 'body') |
0 | 807 decorated_frame = urwid.LineBox(frame) |
808 urwid.WidgetWrap.__init__(self, decorated_frame) | |
809 | |
810 | |
811 | |
5
592cd64933dd
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
4
diff
changeset
|
812 class InputDialog(GenericDialog): |
7 | 813 """Dialog with an edit box""" |
0 | 814 |
6 | 815 def __init__(self, title, instrucions, style=['OK/CANCEL'], default_txt = '', **kwargs): |
0 | 816 instr_wid = urwid.Text(instrucions+':') |
24
67a19cfeab8f
Primitivus now implement showDialog + new "newAlert" bridge method to show a dialog from core
Goffi <goffi@goffi.org>
parents:
22
diff
changeset
|
817 edit_box = AdvancedEdit(edit_text=default_txt) |
5
592cd64933dd
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
4
diff
changeset
|
818 GenericDialog.__init__(self, [instr_wid,edit_box], title, style, ok_value=edit_box, **kwargs) |
25
e6bd6146dd31
Primitivus: fixed focus in Input dialog
Goffi <goffi@goffi.org>
parents:
24
diff
changeset
|
819 self._w.base_widget.set_focus('body') |
0 | 820 |
5
592cd64933dd
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
4
diff
changeset
|
821 class ConfirmDialog(GenericDialog): |
7 | 822 """Dialog with buttons for confirm or cancel an action""" |
0 | 823 |
824 def __init__(self, title, style=['YES/NO'], **kwargs): | |
24
67a19cfeab8f
Primitivus now implement showDialog + new "newAlert" bridge method to show a dialog from core
Goffi <goffi@goffi.org>
parents:
22
diff
changeset
|
825 GenericDialog.__init__(self, [], title, style, **kwargs) |
1 | 826 |
5
592cd64933dd
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
4
diff
changeset
|
827 class Alert(GenericDialog): |
7 | 828 """Dialog with just a message and a OK button""" |
1 | 829 |
830 def __init__(self, title, message, style=['OK'], **kwargs): | |
5
592cd64933dd
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
4
diff
changeset
|
831 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
|
832 |
6 | 833 ## CONTAINERS ## |
834 | |
18
bdc83e857093
Primitivus: new widget ColumnsRoller which show FlowWidgets on the same row, and can roll between them if there is not enough space
Goffi <goffi@goffi.org>
parents:
17
diff
changeset
|
835 class ColumnsRoller(urwid.FlowWidget): |
66 | 836 |
18
bdc83e857093
Primitivus: new widget ColumnsRoller which show FlowWidgets on the same row, and can roll between them if there is not enough space
Goffi <goffi@goffi.org>
parents:
17
diff
changeset
|
837 def __init__(self, widget_list = None, focus_column=0): |
bdc83e857093
Primitivus: new widget ColumnsRoller which show FlowWidgets on the same row, and can roll between them if there is not enough space
Goffi <goffi@goffi.org>
parents:
17
diff
changeset
|
838 self.widget_list = widget_list or [] |
bdc83e857093
Primitivus: new widget ColumnsRoller which show FlowWidgets on the same row, and can roll between them if there is not enough space
Goffi <goffi@goffi.org>
parents:
17
diff
changeset
|
839 self.focus_column = focus_column |
bdc83e857093
Primitivus: new widget ColumnsRoller which show FlowWidgets on the same row, and can roll between them if there is not enough space
Goffi <goffi@goffi.org>
parents:
17
diff
changeset
|
840 self.__start = 0 |
bdc83e857093
Primitivus: new widget ColumnsRoller which show FlowWidgets on the same row, and can roll between them if there is not enough space
Goffi <goffi@goffi.org>
parents:
17
diff
changeset
|
841 self.__next = False |
bdc83e857093
Primitivus: new widget ColumnsRoller which show FlowWidgets on the same row, and can roll between them if there is not enough space
Goffi <goffi@goffi.org>
parents:
17
diff
changeset
|
842 |
bdc83e857093
Primitivus: new widget ColumnsRoller which show FlowWidgets on the same row, and can roll between them if there is not enough space
Goffi <goffi@goffi.org>
parents:
17
diff
changeset
|
843 def addWidget(self, widget, width): |
bdc83e857093
Primitivus: new widget ColumnsRoller which show FlowWidgets on the same row, and can roll between them if there is not enough space
Goffi <goffi@goffi.org>
parents:
17
diff
changeset
|
844 self.widget_list.append((width,widget)) |
bdc83e857093
Primitivus: new widget ColumnsRoller which show FlowWidgets on the same row, and can roll between them if there is not enough space
Goffi <goffi@goffi.org>
parents:
17
diff
changeset
|
845 if len(self.widget_list) == 1: |
bdc83e857093
Primitivus: new widget ColumnsRoller which show FlowWidgets on the same row, and can roll between them if there is not enough space
Goffi <goffi@goffi.org>
parents:
17
diff
changeset
|
846 self.set_focus(0) |
bdc83e857093
Primitivus: new widget ColumnsRoller which show FlowWidgets on the same row, and can roll between them if there is not enough space
Goffi <goffi@goffi.org>
parents:
17
diff
changeset
|
847 |
26
fcc20ac7b68a
Primitivus: major changes in SelectableText, menu can now be used with mouse, TabsContainer show wich tab is selected
Goffi <goffi@goffi.org>
parents:
25
diff
changeset
|
848 def getStartCol(self, widget): |
fcc20ac7b68a
Primitivus: major changes in SelectableText, menu can now be used with mouse, TabsContainer show wich tab is selected
Goffi <goffi@goffi.org>
parents:
25
diff
changeset
|
849 """Return the column of the left corner of the widget""" |
fcc20ac7b68a
Primitivus: major changes in SelectableText, menu can now be used with mouse, TabsContainer show wich tab is selected
Goffi <goffi@goffi.org>
parents:
25
diff
changeset
|
850 start_col = 0 |
fcc20ac7b68a
Primitivus: major changes in SelectableText, menu can now be used with mouse, TabsContainer show wich tab is selected
Goffi <goffi@goffi.org>
parents:
25
diff
changeset
|
851 for wid in self.widget_list[self.__start:]: |
fcc20ac7b68a
Primitivus: major changes in SelectableText, menu can now be used with mouse, TabsContainer show wich tab is selected
Goffi <goffi@goffi.org>
parents:
25
diff
changeset
|
852 if wid[1] == widget: |
fcc20ac7b68a
Primitivus: major changes in SelectableText, menu can now be used with mouse, TabsContainer show wich tab is selected
Goffi <goffi@goffi.org>
parents:
25
diff
changeset
|
853 return start_col |
fcc20ac7b68a
Primitivus: major changes in SelectableText, menu can now be used with mouse, TabsContainer show wich tab is selected
Goffi <goffi@goffi.org>
parents:
25
diff
changeset
|
854 start_col+=wid[0] |
fcc20ac7b68a
Primitivus: major changes in SelectableText, menu can now be used with mouse, TabsContainer show wich tab is selected
Goffi <goffi@goffi.org>
parents:
25
diff
changeset
|
855 return None |
fcc20ac7b68a
Primitivus: major changes in SelectableText, menu can now be used with mouse, TabsContainer show wich tab is selected
Goffi <goffi@goffi.org>
parents:
25
diff
changeset
|
856 |
18
bdc83e857093
Primitivus: new widget ColumnsRoller which show FlowWidgets on the same row, and can roll between them if there is not enough space
Goffi <goffi@goffi.org>
parents:
17
diff
changeset
|
857 def selectable(self): |
bdc83e857093
Primitivus: new widget ColumnsRoller which show FlowWidgets on the same row, and can roll between them if there is not enough space
Goffi <goffi@goffi.org>
parents:
17
diff
changeset
|
858 try: |
bdc83e857093
Primitivus: new widget ColumnsRoller which show FlowWidgets on the same row, and can roll between them if there is not enough space
Goffi <goffi@goffi.org>
parents:
17
diff
changeset
|
859 return self.widget_list[self.focus_column][1].selectable() |
bdc83e857093
Primitivus: new widget ColumnsRoller which show FlowWidgets on the same row, and can roll between them if there is not enough space
Goffi <goffi@goffi.org>
parents:
17
diff
changeset
|
860 except IndexError: |
bdc83e857093
Primitivus: new widget ColumnsRoller which show FlowWidgets on the same row, and can roll between them if there is not enough space
Goffi <goffi@goffi.org>
parents:
17
diff
changeset
|
861 return False |
66 | 862 |
18
bdc83e857093
Primitivus: new widget ColumnsRoller which show FlowWidgets on the same row, and can roll between them if there is not enough space
Goffi <goffi@goffi.org>
parents:
17
diff
changeset
|
863 def keypress(self, size, key): |
bdc83e857093
Primitivus: new widget ColumnsRoller which show FlowWidgets on the same row, and can roll between them if there is not enough space
Goffi <goffi@goffi.org>
parents:
17
diff
changeset
|
864 if key=='left': |
bdc83e857093
Primitivus: new widget ColumnsRoller which show FlowWidgets on the same row, and can roll between them if there is not enough space
Goffi <goffi@goffi.org>
parents:
17
diff
changeset
|
865 if self.focus_column>0: |
bdc83e857093
Primitivus: new widget ColumnsRoller which show FlowWidgets on the same row, and can roll between them if there is not enough space
Goffi <goffi@goffi.org>
parents:
17
diff
changeset
|
866 self.focus_column-=1 |
bdc83e857093
Primitivus: new widget ColumnsRoller which show FlowWidgets on the same row, and can roll between them if there is not enough space
Goffi <goffi@goffi.org>
parents:
17
diff
changeset
|
867 self._invalidate() |
bdc83e857093
Primitivus: new widget ColumnsRoller which show FlowWidgets on the same row, and can roll between them if there is not enough space
Goffi <goffi@goffi.org>
parents:
17
diff
changeset
|
868 return |
bdc83e857093
Primitivus: new widget ColumnsRoller which show FlowWidgets on the same row, and can roll between them if there is not enough space
Goffi <goffi@goffi.org>
parents:
17
diff
changeset
|
869 if key=='right': |
bdc83e857093
Primitivus: new widget ColumnsRoller which show FlowWidgets on the same row, and can roll between them if there is not enough space
Goffi <goffi@goffi.org>
parents:
17
diff
changeset
|
870 if self.focus_column<len(self.widget_list)-1: |
bdc83e857093
Primitivus: new widget ColumnsRoller which show FlowWidgets on the same row, and can roll between them if there is not enough space
Goffi <goffi@goffi.org>
parents:
17
diff
changeset
|
871 self.focus_column+=1 |
bdc83e857093
Primitivus: new widget ColumnsRoller which show FlowWidgets on the same row, and can roll between them if there is not enough space
Goffi <goffi@goffi.org>
parents:
17
diff
changeset
|
872 self._invalidate() |
bdc83e857093
Primitivus: new widget ColumnsRoller which show FlowWidgets on the same row, and can roll between them if there is not enough space
Goffi <goffi@goffi.org>
parents:
17
diff
changeset
|
873 return |
bdc83e857093
Primitivus: new widget ColumnsRoller which show FlowWidgets on the same row, and can roll between them if there is not enough space
Goffi <goffi@goffi.org>
parents:
17
diff
changeset
|
874 if self.focus_column<len(self.widget_list): |
bdc83e857093
Primitivus: new widget ColumnsRoller which show FlowWidgets on the same row, and can roll between them if there is not enough space
Goffi <goffi@goffi.org>
parents:
17
diff
changeset
|
875 return self.widget_list[self.focus_column][1].keypress(size,key) |
bdc83e857093
Primitivus: new widget ColumnsRoller which show FlowWidgets on the same row, and can roll between them if there is not enough space
Goffi <goffi@goffi.org>
parents:
17
diff
changeset
|
876 return key |
bdc83e857093
Primitivus: new widget ColumnsRoller which show FlowWidgets on the same row, and can roll between them if there is not enough space
Goffi <goffi@goffi.org>
parents:
17
diff
changeset
|
877 |
26
fcc20ac7b68a
Primitivus: major changes in SelectableText, menu can now be used with mouse, TabsContainer show wich tab is selected
Goffi <goffi@goffi.org>
parents:
25
diff
changeset
|
878 def getSelected(self): |
fcc20ac7b68a
Primitivus: major changes in SelectableText, menu can now be used with mouse, TabsContainer show wich tab is selected
Goffi <goffi@goffi.org>
parents:
25
diff
changeset
|
879 """Return selected widget""" |
fcc20ac7b68a
Primitivus: major changes in SelectableText, menu can now be used with mouse, TabsContainer show wich tab is selected
Goffi <goffi@goffi.org>
parents:
25
diff
changeset
|
880 return self.widget_list[self.focus_column][1] |
fcc20ac7b68a
Primitivus: major changes in SelectableText, menu can now be used with mouse, TabsContainer show wich tab is selected
Goffi <goffi@goffi.org>
parents:
25
diff
changeset
|
881 |
18
bdc83e857093
Primitivus: new widget ColumnsRoller which show FlowWidgets on the same row, and can roll between them if there is not enough space
Goffi <goffi@goffi.org>
parents:
17
diff
changeset
|
882 def set_focus(self, idx): |
bdc83e857093
Primitivus: new widget ColumnsRoller which show FlowWidgets on the same row, and can roll between them if there is not enough space
Goffi <goffi@goffi.org>
parents:
17
diff
changeset
|
883 if idx>len(self.widget_list)-1: |
bdc83e857093
Primitivus: new widget ColumnsRoller which show FlowWidgets on the same row, and can roll between them if there is not enough space
Goffi <goffi@goffi.org>
parents:
17
diff
changeset
|
884 idx = len(self.widget_list)-1 |
bdc83e857093
Primitivus: new widget ColumnsRoller which show FlowWidgets on the same row, and can roll between them if there is not enough space
Goffi <goffi@goffi.org>
parents:
17
diff
changeset
|
885 self.focus_column = idx |
bdc83e857093
Primitivus: new widget ColumnsRoller which show FlowWidgets on the same row, and can roll between them if there is not enough space
Goffi <goffi@goffi.org>
parents:
17
diff
changeset
|
886 |
bdc83e857093
Primitivus: new widget ColumnsRoller which show FlowWidgets on the same row, and can roll between them if there is not enough space
Goffi <goffi@goffi.org>
parents:
17
diff
changeset
|
887 def rows(self,size,focus=False): |
bdc83e857093
Primitivus: new widget ColumnsRoller which show FlowWidgets on the same row, and can roll between them if there is not enough space
Goffi <goffi@goffi.org>
parents:
17
diff
changeset
|
888 return 1 |
bdc83e857093
Primitivus: new widget ColumnsRoller which show FlowWidgets on the same row, and can roll between them if there is not enough space
Goffi <goffi@goffi.org>
parents:
17
diff
changeset
|
889 |
bdc83e857093
Primitivus: new widget ColumnsRoller which show FlowWidgets on the same row, and can roll between them if there is not enough space
Goffi <goffi@goffi.org>
parents:
17
diff
changeset
|
890 def __calculate_limits(self, size): |
bdc83e857093
Primitivus: new widget ColumnsRoller which show FlowWidgets on the same row, and can roll between them if there is not enough space
Goffi <goffi@goffi.org>
parents:
17
diff
changeset
|
891 (maxcol,) = size |
bdc83e857093
Primitivus: new widget ColumnsRoller which show FlowWidgets on the same row, and can roll between them if there is not enough space
Goffi <goffi@goffi.org>
parents:
17
diff
changeset
|
892 _prev = _next = False |
bdc83e857093
Primitivus: new widget ColumnsRoller which show FlowWidgets on the same row, and can roll between them if there is not enough space
Goffi <goffi@goffi.org>
parents:
17
diff
changeset
|
893 start_wid = 0 |
bdc83e857093
Primitivus: new widget ColumnsRoller which show FlowWidgets on the same row, and can roll between them if there is not enough space
Goffi <goffi@goffi.org>
parents:
17
diff
changeset
|
894 end_wid = len(self.widget_list)-1 |
66 | 895 |
18
bdc83e857093
Primitivus: new widget ColumnsRoller which show FlowWidgets on the same row, and can roll between them if there is not enough space
Goffi <goffi@goffi.org>
parents:
17
diff
changeset
|
896 total_wid = sum([w[0] for w in self.widget_list]) |
bdc83e857093
Primitivus: new widget ColumnsRoller which show FlowWidgets on the same row, and can roll between them if there is not enough space
Goffi <goffi@goffi.org>
parents:
17
diff
changeset
|
897 while total_wid > maxcol: |
bdc83e857093
Primitivus: new widget ColumnsRoller which show FlowWidgets on the same row, and can roll between them if there is not enough space
Goffi <goffi@goffi.org>
parents:
17
diff
changeset
|
898 if self.focus_column == end_wid: |
bdc83e857093
Primitivus: new widget ColumnsRoller which show FlowWidgets on the same row, and can roll between them if there is not enough space
Goffi <goffi@goffi.org>
parents:
17
diff
changeset
|
899 if not _prev: |
bdc83e857093
Primitivus: new widget ColumnsRoller which show FlowWidgets on the same row, and can roll between them if there is not enough space
Goffi <goffi@goffi.org>
parents:
17
diff
changeset
|
900 total_wid+=1 |
bdc83e857093
Primitivus: new widget ColumnsRoller which show FlowWidgets on the same row, and can roll between them if there is not enough space
Goffi <goffi@goffi.org>
parents:
17
diff
changeset
|
901 _prev = True |
bdc83e857093
Primitivus: new widget ColumnsRoller which show FlowWidgets on the same row, and can roll between them if there is not enough space
Goffi <goffi@goffi.org>
parents:
17
diff
changeset
|
902 total_wid-=self.widget_list[start_wid][0] |
bdc83e857093
Primitivus: new widget ColumnsRoller which show FlowWidgets on the same row, and can roll between them if there is not enough space
Goffi <goffi@goffi.org>
parents:
17
diff
changeset
|
903 start_wid+=1 |
bdc83e857093
Primitivus: new widget ColumnsRoller which show FlowWidgets on the same row, and can roll between them if there is not enough space
Goffi <goffi@goffi.org>
parents:
17
diff
changeset
|
904 else: |
bdc83e857093
Primitivus: new widget ColumnsRoller which show FlowWidgets on the same row, and can roll between them if there is not enough space
Goffi <goffi@goffi.org>
parents:
17
diff
changeset
|
905 if not _next: |
bdc83e857093
Primitivus: new widget ColumnsRoller which show FlowWidgets on the same row, and can roll between them if there is not enough space
Goffi <goffi@goffi.org>
parents:
17
diff
changeset
|
906 total_wid+=1 |
bdc83e857093
Primitivus: new widget ColumnsRoller which show FlowWidgets on the same row, and can roll between them if there is not enough space
Goffi <goffi@goffi.org>
parents:
17
diff
changeset
|
907 _next = True |
bdc83e857093
Primitivus: new widget ColumnsRoller which show FlowWidgets on the same row, and can roll between them if there is not enough space
Goffi <goffi@goffi.org>
parents:
17
diff
changeset
|
908 total_wid-=self.widget_list[end_wid][0] |
bdc83e857093
Primitivus: new widget ColumnsRoller which show FlowWidgets on the same row, and can roll between them if there is not enough space
Goffi <goffi@goffi.org>
parents:
17
diff
changeset
|
909 end_wid-=1 |
66 | 910 |
18
bdc83e857093
Primitivus: new widget ColumnsRoller which show FlowWidgets on the same row, and can roll between them if there is not enough space
Goffi <goffi@goffi.org>
parents:
17
diff
changeset
|
911 cols_left = maxcol - total_wid |
26
fcc20ac7b68a
Primitivus: major changes in SelectableText, menu can now be used with mouse, TabsContainer show wich tab is selected
Goffi <goffi@goffi.org>
parents:
25
diff
changeset
|
912 self.__start = start_wid #we need to keep it for getStartCol |
18
bdc83e857093
Primitivus: new widget ColumnsRoller which show FlowWidgets on the same row, and can roll between them if there is not enough space
Goffi <goffi@goffi.org>
parents:
17
diff
changeset
|
913 return _prev,_next,start_wid,end_wid,cols_left |
66 | 914 |
18
bdc83e857093
Primitivus: new widget ColumnsRoller which show FlowWidgets on the same row, and can roll between them if there is not enough space
Goffi <goffi@goffi.org>
parents:
17
diff
changeset
|
915 |
bdc83e857093
Primitivus: new widget ColumnsRoller which show FlowWidgets on the same row, and can roll between them if there is not enough space
Goffi <goffi@goffi.org>
parents:
17
diff
changeset
|
916 def mouse_event(self, size, event, button, x, y, focus): |
bdc83e857093
Primitivus: new widget ColumnsRoller which show FlowWidgets on the same row, and can roll between them if there is not enough space
Goffi <goffi@goffi.org>
parents:
17
diff
changeset
|
917 (maxcol,)=size |
bdc83e857093
Primitivus: new widget ColumnsRoller which show FlowWidgets on the same row, and can roll between them if there is not enough space
Goffi <goffi@goffi.org>
parents:
17
diff
changeset
|
918 |
53
d34f2b0f68d3
urwid 1.0.0 update: fixed missing is_mouse_press
Goffi <goffi@goffi.org>
parents:
44
diff
changeset
|
919 if is_mouse_press(event) and button == 1: |
18
bdc83e857093
Primitivus: new widget ColumnsRoller which show FlowWidgets on the same row, and can roll between them if there is not enough space
Goffi <goffi@goffi.org>
parents:
17
diff
changeset
|
920 _prev,_next,start_wid,end_wid,cols_left = self.__calculate_limits(size) |
bdc83e857093
Primitivus: new widget ColumnsRoller which show FlowWidgets on the same row, and can roll between them if there is not enough space
Goffi <goffi@goffi.org>
parents:
17
diff
changeset
|
921 if x==0 and _prev: |
bdc83e857093
Primitivus: new widget ColumnsRoller which show FlowWidgets on the same row, and can roll between them if there is not enough space
Goffi <goffi@goffi.org>
parents:
17
diff
changeset
|
922 self.keypress(size,'left') |
bdc83e857093
Primitivus: new widget ColumnsRoller which show FlowWidgets on the same row, and can roll between them if there is not enough space
Goffi <goffi@goffi.org>
parents:
17
diff
changeset
|
923 return True |
bdc83e857093
Primitivus: new widget ColumnsRoller which show FlowWidgets on the same row, and can roll between them if there is not enough space
Goffi <goffi@goffi.org>
parents:
17
diff
changeset
|
924 if x==maxcol-1 and _next: |
bdc83e857093
Primitivus: new widget ColumnsRoller which show FlowWidgets on the same row, and can roll between them if there is not enough space
Goffi <goffi@goffi.org>
parents:
17
diff
changeset
|
925 self.keypress(size,'right') |
bdc83e857093
Primitivus: new widget ColumnsRoller which show FlowWidgets on the same row, and can roll between them if there is not enough space
Goffi <goffi@goffi.org>
parents:
17
diff
changeset
|
926 return True |
66 | 927 |
18
bdc83e857093
Primitivus: new widget ColumnsRoller which show FlowWidgets on the same row, and can roll between them if there is not enough space
Goffi <goffi@goffi.org>
parents:
17
diff
changeset
|
928 current_pos = 1 if _prev else 0 |
bdc83e857093
Primitivus: new widget ColumnsRoller which show FlowWidgets on the same row, and can roll between them if there is not enough space
Goffi <goffi@goffi.org>
parents:
17
diff
changeset
|
929 idx = 0 |
bdc83e857093
Primitivus: new widget ColumnsRoller which show FlowWidgets on the same row, and can roll between them if there is not enough space
Goffi <goffi@goffi.org>
parents:
17
diff
changeset
|
930 while current_pos<x and idx<len(self.widget_list): |
bdc83e857093
Primitivus: new widget ColumnsRoller which show FlowWidgets on the same row, and can roll between them if there is not enough space
Goffi <goffi@goffi.org>
parents:
17
diff
changeset
|
931 width,widget = self.widget_list[idx] |
bdc83e857093
Primitivus: new widget ColumnsRoller which show FlowWidgets on the same row, and can roll between them if there is not enough space
Goffi <goffi@goffi.org>
parents:
17
diff
changeset
|
932 if x<=current_pos+width: |
bdc83e857093
Primitivus: new widget ColumnsRoller which show FlowWidgets on the same row, and can roll between them if there is not enough space
Goffi <goffi@goffi.org>
parents:
17
diff
changeset
|
933 self.focus_column = idx |
bdc83e857093
Primitivus: new widget ColumnsRoller which show FlowWidgets on the same row, and can roll between them if there is not enough space
Goffi <goffi@goffi.org>
parents:
17
diff
changeset
|
934 self._invalidate() |
bdc83e857093
Primitivus: new widget ColumnsRoller which show FlowWidgets on the same row, and can roll between them if there is not enough space
Goffi <goffi@goffi.org>
parents:
17
diff
changeset
|
935 if not hasattr(widget,'mouse_event'): |
bdc83e857093
Primitivus: new widget ColumnsRoller which show FlowWidgets on the same row, and can roll between them if there is not enough space
Goffi <goffi@goffi.org>
parents:
17
diff
changeset
|
936 return False |
66 | 937 return widget.mouse_event((width,0), event, button, |
18
bdc83e857093
Primitivus: new widget ColumnsRoller which show FlowWidgets on the same row, and can roll between them if there is not enough space
Goffi <goffi@goffi.org>
parents:
17
diff
changeset
|
938 x-current_pos, 0, focus) |
bdc83e857093
Primitivus: new widget ColumnsRoller which show FlowWidgets on the same row, and can roll between them if there is not enough space
Goffi <goffi@goffi.org>
parents:
17
diff
changeset
|
939 |
bdc83e857093
Primitivus: new widget ColumnsRoller which show FlowWidgets on the same row, and can roll between them if there is not enough space
Goffi <goffi@goffi.org>
parents:
17
diff
changeset
|
940 current_pos+=self.widget_list[idx][0] |
bdc83e857093
Primitivus: new widget ColumnsRoller which show FlowWidgets on the same row, and can roll between them if there is not enough space
Goffi <goffi@goffi.org>
parents:
17
diff
changeset
|
941 idx+=1 |
66 | 942 |
18
bdc83e857093
Primitivus: new widget ColumnsRoller which show FlowWidgets on the same row, and can roll between them if there is not enough space
Goffi <goffi@goffi.org>
parents:
17
diff
changeset
|
943 return False |
66 | 944 |
18
bdc83e857093
Primitivus: new widget ColumnsRoller which show FlowWidgets on the same row, and can roll between them if there is not enough space
Goffi <goffi@goffi.org>
parents:
17
diff
changeset
|
945 def render(self, size, focus=False): |
bdc83e857093
Primitivus: new widget ColumnsRoller which show FlowWidgets on the same row, and can roll between them if there is not enough space
Goffi <goffi@goffi.org>
parents:
17
diff
changeset
|
946 if not self.widget_list: |
bdc83e857093
Primitivus: new widget ColumnsRoller which show FlowWidgets on the same row, and can roll between them if there is not enough space
Goffi <goffi@goffi.org>
parents:
17
diff
changeset
|
947 return SolidCanvas(" ", size[0], 1) |
bdc83e857093
Primitivus: new widget ColumnsRoller which show FlowWidgets on the same row, and can roll between them if there is not enough space
Goffi <goffi@goffi.org>
parents:
17
diff
changeset
|
948 |
bdc83e857093
Primitivus: new widget ColumnsRoller which show FlowWidgets on the same row, and can roll between them if there is not enough space
Goffi <goffi@goffi.org>
parents:
17
diff
changeset
|
949 _prev,_next,start_wid,end_wid,cols_left = self.__calculate_limits(size) |
66 | 950 |
18
bdc83e857093
Primitivus: new widget ColumnsRoller which show FlowWidgets on the same row, and can roll between them if there is not enough space
Goffi <goffi@goffi.org>
parents:
17
diff
changeset
|
951 idx=start_wid |
bdc83e857093
Primitivus: new widget ColumnsRoller which show FlowWidgets on the same row, and can roll between them if there is not enough space
Goffi <goffi@goffi.org>
parents:
17
diff
changeset
|
952 render = [] |
bdc83e857093
Primitivus: new widget ColumnsRoller which show FlowWidgets on the same row, and can roll between them if there is not enough space
Goffi <goffi@goffi.org>
parents:
17
diff
changeset
|
953 |
bdc83e857093
Primitivus: new widget ColumnsRoller which show FlowWidgets on the same row, and can roll between them if there is not enough space
Goffi <goffi@goffi.org>
parents:
17
diff
changeset
|
954 for width,widget in self.widget_list[start_wid:end_wid+1]: |
bdc83e857093
Primitivus: new widget ColumnsRoller which show FlowWidgets on the same row, and can roll between them if there is not enough space
Goffi <goffi@goffi.org>
parents:
17
diff
changeset
|
955 _focus = idx == self.focus_column and focus |
bdc83e857093
Primitivus: new widget ColumnsRoller which show FlowWidgets on the same row, and can roll between them if there is not enough space
Goffi <goffi@goffi.org>
parents:
17
diff
changeset
|
956 render.append((widget.render((width,),_focus),False,_focus,width)) |
bdc83e857093
Primitivus: new widget ColumnsRoller which show FlowWidgets on the same row, and can roll between them if there is not enough space
Goffi <goffi@goffi.org>
parents:
17
diff
changeset
|
957 idx+=1 |
bdc83e857093
Primitivus: new widget ColumnsRoller which show FlowWidgets on the same row, and can roll between them if there is not enough space
Goffi <goffi@goffi.org>
parents:
17
diff
changeset
|
958 if _prev: |
bdc83e857093
Primitivus: new widget ColumnsRoller which show FlowWidgets on the same row, and can roll between them if there is not enough space
Goffi <goffi@goffi.org>
parents:
17
diff
changeset
|
959 render.insert(0,(urwid.Text([u"◀"]).render((1,),False),False,False,1)) |
bdc83e857093
Primitivus: new widget ColumnsRoller which show FlowWidgets on the same row, and can roll between them if there is not enough space
Goffi <goffi@goffi.org>
parents:
17
diff
changeset
|
960 if _next: |
bdc83e857093
Primitivus: new widget ColumnsRoller which show FlowWidgets on the same row, and can roll between them if there is not enough space
Goffi <goffi@goffi.org>
parents:
17
diff
changeset
|
961 render.append((urwid.Text([u"▶"],align='right').render((1+cols_left,),False),False,False,1+cols_left)) |
bdc83e857093
Primitivus: new widget ColumnsRoller which show FlowWidgets on the same row, and can roll between them if there is not enough space
Goffi <goffi@goffi.org>
parents:
17
diff
changeset
|
962 else: |
bdc83e857093
Primitivus: new widget ColumnsRoller which show FlowWidgets on the same row, and can roll between them if there is not enough space
Goffi <goffi@goffi.org>
parents:
17
diff
changeset
|
963 render.append((urwid.SolidCanvas(" "*cols_left, size[0], 1),False,False,cols_left)) |
bdc83e857093
Primitivus: new widget ColumnsRoller which show FlowWidgets on the same row, and can roll between them if there is not enough space
Goffi <goffi@goffi.org>
parents:
17
diff
changeset
|
964 |
bdc83e857093
Primitivus: new widget ColumnsRoller which show FlowWidgets on the same row, and can roll between them if there is not enough space
Goffi <goffi@goffi.org>
parents:
17
diff
changeset
|
965 return urwid.CanvasJoin(render) |
bdc83e857093
Primitivus: new widget ColumnsRoller which show FlowWidgets on the same row, and can roll between them if there is not enough space
Goffi <goffi@goffi.org>
parents:
17
diff
changeset
|
966 |
bdc83e857093
Primitivus: new widget ColumnsRoller which show FlowWidgets on the same row, and can roll between them if there is not enough space
Goffi <goffi@goffi.org>
parents:
17
diff
changeset
|
967 |
5
592cd64933dd
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
4
diff
changeset
|
968 class FocusFrame(urwid.Frame): |
7 | 969 """Frame which manage 'tab' key""" |
5
592cd64933dd
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
4
diff
changeset
|
970 |
592cd64933dd
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
4
diff
changeset
|
971 def keypress(self, size, key): |
19
0b83dd2b15d1
Primitivus: misc improvments on TabsContainer/FocusFrame
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
972 ret = urwid.Frame.keypress(self, size, key) |
0b83dd2b15d1
Primitivus: misc improvments on TabsContainer/FocusFrame
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
973 if not ret: |
0b83dd2b15d1
Primitivus: misc improvments on TabsContainer/FocusFrame
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
974 return |
66 | 975 |
5
592cd64933dd
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
4
diff
changeset
|
976 if key == 'tab': |
592cd64933dd
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
4
diff
changeset
|
977 focus_list = ('header','body','footer') |
592cd64933dd
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
4
diff
changeset
|
978 focus_idx = focus_list.index(self.focus_part) |
592cd64933dd
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
4
diff
changeset
|
979 for i in range(2): |
592cd64933dd
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
4
diff
changeset
|
980 focus_idx = (focus_idx + 1) % len(focus_list) |
592cd64933dd
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
4
diff
changeset
|
981 focus_name = focus_list[focus_idx] |
592cd64933dd
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
4
diff
changeset
|
982 widget = getattr(self,'_'+focus_name) |
592cd64933dd
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
4
diff
changeset
|
983 if widget!=None and widget.selectable(): |
592cd64933dd
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
4
diff
changeset
|
984 self.set_focus(focus_name) |
592cd64933dd
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
4
diff
changeset
|
985 |
66 | 986 return ret |
6 | 987 |
15
8241b3157699
Primitivus: custom_widgets imrpovments
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
988 class TabsContainer(urwid.WidgetWrap): |
8241b3157699
Primitivus: custom_widgets imrpovments
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
989 signals = ['click'] |
8241b3157699
Primitivus: custom_widgets imrpovments
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
990 |
8241b3157699
Primitivus: custom_widgets imrpovments
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
991 def __init__(self): |
26
fcc20ac7b68a
Primitivus: major changes in SelectableText, menu can now be used with mouse, TabsContainer show wich tab is selected
Goffi <goffi@goffi.org>
parents:
25
diff
changeset
|
992 self._current_tab = None |
18
bdc83e857093
Primitivus: new widget ColumnsRoller which show FlowWidgets on the same row, and can roll between them if there is not enough space
Goffi <goffi@goffi.org>
parents:
17
diff
changeset
|
993 self._buttons_cont = ColumnsRoller() |
15
8241b3157699
Primitivus: custom_widgets imrpovments
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
994 self.tabs = [] |
19
0b83dd2b15d1
Primitivus: misc improvments on TabsContainer/FocusFrame
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
995 self.__frame = FocusFrame(urwid.Filler(urwid.Text('')),urwid.Pile([self._buttons_cont,urwid.Divider(u"─")])) |
15
8241b3157699
Primitivus: custom_widgets imrpovments
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
996 urwid.WidgetWrap.__init__(self, self.__frame) |
8241b3157699
Primitivus: custom_widgets imrpovments
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
997 |
8241b3157699
Primitivus: custom_widgets imrpovments
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
998 def keypress(self, size, key): |
19
0b83dd2b15d1
Primitivus: misc improvments on TabsContainer/FocusFrame
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
999 if key=='tab': |
0b83dd2b15d1
Primitivus: misc improvments on TabsContainer/FocusFrame
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
1000 self._w.keypress(size,key) |
0b83dd2b15d1
Primitivus: misc improvments on TabsContainer/FocusFrame
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
1001 return |
0b83dd2b15d1
Primitivus: misc improvments on TabsContainer/FocusFrame
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
1002 return self._w.keypress(size,key) |
15
8241b3157699
Primitivus: custom_widgets imrpovments
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
1003 |
8241b3157699
Primitivus: custom_widgets imrpovments
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
1004 def __buttonClicked(self, button, invisible=False): |
8241b3157699
Primitivus: custom_widgets imrpovments
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
1005 """Called when a button on the tab is changed, |
8241b3157699
Primitivus: custom_widgets imrpovments
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
1006 change the page |
8241b3157699
Primitivus: custom_widgets imrpovments
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
1007 @param button: button clicked |
8241b3157699
Primitivus: custom_widgets imrpovments
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
1008 @param invisible: emit signal only if False""" |
8241b3157699
Primitivus: custom_widgets imrpovments
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
1009 tab_name = button.get_label() |
8241b3157699
Primitivus: custom_widgets imrpovments
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
1010 for tab in self.tabs: |
8241b3157699
Primitivus: custom_widgets imrpovments
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
1011 if tab[0] == tab_name: |
8241b3157699
Primitivus: custom_widgets imrpovments
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
1012 break |
8241b3157699
Primitivus: custom_widgets imrpovments
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
1013 if tab[0] != tab_name: |
8241b3157699
Primitivus: custom_widgets imrpovments
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
1014 error(_("INTERNAL ERROR: Tab not found")) |
8241b3157699
Primitivus: custom_widgets imrpovments
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
1015 assert(False) |
8241b3157699
Primitivus: custom_widgets imrpovments
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
1016 self.__frame.body = tab[1] |
26
fcc20ac7b68a
Primitivus: major changes in SelectableText, menu can now be used with mouse, TabsContainer show wich tab is selected
Goffi <goffi@goffi.org>
parents:
25
diff
changeset
|
1017 button.set_label(('title',button.get_label())) |
fcc20ac7b68a
Primitivus: major changes in SelectableText, menu can now be used with mouse, TabsContainer show wich tab is selected
Goffi <goffi@goffi.org>
parents:
25
diff
changeset
|
1018 if self._current_tab: |
fcc20ac7b68a
Primitivus: major changes in SelectableText, menu can now be used with mouse, TabsContainer show wich tab is selected
Goffi <goffi@goffi.org>
parents:
25
diff
changeset
|
1019 self._current_tab.set_label(self._current_tab.get_label()) |
fcc20ac7b68a
Primitivus: major changes in SelectableText, menu can now be used with mouse, TabsContainer show wich tab is selected
Goffi <goffi@goffi.org>
parents:
25
diff
changeset
|
1020 self._current_tab = button |
15
8241b3157699
Primitivus: custom_widgets imrpovments
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
1021 if not invisible: |
8241b3157699
Primitivus: custom_widgets imrpovments
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
1022 self._emit('click') |
8241b3157699
Primitivus: custom_widgets imrpovments
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
1023 |
8241b3157699
Primitivus: custom_widgets imrpovments
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
1024 def __appendButton(self, name): |
8241b3157699
Primitivus: custom_widgets imrpovments
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
1025 """Append a button to the frame header, |
8241b3157699
Primitivus: custom_widgets imrpovments
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
1026 and link it to the page change method""" |
18
bdc83e857093
Primitivus: new widget ColumnsRoller which show FlowWidgets on the same row, and can roll between them if there is not enough space
Goffi <goffi@goffi.org>
parents:
17
diff
changeset
|
1027 button = CustomButton(name, self.__buttonClicked, left_border = '', right_border=' | ') |
bdc83e857093
Primitivus: new widget ColumnsRoller which show FlowWidgets on the same row, and can roll between them if there is not enough space
Goffi <goffi@goffi.org>
parents:
17
diff
changeset
|
1028 self._buttons_cont.addWidget(button, button.getSize()) |
bdc83e857093
Primitivus: new widget ColumnsRoller which show FlowWidgets on the same row, and can roll between them if there is not enough space
Goffi <goffi@goffi.org>
parents:
17
diff
changeset
|
1029 if len(self._buttons_cont.widget_list) == 1: |
15
8241b3157699
Primitivus: custom_widgets imrpovments
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
1030 #first button: we set the focus and the body |
8241b3157699
Primitivus: custom_widgets imrpovments
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
1031 self._buttons_cont.set_focus(0) |
8241b3157699
Primitivus: custom_widgets imrpovments
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
1032 self.__buttonClicked(button,True) |
8241b3157699
Primitivus: custom_widgets imrpovments
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
1033 |
8241b3157699
Primitivus: custom_widgets imrpovments
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
1034 def addTab(self,name,content=[]): |
8241b3157699
Primitivus: custom_widgets imrpovments
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
1035 """Add a page to the container |
8241b3157699
Primitivus: custom_widgets imrpovments
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
1036 @param name: name of the page (what appear on the tab) |
8241b3157699
Primitivus: custom_widgets imrpovments
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
1037 @param content: content of the page |
8241b3157699
Primitivus: custom_widgets imrpovments
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
1038 @return: ListBox (content of the page)""" |
8241b3157699
Primitivus: custom_widgets imrpovments
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
1039 listbox = urwid.ListBox(urwid.SimpleListWalker(content)) |
8241b3157699
Primitivus: custom_widgets imrpovments
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
1040 self.tabs.append([name,listbox]) |
8241b3157699
Primitivus: custom_widgets imrpovments
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
1041 self.__appendButton(name) |
8241b3157699
Primitivus: custom_widgets imrpovments
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
1042 return listbox |
8241b3157699
Primitivus: custom_widgets imrpovments
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
1043 |
19
0b83dd2b15d1
Primitivus: misc improvments on TabsContainer/FocusFrame
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
1044 def addFooter(self, widget): |
0b83dd2b15d1
Primitivus: misc improvments on TabsContainer/FocusFrame
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
1045 """Add a widget on the bottom of the tab (will be displayed on all pages) |
0b83dd2b15d1
Primitivus: misc improvments on TabsContainer/FocusFrame
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
1046 @param widget: FlowWidget""" |
0b83dd2b15d1
Primitivus: misc improvments on TabsContainer/FocusFrame
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
1047 self._w.footer = widget |
66 | 1048 |
19
0b83dd2b15d1
Primitivus: misc improvments on TabsContainer/FocusFrame
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
1049 |
6 | 1050 ## DECORATORS ## |
1051 class LabelLine(urwid.LineBox): | |
7 | 1052 """Like LineBox, but with a Label centered in the top line""" |
6 | 1053 |
1054 def __init__(self, original_widget, label_widget): | |
1055 urwid.LineBox.__init__(self, original_widget) | |
1056 top_columns = self._w.widget_list[0] | |
1057 top_columns.widget_list[1] = label_widget | |
8 | 1058 |
1059 class VerticalSeparator(urwid.WidgetDecoration, urwid.WidgetWrap): | |
21 | 1060 def __init__(self, original_widget, left_char = u"│", right_char = ''): |
15
8241b3157699
Primitivus: custom_widgets imrpovments
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
1061 """Draw a separator on left and/or right of original_widget.""" |
66 | 1062 |
8 | 1063 widgets = [original_widget] |
1064 if left_char: | |
1065 widgets.insert(0, ('fixed', 1, urwid.SolidFill(left_char))) | |
1066 if right_char: | |
1067 widgets.append(('fixed', 1, urwid.SolidFill(right_char))) | |
1068 columns = urwid.Columns(widgets, box_columns = [0,2], focus_column = 1) | |
1069 urwid.WidgetDecoration.__init__(self, original_widget) | |
1070 urwid.WidgetWrap.__init__(self, columns) | |
1071 | |
66 | 1072 |