annotate urwid_satext/sat_widgets.py @ 79:33677d99ebdf

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