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