annotate frontends/primitivus/custom_widgets.py @ 216:783d6a61e0bd

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