Mercurial > urwid-satext
annotate urwid_satext/sat_widgets.py @ 116:8e9a6a9c727e
minor docstring fix
author | Goffi <goffi@goffi.org> |
---|---|
date | Tue, 17 Nov 2015 12:29:14 +0100 |
parents | 2b7eafea8bdb |
children | 0cf705af755c |
rev | line source |
---|---|
0 | 1 #!/usr/bin/python |
2 # -*- coding: utf-8 -*- | |
3 | |
64 | 4 # Urwid SàT extensions |
108 | 5 # Copyright (C) 2009, 2010, 2011, 2012, 2013, 2014, 2015 Jérôme Poisson (goffi@goffi.org) |
64 | 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 | |
89
2141f07b5fdd
primitivus: no more direct error/warning methods for logging
Goffi <goffi@goffi.org>
parents:
88
diff
changeset
|
21 import logging as log |
44 | 22 import encodings |
23 utf8decode = lambda s: encodings.codecs.utf_8_decode(s)[0] | |
0 | 24 |
107 | 25 import uuid |
26 | |
27 import collections | |
28 | |
59
a99951c9ce2a
Password now use AdvancedEdit to take advantage of shortcuts
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
29 from urwid.util import is_mouse_press #XXX: is_mouse_press is not included in urwid in 1.0.0 |
84
9f683df69a4c
shortcut keys are now managed in separate module, with a class checking for conflicts
Goffi <goffi@goffi.org>
parents:
82
diff
changeset
|
30 from .keys import action_key_map as a_key |
0 | 31 |
90 | 32 FOCUS_KEYS = (a_key['FOCUS_SWITCH'], a_key['FOCUS_UP'], a_key['FOCUS_DOWN']) |
33 | |
10
024b79b61a31
Primitivus: misc fixes + menubar first draft
Goffi <goffi@goffi.org>
parents:
9
diff
changeset
|
34 |
94
66b65ed9baf2
focus direction and rotate boolean are now gotten from getFocusDirection
Goffi <goffi@goffi.org>
parents:
91
diff
changeset
|
35 def getFocusDirection(key, inversed=False): |
66b65ed9baf2
focus direction and rotate boolean are now gotten from getFocusDirection
Goffi <goffi@goffi.org>
parents:
91
diff
changeset
|
36 """Return direction and rotate boolean depending on key |
66b65ed9baf2
focus direction and rotate boolean are now gotten from getFocusDirection
Goffi <goffi@goffi.org>
parents:
91
diff
changeset
|
37 @param key: one of FOCUS_KEYS |
66b65ed9baf2
focus direction and rotate boolean are now gotten from getFocusDirection
Goffi <goffi@goffi.org>
parents:
91
diff
changeset
|
38 @param inversed: inverse directions if True |
66b65ed9baf2
focus direction and rotate boolean are now gotten from getFocusDirection
Goffi <goffi@goffi.org>
parents:
91
diff
changeset
|
39 @return (tuple): (direction, rotate) where |
66b65ed9baf2
focus direction and rotate boolean are now gotten from getFocusDirection
Goffi <goffi@goffi.org>
parents:
91
diff
changeset
|
40 - direction is 1 or -1 |
66b65ed9baf2
focus direction and rotate boolean are now gotten from getFocusDirection
Goffi <goffi@goffi.org>
parents:
91
diff
changeset
|
41 - rotate is False if we should stop at the begin/end of the widgets list |
66b65ed9baf2
focus direction and rotate boolean are now gotten from getFocusDirection
Goffi <goffi@goffi.org>
parents:
91
diff
changeset
|
42 """ |
66b65ed9baf2
focus direction and rotate boolean are now gotten from getFocusDirection
Goffi <goffi@goffi.org>
parents:
91
diff
changeset
|
43 if not inversed: |
66b65ed9baf2
focus direction and rotate boolean are now gotten from getFocusDirection
Goffi <goffi@goffi.org>
parents:
91
diff
changeset
|
44 direction = 1 if key in (a_key['FOCUS_SWITCH'], a_key['FOCUS_UP']) else -1 |
66b65ed9baf2
focus direction and rotate boolean are now gotten from getFocusDirection
Goffi <goffi@goffi.org>
parents:
91
diff
changeset
|
45 else: |
98
8bf5a35450f0
Fixed getFocusDirection direction when inversed, and FocusFrame focus order.
Goffi <goffi@goffi.org>
parents:
97
diff
changeset
|
46 direction = -1 if key in (a_key['FOCUS_SWITCH'], a_key['FOCUS_UP']) else 1 |
94
66b65ed9baf2
focus direction and rotate boolean are now gotten from getFocusDirection
Goffi <goffi@goffi.org>
parents:
91
diff
changeset
|
47 rotate = key == a_key['FOCUS_SWITCH'] |
66b65ed9baf2
focus direction and rotate boolean are now gotten from getFocusDirection
Goffi <goffi@goffi.org>
parents:
91
diff
changeset
|
48 return direction, rotate |
66b65ed9baf2
focus direction and rotate boolean are now gotten from getFocusDirection
Goffi <goffi@goffi.org>
parents:
91
diff
changeset
|
49 |
66b65ed9baf2
focus direction and rotate boolean are now gotten from getFocusDirection
Goffi <goffi@goffi.org>
parents:
91
diff
changeset
|
50 |
4
c94cdbfdf3e8
primitivus: added edition zone at the bottom
Goffi <goffi@goffi.org>
parents:
3
diff
changeset
|
51 class AdvancedEdit(urwid.Edit): |
7 | 52 """Edit box with some custom improvments |
53 new chars: | |
54 - C-a: like 'home' | |
55 - C-e: like 'end' | |
56 - C-k: remove everything on the right of the cursor | |
57 - C-w: remove the word on the back | |
58 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
|
59 signals = urwid.Edit.signals + ['click'] |
4
c94cdbfdf3e8
primitivus: added edition zone at the bottom
Goffi <goffi@goffi.org>
parents:
3
diff
changeset
|
60 |
109 | 61 def getValue(self): |
62 return self.get_edit_text() | |
63 | |
22
dfabea6f73b5
Primitivus: AdvancedEdit and Notification bar improved
Goffi <goffi@goffi.org>
parents:
21
diff
changeset
|
64 def setCompletionMethod(self, callback): |
dfabea6f73b5
Primitivus: AdvancedEdit and Notification bar improved
Goffi <goffi@goffi.org>
parents:
21
diff
changeset
|
65 """Define method called when completion is asked |
dfabea6f73b5
Primitivus: AdvancedEdit and Notification bar improved
Goffi <goffi@goffi.org>
parents:
21
diff
changeset
|
66 @callback: method with 2 arguments: |
dfabea6f73b5
Primitivus: AdvancedEdit and Notification bar improved
Goffi <goffi@goffi.org>
parents:
21
diff
changeset
|
67 - the text to complete |
dfabea6f73b5
Primitivus: AdvancedEdit and Notification bar improved
Goffi <goffi@goffi.org>
parents:
21
diff
changeset
|
68 - if there was already a completion, a dict with |
dfabea6f73b5
Primitivus: AdvancedEdit and Notification bar improved
Goffi <goffi@goffi.org>
parents:
21
diff
changeset
|
69 - 'completed':last completion |
66 | 70 - 'completion_pos': cursor position where the completion starts |
22
dfabea6f73b5
Primitivus: AdvancedEdit and Notification bar improved
Goffi <goffi@goffi.org>
parents:
21
diff
changeset
|
71 - 'position': last completion cursor position |
dfabea6f73b5
Primitivus: AdvancedEdit and Notification bar improved
Goffi <goffi@goffi.org>
parents:
21
diff
changeset
|
72 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
|
73 and which return the full text completed""" |
dfabea6f73b5
Primitivus: AdvancedEdit and Notification bar improved
Goffi <goffi@goffi.org>
parents:
21
diff
changeset
|
74 self.completion_cb = callback |
dfabea6f73b5
Primitivus: AdvancedEdit and Notification bar improved
Goffi <goffi@goffi.org>
parents:
21
diff
changeset
|
75 self.completion_data = {} |
dfabea6f73b5
Primitivus: AdvancedEdit and Notification bar improved
Goffi <goffi@goffi.org>
parents:
21
diff
changeset
|
76 |
4
c94cdbfdf3e8
primitivus: added edition zone at the bottom
Goffi <goffi@goffi.org>
parents:
3
diff
changeset
|
77 def keypress(self, size, key): |
c94cdbfdf3e8
primitivus: added edition zone at the bottom
Goffi <goffi@goffi.org>
parents:
3
diff
changeset
|
78 #TODO: insert mode is not managed yet |
84
9f683df69a4c
shortcut keys are now managed in separate module, with a class checking for conflicts
Goffi <goffi@goffi.org>
parents:
82
diff
changeset
|
79 if key == a_key['EDIT_HOME']: |
4
c94cdbfdf3e8
primitivus: added edition zone at the bottom
Goffi <goffi@goffi.org>
parents:
3
diff
changeset
|
80 key = 'home' |
84
9f683df69a4c
shortcut keys are now managed in separate module, with a class checking for conflicts
Goffi <goffi@goffi.org>
parents:
82
diff
changeset
|
81 elif key == a_key['EDIT_END']: |
4
c94cdbfdf3e8
primitivus: added edition zone at the bottom
Goffi <goffi@goffi.org>
parents:
3
diff
changeset
|
82 key = 'end' |
84
9f683df69a4c
shortcut keys are now managed in separate module, with a class checking for conflicts
Goffi <goffi@goffi.org>
parents:
82
diff
changeset
|
83 elif key == a_key['EDIT_DELETE_TO_END']: |
4
c94cdbfdf3e8
primitivus: added edition zone at the bottom
Goffi <goffi@goffi.org>
parents:
3
diff
changeset
|
84 self._delete_highlighted() |
c94cdbfdf3e8
primitivus: added edition zone at the bottom
Goffi <goffi@goffi.org>
parents:
3
diff
changeset
|
85 self.set_edit_text(self.edit_text[:self.edit_pos]) |
84
9f683df69a4c
shortcut keys are now managed in separate module, with a class checking for conflicts
Goffi <goffi@goffi.org>
parents:
82
diff
changeset
|
86 elif key == a_key['EDIT_DELETE_LAST_WORD']: |
4
c94cdbfdf3e8
primitivus: added edition zone at the bottom
Goffi <goffi@goffi.org>
parents:
3
diff
changeset
|
87 before = self.edit_text[:self.edit_pos] |
c94cdbfdf3e8
primitivus: added edition zone at the bottom
Goffi <goffi@goffi.org>
parents:
3
diff
changeset
|
88 pos = before.rstrip().rfind(" ")+1 |
c94cdbfdf3e8
primitivus: added edition zone at the bottom
Goffi <goffi@goffi.org>
parents:
3
diff
changeset
|
89 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
|
90 self.set_edit_pos(pos) |
84
9f683df69a4c
shortcut keys are now managed in separate module, with a class checking for conflicts
Goffi <goffi@goffi.org>
parents:
82
diff
changeset
|
91 elif key == a_key['EDIT_ENTER']: |
5
592cd64933dd
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
4
diff
changeset
|
92 self._emit('click') |
84
9f683df69a4c
shortcut keys are now managed in separate module, with a class checking for conflicts
Goffi <goffi@goffi.org>
parents:
82
diff
changeset
|
93 elif key == a_key['EDIT_COMPLETE']: |
22
dfabea6f73b5
Primitivus: AdvancedEdit and Notification bar improved
Goffi <goffi@goffi.org>
parents:
21
diff
changeset
|
94 try: |
dfabea6f73b5
Primitivus: AdvancedEdit and Notification bar improved
Goffi <goffi@goffi.org>
parents:
21
diff
changeset
|
95 before = self.edit_text[:self.edit_pos] |
dfabea6f73b5
Primitivus: AdvancedEdit and Notification bar improved
Goffi <goffi@goffi.org>
parents:
21
diff
changeset
|
96 if self.completion_data: |
dfabea6f73b5
Primitivus: AdvancedEdit and Notification bar improved
Goffi <goffi@goffi.org>
parents:
21
diff
changeset
|
97 if (not self.completion_data['completed'] |
dfabea6f73b5
Primitivus: AdvancedEdit and Notification bar improved
Goffi <goffi@goffi.org>
parents:
21
diff
changeset
|
98 or self.completion_data['position'] != self.edit_pos |
dfabea6f73b5
Primitivus: AdvancedEdit and Notification bar improved
Goffi <goffi@goffi.org>
parents:
21
diff
changeset
|
99 or not before.endswith(self.completion_data['completed'])): |
dfabea6f73b5
Primitivus: AdvancedEdit and Notification bar improved
Goffi <goffi@goffi.org>
parents:
21
diff
changeset
|
100 self.completion_data.clear() |
dfabea6f73b5
Primitivus: AdvancedEdit and Notification bar improved
Goffi <goffi@goffi.org>
parents:
21
diff
changeset
|
101 else: |
dfabea6f73b5
Primitivus: AdvancedEdit and Notification bar improved
Goffi <goffi@goffi.org>
parents:
21
diff
changeset
|
102 before = before[:-len(self.completion_data['completed'])] |
dfabea6f73b5
Primitivus: AdvancedEdit and Notification bar improved
Goffi <goffi@goffi.org>
parents:
21
diff
changeset
|
103 complet = self.completion_cb(before, self.completion_data) |
dfabea6f73b5
Primitivus: AdvancedEdit and Notification bar improved
Goffi <goffi@goffi.org>
parents:
21
diff
changeset
|
104 self.completion_data['completed'] = complet[len(before):] |
dfabea6f73b5
Primitivus: AdvancedEdit and Notification bar improved
Goffi <goffi@goffi.org>
parents:
21
diff
changeset
|
105 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
|
106 self.set_edit_pos(len(complet)) |
dfabea6f73b5
Primitivus: AdvancedEdit and Notification bar improved
Goffi <goffi@goffi.org>
parents:
21
diff
changeset
|
107 self.completion_data['position'] = self.edit_pos |
dfabea6f73b5
Primitivus: AdvancedEdit and Notification bar improved
Goffi <goffi@goffi.org>
parents:
21
diff
changeset
|
108 return |
dfabea6f73b5
Primitivus: AdvancedEdit and Notification bar improved
Goffi <goffi@goffi.org>
parents:
21
diff
changeset
|
109 except AttributeError: |
dfabea6f73b5
Primitivus: AdvancedEdit and Notification bar improved
Goffi <goffi@goffi.org>
parents:
21
diff
changeset
|
110 #No completion method defined |
dfabea6f73b5
Primitivus: AdvancedEdit and Notification bar improved
Goffi <goffi@goffi.org>
parents:
21
diff
changeset
|
111 pass |
66 | 112 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
|
113 |
70
24d49f1d735f
added TableContainer + some bug fixes (bad default parameters)
Goffi <goffi@goffi.org>
parents:
69
diff
changeset
|
114 |
59
a99951c9ce2a
Password now use AdvancedEdit to take advantage of shortcuts
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
115 class Password(AdvancedEdit): |
a99951c9ce2a
Password now use AdvancedEdit to take advantage of shortcuts
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
116 """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
|
117 |
a99951c9ce2a
Password now use AdvancedEdit to take advantage of shortcuts
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
118 def __init__(self, *args, **kwargs): |
a99951c9ce2a
Password now use AdvancedEdit to take advantage of shortcuts
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
119 """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
|
120 @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
|
121 """ |
a99951c9ce2a
Password now use AdvancedEdit to take advantage of shortcuts
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
122 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
|
123 self.__real_text='' |
a99951c9ce2a
Password now use AdvancedEdit to take advantage of shortcuts
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
124 super(Password, self).__init__(*args, **kwargs) |
a99951c9ce2a
Password now use AdvancedEdit to take advantage of shortcuts
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
125 |
a99951c9ce2a
Password now use AdvancedEdit to take advantage of shortcuts
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
126 def set_edit_text(self, text): |
a99951c9ce2a
Password now use AdvancedEdit to take advantage of shortcuts
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
127 self.__real_text = text |
a99951c9ce2a
Password now use AdvancedEdit to take advantage of shortcuts
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
128 hidden_txt = len(text)*'*' |
a99951c9ce2a
Password now use AdvancedEdit to take advantage of shortcuts
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
129 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
|
130 |
a99951c9ce2a
Password now use AdvancedEdit to take advantage of shortcuts
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
131 def get_edit_text(self): |
a99951c9ce2a
Password now use AdvancedEdit to take advantage of shortcuts
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
132 return self.__real_text |
a99951c9ce2a
Password now use AdvancedEdit to take advantage of shortcuts
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
133 |
a99951c9ce2a
Password now use AdvancedEdit to take advantage of shortcuts
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
134 def insert_text(self, text): |
a99951c9ce2a
Password now use AdvancedEdit to take advantage of shortcuts
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
135 self._edit_text = self.__real_text |
a99951c9ce2a
Password now use AdvancedEdit to take advantage of shortcuts
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
136 super(Password,self).insert_text(text) |
a99951c9ce2a
Password now use AdvancedEdit to take advantage of shortcuts
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
137 |
a99951c9ce2a
Password now use AdvancedEdit to take advantage of shortcuts
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
138 def render(self, size, focus=False): |
a99951c9ce2a
Password now use AdvancedEdit to take advantage of shortcuts
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
139 return super(Password, self).render(size, focus) |
66 | 140 |
70
24d49f1d735f
added TableContainer + some bug fixes (bad default parameters)
Goffi <goffi@goffi.org>
parents:
69
diff
changeset
|
141 |
57 | 142 class ModalEdit(AdvancedEdit): |
143 """AdvancedEdit with vi-like mode management | |
68
5c28bb50ae0d
new ListOption class which work like unicode, but make the difference between value and label, so the displayed text can be different from the actual value.
Goffi <goffi@goffi.org>
parents:
67
diff
changeset
|
144 - there is a new 'mode' property which can be changed with properties |
57 | 145 specified during init |
146 - completion callback received a new 'mode' argument | |
147 """ | |
148 | |
149 def __init__(self, modes, *args, **kwargs): | |
150 """ first argument is "modes", others are the same paramaters as AdvancedEdit | |
151 @param modes: dictionnary in the form: | |
152 'key_to_change_mode': ('Mode', caption) | |
153 e.g.: 'i': ('INSERTION', '> ') | |
154 There *MUST* be a None key (for NORMAL mode)""" | |
155 assert(isinstance(modes, dict) and None in modes) | |
156 self._modes = modes | |
157 super(ModalEdit, self).__init__(*args, **kwargs) | |
158 self.mode = self._modes[None][0] | |
159 | |
160 @property | |
161 def mode(self): | |
162 return self._mode | |
163 | |
164 @mode.setter | |
165 def mode(self, value): | |
166 mode_key = None | |
167 for key in self._modes: | |
168 if self._modes[key][0] == value: | |
169 mode_key = key | |
170 break | |
66 | 171 |
57 | 172 mode, caption = self._modes[mode_key] |
173 self._mode = mode | |
174 self.set_caption(caption) | |
175 if not mode_key: #we are in NORMAL mode | |
176 self.set_edit_text('') | |
177 | |
178 def setCompletionMethod(self, callback): | |
179 """ Same as AdvancedEdit.setCompletionMethod, but with a third argument: current mode""" | |
180 super(ModalEdit, self).setCompletionMethod(lambda text,data: callback(text, data, self._mode)) | |
181 | |
182 def keypress(self, size, key): | |
84
9f683df69a4c
shortcut keys are now managed in separate module, with a class checking for conflicts
Goffi <goffi@goffi.org>
parents:
82
diff
changeset
|
183 if key == a_key['MODAL_ESCAPE']: |
57 | 184 self.mode = "NORMAL" |
185 return | |
186 if self._mode == 'NORMAL' and key in self._modes: | |
187 self.mode = self._modes[key][0] | |
188 return | |
66 | 189 return super(ModalEdit, self).keypress(size, key) |
4
c94cdbfdf3e8
primitivus: added edition zone at the bottom
Goffi <goffi@goffi.org>
parents:
3
diff
changeset
|
190 |
70
24d49f1d735f
added TableContainer + some bug fixes (bad default parameters)
Goffi <goffi@goffi.org>
parents:
69
diff
changeset
|
191 |
67 | 192 class SurroundedText(urwid.Widget): |
7 | 193 """Text centered on a repeated character (like a Divider, but with a text in the center)""" |
67 | 194 _sizing = frozenset(['flow']) |
6 | 195 |
196 def __init__(self,text,car=utf8decode('─')): | |
197 self.text=text | |
198 self.car=car | |
199 | |
200 def rows(self,size,focus=False): | |
201 return self.display_widget(size, focus).rows(size, focus) | |
202 | |
203 def render(self, size, focus=False): | |
204 return self.display_widget(size, focus).render(size, focus) | |
205 | |
206 def display_widget(self, size, focus): | |
207 (maxcol,) = size | |
208 middle = (maxcol-len(self.text))/2 | |
209 render_text = middle * self.car + self.text + (maxcol - len(self.text) - middle) * self.car | |
210 return urwid.Text(render_text) | |
211 | |
70
24d49f1d735f
added TableContainer + some bug fixes (bad default parameters)
Goffi <goffi@goffi.org>
parents:
69
diff
changeset
|
212 |
95
ca9a77f3b53e
SelectableText is now unselectable if its text is empty, AlwaysSelectable class has the former behaviour.
Goffi <goffi@goffi.org>
parents:
94
diff
changeset
|
213 class AlwaysSelectableText(urwid.WidgetWrap): |
6 | 214 """Text which can be selected with space""" |
0 | 215 signals = ['change'] |
66 | 216 |
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
|
217 def __init__(self, text, align='left', header='', focus_attr='default_focus', selected_text=None, selected=False, data=None): |
95
ca9a77f3b53e
SelectableText is now unselectable if its text is empty, AlwaysSelectable class has the former behaviour.
Goffi <goffi@goffi.org>
parents:
94
diff
changeset
|
218 """ |
ca9a77f3b53e
SelectableText is now unselectable if its text is empty, AlwaysSelectable class has the former behaviour.
Goffi <goffi@goffi.org>
parents:
94
diff
changeset
|
219 @param text: same as urwid.Text's text parameter |
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
|
220 @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
|
221 @select_attr: attrbute to use when selected |
95
ca9a77f3b53e
SelectableText is now unselectable if its text is empty, AlwaysSelectable class has the former behaviour.
Goffi <goffi@goffi.org>
parents:
94
diff
changeset
|
222 @param selected: is the text selected ? |
ca9a77f3b53e
SelectableText is now unselectable if its text is empty, AlwaysSelectable class has the former behaviour.
Goffi <goffi@goffi.org>
parents:
94
diff
changeset
|
223 """ |
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
|
224 self.focus_attr = focus_attr |
107 | 225 self._selected = False |
226 self._was_focused = False | |
69
b39c81cdd863
removed __valid_text: urwid now manage basestring subclasses, it's not necessary anymore
Goffi <goffi@goffi.org>
parents:
68
diff
changeset
|
227 self.header = header |
95
ca9a77f3b53e
SelectableText is now unselectable if its text is empty, AlwaysSelectable class has the former behaviour.
Goffi <goffi@goffi.org>
parents:
94
diff
changeset
|
228 self.text = 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
|
229 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
|
230 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
|
231 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
|
232 |
0 | 233 def getValue(self): |
95
ca9a77f3b53e
SelectableText is now unselectable if its text is empty, AlwaysSelectable class has the former behaviour.
Goffi <goffi@goffi.org>
parents:
94
diff
changeset
|
234 if isinstance(self.text,basestring): |
ca9a77f3b53e
SelectableText is now unselectable if its text is empty, AlwaysSelectable class has the former behaviour.
Goffi <goffi@goffi.org>
parents:
94
diff
changeset
|
235 return self.text |
ca9a77f3b53e
SelectableText is now unselectable if its text is empty, AlwaysSelectable class has the former behaviour.
Goffi <goffi@goffi.org>
parents:
94
diff
changeset
|
236 list_attr = self.text if isinstance(self.text, list) else [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
|
237 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
|
238 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
|
239 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
|
240 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
|
241 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
|
242 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
|
243 return txt |
9 | 244 |
16
263fe4d067ad
Primitivus: notification bar, first draft
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
245 def get_text(self): |
263fe4d067ad
Primitivus: notification bar, first draft
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
246 """for compatibility with urwid.Text""" |
263fe4d067ad
Primitivus: notification bar, first draft
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
247 return self.getValue() |
263fe4d067ad
Primitivus: notification bar, first draft
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
248 |
263fe4d067ad
Primitivus: notification bar, first draft
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
249 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
|
250 """/!\ set_text doesn't change self.selected_txt !""" |
95
ca9a77f3b53e
SelectableText is now unselectable if its text is empty, AlwaysSelectable class has the former behaviour.
Goffi <goffi@goffi.org>
parents:
94
diff
changeset
|
251 self.text = text |
107 | 252 self.setState(self._selected,invisible=True) |
16
263fe4d067ad
Primitivus: notification bar, first draft
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
253 |
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
|
254 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
|
255 """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
|
256 @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
|
257 if text == None: |
27 | 258 text = ('selected',self.getValue()) |
69
b39c81cdd863
removed __valid_text: urwid now manage basestring subclasses, it's not necessary anymore
Goffi <goffi@goffi.org>
parents:
68
diff
changeset
|
259 self.selected_txt = text |
107 | 260 if self._selected: |
261 self.setState(self._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
|
262 |
107 | 263 def _set_txt(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
|
264 txt_list = [self.header] |
107 | 265 txt = self.selected_txt if self._selected else 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
|
266 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
|
267 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
|
268 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
|
269 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
|
270 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
|
271 |
66 | 272 |
0 | 273 def setState(self, selected, invisible=False): |
274 """Change state | |
107 | 275 |
0 | 276 @param selected: boolean state value |
107 | 277 @param invisible: don't emit change signal if True |
278 """ | |
279 assert type(selected)==bool | |
280 self._selected=selected | |
281 self._set_txt() | |
282 self._was_focused = False | |
5
592cd64933dd
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
4
diff
changeset
|
283 self._invalidate() |
0 | 284 if not invisible: |
107 | 285 self._emit("change", self._selected) |
66 | 286 |
0 | 287 def getState(self): |
107 | 288 return self._selected |
0 | 289 |
290 def selectable(self): | |
291 return True | |
292 | |
293 def keypress(self, size, key): | |
84
9f683df69a4c
shortcut keys are now managed in separate module, with a class checking for conflicts
Goffi <goffi@goffi.org>
parents:
82
diff
changeset
|
294 if key in (a_key['TEXT_SELECT'], a_key['TEXT_SELECT2']): |
107 | 295 self.setState(not self._selected) |
0 | 296 else: |
297 return key | |
298 | |
15
8241b3157699
Primitivus: custom_widgets imrpovments
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
299 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
|
300 if is_mouse_press(event) and button == 1: |
107 | 301 self.setState(not self._selected) |
15
8241b3157699
Primitivus: custom_widgets imrpovments
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
302 return True |
66 | 303 |
15
8241b3157699
Primitivus: custom_widgets imrpovments
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
304 return False |
66 | 305 |
0 | 306 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
|
307 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
|
308 if not focus: |
107 | 309 if self._was_focused: |
310 self._set_txt() | |
311 self._was_focused = 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
|
312 else: |
107 | 313 if not self._was_focused: |
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
|
314 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
|
315 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
|
316 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
|
317 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
|
318 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
|
319 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
|
320 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
|
321 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
|
322 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
|
323 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
|
324 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
|
325 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
|
326 self._w.base_widget._invalidate() |
107 | 327 self._was_focused = True #bloody ugly hack :) |
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 return self._w.render(size, focus) |
0 | 329 |
70
24d49f1d735f
added TableContainer + some bug fixes (bad default parameters)
Goffi <goffi@goffi.org>
parents:
69
diff
changeset
|
330 |
95
ca9a77f3b53e
SelectableText is now unselectable if its text is empty, AlwaysSelectable class has the former behaviour.
Goffi <goffi@goffi.org>
parents:
94
diff
changeset
|
331 class SelectableText(AlwaysSelectableText): |
ca9a77f3b53e
SelectableText is now unselectable if its text is empty, AlwaysSelectable class has the former behaviour.
Goffi <goffi@goffi.org>
parents:
94
diff
changeset
|
332 """Like AlwaysSelectableText but not selectable when text is empty""" |
ca9a77f3b53e
SelectableText is now unselectable if its text is empty, AlwaysSelectable class has the former behaviour.
Goffi <goffi@goffi.org>
parents:
94
diff
changeset
|
333 |
ca9a77f3b53e
SelectableText is now unselectable if its text is empty, AlwaysSelectable class has the former behaviour.
Goffi <goffi@goffi.org>
parents:
94
diff
changeset
|
334 def selectable(self): |
ca9a77f3b53e
SelectableText is now unselectable if its text is empty, AlwaysSelectable class has the former behaviour.
Goffi <goffi@goffi.org>
parents:
94
diff
changeset
|
335 return bool(self.text) |
ca9a77f3b53e
SelectableText is now unselectable if its text is empty, AlwaysSelectable class has the former behaviour.
Goffi <goffi@goffi.org>
parents:
94
diff
changeset
|
336 |
ca9a77f3b53e
SelectableText is now unselectable if its text is empty, AlwaysSelectable class has the former behaviour.
Goffi <goffi@goffi.org>
parents:
94
diff
changeset
|
337 |
9 | 338 class ClickableText(SelectableText): |
339 signals = SelectableText.signals + ['click'] | |
66 | 340 |
8 | 341 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
|
342 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
|
343 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
|
344 self._emit('click') |
8 | 345 |
70
24d49f1d735f
added TableContainer + some bug fixes (bad default parameters)
Goffi <goffi@goffi.org>
parents:
69
diff
changeset
|
346 |
15
8241b3157699
Primitivus: custom_widgets imrpovments
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
347 class CustomButton(ClickableText): |
8241b3157699
Primitivus: custom_widgets imrpovments
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
348 |
107 | 349 def __init__(self, label, on_press=None, user_data=None, left_border="[ ", right_border=" ]", align="left"): |
15
8241b3157699
Primitivus: custom_widgets imrpovments
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
350 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
|
351 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
|
352 self.right_border = right_border |
107 | 353 super(CustomButton, self).__init__([left_border, label, right_border], align=align) |
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
|
354 self.size = len(self.get_text()) |
15
8241b3157699
Primitivus: custom_widgets imrpovments
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
355 if on_press: |
8241b3157699
Primitivus: custom_widgets imrpovments
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
356 urwid.connect_signal(self, 'click', on_press, user_data) |
8241b3157699
Primitivus: custom_widgets imrpovments
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
357 |
8241b3157699
Primitivus: custom_widgets imrpovments
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
358 def getSize(self): |
8241b3157699
Primitivus: custom_widgets imrpovments
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
359 """Return representation size of the button""" |
8241b3157699
Primitivus: custom_widgets imrpovments
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
360 return self.size |
8241b3157699
Primitivus: custom_widgets imrpovments
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
361 |
8241b3157699
Primitivus: custom_widgets imrpovments
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
362 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
|
363 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
|
364 |
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
|
365 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
|
366 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
|
367 self.set_text([self.left_border, label, self.right_border]) |
15
8241b3157699
Primitivus: custom_widgets imrpovments
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
368 |
70
24d49f1d735f
added TableContainer + some bug fixes (bad default parameters)
Goffi <goffi@goffi.org>
parents:
69
diff
changeset
|
369 |
68
5c28bb50ae0d
new ListOption class which work like unicode, but make the difference between value and label, so the displayed text can be different from the actual value.
Goffi <goffi@goffi.org>
parents:
67
diff
changeset
|
370 class ListOption(unicode): |
107 | 371 """Unicode which manage label and value |
372 | |
373 This class similar to unicode, but which make the difference between value and label | |
68
5c28bb50ae0d
new ListOption class which work like unicode, but make the difference between value and label, so the displayed text can be different from the actual value.
Goffi <goffi@goffi.org>
parents:
67
diff
changeset
|
374 label is show when use as unicode, the .value attribute contain the actual value |
5c28bb50ae0d
new ListOption class which work like unicode, but make the difference between value and label, so the displayed text can be different from the actual value.
Goffi <goffi@goffi.org>
parents:
67
diff
changeset
|
375 Can be initialised with: |
5c28bb50ae0d
new ListOption class which work like unicode, but make the difference between value and label, so the displayed text can be different from the actual value.
Goffi <goffi@goffi.org>
parents:
67
diff
changeset
|
376 - basestring (label = value = given string) |
5c28bb50ae0d
new ListOption class which work like unicode, but make the difference between value and label, so the displayed text can be different from the actual value.
Goffi <goffi@goffi.org>
parents:
67
diff
changeset
|
377 - a tuple with (value, label) |
70
24d49f1d735f
added TableContainer + some bug fixes (bad default parameters)
Goffi <goffi@goffi.org>
parents:
69
diff
changeset
|
378 XXX: comparaison is made against value, not the label which is the one displayed |
68
5c28bb50ae0d
new ListOption class which work like unicode, but make the difference between value and label, so the displayed text can be different from the actual value.
Goffi <goffi@goffi.org>
parents:
67
diff
changeset
|
379 """ |
5c28bb50ae0d
new ListOption class which work like unicode, but make the difference between value and label, so the displayed text can be different from the actual value.
Goffi <goffi@goffi.org>
parents:
67
diff
changeset
|
380 |
5c28bb50ae0d
new ListOption class which work like unicode, but make the difference between value and label, so the displayed text can be different from the actual value.
Goffi <goffi@goffi.org>
parents:
67
diff
changeset
|
381 def __new__(cls, option): |
5c28bb50ae0d
new ListOption class which work like unicode, but make the difference between value and label, so the displayed text can be different from the actual value.
Goffi <goffi@goffi.org>
parents:
67
diff
changeset
|
382 if (isinstance(option, cls)): |
5c28bb50ae0d
new ListOption class which work like unicode, but make the difference between value and label, so the displayed text can be different from the actual value.
Goffi <goffi@goffi.org>
parents:
67
diff
changeset
|
383 return option |
5c28bb50ae0d
new ListOption class which work like unicode, but make the difference between value and label, so the displayed text can be different from the actual value.
Goffi <goffi@goffi.org>
parents:
67
diff
changeset
|
384 elif isinstance(option, basestring): |
5c28bb50ae0d
new ListOption class which work like unicode, but make the difference between value and label, so the displayed text can be different from the actual value.
Goffi <goffi@goffi.org>
parents:
67
diff
changeset
|
385 value = label = option |
5c28bb50ae0d
new ListOption class which work like unicode, but make the difference between value and label, so the displayed text can be different from the actual value.
Goffi <goffi@goffi.org>
parents:
67
diff
changeset
|
386 elif (isinstance(option, tuple) and len(option) == 2): |
5c28bb50ae0d
new ListOption class which work like unicode, but make the difference between value and label, so the displayed text can be different from the actual value.
Goffi <goffi@goffi.org>
parents:
67
diff
changeset
|
387 value, label = option |
5c28bb50ae0d
new ListOption class which work like unicode, but make the difference between value and label, so the displayed text can be different from the actual value.
Goffi <goffi@goffi.org>
parents:
67
diff
changeset
|
388 else: |
5c28bb50ae0d
new ListOption class which work like unicode, but make the difference between value and label, so the displayed text can be different from the actual value.
Goffi <goffi@goffi.org>
parents:
67
diff
changeset
|
389 raise NotImplementedError |
5c28bb50ae0d
new ListOption class which work like unicode, but make the difference between value and label, so the displayed text can be different from the actual value.
Goffi <goffi@goffi.org>
parents:
67
diff
changeset
|
390 if not label: |
5c28bb50ae0d
new ListOption class which work like unicode, but make the difference between value and label, so the displayed text can be different from the actual value.
Goffi <goffi@goffi.org>
parents:
67
diff
changeset
|
391 label = value |
5c28bb50ae0d
new ListOption class which work like unicode, but make the difference between value and label, so the displayed text can be different from the actual value.
Goffi <goffi@goffi.org>
parents:
67
diff
changeset
|
392 instance = super(ListOption, cls).__new__(cls, label) |
5c28bb50ae0d
new ListOption class which work like unicode, but make the difference between value and label, so the displayed text can be different from the actual value.
Goffi <goffi@goffi.org>
parents:
67
diff
changeset
|
393 instance._value = value |
5c28bb50ae0d
new ListOption class which work like unicode, but make the difference between value and label, so the displayed text can be different from the actual value.
Goffi <goffi@goffi.org>
parents:
67
diff
changeset
|
394 return instance |
5c28bb50ae0d
new ListOption class which work like unicode, but make the difference between value and label, so the displayed text can be different from the actual value.
Goffi <goffi@goffi.org>
parents:
67
diff
changeset
|
395 |
5c28bb50ae0d
new ListOption class which work like unicode, but make the difference between value and label, so the displayed text can be different from the actual value.
Goffi <goffi@goffi.org>
parents:
67
diff
changeset
|
396 def __eq__(self, other): |
5c28bb50ae0d
new ListOption class which work like unicode, but make the difference between value and label, so the displayed text can be different from the actual value.
Goffi <goffi@goffi.org>
parents:
67
diff
changeset
|
397 # XXX: try to compare values, if other has no value |
5c28bb50ae0d
new ListOption class which work like unicode, but make the difference between value and label, so the displayed text can be different from the actual value.
Goffi <goffi@goffi.org>
parents:
67
diff
changeset
|
398 # (e.g. unicode string) try to compare to other itself |
5c28bb50ae0d
new ListOption class which work like unicode, but make the difference between value and label, so the displayed text can be different from the actual value.
Goffi <goffi@goffi.org>
parents:
67
diff
changeset
|
399 try: |
5c28bb50ae0d
new ListOption class which work like unicode, but make the difference between value and label, so the displayed text can be different from the actual value.
Goffi <goffi@goffi.org>
parents:
67
diff
changeset
|
400 return self._value == other._value |
5c28bb50ae0d
new ListOption class which work like unicode, but make the difference between value and label, so the displayed text can be different from the actual value.
Goffi <goffi@goffi.org>
parents:
67
diff
changeset
|
401 except AttributeError: |
5c28bb50ae0d
new ListOption class which work like unicode, but make the difference between value and label, so the displayed text can be different from the actual value.
Goffi <goffi@goffi.org>
parents:
67
diff
changeset
|
402 return self._value == other |
5c28bb50ae0d
new ListOption class which work like unicode, but make the difference between value and label, so the displayed text can be different from the actual value.
Goffi <goffi@goffi.org>
parents:
67
diff
changeset
|
403 |
5c28bb50ae0d
new ListOption class which work like unicode, but make the difference between value and label, so the displayed text can be different from the actual value.
Goffi <goffi@goffi.org>
parents:
67
diff
changeset
|
404 def __ne__(self, other): |
5c28bb50ae0d
new ListOption class which work like unicode, but make the difference between value and label, so the displayed text can be different from the actual value.
Goffi <goffi@goffi.org>
parents:
67
diff
changeset
|
405 # XXX: see __eq__ |
5c28bb50ae0d
new ListOption class which work like unicode, but make the difference between value and label, so the displayed text can be different from the actual value.
Goffi <goffi@goffi.org>
parents:
67
diff
changeset
|
406 try: |
5c28bb50ae0d
new ListOption class which work like unicode, but make the difference between value and label, so the displayed text can be different from the actual value.
Goffi <goffi@goffi.org>
parents:
67
diff
changeset
|
407 return self._value != other._value |
5c28bb50ae0d
new ListOption class which work like unicode, but make the difference between value and label, so the displayed text can be different from the actual value.
Goffi <goffi@goffi.org>
parents:
67
diff
changeset
|
408 except AttributeError: |
5c28bb50ae0d
new ListOption class which work like unicode, but make the difference between value and label, so the displayed text can be different from the actual value.
Goffi <goffi@goffi.org>
parents:
67
diff
changeset
|
409 return self._value != other |
5c28bb50ae0d
new ListOption class which work like unicode, but make the difference between value and label, so the displayed text can be different from the actual value.
Goffi <goffi@goffi.org>
parents:
67
diff
changeset
|
410 |
5c28bb50ae0d
new ListOption class which work like unicode, but make the difference between value and label, so the displayed text can be different from the actual value.
Goffi <goffi@goffi.org>
parents:
67
diff
changeset
|
411 @property |
5c28bb50ae0d
new ListOption class which work like unicode, but make the difference between value and label, so the displayed text can be different from the actual value.
Goffi <goffi@goffi.org>
parents:
67
diff
changeset
|
412 def value(self): |
5c28bb50ae0d
new ListOption class which work like unicode, but make the difference between value and label, so the displayed text can be different from the actual value.
Goffi <goffi@goffi.org>
parents:
67
diff
changeset
|
413 """ return option value """ |
5c28bb50ae0d
new ListOption class which work like unicode, but make the difference between value and label, so the displayed text can be different from the actual value.
Goffi <goffi@goffi.org>
parents:
67
diff
changeset
|
414 return self._value |
5c28bb50ae0d
new ListOption class which work like unicode, but make the difference between value and label, so the displayed text can be different from the actual value.
Goffi <goffi@goffi.org>
parents:
67
diff
changeset
|
415 |
5c28bb50ae0d
new ListOption class which work like unicode, but make the difference between value and label, so the displayed text can be different from the actual value.
Goffi <goffi@goffi.org>
parents:
67
diff
changeset
|
416 @value.setter |
5c28bb50ae0d
new ListOption class which work like unicode, but make the difference between value and label, so the displayed text can be different from the actual value.
Goffi <goffi@goffi.org>
parents:
67
diff
changeset
|
417 def value(self, value): |
5c28bb50ae0d
new ListOption class which work like unicode, but make the difference between value and label, so the displayed text can be different from the actual value.
Goffi <goffi@goffi.org>
parents:
67
diff
changeset
|
418 self._value = value |
5c28bb50ae0d
new ListOption class which work like unicode, but make the difference between value and label, so the displayed text can be different from the actual value.
Goffi <goffi@goffi.org>
parents:
67
diff
changeset
|
419 |
5c28bb50ae0d
new ListOption class which work like unicode, but make the difference between value and label, so the displayed text can be different from the actual value.
Goffi <goffi@goffi.org>
parents:
67
diff
changeset
|
420 @staticmethod |
5c28bb50ae0d
new ListOption class which work like unicode, but make the difference between value and label, so the displayed text can be different from the actual value.
Goffi <goffi@goffi.org>
parents:
67
diff
changeset
|
421 def fromOptions(options): |
5c28bb50ae0d
new ListOption class which work like unicode, but make the difference between value and label, so the displayed text can be different from the actual value.
Goffi <goffi@goffi.org>
parents:
67
diff
changeset
|
422 """ convert a list of string/tuple options to a list of listOption |
5c28bb50ae0d
new ListOption class which work like unicode, but make the difference between value and label, so the displayed text can be different from the actual value.
Goffi <goffi@goffi.org>
parents:
67
diff
changeset
|
423 @param options: list of managed option type (basestring, tuple) |
5c28bb50ae0d
new ListOption class which work like unicode, but make the difference between value and label, so the displayed text can be different from the actual value.
Goffi <goffi@goffi.org>
parents:
67
diff
changeset
|
424 return: list of ListOption |
5c28bb50ae0d
new ListOption class which work like unicode, but make the difference between value and label, so the displayed text can be different from the actual value.
Goffi <goffi@goffi.org>
parents:
67
diff
changeset
|
425 """ |
5c28bb50ae0d
new ListOption class which work like unicode, but make the difference between value and label, so the displayed text can be different from the actual value.
Goffi <goffi@goffi.org>
parents:
67
diff
changeset
|
426 return [(ListOption(option)) for option in options] |
5c28bb50ae0d
new ListOption class which work like unicode, but make the difference between value and label, so the displayed text can be different from the actual value.
Goffi <goffi@goffi.org>
parents:
67
diff
changeset
|
427 |
5c28bb50ae0d
new ListOption class which work like unicode, but make the difference between value and label, so the displayed text can be different from the actual value.
Goffi <goffi@goffi.org>
parents:
67
diff
changeset
|
428 |
91
b447a9c6f1d3
added UnselectableListBox which is a ListBox which can be unselectable when everything is not selectable and visible. Its is used in dialogs
Goffi <goffi@goffi.org>
parents:
90
diff
changeset
|
429 class UnselectableListBox(urwid.ListBox): |
b447a9c6f1d3
added UnselectableListBox which is a ListBox which can be unselectable when everything is not selectable and visible. Its is used in dialogs
Goffi <goffi@goffi.org>
parents:
90
diff
changeset
|
430 """List box that can be unselectable if all widget are unselectable and visible""" |
b447a9c6f1d3
added UnselectableListBox which is a ListBox which can be unselectable when everything is not selectable and visible. Its is used in dialogs
Goffi <goffi@goffi.org>
parents:
90
diff
changeset
|
431 |
b447a9c6f1d3
added UnselectableListBox which is a ListBox which can be unselectable when everything is not selectable and visible. Its is used in dialogs
Goffi <goffi@goffi.org>
parents:
90
diff
changeset
|
432 def __init__(self, body): |
b447a9c6f1d3
added UnselectableListBox which is a ListBox which can be unselectable when everything is not selectable and visible. Its is used in dialogs
Goffi <goffi@goffi.org>
parents:
90
diff
changeset
|
433 super(UnselectableListBox, self).__init__(body) |
b447a9c6f1d3
added UnselectableListBox which is a ListBox which can be unselectable when everything is not selectable and visible. Its is used in dialogs
Goffi <goffi@goffi.org>
parents:
90
diff
changeset
|
434 self.__size_cache = None |
b447a9c6f1d3
added UnselectableListBox which is a ListBox which can be unselectable when everything is not selectable and visible. Its is used in dialogs
Goffi <goffi@goffi.org>
parents:
90
diff
changeset
|
435 |
b447a9c6f1d3
added UnselectableListBox which is a ListBox which can be unselectable when everything is not selectable and visible. Its is used in dialogs
Goffi <goffi@goffi.org>
parents:
90
diff
changeset
|
436 def selectable(self): |
b447a9c6f1d3
added UnselectableListBox which is a ListBox which can be unselectable when everything is not selectable and visible. Its is used in dialogs
Goffi <goffi@goffi.org>
parents:
90
diff
changeset
|
437 """Selectable that return False if everything is visible and nothing is selectable""" |
b447a9c6f1d3
added UnselectableListBox which is a ListBox which can be unselectable when everything is not selectable and visible. Its is used in dialogs
Goffi <goffi@goffi.org>
parents:
90
diff
changeset
|
438 if self.__size_cache is None: |
b447a9c6f1d3
added UnselectableListBox which is a ListBox which can be unselectable when everything is not selectable and visible. Its is used in dialogs
Goffi <goffi@goffi.org>
parents:
90
diff
changeset
|
439 return self._selectable |
b447a9c6f1d3
added UnselectableListBox which is a ListBox which can be unselectable when everything is not selectable and visible. Its is used in dialogs
Goffi <goffi@goffi.org>
parents:
90
diff
changeset
|
440 middle, top, bottom = self.calculate_visible(self.__size_cache, self.__focus_cache) |
b447a9c6f1d3
added UnselectableListBox which is a ListBox which can be unselectable when everything is not selectable and visible. Its is used in dialogs
Goffi <goffi@goffi.org>
parents:
90
diff
changeset
|
441 if top is None or bottom is None: |
b447a9c6f1d3
added UnselectableListBox which is a ListBox which can be unselectable when everything is not selectable and visible. Its is used in dialogs
Goffi <goffi@goffi.org>
parents:
90
diff
changeset
|
442 return True |
b447a9c6f1d3
added UnselectableListBox which is a ListBox which can be unselectable when everything is not selectable and visible. Its is used in dialogs
Goffi <goffi@goffi.org>
parents:
90
diff
changeset
|
443 if top[0] or bottom[0]: |
b447a9c6f1d3
added UnselectableListBox which is a ListBox which can be unselectable when everything is not selectable and visible. Its is used in dialogs
Goffi <goffi@goffi.org>
parents:
90
diff
changeset
|
444 # if not everything is visible, we can select |
b447a9c6f1d3
added UnselectableListBox which is a ListBox which can be unselectable when everything is not selectable and visible. Its is used in dialogs
Goffi <goffi@goffi.org>
parents:
90
diff
changeset
|
445 return True |
b447a9c6f1d3
added UnselectableListBox which is a ListBox which can be unselectable when everything is not selectable and visible. Its is used in dialogs
Goffi <goffi@goffi.org>
parents:
90
diff
changeset
|
446 for wid in self.body: |
b447a9c6f1d3
added UnselectableListBox which is a ListBox which can be unselectable when everything is not selectable and visible. Its is used in dialogs
Goffi <goffi@goffi.org>
parents:
90
diff
changeset
|
447 # if any widget is selectable, we can select |
b447a9c6f1d3
added UnselectableListBox which is a ListBox which can be unselectable when everything is not selectable and visible. Its is used in dialogs
Goffi <goffi@goffi.org>
parents:
90
diff
changeset
|
448 if wid.selectable(): |
b447a9c6f1d3
added UnselectableListBox which is a ListBox which can be unselectable when everything is not selectable and visible. Its is used in dialogs
Goffi <goffi@goffi.org>
parents:
90
diff
changeset
|
449 return True |
b447a9c6f1d3
added UnselectableListBox which is a ListBox which can be unselectable when everything is not selectable and visible. Its is used in dialogs
Goffi <goffi@goffi.org>
parents:
90
diff
changeset
|
450 return False |
b447a9c6f1d3
added UnselectableListBox which is a ListBox which can be unselectable when everything is not selectable and visible. Its is used in dialogs
Goffi <goffi@goffi.org>
parents:
90
diff
changeset
|
451 |
b447a9c6f1d3
added UnselectableListBox which is a ListBox which can be unselectable when everything is not selectable and visible. Its is used in dialogs
Goffi <goffi@goffi.org>
parents:
90
diff
changeset
|
452 def render(self, size, focus=False): |
b447a9c6f1d3
added UnselectableListBox which is a ListBox which can be unselectable when everything is not selectable and visible. Its is used in dialogs
Goffi <goffi@goffi.org>
parents:
90
diff
changeset
|
453 """Call ListBox render, but keep size and focus in cache""" |
b447a9c6f1d3
added UnselectableListBox which is a ListBox which can be unselectable when everything is not selectable and visible. Its is used in dialogs
Goffi <goffi@goffi.org>
parents:
90
diff
changeset
|
454 self.__size_cache = size |
b447a9c6f1d3
added UnselectableListBox which is a ListBox which can be unselectable when everything is not selectable and visible. Its is used in dialogs
Goffi <goffi@goffi.org>
parents:
90
diff
changeset
|
455 self.__focus_cache = focus |
b447a9c6f1d3
added UnselectableListBox which is a ListBox which can be unselectable when everything is not selectable and visible. Its is used in dialogs
Goffi <goffi@goffi.org>
parents:
90
diff
changeset
|
456 return super(UnselectableListBox, self).render(size, focus) |
b447a9c6f1d3
added UnselectableListBox which is a ListBox which can be unselectable when everything is not selectable and visible. Its is used in dialogs
Goffi <goffi@goffi.org>
parents:
90
diff
changeset
|
457 |
b447a9c6f1d3
added UnselectableListBox which is a ListBox which can be unselectable when everything is not selectable and visible. Its is used in dialogs
Goffi <goffi@goffi.org>
parents:
90
diff
changeset
|
458 |
110
436076392538
GenericList + List fixes, better 'change' signal handling, added GenericList.contents property (addind or removing an item there trigger the 'change' signal)
Goffi <goffi@goffi.org>
parents:
109
diff
changeset
|
459 class SimpleListWalkerWithCb(urwid.SimpleListWalker): |
436076392538
GenericList + List fixes, better 'change' signal handling, added GenericList.contents property (addind or removing an item there trigger the 'change' signal)
Goffi <goffi@goffi.org>
parents:
109
diff
changeset
|
460 """a SimpleListWalker which call callbacks on items changes""" |
436076392538
GenericList + List fixes, better 'change' signal handling, added GenericList.contents property (addind or removing an item there trigger the 'change' signal)
Goffi <goffi@goffi.org>
parents:
109
diff
changeset
|
461 |
436076392538
GenericList + List fixes, better 'change' signal handling, added GenericList.contents property (addind or removing an item there trigger the 'change' signal)
Goffi <goffi@goffi.org>
parents:
109
diff
changeset
|
462 def __init__(self, contents, on_new=None, on_delete=None): |
436076392538
GenericList + List fixes, better 'change' signal handling, added GenericList.contents property (addind or removing an item there trigger the 'change' signal)
Goffi <goffi@goffi.org>
parents:
109
diff
changeset
|
463 """ |
436076392538
GenericList + List fixes, better 'change' signal handling, added GenericList.contents property (addind or removing an item there trigger the 'change' signal)
Goffi <goffi@goffi.org>
parents:
109
diff
changeset
|
464 @param contents: list to copy into this object |
436076392538
GenericList + List fixes, better 'change' signal handling, added GenericList.contents property (addind or removing an item there trigger the 'change' signal)
Goffi <goffi@goffi.org>
parents:
109
diff
changeset
|
465 @param on_new: callback to call when an item is added |
436076392538
GenericList + List fixes, better 'change' signal handling, added GenericList.contents property (addind or removing an item there trigger the 'change' signal)
Goffi <goffi@goffi.org>
parents:
109
diff
changeset
|
466 @param on_delete: callback to call when an item is deleted |
436076392538
GenericList + List fixes, better 'change' signal handling, added GenericList.contents property (addind or removing an item there trigger the 'change' signal)
Goffi <goffi@goffi.org>
parents:
109
diff
changeset
|
467 """ |
436076392538
GenericList + List fixes, better 'change' signal handling, added GenericList.contents property (addind or removing an item there trigger the 'change' signal)
Goffi <goffi@goffi.org>
parents:
109
diff
changeset
|
468 # XXX: we can't use modified signal as it doesn't return the modified item |
436076392538
GenericList + List fixes, better 'change' signal handling, added GenericList.contents property (addind or removing an item there trigger the 'change' signal)
Goffi <goffi@goffi.org>
parents:
109
diff
changeset
|
469 super(SimpleListWalkerWithCb, self).__init__(contents) |
436076392538
GenericList + List fixes, better 'change' signal handling, added GenericList.contents property (addind or removing an item there trigger the 'change' signal)
Goffi <goffi@goffi.org>
parents:
109
diff
changeset
|
470 for content in contents: |
436076392538
GenericList + List fixes, better 'change' signal handling, added GenericList.contents property (addind or removing an item there trigger the 'change' signal)
Goffi <goffi@goffi.org>
parents:
109
diff
changeset
|
471 on_new(content) |
436076392538
GenericList + List fixes, better 'change' signal handling, added GenericList.contents property (addind or removing an item there trigger the 'change' signal)
Goffi <goffi@goffi.org>
parents:
109
diff
changeset
|
472 self._on_new = on_new |
436076392538
GenericList + List fixes, better 'change' signal handling, added GenericList.contents property (addind or removing an item there trigger the 'change' signal)
Goffi <goffi@goffi.org>
parents:
109
diff
changeset
|
473 self._on_delete = on_delete |
436076392538
GenericList + List fixes, better 'change' signal handling, added GenericList.contents property (addind or removing an item there trigger the 'change' signal)
Goffi <goffi@goffi.org>
parents:
109
diff
changeset
|
474 |
436076392538
GenericList + List fixes, better 'change' signal handling, added GenericList.contents property (addind or removing an item there trigger the 'change' signal)
Goffi <goffi@goffi.org>
parents:
109
diff
changeset
|
475 def __cbSingle(self, item, cb): |
436076392538
GenericList + List fixes, better 'change' signal handling, added GenericList.contents property (addind or removing an item there trigger the 'change' signal)
Goffi <goffi@goffi.org>
parents:
109
diff
changeset
|
476 try: |
436076392538
GenericList + List fixes, better 'change' signal handling, added GenericList.contents property (addind or removing an item there trigger the 'change' signal)
Goffi <goffi@goffi.org>
parents:
109
diff
changeset
|
477 cb(item) |
436076392538
GenericList + List fixes, better 'change' signal handling, added GenericList.contents property (addind or removing an item there trigger the 'change' signal)
Goffi <goffi@goffi.org>
parents:
109
diff
changeset
|
478 except TypeError: |
436076392538
GenericList + List fixes, better 'change' signal handling, added GenericList.contents property (addind or removing an item there trigger the 'change' signal)
Goffi <goffi@goffi.org>
parents:
109
diff
changeset
|
479 pass |
436076392538
GenericList + List fixes, better 'change' signal handling, added GenericList.contents property (addind or removing an item there trigger the 'change' signal)
Goffi <goffi@goffi.org>
parents:
109
diff
changeset
|
480 |
436076392538
GenericList + List fixes, better 'change' signal handling, added GenericList.contents property (addind or removing an item there trigger the 'change' signal)
Goffi <goffi@goffi.org>
parents:
109
diff
changeset
|
481 def __cbMulti(self, items, cb): |
436076392538
GenericList + List fixes, better 'change' signal handling, added GenericList.contents property (addind or removing an item there trigger the 'change' signal)
Goffi <goffi@goffi.org>
parents:
109
diff
changeset
|
482 if cb is not None: |
436076392538
GenericList + List fixes, better 'change' signal handling, added GenericList.contents property (addind or removing an item there trigger the 'change' signal)
Goffi <goffi@goffi.org>
parents:
109
diff
changeset
|
483 for item in items: |
436076392538
GenericList + List fixes, better 'change' signal handling, added GenericList.contents property (addind or removing an item there trigger the 'change' signal)
Goffi <goffi@goffi.org>
parents:
109
diff
changeset
|
484 cb(item) |
436076392538
GenericList + List fixes, better 'change' signal handling, added GenericList.contents property (addind or removing an item there trigger the 'change' signal)
Goffi <goffi@goffi.org>
parents:
109
diff
changeset
|
485 |
436076392538
GenericList + List fixes, better 'change' signal handling, added GenericList.contents property (addind or removing an item there trigger the 'change' signal)
Goffi <goffi@goffi.org>
parents:
109
diff
changeset
|
486 def __add__(self, new_list): |
436076392538
GenericList + List fixes, better 'change' signal handling, added GenericList.contents property (addind or removing an item there trigger the 'change' signal)
Goffi <goffi@goffi.org>
parents:
109
diff
changeset
|
487 self.__cbMulti(new_list, self._on_new) |
436076392538
GenericList + List fixes, better 'change' signal handling, added GenericList.contents property (addind or removing an item there trigger the 'change' signal)
Goffi <goffi@goffi.org>
parents:
109
diff
changeset
|
488 return super(SimpleListWalkerWithCb, self).__add__(new_list) |
436076392538
GenericList + List fixes, better 'change' signal handling, added GenericList.contents property (addind or removing an item there trigger the 'change' signal)
Goffi <goffi@goffi.org>
parents:
109
diff
changeset
|
489 |
436076392538
GenericList + List fixes, better 'change' signal handling, added GenericList.contents property (addind or removing an item there trigger the 'change' signal)
Goffi <goffi@goffi.org>
parents:
109
diff
changeset
|
490 def __delitem__(self, item): |
436076392538
GenericList + List fixes, better 'change' signal handling, added GenericList.contents property (addind or removing an item there trigger the 'change' signal)
Goffi <goffi@goffi.org>
parents:
109
diff
changeset
|
491 self.__cbSingle(item, self._on_delete) |
436076392538
GenericList + List fixes, better 'change' signal handling, added GenericList.contents property (addind or removing an item there trigger the 'change' signal)
Goffi <goffi@goffi.org>
parents:
109
diff
changeset
|
492 return super(SimpleListWalkerWithCb, self).__delitem__(item) |
436076392538
GenericList + List fixes, better 'change' signal handling, added GenericList.contents property (addind or removing an item there trigger the 'change' signal)
Goffi <goffi@goffi.org>
parents:
109
diff
changeset
|
493 |
436076392538
GenericList + List fixes, better 'change' signal handling, added GenericList.contents property (addind or removing an item there trigger the 'change' signal)
Goffi <goffi@goffi.org>
parents:
109
diff
changeset
|
494 def __delslice__(self, i,j): |
436076392538
GenericList + List fixes, better 'change' signal handling, added GenericList.contents property (addind or removing an item there trigger the 'change' signal)
Goffi <goffi@goffi.org>
parents:
109
diff
changeset
|
495 items = super(SimpleListWalkerWithCb, self).__getslice__(i,j) |
436076392538
GenericList + List fixes, better 'change' signal handling, added GenericList.contents property (addind or removing an item there trigger the 'change' signal)
Goffi <goffi@goffi.org>
parents:
109
diff
changeset
|
496 self.__cbMulti(items, self._on_delete) |
436076392538
GenericList + List fixes, better 'change' signal handling, added GenericList.contents property (addind or removing an item there trigger the 'change' signal)
Goffi <goffi@goffi.org>
parents:
109
diff
changeset
|
497 return super(SimpleListWalkerWithCb, self).__delslice(i,j) |
436076392538
GenericList + List fixes, better 'change' signal handling, added GenericList.contents property (addind or removing an item there trigger the 'change' signal)
Goffi <goffi@goffi.org>
parents:
109
diff
changeset
|
498 |
436076392538
GenericList + List fixes, better 'change' signal handling, added GenericList.contents property (addind or removing an item there trigger the 'change' signal)
Goffi <goffi@goffi.org>
parents:
109
diff
changeset
|
499 def __iadd__(self, y): |
436076392538
GenericList + List fixes, better 'change' signal handling, added GenericList.contents property (addind or removing an item there trigger the 'change' signal)
Goffi <goffi@goffi.org>
parents:
109
diff
changeset
|
500 raise NotImplementedError |
436076392538
GenericList + List fixes, better 'change' signal handling, added GenericList.contents property (addind or removing an item there trigger the 'change' signal)
Goffi <goffi@goffi.org>
parents:
109
diff
changeset
|
501 |
436076392538
GenericList + List fixes, better 'change' signal handling, added GenericList.contents property (addind or removing an item there trigger the 'change' signal)
Goffi <goffi@goffi.org>
parents:
109
diff
changeset
|
502 def __imul__(self, y): |
436076392538
GenericList + List fixes, better 'change' signal handling, added GenericList.contents property (addind or removing an item there trigger the 'change' signal)
Goffi <goffi@goffi.org>
parents:
109
diff
changeset
|
503 raise NotImplementedError |
436076392538
GenericList + List fixes, better 'change' signal handling, added GenericList.contents property (addind or removing an item there trigger the 'change' signal)
Goffi <goffi@goffi.org>
parents:
109
diff
changeset
|
504 |
436076392538
GenericList + List fixes, better 'change' signal handling, added GenericList.contents property (addind or removing an item there trigger the 'change' signal)
Goffi <goffi@goffi.org>
parents:
109
diff
changeset
|
505 def __mul__(self, n): |
436076392538
GenericList + List fixes, better 'change' signal handling, added GenericList.contents property (addind or removing an item there trigger the 'change' signal)
Goffi <goffi@goffi.org>
parents:
109
diff
changeset
|
506 raise NotImplementedError |
436076392538
GenericList + List fixes, better 'change' signal handling, added GenericList.contents property (addind or removing an item there trigger the 'change' signal)
Goffi <goffi@goffi.org>
parents:
109
diff
changeset
|
507 |
436076392538
GenericList + List fixes, better 'change' signal handling, added GenericList.contents property (addind or removing an item there trigger the 'change' signal)
Goffi <goffi@goffi.org>
parents:
109
diff
changeset
|
508 def __rmul__(self, n): |
436076392538
GenericList + List fixes, better 'change' signal handling, added GenericList.contents property (addind or removing an item there trigger the 'change' signal)
Goffi <goffi@goffi.org>
parents:
109
diff
changeset
|
509 raise NotImplementedError |
436076392538
GenericList + List fixes, better 'change' signal handling, added GenericList.contents property (addind or removing an item there trigger the 'change' signal)
Goffi <goffi@goffi.org>
parents:
109
diff
changeset
|
510 |
436076392538
GenericList + List fixes, better 'change' signal handling, added GenericList.contents property (addind or removing an item there trigger the 'change' signal)
Goffi <goffi@goffi.org>
parents:
109
diff
changeset
|
511 def __setitem__(self, i, y): |
436076392538
GenericList + List fixes, better 'change' signal handling, added GenericList.contents property (addind or removing an item there trigger the 'change' signal)
Goffi <goffi@goffi.org>
parents:
109
diff
changeset
|
512 parent = super(SimpleListWalkerWithCb, self) |
436076392538
GenericList + List fixes, better 'change' signal handling, added GenericList.contents property (addind or removing an item there trigger the 'change' signal)
Goffi <goffi@goffi.org>
parents:
109
diff
changeset
|
513 self.__cbSingle(y, self._on_new) |
436076392538
GenericList + List fixes, better 'change' signal handling, added GenericList.contents property (addind or removing an item there trigger the 'change' signal)
Goffi <goffi@goffi.org>
parents:
109
diff
changeset
|
514 to_delete = parent.__getitem__(i) |
436076392538
GenericList + List fixes, better 'change' signal handling, added GenericList.contents property (addind or removing an item there trigger the 'change' signal)
Goffi <goffi@goffi.org>
parents:
109
diff
changeset
|
515 self.__cbSingle(to_delete, self._on_delete) |
436076392538
GenericList + List fixes, better 'change' signal handling, added GenericList.contents property (addind or removing an item there trigger the 'change' signal)
Goffi <goffi@goffi.org>
parents:
109
diff
changeset
|
516 return parent.__setitem__(self, i, y) |
436076392538
GenericList + List fixes, better 'change' signal handling, added GenericList.contents property (addind or removing an item there trigger the 'change' signal)
Goffi <goffi@goffi.org>
parents:
109
diff
changeset
|
517 |
436076392538
GenericList + List fixes, better 'change' signal handling, added GenericList.contents property (addind or removing an item there trigger the 'change' signal)
Goffi <goffi@goffi.org>
parents:
109
diff
changeset
|
518 def __setslice__(self, i, j, y): |
436076392538
GenericList + List fixes, better 'change' signal handling, added GenericList.contents property (addind or removing an item there trigger the 'change' signal)
Goffi <goffi@goffi.org>
parents:
109
diff
changeset
|
519 parent = super(SimpleListWalkerWithCb, self) |
436076392538
GenericList + List fixes, better 'change' signal handling, added GenericList.contents property (addind or removing an item there trigger the 'change' signal)
Goffi <goffi@goffi.org>
parents:
109
diff
changeset
|
520 items_to_delete = parent.__getslice__(i,j) |
436076392538
GenericList + List fixes, better 'change' signal handling, added GenericList.contents property (addind or removing an item there trigger the 'change' signal)
Goffi <goffi@goffi.org>
parents:
109
diff
changeset
|
521 self.__cbMulti(items_to_delete, self._on_delete) |
436076392538
GenericList + List fixes, better 'change' signal handling, added GenericList.contents property (addind or removing an item there trigger the 'change' signal)
Goffi <goffi@goffi.org>
parents:
109
diff
changeset
|
522 if hasattr(y, '__iter__'): |
436076392538
GenericList + List fixes, better 'change' signal handling, added GenericList.contents property (addind or removing an item there trigger the 'change' signal)
Goffi <goffi@goffi.org>
parents:
109
diff
changeset
|
523 self.__cbMulti(y, self._on_new) |
436076392538
GenericList + List fixes, better 'change' signal handling, added GenericList.contents property (addind or removing an item there trigger the 'change' signal)
Goffi <goffi@goffi.org>
parents:
109
diff
changeset
|
524 else: |
436076392538
GenericList + List fixes, better 'change' signal handling, added GenericList.contents property (addind or removing an item there trigger the 'change' signal)
Goffi <goffi@goffi.org>
parents:
109
diff
changeset
|
525 self.__cbSingle(y, self._on_new) |
436076392538
GenericList + List fixes, better 'change' signal handling, added GenericList.contents property (addind or removing an item there trigger the 'change' signal)
Goffi <goffi@goffi.org>
parents:
109
diff
changeset
|
526 return parent.__setslice__(i, j, y) |
436076392538
GenericList + List fixes, better 'change' signal handling, added GenericList.contents property (addind or removing an item there trigger the 'change' signal)
Goffi <goffi@goffi.org>
parents:
109
diff
changeset
|
527 |
436076392538
GenericList + List fixes, better 'change' signal handling, added GenericList.contents property (addind or removing an item there trigger the 'change' signal)
Goffi <goffi@goffi.org>
parents:
109
diff
changeset
|
528 def append(self, obj): |
436076392538
GenericList + List fixes, better 'change' signal handling, added GenericList.contents property (addind or removing an item there trigger the 'change' signal)
Goffi <goffi@goffi.org>
parents:
109
diff
changeset
|
529 self.__cbSingle(obj, self._on_new) |
436076392538
GenericList + List fixes, better 'change' signal handling, added GenericList.contents property (addind or removing an item there trigger the 'change' signal)
Goffi <goffi@goffi.org>
parents:
109
diff
changeset
|
530 return super(SimpleListWalkerWithCb, self).append(obj) |
436076392538
GenericList + List fixes, better 'change' signal handling, added GenericList.contents property (addind or removing an item there trigger the 'change' signal)
Goffi <goffi@goffi.org>
parents:
109
diff
changeset
|
531 |
436076392538
GenericList + List fixes, better 'change' signal handling, added GenericList.contents property (addind or removing an item there trigger the 'change' signal)
Goffi <goffi@goffi.org>
parents:
109
diff
changeset
|
532 def extend(self, it): |
436076392538
GenericList + List fixes, better 'change' signal handling, added GenericList.contents property (addind or removing an item there trigger the 'change' signal)
Goffi <goffi@goffi.org>
parents:
109
diff
changeset
|
533 self.__cbMulti(it, self.__on_new) |
436076392538
GenericList + List fixes, better 'change' signal handling, added GenericList.contents property (addind or removing an item there trigger the 'change' signal)
Goffi <goffi@goffi.org>
parents:
109
diff
changeset
|
534 return super(SimpleListWalkerWithCb, self).extend(it) |
436076392538
GenericList + List fixes, better 'change' signal handling, added GenericList.contents property (addind or removing an item there trigger the 'change' signal)
Goffi <goffi@goffi.org>
parents:
109
diff
changeset
|
535 |
436076392538
GenericList + List fixes, better 'change' signal handling, added GenericList.contents property (addind or removing an item there trigger the 'change' signal)
Goffi <goffi@goffi.org>
parents:
109
diff
changeset
|
536 def insert(self, idx, obj): |
436076392538
GenericList + List fixes, better 'change' signal handling, added GenericList.contents property (addind or removing an item there trigger the 'change' signal)
Goffi <goffi@goffi.org>
parents:
109
diff
changeset
|
537 self.__cbSingle(obj, self.__on_new) |
436076392538
GenericList + List fixes, better 'change' signal handling, added GenericList.contents property (addind or removing an item there trigger the 'change' signal)
Goffi <goffi@goffi.org>
parents:
109
diff
changeset
|
538 return super(SimpleListWalkerWithCb, self).insert(idx, obj) |
436076392538
GenericList + List fixes, better 'change' signal handling, added GenericList.contents property (addind or removing an item there trigger the 'change' signal)
Goffi <goffi@goffi.org>
parents:
109
diff
changeset
|
539 |
436076392538
GenericList + List fixes, better 'change' signal handling, added GenericList.contents property (addind or removing an item there trigger the 'change' signal)
Goffi <goffi@goffi.org>
parents:
109
diff
changeset
|
540 def pop(self, idx=None): |
436076392538
GenericList + List fixes, better 'change' signal handling, added GenericList.contents property (addind or removing an item there trigger the 'change' signal)
Goffi <goffi@goffi.org>
parents:
109
diff
changeset
|
541 if idx is None: |
436076392538
GenericList + List fixes, better 'change' signal handling, added GenericList.contents property (addind or removing an item there trigger the 'change' signal)
Goffi <goffi@goffi.org>
parents:
109
diff
changeset
|
542 idx=len(self)-1 |
436076392538
GenericList + List fixes, better 'change' signal handling, added GenericList.contents property (addind or removing an item there trigger the 'change' signal)
Goffi <goffi@goffi.org>
parents:
109
diff
changeset
|
543 |
436076392538
GenericList + List fixes, better 'change' signal handling, added GenericList.contents property (addind or removing an item there trigger the 'change' signal)
Goffi <goffi@goffi.org>
parents:
109
diff
changeset
|
544 parent = super(SimpleListWalkerWithCb, self) |
436076392538
GenericList + List fixes, better 'change' signal handling, added GenericList.contents property (addind or removing an item there trigger the 'change' signal)
Goffi <goffi@goffi.org>
parents:
109
diff
changeset
|
545 to_remove = parent.__getitem__(idx) |
436076392538
GenericList + List fixes, better 'change' signal handling, added GenericList.contents property (addind or removing an item there trigger the 'change' signal)
Goffi <goffi@goffi.org>
parents:
109
diff
changeset
|
546 self.__cbSingle(to_remove, self._on_delete) |
436076392538
GenericList + List fixes, better 'change' signal handling, added GenericList.contents property (addind or removing an item there trigger the 'change' signal)
Goffi <goffi@goffi.org>
parents:
109
diff
changeset
|
547 return parent.pop(idx) |
436076392538
GenericList + List fixes, better 'change' signal handling, added GenericList.contents property (addind or removing an item there trigger the 'change' signal)
Goffi <goffi@goffi.org>
parents:
109
diff
changeset
|
548 |
436076392538
GenericList + List fixes, better 'change' signal handling, added GenericList.contents property (addind or removing an item there trigger the 'change' signal)
Goffi <goffi@goffi.org>
parents:
109
diff
changeset
|
549 def remove(self, val): |
436076392538
GenericList + List fixes, better 'change' signal handling, added GenericList.contents property (addind or removing an item there trigger the 'change' signal)
Goffi <goffi@goffi.org>
parents:
109
diff
changeset
|
550 ret = super(SimpleListWalkerWithCb, self).remove(val) |
436076392538
GenericList + List fixes, better 'change' signal handling, added GenericList.contents property (addind or removing an item there trigger the 'change' signal)
Goffi <goffi@goffi.org>
parents:
109
diff
changeset
|
551 self.__cbSingle(val, self._on_delete) |
436076392538
GenericList + List fixes, better 'change' signal handling, added GenericList.contents property (addind or removing an item there trigger the 'change' signal)
Goffi <goffi@goffi.org>
parents:
109
diff
changeset
|
552 return ret |
436076392538
GenericList + List fixes, better 'change' signal handling, added GenericList.contents property (addind or removing an item there trigger the 'change' signal)
Goffi <goffi@goffi.org>
parents:
109
diff
changeset
|
553 |
436076392538
GenericList + List fixes, better 'change' signal handling, added GenericList.contents property (addind or removing an item there trigger the 'change' signal)
Goffi <goffi@goffi.org>
parents:
109
diff
changeset
|
554 |
107 | 555 class GenericList(urwid.ListBox): |
5
592cd64933dd
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
4
diff
changeset
|
556 signals = ['click','change'] |
0 | 557 |
70
24d49f1d735f
added TableContainer + some bug fixes (bad default parameters)
Goffi <goffi@goffi.org>
parents:
69
diff
changeset
|
558 def __init__(self, options, style=None, align='left', option_type = SelectableText, on_click=None, on_change=None, user_data=None): |
107 | 559 """Widget managing list of string and their selection |
560 | |
5
592cd64933dd
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
4
diff
changeset
|
561 @param options: list of strings used for options |
592cd64933dd
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
4
diff
changeset
|
562 @param style: list of string: |
592cd64933dd
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
4
diff
changeset
|
563 - 'single' if only one must be selected |
66 | 564 - '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
|
565 - 'can_select_none' if we can select nothing |
592cd64933dd
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
4
diff
changeset
|
566 @param align: alignement of text inside the list |
110
436076392538
GenericList + List fixes, better 'change' signal handling, added GenericList.contents property (addind or removing an item there trigger the 'change' signal)
Goffi <goffi@goffi.org>
parents:
109
diff
changeset
|
567 @param option_type: callable (usually a class) which will be called with: |
436076392538
GenericList + List fixes, better 'change' signal handling, added GenericList.contents property (addind or removing an item there trigger the 'change' signal)
Goffi <goffi@goffi.org>
parents:
109
diff
changeset
|
568 - option as first argument |
436076392538
GenericList + List fixes, better 'change' signal handling, added GenericList.contents property (addind or removing an item there trigger the 'change' signal)
Goffi <goffi@goffi.org>
parents:
109
diff
changeset
|
569 - align=align as keyword argument |
5
592cd64933dd
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
4
diff
changeset
|
570 @param on_click: method called when click signal is emited |
110
436076392538
GenericList + List fixes, better 'change' signal handling, added GenericList.contents property (addind or removing an item there trigger the 'change' signal)
Goffi <goffi@goffi.org>
parents:
109
diff
changeset
|
571 @param on_change: method called when change signal is emited |
5
592cd64933dd
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
4
diff
changeset
|
572 @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
|
573 """ |
70
24d49f1d735f
added TableContainer + some bug fixes (bad default parameters)
Goffi <goffi@goffi.org>
parents:
69
diff
changeset
|
574 if style is None: |
24d49f1d735f
added TableContainer + some bug fixes (bad default parameters)
Goffi <goffi@goffi.org>
parents:
69
diff
changeset
|
575 style = [] |
0 | 576 self.single = 'single' in style |
5
592cd64933dd
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
4
diff
changeset
|
577 self.no_first_select = 'no_first_select' in style |
592cd64933dd
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
4
diff
changeset
|
578 self.can_select_none = 'can_select_none' in style |
0 | 579 self.align = align |
8 | 580 self.option_type = option_type |
5
592cd64933dd
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
4
diff
changeset
|
581 self.first_display = True |
66 | 582 |
5
592cd64933dd
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
4
diff
changeset
|
583 if on_click: |
592cd64933dd
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
4
diff
changeset
|
584 urwid.connect_signal(self, 'click', on_click, user_data) |
66 | 585 |
5
592cd64933dd
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
4
diff
changeset
|
586 if on_change: |
592cd64933dd
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
4
diff
changeset
|
587 urwid.connect_signal(self, 'change', on_change, user_data) |
66 | 588 |
110
436076392538
GenericList + List fixes, better 'change' signal handling, added GenericList.contents property (addind or removing an item there trigger the 'change' signal)
Goffi <goffi@goffi.org>
parents:
109
diff
changeset
|
589 self.content = SimpleListWalkerWithCb([], self._addSignals, lambda widget: self._emit('change')) |
107 | 590 super(GenericList, self).__init__(self.content) |
1 | 591 self.changeValues(options) |
0 | 592 |
110
436076392538
GenericList + List fixes, better 'change' signal handling, added GenericList.contents property (addind or removing an item there trigger the 'change' signal)
Goffi <goffi@goffi.org>
parents:
109
diff
changeset
|
593 def _addSignals(self, widget): |
436076392538
GenericList + List fixes, better 'change' signal handling, added GenericList.contents property (addind or removing an item there trigger the 'change' signal)
Goffi <goffi@goffi.org>
parents:
109
diff
changeset
|
594 for signal, callback in (('change', self._onStateChange), ('click', self._onClick)): |
436076392538
GenericList + List fixes, better 'change' signal handling, added GenericList.contents property (addind or removing an item there trigger the 'change' signal)
Goffi <goffi@goffi.org>
parents:
109
diff
changeset
|
595 try: |
436076392538
GenericList + List fixes, better 'change' signal handling, added GenericList.contents property (addind or removing an item there trigger the 'change' signal)
Goffi <goffi@goffi.org>
parents:
109
diff
changeset
|
596 urwid.connect_signal(widget, signal, callback) |
436076392538
GenericList + List fixes, better 'change' signal handling, added GenericList.contents property (addind or removing an item there trigger the 'change' signal)
Goffi <goffi@goffi.org>
parents:
109
diff
changeset
|
597 except NameError: |
436076392538
GenericList + List fixes, better 'change' signal handling, added GenericList.contents property (addind or removing an item there trigger the 'change' signal)
Goffi <goffi@goffi.org>
parents:
109
diff
changeset
|
598 pass #the widget given doesn't support the signal |
436076392538
GenericList + List fixes, better 'change' signal handling, added GenericList.contents property (addind or removing an item there trigger the 'change' signal)
Goffi <goffi@goffi.org>
parents:
109
diff
changeset
|
599 |
436076392538
GenericList + List fixes, better 'change' signal handling, added GenericList.contents property (addind or removing an item there trigger the 'change' signal)
Goffi <goffi@goffi.org>
parents:
109
diff
changeset
|
600 @property |
436076392538
GenericList + List fixes, better 'change' signal handling, added GenericList.contents property (addind or removing an item there trigger the 'change' signal)
Goffi <goffi@goffi.org>
parents:
109
diff
changeset
|
601 def contents(self): |
436076392538
GenericList + List fixes, better 'change' signal handling, added GenericList.contents property (addind or removing an item there trigger the 'change' signal)
Goffi <goffi@goffi.org>
parents:
109
diff
changeset
|
602 return self.content |
436076392538
GenericList + List fixes, better 'change' signal handling, added GenericList.contents property (addind or removing an item there trigger the 'change' signal)
Goffi <goffi@goffi.org>
parents:
109
diff
changeset
|
603 |
436076392538
GenericList + List fixes, better 'change' signal handling, added GenericList.contents property (addind or removing an item there trigger the 'change' signal)
Goffi <goffi@goffi.org>
parents:
109
diff
changeset
|
604 def _onStateChange(self, widget, selected, *args): |
0 | 605 if self.single: |
5
592cd64933dd
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
4
diff
changeset
|
606 if not selected and not self.can_select_none: |
0 | 607 #if in single mode, it's forbidden to unselect a value |
608 widget.setState(True, invisible=True) | |
609 return | |
5
592cd64933dd
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
4
diff
changeset
|
610 if selected: |
0 | 611 self.unselectAll(invisible=True) |
612 widget.setState(True, invisible=True) | |
110
436076392538
GenericList + List fixes, better 'change' signal handling, added GenericList.contents property (addind or removing an item there trigger the 'change' signal)
Goffi <goffi@goffi.org>
parents:
109
diff
changeset
|
613 self._emit("change", widget, selected, *args) |
0 | 614 |
110
436076392538
GenericList + List fixes, better 'change' signal handling, added GenericList.contents property (addind or removing an item there trigger the 'change' signal)
Goffi <goffi@goffi.org>
parents:
109
diff
changeset
|
615 def _onClick(self, widget, *args): |
436076392538
GenericList + List fixes, better 'change' signal handling, added GenericList.contents property (addind or removing an item there trigger the 'change' signal)
Goffi <goffi@goffi.org>
parents:
109
diff
changeset
|
616 if widget not in self.content: |
436076392538
GenericList + List fixes, better 'change' signal handling, added GenericList.contents property (addind or removing an item there trigger the 'change' signal)
Goffi <goffi@goffi.org>
parents:
109
diff
changeset
|
617 urwid.disconnect_signal(widget, "click", self._onClick) |
436076392538
GenericList + List fixes, better 'change' signal handling, added GenericList.contents property (addind or removing an item there trigger the 'change' signal)
Goffi <goffi@goffi.org>
parents:
109
diff
changeset
|
618 return |
436076392538
GenericList + List fixes, better 'change' signal handling, added GenericList.contents property (addind or removing an item there trigger the 'change' signal)
Goffi <goffi@goffi.org>
parents:
109
diff
changeset
|
619 self._emit("click", widget, *args) |
0 | 620 |
621 def unselectAll(self, invisible=False): | |
622 for widget in self.content: | |
623 if widget.getState(): | |
624 widget.setState(False, invisible) | |
625 widget._invalidate() | |
626 | |
2
07b7dcd314ff
primitivus: basic contact list, connexion now work \o/
Goffi <goffi@goffi.org>
parents:
1
diff
changeset
|
627 def deleteValue(self, value): |
07b7dcd314ff
primitivus: basic contact list, connexion now work \o/
Goffi <goffi@goffi.org>
parents:
1
diff
changeset
|
628 """Delete the first value equal to the param given""" |
5
592cd64933dd
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
4
diff
changeset
|
629 for widget in self.content: |
592cd64933dd
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
4
diff
changeset
|
630 if widget.getValue() == value: |
592cd64933dd
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
4
diff
changeset
|
631 self.content.remove(widget) |
592cd64933dd
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
4
diff
changeset
|
632 self._emit('change') |
592cd64933dd
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
4
diff
changeset
|
633 return |
592cd64933dd
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
4
diff
changeset
|
634 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
|
635 |
5
592cd64933dd
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
4
diff
changeset
|
636 def getSelectedValue(self): |
1 | 637 """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
|
638 values = self.getSelectedValues() |
1 | 639 return values[0] if values else None |
640 | |
5
592cd64933dd
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
4
diff
changeset
|
641 def getAllValues(self): |
592cd64933dd
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
4
diff
changeset
|
642 """Return values of all items""" |
592cd64933dd
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
4
diff
changeset
|
643 return [widget.getValue() for widget in self.content] |
592cd64933dd
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
4
diff
changeset
|
644 |
592cd64933dd
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
4
diff
changeset
|
645 def getSelectedValues(self): |
592cd64933dd
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
4
diff
changeset
|
646 """Return values of selected items""" |
0 | 647 result = [] |
648 for widget in self.content: | |
649 if widget.getState(): | |
650 result.append(widget.getValue()) | |
651 return result | |
652 | |
653 def changeValues(self, new_values): | |
68
5c28bb50ae0d
new ListOption class which work like unicode, but make the difference between value and label, so the displayed text can be different from the actual value.
Goffi <goffi@goffi.org>
parents:
67
diff
changeset
|
654 """Change all values in one shot""" |
5c28bb50ae0d
new ListOption class which work like unicode, but make the difference between value and label, so the displayed text can be different from the actual value.
Goffi <goffi@goffi.org>
parents:
67
diff
changeset
|
655 new_values = ListOption.fromOptions(new_values) |
5
592cd64933dd
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
4
diff
changeset
|
656 if not self.first_display: |
592cd64933dd
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
4
diff
changeset
|
657 old_selected = self.getSelectedValues() |
592cd64933dd
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
4
diff
changeset
|
658 widgets = [] |
592cd64933dd
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
4
diff
changeset
|
659 for option in new_values: |
110
436076392538
GenericList + List fixes, better 'change' signal handling, added GenericList.contents property (addind or removing an item there trigger the 'change' signal)
Goffi <goffi@goffi.org>
parents:
109
diff
changeset
|
660 widget = self.option_type(option, align=self.align) |
5
592cd64933dd
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
4
diff
changeset
|
661 if not self.first_display and option in old_selected: |
592cd64933dd
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
4
diff
changeset
|
662 widget.setState(True) |
592cd64933dd
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
4
diff
changeset
|
663 widgets.append(widget) |
0 | 664 self.content[:] = widgets |
5
592cd64933dd
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
4
diff
changeset
|
665 if self.first_display and self.single and new_values and not self.no_first_select: |
1 | 666 self.content[0].setState(True) |
5
592cd64933dd
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
4
diff
changeset
|
667 self._emit('change') |
66 | 668 self.first_display = False |
5
592cd64933dd
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
4
diff
changeset
|
669 |
80
2d66ac0f4d75
add move_focus parameter to the methods selectValue(s) of list widgets
souliane <souliane@mailoo.org>
parents:
79
diff
changeset
|
670 def selectValue(self, value, move_focus=True): |
2d66ac0f4d75
add move_focus parameter to the methods selectValue(s) of list widgets
souliane <souliane@mailoo.org>
parents:
79
diff
changeset
|
671 """Select the first item which has the given value. |
2d66ac0f4d75
add move_focus parameter to the methods selectValue(s) of list widgets
souliane <souliane@mailoo.org>
parents:
79
diff
changeset
|
672 |
2d66ac0f4d75
add move_focus parameter to the methods selectValue(s) of list widgets
souliane <souliane@mailoo.org>
parents:
79
diff
changeset
|
673 @param value |
107 | 674 @param move_focus (bool): |
675 - True to move the focus on the selected value, | |
676 - False to leave the focus position unchanged. | |
677 | |
80
2d66ac0f4d75
add move_focus parameter to the methods selectValue(s) of list widgets
souliane <souliane@mailoo.org>
parents:
79
diff
changeset
|
678 """ |
0 | 679 self.unselectAll() |
680 idx = 0 | |
681 for widget in self.content: | |
28
654d31983f19
primitivus: fixed misnamed method in custom widget
Goffi <goffi@goffi.org>
parents:
27
diff
changeset
|
682 if widget.getValue() == value: |
0 | 683 widget.setState(True) |
80
2d66ac0f4d75
add move_focus parameter to the methods selectValue(s) of list widgets
souliane <souliane@mailoo.org>
parents:
79
diff
changeset
|
684 if move_focus: |
107 | 685 self.focus_position = idx |
0 | 686 return |
687 idx+=1 | |
688 | |
80
2d66ac0f4d75
add move_focus parameter to the methods selectValue(s) of list widgets
souliane <souliane@mailoo.org>
parents:
79
diff
changeset
|
689 def selectValues(self, values, move_focus=True): |
2d66ac0f4d75
add move_focus parameter to the methods selectValue(s) of list widgets
souliane <souliane@mailoo.org>
parents:
79
diff
changeset
|
690 """Select all the given values. |
2d66ac0f4d75
add move_focus parameter to the methods selectValue(s) of list widgets
souliane <souliane@mailoo.org>
parents:
79
diff
changeset
|
691 |
2d66ac0f4d75
add move_focus parameter to the methods selectValue(s) of list widgets
souliane <souliane@mailoo.org>
parents:
79
diff
changeset
|
692 @param values [set, list] |
2d66ac0f4d75
add move_focus parameter to the methods selectValue(s) of list widgets
souliane <souliane@mailoo.org>
parents:
79
diff
changeset
|
693 @param move_focus (boolean): True to move the focus on the last selected value, |
2d66ac0f4d75
add move_focus parameter to the methods selectValue(s) of list widgets
souliane <souliane@mailoo.org>
parents:
79
diff
changeset
|
694 False to leave the focus position unchanged. |
2d66ac0f4d75
add move_focus parameter to the methods selectValue(s) of list widgets
souliane <souliane@mailoo.org>
parents:
79
diff
changeset
|
695 """ |
78
56c02f4731f9
added selectValues for lists widgets that support multi-selection
souliane <souliane@mailoo.org>
parents:
77
diff
changeset
|
696 if self.single: |
56c02f4731f9
added selectValues for lists widgets that support multi-selection
souliane <souliane@mailoo.org>
parents:
77
diff
changeset
|
697 if values: |
80
2d66ac0f4d75
add move_focus parameter to the methods selectValue(s) of list widgets
souliane <souliane@mailoo.org>
parents:
79
diff
changeset
|
698 self.selectValue(values[-1], move_focus) |
78
56c02f4731f9
added selectValues for lists widgets that support multi-selection
souliane <souliane@mailoo.org>
parents:
77
diff
changeset
|
699 return |
56c02f4731f9
added selectValues for lists widgets that support multi-selection
souliane <souliane@mailoo.org>
parents:
77
diff
changeset
|
700 self.unselectAll() |
56c02f4731f9
added selectValues for lists widgets that support multi-selection
souliane <souliane@mailoo.org>
parents:
77
diff
changeset
|
701 for value in values: |
56c02f4731f9
added selectValues for lists widgets that support multi-selection
souliane <souliane@mailoo.org>
parents:
77
diff
changeset
|
702 idx = 0 |
56c02f4731f9
added selectValues for lists widgets that support multi-selection
souliane <souliane@mailoo.org>
parents:
77
diff
changeset
|
703 for widget in self.content: |
56c02f4731f9
added selectValues for lists widgets that support multi-selection
souliane <souliane@mailoo.org>
parents:
77
diff
changeset
|
704 if widget.getValue() == value: |
56c02f4731f9
added selectValues for lists widgets that support multi-selection
souliane <souliane@mailoo.org>
parents:
77
diff
changeset
|
705 widget.setState(True) |
80
2d66ac0f4d75
add move_focus parameter to the methods selectValue(s) of list widgets
souliane <souliane@mailoo.org>
parents:
79
diff
changeset
|
706 if move_focus: |
107 | 707 self.focus_position = idx |
78
56c02f4731f9
added selectValues for lists widgets that support multi-selection
souliane <souliane@mailoo.org>
parents:
77
diff
changeset
|
708 idx += 1 |
56c02f4731f9
added selectValues for lists widgets that support multi-selection
souliane <souliane@mailoo.org>
parents:
77
diff
changeset
|
709 |
70
24d49f1d735f
added TableContainer + some bug fixes (bad default parameters)
Goffi <goffi@goffi.org>
parents:
69
diff
changeset
|
710 |
67 | 711 class List(urwid.Widget): |
5
592cd64933dd
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
4
diff
changeset
|
712 """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
|
713 signals = ['click','change'] |
67 | 714 _sizing = frozenset(['flow']) |
5
592cd64933dd
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
4
diff
changeset
|
715 |
70
24d49f1d735f
added TableContainer + some bug fixes (bad default parameters)
Goffi <goffi@goffi.org>
parents:
69
diff
changeset
|
716 def __init__(self, options, style=None, max_height=5, align='left', option_type = SelectableText, on_click=None, on_change=None, user_data=None): |
24d49f1d735f
added TableContainer + some bug fixes (bad default parameters)
Goffi <goffi@goffi.org>
parents:
69
diff
changeset
|
717 if style is None: |
24d49f1d735f
added TableContainer + some bug fixes (bad default parameters)
Goffi <goffi@goffi.org>
parents:
69
diff
changeset
|
718 style = [] |
8 | 719 self.genericList = GenericList(options, style, align, option_type, on_click, on_change, user_data) |
110
436076392538
GenericList + List fixes, better 'change' signal handling, added GenericList.contents property (addind or removing an item there trigger the 'change' signal)
Goffi <goffi@goffi.org>
parents:
109
diff
changeset
|
720 urwid.connect_signal(self.genericList, 'change', lambda *args: self._emit('change')) |
66 | 721 self.max_height = max_height |
5
592cd64933dd
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
4
diff
changeset
|
722 |
110
436076392538
GenericList + List fixes, better 'change' signal handling, added GenericList.contents property (addind or removing an item there trigger the 'change' signal)
Goffi <goffi@goffi.org>
parents:
109
diff
changeset
|
723 @property |
436076392538
GenericList + List fixes, better 'change' signal handling, added GenericList.contents property (addind or removing an item there trigger the 'change' signal)
Goffi <goffi@goffi.org>
parents:
109
diff
changeset
|
724 def contents(self): |
436076392538
GenericList + List fixes, better 'change' signal handling, added GenericList.contents property (addind or removing an item there trigger the 'change' signal)
Goffi <goffi@goffi.org>
parents:
109
diff
changeset
|
725 return self.genericList.content |
70
24d49f1d735f
added TableContainer + some bug fixes (bad default parameters)
Goffi <goffi@goffi.org>
parents:
69
diff
changeset
|
726 |
5
592cd64933dd
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
4
diff
changeset
|
727 def selectable(self): |
592cd64933dd
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
4
diff
changeset
|
728 return True |
592cd64933dd
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
4
diff
changeset
|
729 |
110
436076392538
GenericList + List fixes, better 'change' signal handling, added GenericList.contents property (addind or removing an item there trigger the 'change' signal)
Goffi <goffi@goffi.org>
parents:
109
diff
changeset
|
730 def get_cursor_coords(self, size): |
436076392538
GenericList + List fixes, better 'change' signal handling, added GenericList.contents property (addind or removing an item there trigger the 'change' signal)
Goffi <goffi@goffi.org>
parents:
109
diff
changeset
|
731 return self.genericList.get_cursor_coords((size[0], self._getHeight(size, True))) |
436076392538
GenericList + List fixes, better 'change' signal handling, added GenericList.contents property (addind or removing an item there trigger the 'change' signal)
Goffi <goffi@goffi.org>
parents:
109
diff
changeset
|
732 |
5
592cd64933dd
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
4
diff
changeset
|
733 def keypress(self, size, key): |
592cd64933dd
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
4
diff
changeset
|
734 return self.displayWidget(size,True).keypress(size, key) |
66 | 735 |
5
592cd64933dd
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
4
diff
changeset
|
736 def unselectAll(self, invisible=False): |
592cd64933dd
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
4
diff
changeset
|
737 return self.genericList.unselectAll(invisible) |
66 | 738 |
5
592cd64933dd
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
4
diff
changeset
|
739 def deleteValue(self, value): |
592cd64933dd
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
4
diff
changeset
|
740 return self.genericList.deleteValue(value) |
592cd64933dd
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
4
diff
changeset
|
741 |
592cd64933dd
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
4
diff
changeset
|
742 def getSelectedValue(self): |
592cd64933dd
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
4
diff
changeset
|
743 return self.genericList.getSelectedValue() |
592cd64933dd
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
4
diff
changeset
|
744 |
592cd64933dd
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
4
diff
changeset
|
745 def getAllValues(self): |
592cd64933dd
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
4
diff
changeset
|
746 return self.genericList.getAllValues() |
592cd64933dd
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
4
diff
changeset
|
747 |
592cd64933dd
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
4
diff
changeset
|
748 def getSelectedValues(self): |
592cd64933dd
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
4
diff
changeset
|
749 return self.genericList.getSelectedValues() |
592cd64933dd
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
4
diff
changeset
|
750 |
592cd64933dd
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
4
diff
changeset
|
751 def changeValues(self, new_values): |
592cd64933dd
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
4
diff
changeset
|
752 return self.genericList.changeValues(new_values) |
592cd64933dd
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
4
diff
changeset
|
753 |
81
0ebd13729039
fixes default values for methods selectValue(s) of class List
souliane <souliane@mailoo.org>
parents:
80
diff
changeset
|
754 def selectValue(self, value, move_focus=True): |
80
2d66ac0f4d75
add move_focus parameter to the methods selectValue(s) of list widgets
souliane <souliane@mailoo.org>
parents:
79
diff
changeset
|
755 return self.genericList.selectValue(value, move_focus) |
5
592cd64933dd
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
4
diff
changeset
|
756 |
81
0ebd13729039
fixes default values for methods selectValue(s) of class List
souliane <souliane@mailoo.org>
parents:
80
diff
changeset
|
757 def selectValues(self, values, move_focus=True): |
80
2d66ac0f4d75
add move_focus parameter to the methods selectValue(s) of list widgets
souliane <souliane@mailoo.org>
parents:
79
diff
changeset
|
758 return self.genericList.selectValues(values, move_focus) |
78
56c02f4731f9
added selectValues for lists widgets that support multi-selection
souliane <souliane@mailoo.org>
parents:
77
diff
changeset
|
759 |
5
592cd64933dd
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
4
diff
changeset
|
760 def render(self, size, focus=False): |
592cd64933dd
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
4
diff
changeset
|
761 return self.displayWidget(size, focus).render(size, focus) |
66 | 762 |
5
592cd64933dd
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
4
diff
changeset
|
763 def rows(self, size, focus=False): |
592cd64933dd
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
4
diff
changeset
|
764 return self.displayWidget(size, focus).rows(size, focus) |
592cd64933dd
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
4
diff
changeset
|
765 |
110
436076392538
GenericList + List fixes, better 'change' signal handling, added GenericList.contents property (addind or removing an item there trigger the 'change' signal)
Goffi <goffi@goffi.org>
parents:
109
diff
changeset
|
766 def _getHeight(self, size, focus): |
5
592cd64933dd
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
4
diff
changeset
|
767 list_size = sum([wid.rows(size, focus) for wid in self.genericList.content]) |
66 | 768 height = min(list_size,self.max_height) or 1 |
110
436076392538
GenericList + List fixes, better 'change' signal handling, added GenericList.contents property (addind or removing an item there trigger the 'change' signal)
Goffi <goffi@goffi.org>
parents:
109
diff
changeset
|
769 return height |
436076392538
GenericList + List fixes, better 'change' signal handling, added GenericList.contents property (addind or removing an item there trigger the 'change' signal)
Goffi <goffi@goffi.org>
parents:
109
diff
changeset
|
770 |
436076392538
GenericList + List fixes, better 'change' signal handling, added GenericList.contents property (addind or removing an item there trigger the 'change' signal)
Goffi <goffi@goffi.org>
parents:
109
diff
changeset
|
771 def displayWidget(self, size, focus): |
436076392538
GenericList + List fixes, better 'change' signal handling, added GenericList.contents property (addind or removing an item there trigger the 'change' signal)
Goffi <goffi@goffi.org>
parents:
109
diff
changeset
|
772 return urwid.BoxAdapter(self.genericList, self._getHeight(size, focus)) |
5
592cd64933dd
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
4
diff
changeset
|
773 |
70
24d49f1d735f
added TableContainer + some bug fixes (bad default parameters)
Goffi <goffi@goffi.org>
parents:
69
diff
changeset
|
774 |
10
024b79b61a31
Primitivus: misc fixes + menubar first draft
Goffi <goffi@goffi.org>
parents:
9
diff
changeset
|
775 ## MISC ## |
024b79b61a31
Primitivus: misc fixes + menubar first draft
Goffi <goffi@goffi.org>
parents:
9
diff
changeset
|
776 |
16
263fe4d067ad
Primitivus: notification bar, first draft
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
777 class NotificationBar(urwid.WidgetWrap): |
263fe4d067ad
Primitivus: notification bar, first draft
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
778 """Bar used to show misc information to user""" |
263fe4d067ad
Primitivus: notification bar, first draft
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
779 signals = ['change'] |
263fe4d067ad
Primitivus: notification bar, first draft
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
780 |
263fe4d067ad
Primitivus: notification bar, first draft
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
781 def __init__(self): |
263fe4d067ad
Primitivus: notification bar, first draft
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
782 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
|
783 self.message = ClickableText('') |
16
263fe4d067ad
Primitivus: notification bar, first draft
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
784 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
|
785 self.progress = ClickableText('') |
22
dfabea6f73b5
Primitivus: AdvancedEdit and Notification bar improved
Goffi <goffi@goffi.org>
parents:
21
diff
changeset
|
786 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
|
787 urwid.WidgetWrap.__init__(self, urwid.AttrMap(self.columns,'notifs')) |
263fe4d067ad
Primitivus: notification bar, first draft
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
788 self.notifs = [] |
66 | 789 |
114
bf38c1c0db3b
notificationBar: added removePopUp to remove a widget in the queue
Goffi <goffi@goffi.org>
parents:
113
diff
changeset
|
790 def _modQueue(self): |
16
263fe4d067ad
Primitivus: notification bar, first draft
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
791 """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
|
792 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
|
793 self._emit('change') |
263fe4d067ad
Primitivus: notification bar, first draft
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
794 |
22
dfabea6f73b5
Primitivus: AdvancedEdit and Notification bar improved
Goffi <goffi@goffi.org>
parents:
21
diff
changeset
|
795 def setProgress(self,percentage): |
dfabea6f73b5
Primitivus: AdvancedEdit and Notification bar improved
Goffi <goffi@goffi.org>
parents:
21
diff
changeset
|
796 """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
|
797 if percentage == None: |
dfabea6f73b5
Primitivus: AdvancedEdit and Notification bar improved
Goffi <goffi@goffi.org>
parents:
21
diff
changeset
|
798 self.progress.set_text('') |
dfabea6f73b5
Primitivus: AdvancedEdit and Notification bar improved
Goffi <goffi@goffi.org>
parents:
21
diff
changeset
|
799 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
|
800 self.progress.set_text(('notifs','%02i%%' % percentage)) |
97 | 801 if self.columns.focus != self.progress: |
802 self.columns.focus_position = len(self.columns.contents)-1 | |
22
dfabea6f73b5
Primitivus: AdvancedEdit and Notification bar improved
Goffi <goffi@goffi.org>
parents:
21
diff
changeset
|
803 self._emit('change') |
dfabea6f73b5
Primitivus: AdvancedEdit and Notification bar improved
Goffi <goffi@goffi.org>
parents:
21
diff
changeset
|
804 |
16
263fe4d067ad
Primitivus: notification bar, first draft
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
805 def addPopUp(self, pop_up_widget): |
263fe4d067ad
Primitivus: notification bar, first draft
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
806 """Add a popup to the waiting queue""" |
263fe4d067ad
Primitivus: notification bar, first draft
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
807 self.notifs.append(('popup',pop_up_widget)) |
114
bf38c1c0db3b
notificationBar: added removePopUp to remove a widget in the queue
Goffi <goffi@goffi.org>
parents:
113
diff
changeset
|
808 self._modQueue() |
bf38c1c0db3b
notificationBar: added removePopUp to remove a widget in the queue
Goffi <goffi@goffi.org>
parents:
113
diff
changeset
|
809 |
bf38c1c0db3b
notificationBar: added removePopUp to remove a widget in the queue
Goffi <goffi@goffi.org>
parents:
113
diff
changeset
|
810 def removePopUp(self, pop_up_widget): |
bf38c1c0db3b
notificationBar: added removePopUp to remove a widget in the queue
Goffi <goffi@goffi.org>
parents:
113
diff
changeset
|
811 """Remove a popup from the waiting queue""" |
bf38c1c0db3b
notificationBar: added removePopUp to remove a widget in the queue
Goffi <goffi@goffi.org>
parents:
113
diff
changeset
|
812 self.notifs.remove(pop_up_widget) |
bf38c1c0db3b
notificationBar: added removePopUp to remove a widget in the queue
Goffi <goffi@goffi.org>
parents:
113
diff
changeset
|
813 self._modQueue() |
16
263fe4d067ad
Primitivus: notification bar, first draft
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
814 |
263fe4d067ad
Primitivus: notification bar, first draft
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
815 def addMessage(self, message): |
263fe4d067ad
Primitivus: notification bar, first draft
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
816 "Add a message to the notificatio bar" |
263fe4d067ad
Primitivus: notification bar, first draft
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
817 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
|
818 self.message.set_text(('notifs',message)) |
16
263fe4d067ad
Primitivus: notification bar, first draft
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
819 self._invalidate() |
263fe4d067ad
Primitivus: notification bar, first draft
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
820 self._emit('change') |
263fe4d067ad
Primitivus: notification bar, first draft
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
821 else: |
263fe4d067ad
Primitivus: notification bar, first draft
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
822 self.notifs.append(('message',message)) |
114
bf38c1c0db3b
notificationBar: added removePopUp to remove a widget in the queue
Goffi <goffi@goffi.org>
parents:
113
diff
changeset
|
823 self._modQueue() |
16
263fe4d067ad
Primitivus: notification bar, first draft
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
824 |
263fe4d067ad
Primitivus: notification bar, first draft
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
825 def showNext(self): |
263fe4d067ad
Primitivus: notification bar, first draft
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
826 """Show next message if any, else delete current message""" |
263fe4d067ad
Primitivus: notification bar, first draft
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
827 found = None |
263fe4d067ad
Primitivus: notification bar, first draft
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
828 for notif in self.notifs: |
263fe4d067ad
Primitivus: notification bar, first draft
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
829 if notif[0] == "message": |
263fe4d067ad
Primitivus: notification bar, first draft
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
830 found = notif |
263fe4d067ad
Primitivus: notification bar, first draft
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
831 break |
263fe4d067ad
Primitivus: notification bar, first draft
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
832 if found: |
263fe4d067ad
Primitivus: notification bar, first draft
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
833 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
|
834 self.message.set_text(('notifs',found[1])) |
114
bf38c1c0db3b
notificationBar: added removePopUp to remove a widget in the queue
Goffi <goffi@goffi.org>
parents:
113
diff
changeset
|
835 self._modQueue() |
97 | 836 self.focus_possition = 1 |
16
263fe4d067ad
Primitivus: notification bar, first draft
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
837 else: |
263fe4d067ad
Primitivus: notification bar, first draft
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
838 self.message.set_text('') |
263fe4d067ad
Primitivus: notification bar, first draft
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
839 self._emit('change') |
263fe4d067ad
Primitivus: notification bar, first draft
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
840 |
263fe4d067ad
Primitivus: notification bar, first draft
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
841 def getNextPopup(self): |
263fe4d067ad
Primitivus: notification bar, first draft
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
842 """Return next pop-up and remove it from the queue |
263fe4d067ad
Primitivus: notification bar, first draft
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
843 @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
|
844 ret = None |
263fe4d067ad
Primitivus: notification bar, first draft
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
845 for notif in self.notifs: |
263fe4d067ad
Primitivus: notification bar, first draft
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
846 if notif[0] == 'popup': |
263fe4d067ad
Primitivus: notification bar, first draft
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
847 ret = notif[1] |
263fe4d067ad
Primitivus: notification bar, first draft
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
848 break |
263fe4d067ad
Primitivus: notification bar, first draft
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
849 if ret: |
263fe4d067ad
Primitivus: notification bar, first draft
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
850 self.notifs.remove(notif) |
114
bf38c1c0db3b
notificationBar: added removePopUp to remove a widget in the queue
Goffi <goffi@goffi.org>
parents:
113
diff
changeset
|
851 self._modQueue() |
16
263fe4d067ad
Primitivus: notification bar, first draft
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
852 return ret |
263fe4d067ad
Primitivus: notification bar, first draft
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
853 |
263fe4d067ad
Primitivus: notification bar, first draft
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
854 def isQueueEmpty(self): |
263fe4d067ad
Primitivus: notification bar, first draft
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
855 return not bool(self.notifs) |
263fe4d067ad
Primitivus: notification bar, first draft
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
856 |
263fe4d067ad
Primitivus: notification bar, first draft
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
857 def canHide(self): |
97 | 858 """Return True if there is no important information to show""" |
22
dfabea6f73b5
Primitivus: AdvancedEdit and Notification bar improved
Goffi <goffi@goffi.org>
parents:
21
diff
changeset
|
859 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
|
860 |
263fe4d067ad
Primitivus: notification bar, first draft
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
861 |
11 | 862 class MenuBox(urwid.WidgetWrap): |
15
8241b3157699
Primitivus: custom_widgets imrpovments
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
863 """Show menu items of a category in a box""" |
11 | 864 signals = ['click'] |
66 | 865 |
11 | 866 def __init__(self,parent,items): |
867 self.parent = parent | |
868 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
|
869 content = urwid.SimpleListWalker([ClickableText(('menuitem',text)) for text in items]) |
11 | 870 for wid in content: |
871 urwid.connect_signal(wid, 'click', self.onClick) | |
872 | |
873 self.listBox = urwid.ListBox(content) | |
874 menubox = urwid.LineBox(urwid.BoxAdapter(self.listBox,len(items))) | |
875 urwid.WidgetWrap.__init__(self,menubox) | |
876 | |
877 def getValue(self): | |
878 return self.selected | |
66 | 879 |
11 | 880 def keypress(self, size, key): |
84
9f683df69a4c
shortcut keys are now managed in separate module, with a class checking for conflicts
Goffi <goffi@goffi.org>
parents:
82
diff
changeset
|
881 if key==a_key['MENU_BOX_UP']: |
11 | 882 if self.listBox.get_focus()[1] == 0: |
883 self.parent.keypress(size, key) | |
84
9f683df69a4c
shortcut keys are now managed in separate module, with a class checking for conflicts
Goffi <goffi@goffi.org>
parents:
82
diff
changeset
|
884 elif key in (a_key['MENU_BOX_LEFT'], a_key['MENU_BOX_RIGHT']): |
11 | 885 self.parent.keypress(size,'up') |
886 self.parent.keypress(size,key) | |
887 return super(MenuBox,self).keypress(size,key) | |
66 | 888 |
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
|
889 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
|
890 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
|
891 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
|
892 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
|
893 return super(MenuBox,self).mouse_event(size, event, button, x, y, focus) |
11 | 894 |
895 def onClick(self, wid): | |
896 self.selected = wid.getValue() | |
897 self._emit('click') | |
898 | |
70
24d49f1d735f
added TableContainer + some bug fixes (bad default parameters)
Goffi <goffi@goffi.org>
parents:
69
diff
changeset
|
899 |
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
|
900 class Menu(urwid.WidgetWrap): |
10
024b79b61a31
Primitivus: misc fixes + menubar first draft
Goffi <goffi@goffi.org>
parents:
9
diff
changeset
|
901 |
12
7e63429cc929
Primitivus: menu are now managed and fully working
Goffi <goffi@goffi.org>
parents:
11
diff
changeset
|
902 def __init__(self,loop, x_orig=0): |
7e63429cc929
Primitivus: menu are now managed and fully working
Goffi <goffi@goffi.org>
parents:
11
diff
changeset
|
903 """Menu widget |
7e63429cc929
Primitivus: menu are now managed and fully working
Goffi <goffi@goffi.org>
parents:
11
diff
changeset
|
904 @param loop: main loop of urwid |
7e63429cc929
Primitivus: menu are now managed and fully working
Goffi <goffi@goffi.org>
parents:
11
diff
changeset
|
905 @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
|
906 """ |
11 | 907 self.loop = loop |
908 self.menu_keys = [] | |
909 self.menu = {} | |
12
7e63429cc929
Primitivus: menu are now managed and fully working
Goffi <goffi@goffi.org>
parents:
11
diff
changeset
|
910 self.x_orig = x_orig |
10
024b79b61a31
Primitivus: misc fixes + menubar first draft
Goffi <goffi@goffi.org>
parents:
9
diff
changeset
|
911 self.shortcuts = {} #keyboard shortcuts |
11 | 912 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
|
913 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
|
914 urwid.WidgetWrap.__init__(self, urwid.AttrMap(col_rol,'menubar')) |
66 | 915 |
11 | 916 def selectable(self): |
917 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
|
918 |
8cccbaadb9c5
Primitivus: menu roller doesn't go anymore on a menu if it's empty
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
919 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
|
920 """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
|
921 return len(self.menu_keys) |
66 | 922 |
12
7e63429cc929
Primitivus: menu are now managed and fully working
Goffi <goffi@goffi.org>
parents:
11
diff
changeset
|
923 def setOrigX(self, orig_x): |
7e63429cc929
Primitivus: menu are now managed and fully working
Goffi <goffi@goffi.org>
parents:
11
diff
changeset
|
924 self.x_orig = orig_x |
7e63429cc929
Primitivus: menu are now managed and fully working
Goffi <goffi@goffi.org>
parents:
11
diff
changeset
|
925 |
70
24d49f1d735f
added TableContainer + some bug fixes (bad default parameters)
Goffi <goffi@goffi.org>
parents:
69
diff
changeset
|
926 def __buildOverlay(self, menu_key, columns): |
11 | 927 """Build the overlay menu which show menuitems |
928 @param menu_key: name of the category | |
70
24d49f1d735f
added TableContainer + some bug fixes (bad default parameters)
Goffi <goffi@goffi.org>
parents:
69
diff
changeset
|
929 @param columns: column number where the menubox must be displayed""" |
11 | 930 max_len = 0 |
931 for item in self.menu[menu_key]: | |
932 if len(item[0]) > max_len: | |
933 max_len = len(item[0]) | |
934 | |
935 self.save_bottom = self.loop.widget | |
936 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
|
937 urwid.connect_signal(menu_box, 'click', self.onItemClick) |
66 | 938 |
939 self.loop.widget = urwid.Overlay(urwid.AttrMap(menu_box,'menubar'),self.save_bottom,('fixed left', columns),max_len+2,('fixed top',1),None) | |
11 | 940 |
941 def keypress(self, size, key): | |
84
9f683df69a4c
shortcut keys are now managed in separate module, with a class checking for conflicts
Goffi <goffi@goffi.org>
parents:
82
diff
changeset
|
942 if key == a_key['MENU_DOWN']: |
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
|
943 key = 'enter' |
84
9f683df69a4c
shortcut keys are now managed in separate module, with a class checking for conflicts
Goffi <goffi@goffi.org>
parents:
82
diff
changeset
|
944 elif key == a_key['MENU_UP']: |
11 | 945 if self.save_bottom: |
946 self.loop.widget = self.save_bottom | |
947 self.save_bottom = None | |
66 | 948 |
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
|
949 return self._w.base_widget.keypress(size, key) |
66 | 950 |
10
024b79b61a31
Primitivus: misc fixes + menubar first draft
Goffi <goffi@goffi.org>
parents:
9
diff
changeset
|
951 def checkShortcuts(self, key): |
024b79b61a31
Primitivus: misc fixes + menubar first draft
Goffi <goffi@goffi.org>
parents:
9
diff
changeset
|
952 for shortcut in self.shortcuts.keys(): |
024b79b61a31
Primitivus: misc fixes + menubar first draft
Goffi <goffi@goffi.org>
parents:
9
diff
changeset
|
953 if key == shortcut: |
11 | 954 category, item, callback = self.shortcuts[shortcut] |
10
024b79b61a31
Primitivus: misc fixes + menubar first draft
Goffi <goffi@goffi.org>
parents:
9
diff
changeset
|
955 callback((category, item)) |
024b79b61a31
Primitivus: misc fixes + menubar first draft
Goffi <goffi@goffi.org>
parents:
9
diff
changeset
|
956 return key |
024b79b61a31
Primitivus: misc fixes + menubar first draft
Goffi <goffi@goffi.org>
parents:
9
diff
changeset
|
957 |
79
33677d99ebdf
addMenu allows to add a new category without adding an item
souliane <souliane@mailoo.org>
parents:
78
diff
changeset
|
958 def addMenu(self, category, item=None, callback=None, shortcut=None): |
33677d99ebdf
addMenu allows to add a new category without adding an item
souliane <souliane@mailoo.org>
parents:
78
diff
changeset
|
959 """Create the category if new and add a menu item (if item is not None). |
33677d99ebdf
addMenu allows to add a new category without adding an item
souliane <souliane@mailoo.org>
parents:
78
diff
changeset
|
960 |
10
024b79b61a31
Primitivus: misc fixes + menubar first draft
Goffi <goffi@goffi.org>
parents:
9
diff
changeset
|
961 @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
|
962 @param item: menu item (e.g. new/close/about) |
024b79b61a31
Primitivus: misc fixes + menubar first draft
Goffi <goffi@goffi.org>
parents:
9
diff
changeset
|
963 @callback: method to call when item is selected""" |
024b79b61a31
Primitivus: misc fixes + menubar first draft
Goffi <goffi@goffi.org>
parents:
9
diff
changeset
|
964 if not category in self.menu.keys(): |
024b79b61a31
Primitivus: misc fixes + menubar first draft
Goffi <goffi@goffi.org>
parents:
9
diff
changeset
|
965 self.menu_keys.append(category) |
024b79b61a31
Primitivus: misc fixes + menubar first draft
Goffi <goffi@goffi.org>
parents:
9
diff
changeset
|
966 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
|
967 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
|
968 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
|
969 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
|
970 self._w.base_widget.addWidget(button,button.getSize()) |
79
33677d99ebdf
addMenu allows to add a new category without adding an item
souliane <souliane@mailoo.org>
parents:
78
diff
changeset
|
971 if not item: |
33677d99ebdf
addMenu allows to add a new category without adding an item
souliane <souliane@mailoo.org>
parents:
78
diff
changeset
|
972 return |
11 | 973 self.menu[category].append((item, callback)) |
10
024b79b61a31
Primitivus: misc fixes + menubar first draft
Goffi <goffi@goffi.org>
parents:
9
diff
changeset
|
974 if shortcut: |
024b79b61a31
Primitivus: misc fixes + menubar first draft
Goffi <goffi@goffi.org>
parents:
9
diff
changeset
|
975 assert(shortcut not in self.shortcuts.keys()) |
024b79b61a31
Primitivus: misc fixes + menubar first draft
Goffi <goffi@goffi.org>
parents:
9
diff
changeset
|
976 self.shortcuts[shortcut] = (category, item, callback) |
024b79b61a31
Primitivus: misc fixes + menubar first draft
Goffi <goffi@goffi.org>
parents:
9
diff
changeset
|
977 |
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
|
978 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
|
979 category = self._w.base_widget.getSelected().get_label() |
11 | 980 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
|
981 callback = None |
11 | 982 for menu_item in self.menu[category]: |
983 if item == menu_item[0]: | |
984 callback = menu_item[1] | |
985 break | |
986 if callback: | |
84
9f683df69a4c
shortcut keys are now managed in separate module, with a class checking for conflicts
Goffi <goffi@goffi.org>
parents:
82
diff
changeset
|
987 self.keypress(None, a_key['MENU_UP']) |
11 | 988 callback((category, item)) |
66 | 989 |
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
|
990 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
|
991 self.__buildOverlay(button.get_label(), |
66 | 992 self.x_orig + self._w.base_widget.getStartCol(button)) |
993 | |
107 | 994 MenuItem = collections.namedtuple('MenuItem', ('name', 'widget')) |
11 | 995 |
12
7e63429cc929
Primitivus: menu are now managed and fully working
Goffi <goffi@goffi.org>
parents:
11
diff
changeset
|
996 class MenuRoller(urwid.WidgetWrap): |
7e63429cc929
Primitivus: menu are now managed and fully working
Goffi <goffi@goffi.org>
parents:
11
diff
changeset
|
997 |
107 | 998 def __init__(self, menus_list): |
12
7e63429cc929
Primitivus: menu are now managed and fully working
Goffi <goffi@goffi.org>
parents:
11
diff
changeset
|
999 """Create a MenuRoller |
107 | 1000 |
1001 @param menus_list: list of tuples which can be either: | |
1002 - (name, Menu instance) | |
1003 - (name, Menu instance, id) | |
12
7e63429cc929
Primitivus: menu are now managed and fully working
Goffi <goffi@goffi.org>
parents:
11
diff
changeset
|
1004 """ |
107 | 1005 assert menus_list |
1006 self.selected = None | |
1007 self.menu_items = collections.OrderedDict() | |
66 | 1008 |
1009 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
|
1010 urwid.WidgetWrap.__init__(self, self.columns) |
66 | 1011 |
12
7e63429cc929
Primitivus: menu are now managed and fully working
Goffi <goffi@goffi.org>
parents:
11
diff
changeset
|
1012 for menu_tuple in menus_list: |
107 | 1013 try: |
1014 name, menu, id_ = menu_tuple | |
1015 except ValueError: | |
1016 name, menu = menu_tuple | |
1017 id_ = None | |
1018 self.addMenu(name, menu, id_) | |
12
7e63429cc929
Primitivus: menu are now managed and fully working
Goffi <goffi@goffi.org>
parents:
11
diff
changeset
|
1019 |
77
e1655ba45fae
MenuRoller doesn't propagate key pressed anymore if it manage a 'up' or 'down' event
Goffi <goffi@goffi.org>
parents:
76
diff
changeset
|
1020 def _showSelected(self): |
12
7e63429cc929
Primitivus: menu are now managed and fully working
Goffi <goffi@goffi.org>
parents:
11
diff
changeset
|
1021 """show menu selected""" |
107 | 1022 if self.selected is None: |
1023 self.columns.contents[0] = (urwid.Text(''), ('given', 0, False)) | |
1024 self.columns.contents[1] = (urwid.Text(''), ('weight', 1, False)) | |
1025 else: | |
1026 menu_item = self.menu_items[self.selected] | |
1027 name_txt = u'\u21c9 ' + menu_item.name + u' \u21c7 ' | |
1028 current_name = ClickableText(name_txt) | |
1029 name_len = len(name_txt) | |
1030 current_menu = menu_item.widget | |
1031 current_menu.setOrigX(name_len) | |
1032 self.columns.contents[0] = (current_name, ('given', name_len, False)) | |
1033 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
|
1034 |
7e63429cc929
Primitivus: menu are now managed and fully working
Goffi <goffi@goffi.org>
parents:
11
diff
changeset
|
1035 def keypress(self, size, key): |
107 | 1036 menu_ids = self.menu_items.keys() |
1037 try: | |
1038 idx = menu_ids.index(self.selected) | |
1039 except ValueError: | |
1040 return super(MenuRoller, self).keypress(size, key) | |
1041 | |
84
9f683df69a4c
shortcut keys are now managed in separate module, with a class checking for conflicts
Goffi <goffi@goffi.org>
parents:
82
diff
changeset
|
1042 if key==a_key['MENU_ROLLER_UP']: |
88
c95462c21966
primitivus (menu): MENU_ROLLER_(UP,DOWN) are not transmitted to next widget anymore
Goffi <goffi@goffi.org>
parents:
84
diff
changeset
|
1043 if self.columns.get_focus_column()==0: |
107 | 1044 if idx > 0: |
1045 self.selected = menu_ids[idx-1] | |
88
c95462c21966
primitivus (menu): MENU_ROLLER_(UP,DOWN) are not transmitted to next widget anymore
Goffi <goffi@goffi.org>
parents:
84
diff
changeset
|
1046 self._showSelected() |
77
e1655ba45fae
MenuRoller doesn't propagate key pressed anymore if it manage a 'up' or 'down' event
Goffi <goffi@goffi.org>
parents:
76
diff
changeset
|
1047 return |
84
9f683df69a4c
shortcut keys are now managed in separate module, with a class checking for conflicts
Goffi <goffi@goffi.org>
parents:
82
diff
changeset
|
1048 elif key==a_key['MENU_ROLLER_DOWN']: |
88
c95462c21966
primitivus (menu): MENU_ROLLER_(UP,DOWN) are not transmitted to next widget anymore
Goffi <goffi@goffi.org>
parents:
84
diff
changeset
|
1049 if self.columns.get_focus_column()==0: |
107 | 1050 if idx < len(menu_ids)-1: |
1051 self.selected = menu_ids[idx+1] | |
88
c95462c21966
primitivus (menu): MENU_ROLLER_(UP,DOWN) are not transmitted to next widget anymore
Goffi <goffi@goffi.org>
parents:
84
diff
changeset
|
1052 self._showSelected() |
77
e1655ba45fae
MenuRoller doesn't propagate key pressed anymore if it manage a 'up' or 'down' event
Goffi <goffi@goffi.org>
parents:
76
diff
changeset
|
1053 return |
84
9f683df69a4c
shortcut keys are now managed in separate module, with a class checking for conflicts
Goffi <goffi@goffi.org>
parents:
82
diff
changeset
|
1054 elif key==a_key['MENU_ROLLER_RIGHT']: |
13
8cccbaadb9c5
Primitivus: menu roller doesn't go anymore on a menu if it's empty
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
1055 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
|
1056 (isinstance(self.columns.contents[1][0], urwid.Text) or \ |
107 | 1057 self.menu_items[self.selected].widget.getMenuSize()==0): |
13
8cccbaadb9c5
Primitivus: menu roller doesn't go anymore on a menu if it's empty
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
1058 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
|
1059 |
7e63429cc929
Primitivus: menu are now managed and fully working
Goffi <goffi@goffi.org>
parents:
11
diff
changeset
|
1060 return super(MenuRoller, self).keypress(size, key) |
7e63429cc929
Primitivus: menu are now managed and fully working
Goffi <goffi@goffi.org>
parents:
11
diff
changeset
|
1061 |
107 | 1062 def addMenu(self, name, widget, menu_id=None): |
1063 """Add a menu | |
1064 | |
1065 @param name: name of the menu to add, it name already exists, menu is not added | |
1066 @param widget: instance of Menu | |
1067 @param menu_id: id to use of this menu, or None to generate | |
1068 @return: menu_id | |
1069 """ | |
1070 names = {menu_item.name: id_ for id_, menu_item in self.menu_items.iteritems()} | |
1071 | |
1072 if name not in names: | |
1073 id_ = menu_id or str(uuid.uuid4()) | |
1074 if id_ in self.menu_items: | |
1075 raise ValueError('Conflict: the id [{}] is already used'.format(id_)) | |
1076 self.menu_items[id_] = MenuItem(name, widget) | |
1077 else: | |
1078 id_ = names[name] | |
1079 menu_item = self.menu_items[id_] | |
1080 if menu_item.widget is not widget: | |
1081 raise ValueError("The menu with id [{}] exists and doesn't contain the given instance. Use replaceMenu if you want to change the menu.".format(id_)) | |
1082 if self.selected is None: | |
1083 self.selected = id_ | |
1084 self._showSelected() | |
1085 return id_ | |
1086 | |
1087 def replaceMenu(self, name, widget, menu_id): | |
1088 """Add a menu or replace it if the id already exists | |
1089 | |
1090 @param name: name of the menu to add, it name already exists, menu is not added | |
1091 @param widget: instance of Menu | |
1092 @param menu_id: id or the menu | |
1093 """ | |
1094 assert menu_id is not None | |
1095 if menu_id in self.menu_items: | |
1096 del self.menu_items[menu_id] | |
1097 self.addMenu(name, widget, menu_id) | |
1098 if self.selected == menu_id: | |
77
e1655ba45fae
MenuRoller doesn't propagate key pressed anymore if it manage a 'up' or 'down' event
Goffi <goffi@goffi.org>
parents:
76
diff
changeset
|
1099 self._showSelected() #if we are on the menu, we update it |
12
7e63429cc929
Primitivus: menu are now managed and fully working
Goffi <goffi@goffi.org>
parents:
11
diff
changeset
|
1100 |
107 | 1101 def removeMenu(self, menu_id): |
1102 del self.menu_items[menu_id] | |
1103 if self.selected == menu_id: | |
113
77ccc1dd2261
MenuRoller: fixed crash when deleting a displayed menu
Goffi <goffi@goffi.org>
parents:
111
diff
changeset
|
1104 try: |
77ccc1dd2261
MenuRoller: fixed crash when deleting a displayed menu
Goffi <goffi@goffi.org>
parents:
111
diff
changeset
|
1105 self.selected = self.menu_items.iterkeys().next() |
77ccc1dd2261
MenuRoller: fixed crash when deleting a displayed menu
Goffi <goffi@goffi.org>
parents:
111
diff
changeset
|
1106 except StopIteration: |
77ccc1dd2261
MenuRoller: fixed crash when deleting a displayed menu
Goffi <goffi@goffi.org>
parents:
111
diff
changeset
|
1107 self.selected = None |
107 | 1108 self._showSelected() |
15
8241b3157699
Primitivus: custom_widgets imrpovments
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
1109 |
12
7e63429cc929
Primitivus: menu are now managed and fully working
Goffi <goffi@goffi.org>
parents:
11
diff
changeset
|
1110 def checkShortcuts(self, key): |
107 | 1111 for menu_item in self.menu_items.values(): |
1112 key = menu_item.widget.checkShortcuts(key) | |
12
7e63429cc929
Primitivus: menu are now managed and fully working
Goffi <goffi@goffi.org>
parents:
11
diff
changeset
|
1113 return key |
66 | 1114 |
10
024b79b61a31
Primitivus: misc fixes + menubar first draft
Goffi <goffi@goffi.org>
parents:
9
diff
changeset
|
1115 |
6 | 1116 ## DIALOGS ## |
1117 | |
5
592cd64933dd
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
4
diff
changeset
|
1118 class GenericDialog(urwid.WidgetWrap): |
0 | 1119 |
70
24d49f1d735f
added TableContainer + some bug fixes (bad default parameters)
Goffi <goffi@goffi.org>
parents:
69
diff
changeset
|
1120 def __init__(self, widgets_lst, title, style=None, **kwargs): |
24d49f1d735f
added TableContainer + some bug fixes (bad default parameters)
Goffi <goffi@goffi.org>
parents:
69
diff
changeset
|
1121 if style is None: |
24d49f1d735f
added TableContainer + some bug fixes (bad default parameters)
Goffi <goffi@goffi.org>
parents:
69
diff
changeset
|
1122 style = [] |
0 | 1123 frame_header = urwid.AttrMap(urwid.Text(title,'center'),'title') |
66 | 1124 |
115
2b7eafea8bdb
GenericDialog: buttons callbacks can now be set after widget creation
Goffi <goffi@goffi.org>
parents:
114
diff
changeset
|
1125 self.buttons = collections.OrderedDict() |
0 | 1126 |
1127 if "OK/CANCEL" in style: | |
115
2b7eafea8bdb
GenericDialog: buttons callbacks can now be set after widget creation
Goffi <goffi@goffi.org>
parents:
114
diff
changeset
|
1128 self.buttons['cancel'] = urwid.Button(_("Cancel"), kwargs.get('cancel_cb'), kwargs.get('cancel_value')) |
2b7eafea8bdb
GenericDialog: buttons callbacks can now be set after widget creation
Goffi <goffi@goffi.org>
parents:
114
diff
changeset
|
1129 self.buttons['ok'] = urwid.Button(_("Ok"), kwargs.get('ok_cb'), kwargs.get('ok_value')) |
0 | 1130 elif "YES/NO" in style: |
115
2b7eafea8bdb
GenericDialog: buttons callbacks can now be set after widget creation
Goffi <goffi@goffi.org>
parents:
114
diff
changeset
|
1131 self.buttons['yes'] = urwid.Button(_("Yes"), kwargs.get('yes_cb'), kwargs.get('yes_value')) |
2b7eafea8bdb
GenericDialog: buttons callbacks can now be set after widget creation
Goffi <goffi@goffi.org>
parents:
114
diff
changeset
|
1132 self.buttons['no'] = urwid.Button(_("No"), kwargs.get('no_cb'), kwargs.get('no_value')) |
1 | 1133 if "OK" in style: |
115
2b7eafea8bdb
GenericDialog: buttons callbacks can now be set after widget creation
Goffi <goffi@goffi.org>
parents:
114
diff
changeset
|
1134 self.buttons['ok'] = urwid.Button(_("Ok"), kwargs.get('ok_cb'), kwargs.get('ok_value')) |
2b7eafea8bdb
GenericDialog: buttons callbacks can now be set after widget creation
Goffi <goffi@goffi.org>
parents:
114
diff
changeset
|
1135 if self.buttons: |
2b7eafea8bdb
GenericDialog: buttons callbacks can now be set after widget creation
Goffi <goffi@goffi.org>
parents:
114
diff
changeset
|
1136 buttons_flow = urwid.GridFlow(self.buttons.values(), max([len(button.get_label()) for button in self.buttons.itervalues()])+4, 1, 1, 'center') |
0 | 1137 body_content = urwid.SimpleListWalker(widgets_lst) |
91
b447a9c6f1d3
added UnselectableListBox which is a ListBox which can be unselectable when everything is not selectable and visible. Its is used in dialogs
Goffi <goffi@goffi.org>
parents:
90
diff
changeset
|
1138 frame_body = UnselectableListBox(body_content) |
115
2b7eafea8bdb
GenericDialog: buttons callbacks can now be set after widget creation
Goffi <goffi@goffi.org>
parents:
114
diff
changeset
|
1139 frame = FocusFrame(frame_body, frame_header, buttons_flow if self.buttons else None, 'footer' if self.buttons else 'body') |
0 | 1140 decorated_frame = urwid.LineBox(frame) |
1141 urwid.WidgetWrap.__init__(self, decorated_frame) | |
1142 | |
115
2b7eafea8bdb
GenericDialog: buttons callbacks can now be set after widget creation
Goffi <goffi@goffi.org>
parents:
114
diff
changeset
|
1143 def setCallback(self, name, callback, data=None): |
2b7eafea8bdb
GenericDialog: buttons callbacks can now be set after widget creation
Goffi <goffi@goffi.org>
parents:
114
diff
changeset
|
1144 """Set the callback associated with a button press |
2b7eafea8bdb
GenericDialog: buttons callbacks can now be set after widget creation
Goffi <goffi@goffi.org>
parents:
114
diff
changeset
|
1145 |
2b7eafea8bdb
GenericDialog: buttons callbacks can now be set after widget creation
Goffi <goffi@goffi.org>
parents:
114
diff
changeset
|
1146 @param name: one of "ok", "cancel", "yest", "no" |
2b7eafea8bdb
GenericDialog: buttons callbacks can now be set after widget creation
Goffi <goffi@goffi.org>
parents:
114
diff
changeset
|
1147 @aram callback(callable): method to call on requested action |
116 | 1148 @param data: argument to send to the callback (first one will be the button widget) |
115
2b7eafea8bdb
GenericDialog: buttons callbacks can now be set after widget creation
Goffi <goffi@goffi.org>
parents:
114
diff
changeset
|
1149 @raise KeyError if name is invalid |
2b7eafea8bdb
GenericDialog: buttons callbacks can now be set after widget creation
Goffi <goffi@goffi.org>
parents:
114
diff
changeset
|
1150 """ |
2b7eafea8bdb
GenericDialog: buttons callbacks can now be set after widget creation
Goffi <goffi@goffi.org>
parents:
114
diff
changeset
|
1151 button = self.buttons[name] |
2b7eafea8bdb
GenericDialog: buttons callbacks can now be set after widget creation
Goffi <goffi@goffi.org>
parents:
114
diff
changeset
|
1152 urwid.connect_signal(button, 'click', callback, data) |
2b7eafea8bdb
GenericDialog: buttons callbacks can now be set after widget creation
Goffi <goffi@goffi.org>
parents:
114
diff
changeset
|
1153 |
0 | 1154 |
5
592cd64933dd
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
4
diff
changeset
|
1155 class InputDialog(GenericDialog): |
7 | 1156 """Dialog with an edit box""" |
0 | 1157 |
70
24d49f1d735f
added TableContainer + some bug fixes (bad default parameters)
Goffi <goffi@goffi.org>
parents:
69
diff
changeset
|
1158 def __init__(self, title, instrucions, style=None, default_txt = '', **kwargs): |
24d49f1d735f
added TableContainer + some bug fixes (bad default parameters)
Goffi <goffi@goffi.org>
parents:
69
diff
changeset
|
1159 if style is None: |
24d49f1d735f
added TableContainer + some bug fixes (bad default parameters)
Goffi <goffi@goffi.org>
parents:
69
diff
changeset
|
1160 style = ['OK/CANCEL'] |
0 | 1161 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
|
1162 edit_box = AdvancedEdit(edit_text=default_txt) |
5
592cd64933dd
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
4
diff
changeset
|
1163 GenericDialog.__init__(self, [instr_wid,edit_box], title, style, ok_value=edit_box, **kwargs) |
74
0afff3c54b6e
replaced deprecated set_focus by focus_position
Goffi <goffi@goffi.org>
parents:
71
diff
changeset
|
1164 self._w.base_widget.focusposition = 'body' |
0 | 1165 |
70
24d49f1d735f
added TableContainer + some bug fixes (bad default parameters)
Goffi <goffi@goffi.org>
parents:
69
diff
changeset
|
1166 |
5
592cd64933dd
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
4
diff
changeset
|
1167 class ConfirmDialog(GenericDialog): |
7 | 1168 """Dialog with buttons for confirm or cancel an action""" |
0 | 1169 |
82
c456beff1779
ConfirmDialog now manage a body message
Goffi <goffi@goffi.org>
parents:
81
diff
changeset
|
1170 def __init__(self, title, message=None, style=None, **kwargs): |
70
24d49f1d735f
added TableContainer + some bug fixes (bad default parameters)
Goffi <goffi@goffi.org>
parents:
69
diff
changeset
|
1171 if style is None: |
24d49f1d735f
added TableContainer + some bug fixes (bad default parameters)
Goffi <goffi@goffi.org>
parents:
69
diff
changeset
|
1172 style = ['YES/NO'] |
82
c456beff1779
ConfirmDialog now manage a body message
Goffi <goffi@goffi.org>
parents:
81
diff
changeset
|
1173 GenericDialog.__init__(self, |
c456beff1779
ConfirmDialog now manage a body message
Goffi <goffi@goffi.org>
parents:
81
diff
changeset
|
1174 [urwid.Text(message, 'center')] if message is not None else [], |
c456beff1779
ConfirmDialog now manage a body message
Goffi <goffi@goffi.org>
parents:
81
diff
changeset
|
1175 title, |
c456beff1779
ConfirmDialog now manage a body message
Goffi <goffi@goffi.org>
parents:
81
diff
changeset
|
1176 style, |
c456beff1779
ConfirmDialog now manage a body message
Goffi <goffi@goffi.org>
parents:
81
diff
changeset
|
1177 **kwargs) |
1 | 1178 |
70
24d49f1d735f
added TableContainer + some bug fixes (bad default parameters)
Goffi <goffi@goffi.org>
parents:
69
diff
changeset
|
1179 |
5
592cd64933dd
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
4
diff
changeset
|
1180 class Alert(GenericDialog): |
7 | 1181 """Dialog with just a message and a OK button""" |
1 | 1182 |
115
2b7eafea8bdb
GenericDialog: buttons callbacks can now be set after widget creation
Goffi <goffi@goffi.org>
parents:
114
diff
changeset
|
1183 def __init__(self, title, message, style=None, **kwargs): |
2b7eafea8bdb
GenericDialog: buttons callbacks can now be set after widget creation
Goffi <goffi@goffi.org>
parents:
114
diff
changeset
|
1184 if style is None: |
2b7eafea8bdb
GenericDialog: buttons callbacks can now be set after widget creation
Goffi <goffi@goffi.org>
parents:
114
diff
changeset
|
1185 style= ['OK'] |
5
592cd64933dd
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
4
diff
changeset
|
1186 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
|
1187 |
6 | 1188 ## CONTAINERS ## |
1189 | |
67 | 1190 class ColumnsRoller(urwid.Widget): |
1191 _sizing = frozenset(['flow']) | |
66 | 1192 |
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
|
1193 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
|
1194 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
|
1195 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
|
1196 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
|
1197 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
|
1198 |
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
|
1199 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
|
1200 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
|
1201 if len(self.widget_list) == 1: |
74
0afff3c54b6e
replaced deprecated set_focus by focus_position
Goffi <goffi@goffi.org>
parents:
71
diff
changeset
|
1202 self.focus_position = 0 |
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
|
1203 |
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
|
1204 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
|
1205 """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
|
1206 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
|
1207 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
|
1208 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
|
1209 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
|
1210 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
|
1211 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
|
1212 |
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
|
1213 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
|
1214 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
|
1215 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
|
1216 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
|
1217 return False |
66 | 1218 |
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
|
1219 def keypress(self, size, key): |
84
9f683df69a4c
shortcut keys are now managed in separate module, with a class checking for conflicts
Goffi <goffi@goffi.org>
parents:
82
diff
changeset
|
1220 if key==a_key['COLUMNS_ROLLER_LEFT']: |
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
|
1221 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
|
1222 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
|
1223 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
|
1224 return |
84
9f683df69a4c
shortcut keys are now managed in separate module, with a class checking for conflicts
Goffi <goffi@goffi.org>
parents:
82
diff
changeset
|
1225 if key==a_key['COLUMNS_ROLLER_RIGHT']: |
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
|
1226 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
|
1227 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
|
1228 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
|
1229 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
|
1230 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
|
1231 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
|
1232 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
|
1233 |
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
|
1234 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
|
1235 """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
|
1236 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
|
1237 |
74
0afff3c54b6e
replaced deprecated set_focus by focus_position
Goffi <goffi@goffi.org>
parents:
71
diff
changeset
|
1238 @property |
0afff3c54b6e
replaced deprecated set_focus by focus_position
Goffi <goffi@goffi.org>
parents:
71
diff
changeset
|
1239 def focus_position(self): |
0afff3c54b6e
replaced deprecated set_focus by focus_position
Goffi <goffi@goffi.org>
parents:
71
diff
changeset
|
1240 return self.focus_column |
0afff3c54b6e
replaced deprecated set_focus by focus_position
Goffi <goffi@goffi.org>
parents:
71
diff
changeset
|
1241 |
0afff3c54b6e
replaced deprecated set_focus by focus_position
Goffi <goffi@goffi.org>
parents:
71
diff
changeset
|
1242 @focus_position.setter |
0afff3c54b6e
replaced deprecated set_focus by focus_position
Goffi <goffi@goffi.org>
parents:
71
diff
changeset
|
1243 def focus_position(self, idx): |
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
|
1244 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
|
1245 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
|
1246 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
|
1247 |
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
|
1248 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
|
1249 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
|
1250 |
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
|
1251 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
|
1252 (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
|
1253 _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
|
1254 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
|
1255 end_wid = len(self.widget_list)-1 |
66 | 1256 |
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
|
1257 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
|
1258 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
|
1259 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
|
1260 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
|
1261 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
|
1262 _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
|
1263 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
|
1264 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
|
1265 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
|
1266 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
|
1267 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
|
1268 _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
|
1269 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
|
1270 end_wid-=1 |
66 | 1271 |
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
|
1272 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
|
1273 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
|
1274 return _prev,_next,start_wid,end_wid,cols_left |
66 | 1275 |
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
|
1276 |
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
|
1277 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
|
1278 (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
|
1279 |
53
d34f2b0f68d3
urwid 1.0.0 update: fixed missing is_mouse_press
Goffi <goffi@goffi.org>
parents:
44
diff
changeset
|
1280 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
|
1281 _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
|
1282 if x==0 and _prev: |
84
9f683df69a4c
shortcut keys are now managed in separate module, with a class checking for conflicts
Goffi <goffi@goffi.org>
parents:
82
diff
changeset
|
1283 self.keypress(size, a_key['COLUMNS_ROLLER_LEFT']) |
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
|
1284 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
|
1285 if x==maxcol-1 and _next: |
84
9f683df69a4c
shortcut keys are now managed in separate module, with a class checking for conflicts
Goffi <goffi@goffi.org>
parents:
82
diff
changeset
|
1286 self.keypress(size, a_key['COLUMNS_ROLLER_RIGHT']) |
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
|
1287 return True |
66 | 1288 |
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
|
1289 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
|
1290 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
|
1291 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
|
1292 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
|
1293 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
|
1294 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
|
1295 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
|
1296 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
|
1297 return False |
66 | 1298 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
|
1299 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
|
1300 |
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
|
1301 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
|
1302 idx+=1 |
66 | 1303 |
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
|
1304 return False |
66 | 1305 |
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
|
1306 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
|
1307 if not self.widget_list: |
84
9f683df69a4c
shortcut keys are now managed in separate module, with a class checking for conflicts
Goffi <goffi@goffi.org>
parents:
82
diff
changeset
|
1308 return urwid.SolidCanvas(" ", size[0], 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
|
1309 |
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
|
1310 _prev,_next,start_wid,end_wid,cols_left = self.__calculate_limits(size) |
66 | 1311 |
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
|
1312 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
|
1313 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
|
1314 |
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
|
1315 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
|
1316 _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
|
1317 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
|
1318 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
|
1319 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
|
1320 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
|
1321 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
|
1322 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
|
1323 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
|
1324 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
|
1325 |
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
|
1326 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
|
1327 |
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
|
1328 |
96
44fc94b0fe18
new FocusPile widget: a Pile which manage FOCUS_KEYS
Goffi <goffi@goffi.org>
parents:
95
diff
changeset
|
1329 class FocusPile(urwid.Pile): |
44fc94b0fe18
new FocusPile widget: a Pile which manage FOCUS_KEYS
Goffi <goffi@goffi.org>
parents:
95
diff
changeset
|
1330 """A Pile Widget which manage SàT Focus keys""" |
44fc94b0fe18
new FocusPile widget: a Pile which manage FOCUS_KEYS
Goffi <goffi@goffi.org>
parents:
95
diff
changeset
|
1331 _focus_inversed = False |
44fc94b0fe18
new FocusPile widget: a Pile which manage FOCUS_KEYS
Goffi <goffi@goffi.org>
parents:
95
diff
changeset
|
1332 |
44fc94b0fe18
new FocusPile widget: a Pile which manage FOCUS_KEYS
Goffi <goffi@goffi.org>
parents:
95
diff
changeset
|
1333 def keypress(self, size, key): |
44fc94b0fe18
new FocusPile widget: a Pile which manage FOCUS_KEYS
Goffi <goffi@goffi.org>
parents:
95
diff
changeset
|
1334 ret = super(FocusPile, self).keypress(size, key) |
44fc94b0fe18
new FocusPile widget: a Pile which manage FOCUS_KEYS
Goffi <goffi@goffi.org>
parents:
95
diff
changeset
|
1335 if not ret: |
44fc94b0fe18
new FocusPile widget: a Pile which manage FOCUS_KEYS
Goffi <goffi@goffi.org>
parents:
95
diff
changeset
|
1336 return |
44fc94b0fe18
new FocusPile widget: a Pile which manage FOCUS_KEYS
Goffi <goffi@goffi.org>
parents:
95
diff
changeset
|
1337 |
44fc94b0fe18
new FocusPile widget: a Pile which manage FOCUS_KEYS
Goffi <goffi@goffi.org>
parents:
95
diff
changeset
|
1338 if key in FOCUS_KEYS: |
44fc94b0fe18
new FocusPile widget: a Pile which manage FOCUS_KEYS
Goffi <goffi@goffi.org>
parents:
95
diff
changeset
|
1339 direction, rotate = getFocusDirection(key, inversed = self._focus_inversed) |
44fc94b0fe18
new FocusPile widget: a Pile which manage FOCUS_KEYS
Goffi <goffi@goffi.org>
parents:
95
diff
changeset
|
1340 max_pos = len(self.contents) - 1 |
44fc94b0fe18
new FocusPile widget: a Pile which manage FOCUS_KEYS
Goffi <goffi@goffi.org>
parents:
95
diff
changeset
|
1341 new_pos = self.focus_position + direction |
44fc94b0fe18
new FocusPile widget: a Pile which manage FOCUS_KEYS
Goffi <goffi@goffi.org>
parents:
95
diff
changeset
|
1342 if rotate: |
44fc94b0fe18
new FocusPile widget: a Pile which manage FOCUS_KEYS
Goffi <goffi@goffi.org>
parents:
95
diff
changeset
|
1343 if new_pos > max_pos: |
44fc94b0fe18
new FocusPile widget: a Pile which manage FOCUS_KEYS
Goffi <goffi@goffi.org>
parents:
95
diff
changeset
|
1344 new_pos = 0 |
44fc94b0fe18
new FocusPile widget: a Pile which manage FOCUS_KEYS
Goffi <goffi@goffi.org>
parents:
95
diff
changeset
|
1345 elif new_pos < 0: |
44fc94b0fe18
new FocusPile widget: a Pile which manage FOCUS_KEYS
Goffi <goffi@goffi.org>
parents:
95
diff
changeset
|
1346 new_pos = max_pos |
44fc94b0fe18
new FocusPile widget: a Pile which manage FOCUS_KEYS
Goffi <goffi@goffi.org>
parents:
95
diff
changeset
|
1347 try: |
44fc94b0fe18
new FocusPile widget: a Pile which manage FOCUS_KEYS
Goffi <goffi@goffi.org>
parents:
95
diff
changeset
|
1348 self.focus_position = new_pos |
44fc94b0fe18
new FocusPile widget: a Pile which manage FOCUS_KEYS
Goffi <goffi@goffi.org>
parents:
95
diff
changeset
|
1349 except IndexError: |
44fc94b0fe18
new FocusPile widget: a Pile which manage FOCUS_KEYS
Goffi <goffi@goffi.org>
parents:
95
diff
changeset
|
1350 pass |
44fc94b0fe18
new FocusPile widget: a Pile which manage FOCUS_KEYS
Goffi <goffi@goffi.org>
parents:
95
diff
changeset
|
1351 |
44fc94b0fe18
new FocusPile widget: a Pile which manage FOCUS_KEYS
Goffi <goffi@goffi.org>
parents:
95
diff
changeset
|
1352 return key |
44fc94b0fe18
new FocusPile widget: a Pile which manage FOCUS_KEYS
Goffi <goffi@goffi.org>
parents:
95
diff
changeset
|
1353 |
44fc94b0fe18
new FocusPile widget: a Pile which manage FOCUS_KEYS
Goffi <goffi@goffi.org>
parents:
95
diff
changeset
|
1354 |
90 | 1355 class FocusFrame(urwid.Frame): |
94
66b65ed9baf2
focus direction and rotate boolean are now gotten from getFocusDirection
Goffi <goffi@goffi.org>
parents:
91
diff
changeset
|
1356 """Frame-like which manage SàT Focus Keys""" |
98
8bf5a35450f0
Fixed getFocusDirection direction when inversed, and FocusFrame focus order.
Goffi <goffi@goffi.org>
parents:
97
diff
changeset
|
1357 ordered_positions = ('footer', 'body', 'header') |
5
592cd64933dd
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
4
diff
changeset
|
1358 |
592cd64933dd
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
4
diff
changeset
|
1359 def keypress(self, size, key): |
75
8ff563825080
FocusFrame is now based on Pile instead of Frame, header, body and footer attributes can be used to change part at any time
Goffi <goffi@goffi.org>
parents:
74
diff
changeset
|
1360 ret = super(FocusFrame, self).keypress(size, key) |
19
0b83dd2b15d1
Primitivus: misc improvments on TabsContainer/FocusFrame
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
1361 if not ret: |
0b83dd2b15d1
Primitivus: misc improvments on TabsContainer/FocusFrame
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
1362 return |
66 | 1363 |
90 | 1364 if key in FOCUS_KEYS: |
98
8bf5a35450f0
Fixed getFocusDirection direction when inversed, and FocusFrame focus order.
Goffi <goffi@goffi.org>
parents:
97
diff
changeset
|
1365 direction, rotate = getFocusDirection(key) |
90 | 1366 |
98
8bf5a35450f0
Fixed getFocusDirection direction when inversed, and FocusFrame focus order.
Goffi <goffi@goffi.org>
parents:
97
diff
changeset
|
1367 positions = [pos for pos in self.ordered_positions if pos in self] |
8bf5a35450f0
Fixed getFocusDirection direction when inversed, and FocusFrame focus order.
Goffi <goffi@goffi.org>
parents:
97
diff
changeset
|
1368 selectables = [pos for pos in positions if self.contents[pos][0].selectable()] # keep positions which exists and have a selectable widget |
90 | 1369 if not selectables: |
1370 # no widget is selectable, we just return | |
1371 return | |
1372 idx = selectables.index(self.focus_position) + direction | |
1373 if not rotate and (idx < 0 or idx >= len(selectables)): | |
1374 # if we don't rotate, we stay where we are on the first and last position | |
1375 return | |
75
8ff563825080
FocusFrame is now based on Pile instead of Frame, header, body and footer attributes can be used to change part at any time
Goffi <goffi@goffi.org>
parents:
74
diff
changeset
|
1376 try: |
90 | 1377 self.focus_position = selectables[idx] |
75
8ff563825080
FocusFrame is now based on Pile instead of Frame, header, body and footer attributes can be used to change part at any time
Goffi <goffi@goffi.org>
parents:
74
diff
changeset
|
1378 except IndexError: |
90 | 1379 # happen if idx > len(selectables) |
1380 self.focus_position = selectables[0] | |
1381 return | |
5
592cd64933dd
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
4
diff
changeset
|
1382 |
66 | 1383 return ret |
6 | 1384 |
90 | 1385 def get_cursor_coords(self, size): |
1386 """Return the cursor coordinates of the focus widget.""" | |
1387 if not self.selectable(): | |
1388 return None | |
1389 if not hasattr(self.focus, 'get_cursor_coords'): | |
1390 return None | |
1391 maxcol, maxrow = size | |
1392 try: | |
1393 if self.focus_position != 'body': | |
1394 # only body is a box widget | |
1395 size = (maxcol,) | |
1396 col, row = self.focus.get_cursor_coords(size) | |
1397 except TypeError: | |
1398 return None | |
1399 if self.focus_position == 'header': | |
1400 return (col, row) | |
1401 if self.focus_position == 'body': | |
1402 header_rows = self.header.rows((maxcol,)) | |
1403 return (col, row + header_rows) | |
1404 if self.focus_position == 'footer': | |
1405 footer_rows = self.footer.rows((maxcol,)) | |
1406 return (col, row + (maxrow - footer_rows)) | |
1407 raise Exception('This line should not be reached') | |
1408 | |
70
24d49f1d735f
added TableContainer + some bug fixes (bad default parameters)
Goffi <goffi@goffi.org>
parents:
69
diff
changeset
|
1409 |
15
8241b3157699
Primitivus: custom_widgets imrpovments
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
1410 class TabsContainer(urwid.WidgetWrap): |
76
6c2a1b349416
TabsContainer now accept any box widget as tab content
Goffi <goffi@goffi.org>
parents:
75
diff
changeset
|
1411 """ Container which can contain multiple box widgets associated to named tabs """ |
15
8241b3157699
Primitivus: custom_widgets imrpovments
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
1412 signals = ['click'] |
8241b3157699
Primitivus: custom_widgets imrpovments
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
1413 |
8241b3157699
Primitivus: custom_widgets imrpovments
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
1414 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
|
1415 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
|
1416 self._buttons_cont = ColumnsRoller() |
15
8241b3157699
Primitivus: custom_widgets imrpovments
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
1417 self.tabs = [] |
90 | 1418 self._frame = FocusFrame(urwid.Filler(urwid.Text('')),urwid.Pile([self._buttons_cont,urwid.Divider(u"─")])) |
1419 urwid.WidgetWrap.__init__(self, self._frame) | |
15
8241b3157699
Primitivus: custom_widgets imrpovments
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
1420 |
8241b3157699
Primitivus: custom_widgets imrpovments
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
1421 def keypress(self, size, key): |
19
0b83dd2b15d1
Primitivus: misc improvments on TabsContainer/FocusFrame
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
1422 return self._w.keypress(size,key) |
15
8241b3157699
Primitivus: custom_widgets imrpovments
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
1423 |
76
6c2a1b349416
TabsContainer now accept any box widget as tab content
Goffi <goffi@goffi.org>
parents:
75
diff
changeset
|
1424 def _buttonClicked(self, button, invisible=False): |
15
8241b3157699
Primitivus: custom_widgets imrpovments
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
1425 """Called when a button on the tab is changed, |
8241b3157699
Primitivus: custom_widgets imrpovments
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
1426 change the page |
8241b3157699
Primitivus: custom_widgets imrpovments
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
1427 @param button: button clicked |
8241b3157699
Primitivus: custom_widgets imrpovments
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
1428 @param invisible: emit signal only if False""" |
8241b3157699
Primitivus: custom_widgets imrpovments
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
1429 tab_name = button.get_label() |
8241b3157699
Primitivus: custom_widgets imrpovments
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
1430 for tab in self.tabs: |
8241b3157699
Primitivus: custom_widgets imrpovments
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
1431 if tab[0] == tab_name: |
8241b3157699
Primitivus: custom_widgets imrpovments
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
1432 break |
8241b3157699
Primitivus: custom_widgets imrpovments
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
1433 if tab[0] != tab_name: |
89
2141f07b5fdd
primitivus: no more direct error/warning methods for logging
Goffi <goffi@goffi.org>
parents:
88
diff
changeset
|
1434 log.error(_("INTERNAL ERROR: Tab not found")) |
15
8241b3157699
Primitivus: custom_widgets imrpovments
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
1435 assert(False) |
90 | 1436 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
|
1437 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
|
1438 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
|
1439 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
|
1440 self._current_tab = button |
15
8241b3157699
Primitivus: custom_widgets imrpovments
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
1441 if not invisible: |
8241b3157699
Primitivus: custom_widgets imrpovments
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
1442 self._emit('click') |
8241b3157699
Primitivus: custom_widgets imrpovments
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
1443 |
111
1cdf4a00b68d
TabsContainer: allow to select a tab when adding it
souliane <souliane@mailoo.org>
parents:
110
diff
changeset
|
1444 def _appendButton(self, name, selected=False): |
1cdf4a00b68d
TabsContainer: allow to select a tab when adding it
souliane <souliane@mailoo.org>
parents:
110
diff
changeset
|
1445 """Append a button to the frame header, and link it to the page change method. |
113
77ccc1dd2261
MenuRoller: fixed crash when deleting a displayed menu
Goffi <goffi@goffi.org>
parents:
111
diff
changeset
|
1446 |
111
1cdf4a00b68d
TabsContainer: allow to select a tab when adding it
souliane <souliane@mailoo.org>
parents:
110
diff
changeset
|
1447 @param name (unicode): button name |
1cdf4a00b68d
TabsContainer: allow to select a tab when adding it
souliane <souliane@mailoo.org>
parents:
110
diff
changeset
|
1448 @param selected (bool): set to True to select this tab |
1cdf4a00b68d
TabsContainer: allow to select a tab when adding it
souliane <souliane@mailoo.org>
parents:
110
diff
changeset
|
1449 """ |
76
6c2a1b349416
TabsContainer now accept any box widget as tab content
Goffi <goffi@goffi.org>
parents:
75
diff
changeset
|
1450 button = CustomButton(name, self._buttonClicked, left_border = '', right_border=' | ') |
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
|
1451 self._buttons_cont.addWidget(button, button.getSize()) |
111
1cdf4a00b68d
TabsContainer: allow to select a tab when adding it
souliane <souliane@mailoo.org>
parents:
110
diff
changeset
|
1452 count = len(self._buttons_cont.widget_list) |
1cdf4a00b68d
TabsContainer: allow to select a tab when adding it
souliane <souliane@mailoo.org>
parents:
110
diff
changeset
|
1453 if selected or count == 1: |
1cdf4a00b68d
TabsContainer: allow to select a tab when adding it
souliane <souliane@mailoo.org>
parents:
110
diff
changeset
|
1454 # first/selected button: we set the focus and the body |
1cdf4a00b68d
TabsContainer: allow to select a tab when adding it
souliane <souliane@mailoo.org>
parents:
110
diff
changeset
|
1455 self.selectTab(count - 1) |
15
8241b3157699
Primitivus: custom_widgets imrpovments
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
1456 |
111
1cdf4a00b68d
TabsContainer: allow to select a tab when adding it
souliane <souliane@mailoo.org>
parents:
110
diff
changeset
|
1457 def addTab(self, name, content=None, selected=False): |
15
8241b3157699
Primitivus: custom_widgets imrpovments
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
1458 """Add a page to the container |
111
1cdf4a00b68d
TabsContainer: allow to select a tab when adding it
souliane <souliane@mailoo.org>
parents:
110
diff
changeset
|
1459 |
15
8241b3157699
Primitivus: custom_widgets imrpovments
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
1460 @param name: name of the page (what appear on the tab) |
76
6c2a1b349416
TabsContainer now accept any box widget as tab content
Goffi <goffi@goffi.org>
parents:
75
diff
changeset
|
1461 @param content: content of the page: |
6c2a1b349416
TabsContainer now accept any box widget as tab content
Goffi <goffi@goffi.org>
parents:
75
diff
changeset
|
1462 - if None create and empty Listbox |
6c2a1b349416
TabsContainer now accept any box widget as tab content
Goffi <goffi@goffi.org>
parents:
75
diff
changeset
|
1463 - if it is a list instance, create a ListBox with the list in a body |
6c2a1b349416
TabsContainer now accept any box widget as tab content
Goffi <goffi@goffi.org>
parents:
75
diff
changeset
|
1464 - else it must be a box widget which will be used instead of the ListBox |
111
1cdf4a00b68d
TabsContainer: allow to select a tab when adding it
souliane <souliane@mailoo.org>
parents:
110
diff
changeset
|
1465 @param selected (bool): set to True to select this tab |
15
8241b3157699
Primitivus: custom_widgets imrpovments
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
1466 @return: ListBox (content of the page)""" |
76
6c2a1b349416
TabsContainer now accept any box widget as tab content
Goffi <goffi@goffi.org>
parents:
75
diff
changeset
|
1467 if content is None or isinstance(content, list): |
6c2a1b349416
TabsContainer now accept any box widget as tab content
Goffi <goffi@goffi.org>
parents:
75
diff
changeset
|
1468 tab = urwid.ListBox(urwid.SimpleListWalker(content or [])) |
6c2a1b349416
TabsContainer now accept any box widget as tab content
Goffi <goffi@goffi.org>
parents:
75
diff
changeset
|
1469 else: |
6c2a1b349416
TabsContainer now accept any box widget as tab content
Goffi <goffi@goffi.org>
parents:
75
diff
changeset
|
1470 tab = content |
6c2a1b349416
TabsContainer now accept any box widget as tab content
Goffi <goffi@goffi.org>
parents:
75
diff
changeset
|
1471 |
6c2a1b349416
TabsContainer now accept any box widget as tab content
Goffi <goffi@goffi.org>
parents:
75
diff
changeset
|
1472 self.tabs.append([name, tab]) |
111
1cdf4a00b68d
TabsContainer: allow to select a tab when adding it
souliane <souliane@mailoo.org>
parents:
110
diff
changeset
|
1473 self._appendButton(name, selected) |
76
6c2a1b349416
TabsContainer now accept any box widget as tab content
Goffi <goffi@goffi.org>
parents:
75
diff
changeset
|
1474 return tab |
15
8241b3157699
Primitivus: custom_widgets imrpovments
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
1475 |
19
0b83dd2b15d1
Primitivus: misc improvments on TabsContainer/FocusFrame
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
1476 def addFooter(self, widget): |
0b83dd2b15d1
Primitivus: misc improvments on TabsContainer/FocusFrame
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
1477 """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
|
1478 @param widget: FlowWidget""" |
0b83dd2b15d1
Primitivus: misc improvments on TabsContainer/FocusFrame
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
1479 self._w.footer = widget |
66 | 1480 |
111
1cdf4a00b68d
TabsContainer: allow to select a tab when adding it
souliane <souliane@mailoo.org>
parents:
110
diff
changeset
|
1481 def selectTab(self, index): |
1cdf4a00b68d
TabsContainer: allow to select a tab when adding it
souliane <souliane@mailoo.org>
parents:
110
diff
changeset
|
1482 """Select a tab. |
1cdf4a00b68d
TabsContainer: allow to select a tab when adding it
souliane <souliane@mailoo.org>
parents:
110
diff
changeset
|
1483 |
1cdf4a00b68d
TabsContainer: allow to select a tab when adding it
souliane <souliane@mailoo.org>
parents:
110
diff
changeset
|
1484 @param index (int): index of the tab to select |
1cdf4a00b68d
TabsContainer: allow to select a tab when adding it
souliane <souliane@mailoo.org>
parents:
110
diff
changeset
|
1485 """ |
1cdf4a00b68d
TabsContainer: allow to select a tab when adding it
souliane <souliane@mailoo.org>
parents:
110
diff
changeset
|
1486 self._buttons_cont.focus_position = index |
1cdf4a00b68d
TabsContainer: allow to select a tab when adding it
souliane <souliane@mailoo.org>
parents:
110
diff
changeset
|
1487 self._buttonClicked(self._buttons_cont.widget_list[index][1], True) |
1cdf4a00b68d
TabsContainer: allow to select a tab when adding it
souliane <souliane@mailoo.org>
parents:
110
diff
changeset
|
1488 |
19
0b83dd2b15d1
Primitivus: misc improvments on TabsContainer/FocusFrame
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
1489 |
70
24d49f1d735f
added TableContainer + some bug fixes (bad default parameters)
Goffi <goffi@goffi.org>
parents:
69
diff
changeset
|
1490 class HighlightColumns(urwid.AttrMap): |
24d49f1d735f
added TableContainer + some bug fixes (bad default parameters)
Goffi <goffi@goffi.org>
parents:
69
diff
changeset
|
1491 """ Decorated columns which highlight all or some columns """ |
24d49f1d735f
added TableContainer + some bug fixes (bad default parameters)
Goffi <goffi@goffi.org>
parents:
69
diff
changeset
|
1492 |
24d49f1d735f
added TableContainer + some bug fixes (bad default parameters)
Goffi <goffi@goffi.org>
parents:
69
diff
changeset
|
1493 def __init__(self, highlight_cols, highlight_attr, *args, **kwargs): |
24d49f1d735f
added TableContainer + some bug fixes (bad default parameters)
Goffi <goffi@goffi.org>
parents:
69
diff
changeset
|
1494 """ Create the HighlightColumns |
24d49f1d735f
added TableContainer + some bug fixes (bad default parameters)
Goffi <goffi@goffi.org>
parents:
69
diff
changeset
|
1495 @param highlight_cols: tuple of columns to highlight, () to highlight to whole row |
24d49f1d735f
added TableContainer + some bug fixes (bad default parameters)
Goffi <goffi@goffi.org>
parents:
69
diff
changeset
|
1496 @param highlight_attr: name of the attribute to use when focused |
24d49f1d735f
added TableContainer + some bug fixes (bad default parameters)
Goffi <goffi@goffi.org>
parents:
69
diff
changeset
|
1497 other parameter are passed to urwid Columns |
24d49f1d735f
added TableContainer + some bug fixes (bad default parameters)
Goffi <goffi@goffi.org>
parents:
69
diff
changeset
|
1498 |
24d49f1d735f
added TableContainer + some bug fixes (bad default parameters)
Goffi <goffi@goffi.org>
parents:
69
diff
changeset
|
1499 """ |
24d49f1d735f
added TableContainer + some bug fixes (bad default parameters)
Goffi <goffi@goffi.org>
parents:
69
diff
changeset
|
1500 columns = urwid.Columns(*args, **kwargs) |
24d49f1d735f
added TableContainer + some bug fixes (bad default parameters)
Goffi <goffi@goffi.org>
parents:
69
diff
changeset
|
1501 self.highlight_cols = highlight_cols |
24d49f1d735f
added TableContainer + some bug fixes (bad default parameters)
Goffi <goffi@goffi.org>
parents:
69
diff
changeset
|
1502 self.highlight_attr = highlight_attr |
24d49f1d735f
added TableContainer + some bug fixes (bad default parameters)
Goffi <goffi@goffi.org>
parents:
69
diff
changeset
|
1503 self.has_focus = False |
24d49f1d735f
added TableContainer + some bug fixes (bad default parameters)
Goffi <goffi@goffi.org>
parents:
69
diff
changeset
|
1504 if highlight_cols == (): |
24d49f1d735f
added TableContainer + some bug fixes (bad default parameters)
Goffi <goffi@goffi.org>
parents:
69
diff
changeset
|
1505 super(HighlightColumns, self).__init__(columns, None, highlight_attr) |
24d49f1d735f
added TableContainer + some bug fixes (bad default parameters)
Goffi <goffi@goffi.org>
parents:
69
diff
changeset
|
1506 self.highlight_cols = None |
24d49f1d735f
added TableContainer + some bug fixes (bad default parameters)
Goffi <goffi@goffi.org>
parents:
69
diff
changeset
|
1507 else: |
24d49f1d735f
added TableContainer + some bug fixes (bad default parameters)
Goffi <goffi@goffi.org>
parents:
69
diff
changeset
|
1508 super(HighlightColumns, self).__init__(columns, None) |
24d49f1d735f
added TableContainer + some bug fixes (bad default parameters)
Goffi <goffi@goffi.org>
parents:
69
diff
changeset
|
1509 |
24d49f1d735f
added TableContainer + some bug fixes (bad default parameters)
Goffi <goffi@goffi.org>
parents:
69
diff
changeset
|
1510 @property |
24d49f1d735f
added TableContainer + some bug fixes (bad default parameters)
Goffi <goffi@goffi.org>
parents:
69
diff
changeset
|
1511 def options(self): |
24d49f1d735f
added TableContainer + some bug fixes (bad default parameters)
Goffi <goffi@goffi.org>
parents:
69
diff
changeset
|
1512 return self.base_widget.options |
24d49f1d735f
added TableContainer + some bug fixes (bad default parameters)
Goffi <goffi@goffi.org>
parents:
69
diff
changeset
|
1513 |
24d49f1d735f
added TableContainer + some bug fixes (bad default parameters)
Goffi <goffi@goffi.org>
parents:
69
diff
changeset
|
1514 @property |
24d49f1d735f
added TableContainer + some bug fixes (bad default parameters)
Goffi <goffi@goffi.org>
parents:
69
diff
changeset
|
1515 def contents(self): |
24d49f1d735f
added TableContainer + some bug fixes (bad default parameters)
Goffi <goffi@goffi.org>
parents:
69
diff
changeset
|
1516 return self.base_widget.contents |
24d49f1d735f
added TableContainer + some bug fixes (bad default parameters)
Goffi <goffi@goffi.org>
parents:
69
diff
changeset
|
1517 |
24d49f1d735f
added TableContainer + some bug fixes (bad default parameters)
Goffi <goffi@goffi.org>
parents:
69
diff
changeset
|
1518 @property |
24d49f1d735f
added TableContainer + some bug fixes (bad default parameters)
Goffi <goffi@goffi.org>
parents:
69
diff
changeset
|
1519 def focus_position(self): |
24d49f1d735f
added TableContainer + some bug fixes (bad default parameters)
Goffi <goffi@goffi.org>
parents:
69
diff
changeset
|
1520 return self.base_widget.focus_position |
24d49f1d735f
added TableContainer + some bug fixes (bad default parameters)
Goffi <goffi@goffi.org>
parents:
69
diff
changeset
|
1521 |
24d49f1d735f
added TableContainer + some bug fixes (bad default parameters)
Goffi <goffi@goffi.org>
parents:
69
diff
changeset
|
1522 @focus_position.setter |
24d49f1d735f
added TableContainer + some bug fixes (bad default parameters)
Goffi <goffi@goffi.org>
parents:
69
diff
changeset
|
1523 def focus_position(self, value): |
24d49f1d735f
added TableContainer + some bug fixes (bad default parameters)
Goffi <goffi@goffi.org>
parents:
69
diff
changeset
|
1524 self.base_widget.focus_position = value |
24d49f1d735f
added TableContainer + some bug fixes (bad default parameters)
Goffi <goffi@goffi.org>
parents:
69
diff
changeset
|
1525 |
24d49f1d735f
added TableContainer + some bug fixes (bad default parameters)
Goffi <goffi@goffi.org>
parents:
69
diff
changeset
|
1526 def addWidget(self, wid, options): |
24d49f1d735f
added TableContainer + some bug fixes (bad default parameters)
Goffi <goffi@goffi.org>
parents:
69
diff
changeset
|
1527 """ Add a widget to the columns |
24d49f1d735f
added TableContainer + some bug fixes (bad default parameters)
Goffi <goffi@goffi.org>
parents:
69
diff
changeset
|
1528 Widget is wrapped with AttrMap, that's why Columns.contents should not be used directly for appending new widgets |
24d49f1d735f
added TableContainer + some bug fixes (bad default parameters)
Goffi <goffi@goffi.org>
parents:
69
diff
changeset
|
1529 @param wid: widget to add |
24d49f1d735f
added TableContainer + some bug fixes (bad default parameters)
Goffi <goffi@goffi.org>
parents:
69
diff
changeset
|
1530 @param options: result of Columns.options(...) |
24d49f1d735f
added TableContainer + some bug fixes (bad default parameters)
Goffi <goffi@goffi.org>
parents:
69
diff
changeset
|
1531 |
24d49f1d735f
added TableContainer + some bug fixes (bad default parameters)
Goffi <goffi@goffi.org>
parents:
69
diff
changeset
|
1532 """ |
24d49f1d735f
added TableContainer + some bug fixes (bad default parameters)
Goffi <goffi@goffi.org>
parents:
69
diff
changeset
|
1533 wrapper = urwid.AttrMap(wid, None) |
24d49f1d735f
added TableContainer + some bug fixes (bad default parameters)
Goffi <goffi@goffi.org>
parents:
69
diff
changeset
|
1534 self.base_widget.contents.append((wrapper, options)) |
24d49f1d735f
added TableContainer + some bug fixes (bad default parameters)
Goffi <goffi@goffi.org>
parents:
69
diff
changeset
|
1535 |
24d49f1d735f
added TableContainer + some bug fixes (bad default parameters)
Goffi <goffi@goffi.org>
parents:
69
diff
changeset
|
1536 |
24d49f1d735f
added TableContainer + some bug fixes (bad default parameters)
Goffi <goffi@goffi.org>
parents:
69
diff
changeset
|
1537 def render(self, size, focus=False): |
24d49f1d735f
added TableContainer + some bug fixes (bad default parameters)
Goffi <goffi@goffi.org>
parents:
69
diff
changeset
|
1538 if self.highlight_cols and focus != self.has_focus: |
24d49f1d735f
added TableContainer + some bug fixes (bad default parameters)
Goffi <goffi@goffi.org>
parents:
69
diff
changeset
|
1539 self.has_focus = focus |
24d49f1d735f
added TableContainer + some bug fixes (bad default parameters)
Goffi <goffi@goffi.org>
parents:
69
diff
changeset
|
1540 for idx in self.highlight_cols: |
24d49f1d735f
added TableContainer + some bug fixes (bad default parameters)
Goffi <goffi@goffi.org>
parents:
69
diff
changeset
|
1541 wid = self.base_widget.contents[idx][0] |
24d49f1d735f
added TableContainer + some bug fixes (bad default parameters)
Goffi <goffi@goffi.org>
parents:
69
diff
changeset
|
1542 wid.set_attr_map({None: self.highlight_attr if focus else None}) |
24d49f1d735f
added TableContainer + some bug fixes (bad default parameters)
Goffi <goffi@goffi.org>
parents:
69
diff
changeset
|
1543 |
24d49f1d735f
added TableContainer + some bug fixes (bad default parameters)
Goffi <goffi@goffi.org>
parents:
69
diff
changeset
|
1544 return super(HighlightColumns, self).render(size, focus) |
24d49f1d735f
added TableContainer + some bug fixes (bad default parameters)
Goffi <goffi@goffi.org>
parents:
69
diff
changeset
|
1545 |
24d49f1d735f
added TableContainer + some bug fixes (bad default parameters)
Goffi <goffi@goffi.org>
parents:
69
diff
changeset
|
1546 |
24d49f1d735f
added TableContainer + some bug fixes (bad default parameters)
Goffi <goffi@goffi.org>
parents:
69
diff
changeset
|
1547 class TableContainer(urwid.WidgetWrap): |
24d49f1d735f
added TableContainer + some bug fixes (bad default parameters)
Goffi <goffi@goffi.org>
parents:
69
diff
changeset
|
1548 """ Widgets are disposed in row and columns """ |
24d49f1d735f
added TableContainer + some bug fixes (bad default parameters)
Goffi <goffi@goffi.org>
parents:
69
diff
changeset
|
1549 signals = ['click'] |
24d49f1d735f
added TableContainer + some bug fixes (bad default parameters)
Goffi <goffi@goffi.org>
parents:
69
diff
changeset
|
1550 |
24d49f1d735f
added TableContainer + some bug fixes (bad default parameters)
Goffi <goffi@goffi.org>
parents:
69
diff
changeset
|
1551 def __init__(self, items=None, columns=None, dividechars=1, row_selectable=False, select_key='enter', options=None): |
24d49f1d735f
added TableContainer + some bug fixes (bad default parameters)
Goffi <goffi@goffi.org>
parents:
69
diff
changeset
|
1552 """ Create a TableContainer |
24d49f1d735f
added TableContainer + some bug fixes (bad default parameters)
Goffi <goffi@goffi.org>
parents:
69
diff
changeset
|
1553 @param items: iterable of widgets to add to this container |
24d49f1d735f
added TableContainer + some bug fixes (bad default parameters)
Goffi <goffi@goffi.org>
parents:
69
diff
changeset
|
1554 @param columns: nb of columns of this table |
24d49f1d735f
added TableContainer + some bug fixes (bad default parameters)
Goffi <goffi@goffi.org>
parents:
69
diff
changeset
|
1555 @param dividechars: same as dividechars param for urwid.Columns |
24d49f1d735f
added TableContainer + some bug fixes (bad default parameters)
Goffi <goffi@goffi.org>
parents:
69
diff
changeset
|
1556 @param row_selectable: if True, row are always selectable, even if they don't contain any selectable widget |
24d49f1d735f
added TableContainer + some bug fixes (bad default parameters)
Goffi <goffi@goffi.org>
parents:
69
diff
changeset
|
1557 @param options: dictionnary with the following keys: |
24d49f1d735f
added TableContainer + some bug fixes (bad default parameters)
Goffi <goffi@goffi.org>
parents:
69
diff
changeset
|
1558 - ADAPT: tuple of columns for which the size must be adapted to its contents, |
24d49f1d735f
added TableContainer + some bug fixes (bad default parameters)
Goffi <goffi@goffi.org>
parents:
69
diff
changeset
|
1559 empty tuple for all columns |
24d49f1d735f
added TableContainer + some bug fixes (bad default parameters)
Goffi <goffi@goffi.org>
parents:
69
diff
changeset
|
1560 - HIGHLIGHT: tuple of columns which must be higlighted on focus, |
24d49f1d735f
added TableContainer + some bug fixes (bad default parameters)
Goffi <goffi@goffi.org>
parents:
69
diff
changeset
|
1561 empty tuple for the whole row |
24d49f1d735f
added TableContainer + some bug fixes (bad default parameters)
Goffi <goffi@goffi.org>
parents:
69
diff
changeset
|
1562 - FOCUS_ATTR: Attribute name to use when focused (see HIGHLIGHT). Default is "table_selected" |
24d49f1d735f
added TableContainer + some bug fixes (bad default parameters)
Goffi <goffi@goffi.org>
parents:
69
diff
changeset
|
1563 |
24d49f1d735f
added TableContainer + some bug fixes (bad default parameters)
Goffi <goffi@goffi.org>
parents:
69
diff
changeset
|
1564 """ |
24d49f1d735f
added TableContainer + some bug fixes (bad default parameters)
Goffi <goffi@goffi.org>
parents:
69
diff
changeset
|
1565 pile = urwid.Pile([]) |
24d49f1d735f
added TableContainer + some bug fixes (bad default parameters)
Goffi <goffi@goffi.org>
parents:
69
diff
changeset
|
1566 super(TableContainer, self).__init__(pile) |
24d49f1d735f
added TableContainer + some bug fixes (bad default parameters)
Goffi <goffi@goffi.org>
parents:
69
diff
changeset
|
1567 if items is None: |
24d49f1d735f
added TableContainer + some bug fixes (bad default parameters)
Goffi <goffi@goffi.org>
parents:
69
diff
changeset
|
1568 items = [] |
24d49f1d735f
added TableContainer + some bug fixes (bad default parameters)
Goffi <goffi@goffi.org>
parents:
69
diff
changeset
|
1569 if columns is None: # if columns is None, we suppose only one row is given in items |
24d49f1d735f
added TableContainer + some bug fixes (bad default parameters)
Goffi <goffi@goffi.org>
parents:
69
diff
changeset
|
1570 columns = len(items) |
24d49f1d735f
added TableContainer + some bug fixes (bad default parameters)
Goffi <goffi@goffi.org>
parents:
69
diff
changeset
|
1571 assert columns |
24d49f1d735f
added TableContainer + some bug fixes (bad default parameters)
Goffi <goffi@goffi.org>
parents:
69
diff
changeset
|
1572 self._columns = columns |
24d49f1d735f
added TableContainer + some bug fixes (bad default parameters)
Goffi <goffi@goffi.org>
parents:
69
diff
changeset
|
1573 self._row_selectable = row_selectable |
24d49f1d735f
added TableContainer + some bug fixes (bad default parameters)
Goffi <goffi@goffi.org>
parents:
69
diff
changeset
|
1574 self.select_key = select_key |
24d49f1d735f
added TableContainer + some bug fixes (bad default parameters)
Goffi <goffi@goffi.org>
parents:
69
diff
changeset
|
1575 if options is None: |
24d49f1d735f
added TableContainer + some bug fixes (bad default parameters)
Goffi <goffi@goffi.org>
parents:
69
diff
changeset
|
1576 options = {} |
24d49f1d735f
added TableContainer + some bug fixes (bad default parameters)
Goffi <goffi@goffi.org>
parents:
69
diff
changeset
|
1577 for opt in ['ADAPT', 'HIGHLIGHT']: |
24d49f1d735f
added TableContainer + some bug fixes (bad default parameters)
Goffi <goffi@goffi.org>
parents:
69
diff
changeset
|
1578 if opt in options: |
24d49f1d735f
added TableContainer + some bug fixes (bad default parameters)
Goffi <goffi@goffi.org>
parents:
69
diff
changeset
|
1579 try: |
24d49f1d735f
added TableContainer + some bug fixes (bad default parameters)
Goffi <goffi@goffi.org>
parents:
69
diff
changeset
|
1580 options[opt] = tuple(options[opt]) |
24d49f1d735f
added TableContainer + some bug fixes (bad default parameters)
Goffi <goffi@goffi.org>
parents:
69
diff
changeset
|
1581 except TypeError: |
89
2141f07b5fdd
primitivus: no more direct error/warning methods for logging
Goffi <goffi@goffi.org>
parents:
88
diff
changeset
|
1582 log.warning('[%s] option is not a tuple' % opt) |
70
24d49f1d735f
added TableContainer + some bug fixes (bad default parameters)
Goffi <goffi@goffi.org>
parents:
69
diff
changeset
|
1583 options[opt] = () |
24d49f1d735f
added TableContainer + some bug fixes (bad default parameters)
Goffi <goffi@goffi.org>
parents:
69
diff
changeset
|
1584 self._options = options |
24d49f1d735f
added TableContainer + some bug fixes (bad default parameters)
Goffi <goffi@goffi.org>
parents:
69
diff
changeset
|
1585 self._dividechars = dividechars |
24d49f1d735f
added TableContainer + some bug fixes (bad default parameters)
Goffi <goffi@goffi.org>
parents:
69
diff
changeset
|
1586 self._idx = 0 |
24d49f1d735f
added TableContainer + some bug fixes (bad default parameters)
Goffi <goffi@goffi.org>
parents:
69
diff
changeset
|
1587 self._longuest = self._columns * [0] |
24d49f1d735f
added TableContainer + some bug fixes (bad default parameters)
Goffi <goffi@goffi.org>
parents:
69
diff
changeset
|
1588 self._next_row_idx = None |
24d49f1d735f
added TableContainer + some bug fixes (bad default parameters)
Goffi <goffi@goffi.org>
parents:
69
diff
changeset
|
1589 for item in items: |
24d49f1d735f
added TableContainer + some bug fixes (bad default parameters)
Goffi <goffi@goffi.org>
parents:
69
diff
changeset
|
1590 self.addWidget(item) |
24d49f1d735f
added TableContainer + some bug fixes (bad default parameters)
Goffi <goffi@goffi.org>
parents:
69
diff
changeset
|
1591 |
24d49f1d735f
added TableContainer + some bug fixes (bad default parameters)
Goffi <goffi@goffi.org>
parents:
69
diff
changeset
|
1592 def _getIdealSize(self, widget): |
24d49f1d735f
added TableContainer + some bug fixes (bad default parameters)
Goffi <goffi@goffi.org>
parents:
69
diff
changeset
|
1593 """ return preferred size for widget, or 0 if we can't find it """ |
24d49f1d735f
added TableContainer + some bug fixes (bad default parameters)
Goffi <goffi@goffi.org>
parents:
69
diff
changeset
|
1594 try: |
24d49f1d735f
added TableContainer + some bug fixes (bad default parameters)
Goffi <goffi@goffi.org>
parents:
69
diff
changeset
|
1595 return len(widget.text) |
24d49f1d735f
added TableContainer + some bug fixes (bad default parameters)
Goffi <goffi@goffi.org>
parents:
69
diff
changeset
|
1596 except AttributeError: |
24d49f1d735f
added TableContainer + some bug fixes (bad default parameters)
Goffi <goffi@goffi.org>
parents:
69
diff
changeset
|
1597 return 0 |
24d49f1d735f
added TableContainer + some bug fixes (bad default parameters)
Goffi <goffi@goffi.org>
parents:
69
diff
changeset
|
1598 |
24d49f1d735f
added TableContainer + some bug fixes (bad default parameters)
Goffi <goffi@goffi.org>
parents:
69
diff
changeset
|
1599 def keypress(self, size, key): |
24d49f1d735f
added TableContainer + some bug fixes (bad default parameters)
Goffi <goffi@goffi.org>
parents:
69
diff
changeset
|
1600 if key == self.select_key and self._row_selectable: |
24d49f1d735f
added TableContainer + some bug fixes (bad default parameters)
Goffi <goffi@goffi.org>
parents:
69
diff
changeset
|
1601 self._emit('click') |
24d49f1d735f
added TableContainer + some bug fixes (bad default parameters)
Goffi <goffi@goffi.org>
parents:
69
diff
changeset
|
1602 else: |
24d49f1d735f
added TableContainer + some bug fixes (bad default parameters)
Goffi <goffi@goffi.org>
parents:
69
diff
changeset
|
1603 return super(TableContainer, self).keypress(size, key) |
24d49f1d735f
added TableContainer + some bug fixes (bad default parameters)
Goffi <goffi@goffi.org>
parents:
69
diff
changeset
|
1604 |
24d49f1d735f
added TableContainer + some bug fixes (bad default parameters)
Goffi <goffi@goffi.org>
parents:
69
diff
changeset
|
1605 |
24d49f1d735f
added TableContainer + some bug fixes (bad default parameters)
Goffi <goffi@goffi.org>
parents:
69
diff
changeset
|
1606 def addWidget(self, widget): |
24d49f1d735f
added TableContainer + some bug fixes (bad default parameters)
Goffi <goffi@goffi.org>
parents:
69
diff
changeset
|
1607 # TODO: use a contents property ? |
24d49f1d735f
added TableContainer + some bug fixes (bad default parameters)
Goffi <goffi@goffi.org>
parents:
69
diff
changeset
|
1608 pile = self._w |
24d49f1d735f
added TableContainer + some bug fixes (bad default parameters)
Goffi <goffi@goffi.org>
parents:
69
diff
changeset
|
1609 col_idx = self._idx % self._columns |
24d49f1d735f
added TableContainer + some bug fixes (bad default parameters)
Goffi <goffi@goffi.org>
parents:
69
diff
changeset
|
1610 |
24d49f1d735f
added TableContainer + some bug fixes (bad default parameters)
Goffi <goffi@goffi.org>
parents:
69
diff
changeset
|
1611 options = None |
24d49f1d735f
added TableContainer + some bug fixes (bad default parameters)
Goffi <goffi@goffi.org>
parents:
69
diff
changeset
|
1612 |
24d49f1d735f
added TableContainer + some bug fixes (bad default parameters)
Goffi <goffi@goffi.org>
parents:
69
diff
changeset
|
1613 if col_idx == 0: |
24d49f1d735f
added TableContainer + some bug fixes (bad default parameters)
Goffi <goffi@goffi.org>
parents:
69
diff
changeset
|
1614 # we have a new row |
24d49f1d735f
added TableContainer + some bug fixes (bad default parameters)
Goffi <goffi@goffi.org>
parents:
69
diff
changeset
|
1615 columns = HighlightColumns(self._options.get('HIGHLIGHT'), self._options.get('FOCUS_ATTR', 'table_selected'), [], dividechars=self._dividechars) |
24d49f1d735f
added TableContainer + some bug fixes (bad default parameters)
Goffi <goffi@goffi.org>
parents:
69
diff
changeset
|
1616 columns.row_idx = self._next_row_idx |
24d49f1d735f
added TableContainer + some bug fixes (bad default parameters)
Goffi <goffi@goffi.org>
parents:
69
diff
changeset
|
1617 pile.contents.append((columns, pile.options())) |
24d49f1d735f
added TableContainer + some bug fixes (bad default parameters)
Goffi <goffi@goffi.org>
parents:
69
diff
changeset
|
1618 else: |
24d49f1d735f
added TableContainer + some bug fixes (bad default parameters)
Goffi <goffi@goffi.org>
parents:
69
diff
changeset
|
1619 columns = pile.contents[-1][0] |
24d49f1d735f
added TableContainer + some bug fixes (bad default parameters)
Goffi <goffi@goffi.org>
parents:
69
diff
changeset
|
1620 |
24d49f1d735f
added TableContainer + some bug fixes (bad default parameters)
Goffi <goffi@goffi.org>
parents:
69
diff
changeset
|
1621 if 'ADAPT' in self._options and (col_idx in self._options['ADAPT'] |
24d49f1d735f
added TableContainer + some bug fixes (bad default parameters)
Goffi <goffi@goffi.org>
parents:
69
diff
changeset
|
1622 or self._options['ADAPT'] == ()): |
24d49f1d735f
added TableContainer + some bug fixes (bad default parameters)
Goffi <goffi@goffi.org>
parents:
69
diff
changeset
|
1623 current_len = self._getIdealSize(widget) |
24d49f1d735f
added TableContainer + some bug fixes (bad default parameters)
Goffi <goffi@goffi.org>
parents:
69
diff
changeset
|
1624 longuest = self._longuest[col_idx] |
24d49f1d735f
added TableContainer + some bug fixes (bad default parameters)
Goffi <goffi@goffi.org>
parents:
69
diff
changeset
|
1625 max_len = max(longuest, current_len) |
24d49f1d735f
added TableContainer + some bug fixes (bad default parameters)
Goffi <goffi@goffi.org>
parents:
69
diff
changeset
|
1626 if max_len > longuest: |
24d49f1d735f
added TableContainer + some bug fixes (bad default parameters)
Goffi <goffi@goffi.org>
parents:
69
diff
changeset
|
1627 self._longuest[col_idx] = max_len |
24d49f1d735f
added TableContainer + some bug fixes (bad default parameters)
Goffi <goffi@goffi.org>
parents:
69
diff
changeset
|
1628 for wid,_ in pile.contents[:-1]: |
24d49f1d735f
added TableContainer + some bug fixes (bad default parameters)
Goffi <goffi@goffi.org>
parents:
69
diff
changeset
|
1629 col = wid.base_widget |
24d49f1d735f
added TableContainer + some bug fixes (bad default parameters)
Goffi <goffi@goffi.org>
parents:
69
diff
changeset
|
1630 col.contents[col_idx] = (col.contents[col_idx][0], col.options('given', max_len)) |
24d49f1d735f
added TableContainer + some bug fixes (bad default parameters)
Goffi <goffi@goffi.org>
parents:
69
diff
changeset
|
1631 options = columns.options('given', max_len) if max_len else columns.options() |
24d49f1d735f
added TableContainer + some bug fixes (bad default parameters)
Goffi <goffi@goffi.org>
parents:
69
diff
changeset
|
1632 |
24d49f1d735f
added TableContainer + some bug fixes (bad default parameters)
Goffi <goffi@goffi.org>
parents:
69
diff
changeset
|
1633 columns.addWidget(widget, options or columns.options()) |
24d49f1d735f
added TableContainer + some bug fixes (bad default parameters)
Goffi <goffi@goffi.org>
parents:
69
diff
changeset
|
1634 |
24d49f1d735f
added TableContainer + some bug fixes (bad default parameters)
Goffi <goffi@goffi.org>
parents:
69
diff
changeset
|
1635 if self._row_selectable and col_idx == self._columns - 1: |
24d49f1d735f
added TableContainer + some bug fixes (bad default parameters)
Goffi <goffi@goffi.org>
parents:
69
diff
changeset
|
1636 columns.addWidget(urwid.SelectableIcon(''), columns.options('given', 0)) |
24d49f1d735f
added TableContainer + some bug fixes (bad default parameters)
Goffi <goffi@goffi.org>
parents:
69
diff
changeset
|
1637 |
24d49f1d735f
added TableContainer + some bug fixes (bad default parameters)
Goffi <goffi@goffi.org>
parents:
69
diff
changeset
|
1638 if not columns.selectable() and columns.contents[-1][0].base_widget.selectable(): |
24d49f1d735f
added TableContainer + some bug fixes (bad default parameters)
Goffi <goffi@goffi.org>
parents:
69
diff
changeset
|
1639 columns.focus_position = len(columns.contents)-1 |
99
b2fee87c1d5a
Fixed focus when first row is not selectable in TableContainer
Goffi <goffi@goffi.org>
parents:
98
diff
changeset
|
1640 if not self.selectable() and columns.selectable(): |
b2fee87c1d5a
Fixed focus when first row is not selectable in TableContainer
Goffi <goffi@goffi.org>
parents:
98
diff
changeset
|
1641 pile.focus_position = len(pile.contents) - 1 |
70
24d49f1d735f
added TableContainer + some bug fixes (bad default parameters)
Goffi <goffi@goffi.org>
parents:
69
diff
changeset
|
1642 self._idx += 1 |
24d49f1d735f
added TableContainer + some bug fixes (bad default parameters)
Goffi <goffi@goffi.org>
parents:
69
diff
changeset
|
1643 |
24d49f1d735f
added TableContainer + some bug fixes (bad default parameters)
Goffi <goffi@goffi.org>
parents:
69
diff
changeset
|
1644 def setRowIndex(self, idx): |
24d49f1d735f
added TableContainer + some bug fixes (bad default parameters)
Goffi <goffi@goffi.org>
parents:
69
diff
changeset
|
1645 self._next_row_idx = idx |
24d49f1d735f
added TableContainer + some bug fixes (bad default parameters)
Goffi <goffi@goffi.org>
parents:
69
diff
changeset
|
1646 |
24d49f1d735f
added TableContainer + some bug fixes (bad default parameters)
Goffi <goffi@goffi.org>
parents:
69
diff
changeset
|
1647 def getSelectedWidgets(self): |
24d49f1d735f
added TableContainer + some bug fixes (bad default parameters)
Goffi <goffi@goffi.org>
parents:
69
diff
changeset
|
1648 columns = self._w.focus |
24d49f1d735f
added TableContainer + some bug fixes (bad default parameters)
Goffi <goffi@goffi.org>
parents:
69
diff
changeset
|
1649 return (wid for wid, _ in columns.contents) |
24d49f1d735f
added TableContainer + some bug fixes (bad default parameters)
Goffi <goffi@goffi.org>
parents:
69
diff
changeset
|
1650 |
24d49f1d735f
added TableContainer + some bug fixes (bad default parameters)
Goffi <goffi@goffi.org>
parents:
69
diff
changeset
|
1651 def getSelectedIndex(self): |
24d49f1d735f
added TableContainer + some bug fixes (bad default parameters)
Goffi <goffi@goffi.org>
parents:
69
diff
changeset
|
1652 columns = self._w.focus |
24d49f1d735f
added TableContainer + some bug fixes (bad default parameters)
Goffi <goffi@goffi.org>
parents:
69
diff
changeset
|
1653 return columns.row_idx |
24d49f1d735f
added TableContainer + some bug fixes (bad default parameters)
Goffi <goffi@goffi.org>
parents:
69
diff
changeset
|
1654 |
6 | 1655 ## DECORATORS ## |
1656 class LabelLine(urwid.LineBox): | |
7 | 1657 """Like LineBox, but with a Label centered in the top line""" |
6 | 1658 |
1659 def __init__(self, original_widget, label_widget): | |
1660 urwid.LineBox.__init__(self, original_widget) | |
1661 top_columns = self._w.widget_list[0] | |
1662 top_columns.widget_list[1] = label_widget | |
8 | 1663 |
70
24d49f1d735f
added TableContainer + some bug fixes (bad default parameters)
Goffi <goffi@goffi.org>
parents:
69
diff
changeset
|
1664 |
8 | 1665 class VerticalSeparator(urwid.WidgetDecoration, urwid.WidgetWrap): |
21 | 1666 def __init__(self, original_widget, left_char = u"│", right_char = ''): |
15
8241b3157699
Primitivus: custom_widgets imrpovments
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
1667 """Draw a separator on left and/or right of original_widget.""" |
66 | 1668 |
8 | 1669 widgets = [original_widget] |
1670 if left_char: | |
1671 widgets.insert(0, ('fixed', 1, urwid.SolidFill(left_char))) | |
1672 if right_char: | |
1673 widgets.append(('fixed', 1, urwid.SolidFill(right_char))) | |
1674 columns = urwid.Columns(widgets, box_columns = [0,2], focus_column = 1) | |
1675 urwid.WidgetDecoration.__init__(self, original_widget) | |
1676 urwid.WidgetWrap.__init__(self, columns) | |
1677 | |
66 | 1678 |