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