annotate frontends/primitivus/custom_widgets.py @ 2:07b7dcd314ff

primitivus: basic contact list, connexion now work \o/
author Goffi <goffi@goffi.org>
date Thu, 01 Jul 2010 18:52:51 +0800
parents a5c9603dac37
children 6290022ae74d
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
cb72fb2bfa0d Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
4 """
cb72fb2bfa0d Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
5 Primitivus: a SAT frontend
cb72fb2bfa0d Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
6 Copyright (C) 2009, 2010 Jérôme Poisson (goffi@goffi.org)
cb72fb2bfa0d Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
7
cb72fb2bfa0d Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
8 This program is free software: you can redistribute it and/or modify
cb72fb2bfa0d Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
9 it under the terms of the GNU General Public License as published by
cb72fb2bfa0d Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
10 the Free Software Foundation, either version 3 of the License, or
cb72fb2bfa0d Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
11 (at your option) any later version.
cb72fb2bfa0d Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
12
cb72fb2bfa0d Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
13 This program is distributed in the hope that it will be useful,
cb72fb2bfa0d Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
cb72fb2bfa0d Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
cb72fb2bfa0d Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
16 GNU General Public License for more details.
cb72fb2bfa0d Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
17
cb72fb2bfa0d Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
18 You should have received a copy of the GNU General Public License
cb72fb2bfa0d Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
19 along with this program. If not, see <http://www.gnu.org/licenses/>.
cb72fb2bfa0d Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
20 """
cb72fb2bfa0d Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
21
cb72fb2bfa0d Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
22 import urwid
cb72fb2bfa0d Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
23
cb72fb2bfa0d Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
24 class Password(urwid.Edit):
cb72fb2bfa0d Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
25
cb72fb2bfa0d Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
26 def __init__(self, *args, **kwargs):
cb72fb2bfa0d Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
27 self.hidden_char=kwargs['hidden_char'] if kwargs.has_key('hidden_char') else '*'
cb72fb2bfa0d Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
28 self.__real_text=''
cb72fb2bfa0d Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
29 super(Password, self).__init__(*args, **kwargs)
cb72fb2bfa0d Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
30
cb72fb2bfa0d Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
31 def set_edit_text(self, text):
cb72fb2bfa0d Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
32 self.__real_text = text
cb72fb2bfa0d Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
33 hidden_txt = len(text)*'*'
cb72fb2bfa0d Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
34 super(Password, self).set_edit_text(hidden_txt)
cb72fb2bfa0d Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
35
cb72fb2bfa0d Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
36 def get_edit_text(self):
cb72fb2bfa0d Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
37 return self.__real_text
cb72fb2bfa0d Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
38
cb72fb2bfa0d Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
39 class SelectableText(urwid.FlowWidget):
cb72fb2bfa0d Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
40 signals = ['change']
cb72fb2bfa0d Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
41
cb72fb2bfa0d Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
42 def __init__(self, text, align='left'):
cb72fb2bfa0d Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
43 self.text=unicode(text)
cb72fb2bfa0d Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
44 self.align = align
cb72fb2bfa0d Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
45 self.__selected=False
cb72fb2bfa0d Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
46
cb72fb2bfa0d Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
47 def getValue(self):
cb72fb2bfa0d Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
48 return self.text
cb72fb2bfa0d Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
49
cb72fb2bfa0d Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
50 def setState(self, selected, invisible=False):
cb72fb2bfa0d Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
51 """Change state
cb72fb2bfa0d Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
52 @param selected: boolean state value
cb72fb2bfa0d Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
53 @param invisible: don't emit change signal if True"""
cb72fb2bfa0d Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
54 assert(type(selected)==bool)
cb72fb2bfa0d Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
55 self.__selected=selected
cb72fb2bfa0d Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
56 if not invisible:
cb72fb2bfa0d Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
57 self._emit("change", self.__selected)
cb72fb2bfa0d Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
58 self._invalidate()
cb72fb2bfa0d Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
59
cb72fb2bfa0d Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
60 def getState(self):
cb72fb2bfa0d Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
61 return self.__selected
cb72fb2bfa0d Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
62
cb72fb2bfa0d Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
63 def selectable(self):
cb72fb2bfa0d Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
64 return True
cb72fb2bfa0d Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
65
cb72fb2bfa0d Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
66 def keypress(self, size, key):
cb72fb2bfa0d Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
67 if key==' ' or key=='enter':
cb72fb2bfa0d Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
68 self.setState(not self.__selected)
cb72fb2bfa0d Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
69 else:
cb72fb2bfa0d Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
70 return key
cb72fb2bfa0d Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
71
cb72fb2bfa0d Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
72 def rows(self,size,focus=False):
cb72fb2bfa0d Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
73 return self.display_widget(size, focus).rows(size, focus)
cb72fb2bfa0d Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
74
cb72fb2bfa0d Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
75 def render(self, size, focus=False):
cb72fb2bfa0d Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
76 return self.display_widget(size, focus).render(size, focus)
cb72fb2bfa0d Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
77
cb72fb2bfa0d Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
78 def display_widget(self, size, focus):
cb72fb2bfa0d Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
79 attr = 'selected' if self.__selected else 'default'
cb72fb2bfa0d Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
80 if focus:
cb72fb2bfa0d Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
81 attr+="_focus"
cb72fb2bfa0d Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
82 return urwid.Text((attr,self.text), align=self.align)
cb72fb2bfa0d Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
83
cb72fb2bfa0d Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
84 class List(urwid.WidgetWrap):
cb72fb2bfa0d Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
85 signals = ['change']
cb72fb2bfa0d Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
86
cb72fb2bfa0d Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
87 def __init__(self, options, style=[], align='left', on_state_change=None, user_data=None):
cb72fb2bfa0d Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
88 self.single = 'single' in style
cb72fb2bfa0d Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
89 self.align = align
cb72fb2bfa0d Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
90
cb72fb2bfa0d Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
91 if on_state_change:
cb72fb2bfa0d Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
92 urwid.connect_signal(self, 'change', on_state_change, user_data)
cb72fb2bfa0d Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
93
1
a5c9603dac37 primitivus: added Alert widget
Goffi <goffi@goffi.org>
parents: 0
diff changeset
94 self.content = urwid.SimpleListWalker([])
0
cb72fb2bfa0d Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
95 self.list_box = urwid.ListBox(self.content)
1
a5c9603dac37 primitivus: added Alert widget
Goffi <goffi@goffi.org>
parents: 0
diff changeset
96 self.changeValues(options)
0
cb72fb2bfa0d Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
97
cb72fb2bfa0d Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
98 def __onStateChange(self, widget, selected):
cb72fb2bfa0d Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
99 if self.single:
cb72fb2bfa0d Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
100 if not selected:
cb72fb2bfa0d Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
101 #if in single mode, it's forbidden to unselect a value
cb72fb2bfa0d Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
102 widget.setState(True, invisible=True)
cb72fb2bfa0d Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
103 return
cb72fb2bfa0d Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
104 else:
cb72fb2bfa0d Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
105 self.unselectAll(invisible=True)
cb72fb2bfa0d Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
106 widget.setState(True, invisible=True)
cb72fb2bfa0d Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
107 self._emit("change")
cb72fb2bfa0d Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
108
cb72fb2bfa0d Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
109
cb72fb2bfa0d Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
110 def unselectAll(self, invisible=False):
cb72fb2bfa0d Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
111 for widget in self.content:
cb72fb2bfa0d Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
112 if widget.getState():
cb72fb2bfa0d Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
113 widget.setState(False, invisible)
cb72fb2bfa0d Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
114 widget._invalidate()
cb72fb2bfa0d Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
115
2
07b7dcd314ff primitivus: basic contact list, connexion now work \o/
Goffi <goffi@goffi.org>
parents: 1
diff changeset
116 def deleteValue(self, value):
07b7dcd314ff primitivus: basic contact list, connexion now work \o/
Goffi <goffi@goffi.org>
parents: 1
diff changeset
117 """Delete the first value equal to the param given"""
07b7dcd314ff primitivus: basic contact list, connexion now work \o/
Goffi <goffi@goffi.org>
parents: 1
diff changeset
118 try:
07b7dcd314ff primitivus: basic contact list, connexion now work \o/
Goffi <goffi@goffi.org>
parents: 1
diff changeset
119 self.content.remove(value)
07b7dcd314ff primitivus: basic contact list, connexion now work \o/
Goffi <goffi@goffi.org>
parents: 1
diff changeset
120 except ValueError:
07b7dcd314ff primitivus: basic contact list, connexion now work \o/
Goffi <goffi@goffi.org>
parents: 1
diff changeset
121 pass
07b7dcd314ff primitivus: basic contact list, connexion now work \o/
Goffi <goffi@goffi.org>
parents: 1
diff changeset
122
1
a5c9603dac37 primitivus: added Alert widget
Goffi <goffi@goffi.org>
parents: 0
diff changeset
123 def getValue(self):
a5c9603dac37 primitivus: added Alert widget
Goffi <goffi@goffi.org>
parents: 0
diff changeset
124 """Convenience method to get the value selected as a string in single mode, or None"""
a5c9603dac37 primitivus: added Alert widget
Goffi <goffi@goffi.org>
parents: 0
diff changeset
125 values = self.getValues()
a5c9603dac37 primitivus: added Alert widget
Goffi <goffi@goffi.org>
parents: 0
diff changeset
126 return values[0] if values else None
a5c9603dac37 primitivus: added Alert widget
Goffi <goffi@goffi.org>
parents: 0
diff changeset
127
0
cb72fb2bfa0d Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
128 def getValues(self):
cb72fb2bfa0d Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
129 result = []
cb72fb2bfa0d Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
130 for widget in self.content:
cb72fb2bfa0d Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
131 if widget.getState():
cb72fb2bfa0d Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
132 result.append(widget.getValue())
cb72fb2bfa0d Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
133 return result
cb72fb2bfa0d Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
134
cb72fb2bfa0d Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
135 def changeValues(self, new_values):
2
07b7dcd314ff primitivus: basic contact list, connexion now work \o/
Goffi <goffi@goffi.org>
parents: 1
diff changeset
136 """Change all value in one shot"""
1
a5c9603dac37 primitivus: added Alert widget
Goffi <goffi@goffi.org>
parents: 0
diff changeset
137 widgets = [SelectableText(option, self.align) for option in new_values]
a5c9603dac37 primitivus: added Alert widget
Goffi <goffi@goffi.org>
parents: 0
diff changeset
138 for widget in widgets:
a5c9603dac37 primitivus: added Alert widget
Goffi <goffi@goffi.org>
parents: 0
diff changeset
139 urwid.connect_signal(widget, 'change', self.__onStateChange)
0
cb72fb2bfa0d Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
140 self.content[:] = widgets
1
a5c9603dac37 primitivus: added Alert widget
Goffi <goffi@goffi.org>
parents: 0
diff changeset
141 if self.single and new_values:
a5c9603dac37 primitivus: added Alert widget
Goffi <goffi@goffi.org>
parents: 0
diff changeset
142 self.content[0].setState(True)
a5c9603dac37 primitivus: added Alert widget
Goffi <goffi@goffi.org>
parents: 0
diff changeset
143 display_widget = urwid.BoxAdapter(self.list_box, min(len(new_values),5))
a5c9603dac37 primitivus: added Alert widget
Goffi <goffi@goffi.org>
parents: 0
diff changeset
144 urwid.WidgetWrap.__init__(self, display_widget)
0
cb72fb2bfa0d Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
145
cb72fb2bfa0d Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
146 def selectValue(self, value):
cb72fb2bfa0d Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
147 self.unselectAll()
cb72fb2bfa0d Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
148 idx = 0
cb72fb2bfa0d Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
149 for widget in self.content:
cb72fb2bfa0d Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
150 if widget.getValue() == value:
cb72fb2bfa0d Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
151 widget.setState(True)
cb72fb2bfa0d Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
152 self.list_box.set_focus(idx)
cb72fb2bfa0d Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
153 return
cb72fb2bfa0d Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
154 idx+=1
cb72fb2bfa0d Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
155
cb72fb2bfa0d Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
156 class genericDialog(urwid.WidgetWrap):
cb72fb2bfa0d Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
157
cb72fb2bfa0d Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
158 def __init__(self, widgets_lst, title, style=[], **kwargs):
cb72fb2bfa0d Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
159 frame_header = urwid.AttrMap(urwid.Text(title,'center'),'title')
cb72fb2bfa0d Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
160
cb72fb2bfa0d Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
161 buttons = None
cb72fb2bfa0d Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
162
cb72fb2bfa0d Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
163 if "OK/CANCEL" in style:
cb72fb2bfa0d Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
164 buttons = [urwid.Button(_("Cancel"), kwargs['cancel_cb']),
cb72fb2bfa0d Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
165 urwid.Button(_("Ok"), kwargs['ok_cb'], kwargs['ok_value'])]
cb72fb2bfa0d Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
166 elif "YES/NO" in style:
cb72fb2bfa0d Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
167 buttons = [urwid.Button(_("Yes"), kwargs['yes_cb']),
cb72fb2bfa0d Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
168 urwid.Button(_("No"), kwargs['no_cb'], kwargs['yes_value'])]
1
a5c9603dac37 primitivus: added Alert widget
Goffi <goffi@goffi.org>
parents: 0
diff changeset
169 if "OK" in style:
a5c9603dac37 primitivus: added Alert widget
Goffi <goffi@goffi.org>
parents: 0
diff changeset
170 buttons = [urwid.Button(_("Ok"), kwargs['ok_cb'], kwargs['ok_value'])]
0
cb72fb2bfa0d Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
171 if buttons:
cb72fb2bfa0d Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
172 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
173 widgets_lst.append(buttons_flow)
cb72fb2bfa0d Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
174 body_content = urwid.SimpleListWalker(widgets_lst)
cb72fb2bfa0d Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
175 frame_body = urwid.ListBox(body_content)
cb72fb2bfa0d Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
176 frame = urwid.Frame(frame_body, frame_header)
cb72fb2bfa0d Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
177 decorated_frame = urwid.LineBox(frame)
cb72fb2bfa0d Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
178 urwid.WidgetWrap.__init__(self, decorated_frame)
cb72fb2bfa0d Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
179
cb72fb2bfa0d Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
180
cb72fb2bfa0d Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
181
cb72fb2bfa0d Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
182 class InputDialog(genericDialog):
cb72fb2bfa0d Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
183
cb72fb2bfa0d Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
184 def __init__(self, title, instrucions, style=['OK/CANCEL'], **kwargs):
cb72fb2bfa0d Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
185 instr_wid = urwid.Text(instrucions+':')
cb72fb2bfa0d Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
186 edit_box = urwid.Edit()
cb72fb2bfa0d Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
187 genericDialog.__init__(self, [instr_wid,edit_box], title, style, ok_value=edit_box, **kwargs)
cb72fb2bfa0d Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
188
cb72fb2bfa0d Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
189 class ConfirmDialog(genericDialog):
cb72fb2bfa0d Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
190
cb72fb2bfa0d Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
191 def __init__(self, title, style=['YES/NO'], **kwargs):
cb72fb2bfa0d Primitivus: profile manager
Goffi <goffi@goffi.org>
parents:
diff changeset
192 genericDialog.__init__(self, [], title, style, yes_value=None, **kwargs)
1
a5c9603dac37 primitivus: added Alert widget
Goffi <goffi@goffi.org>
parents: 0
diff changeset
193
a5c9603dac37 primitivus: added Alert widget
Goffi <goffi@goffi.org>
parents: 0
diff changeset
194 class Alert(genericDialog):
a5c9603dac37 primitivus: added Alert widget
Goffi <goffi@goffi.org>
parents: 0
diff changeset
195
a5c9603dac37 primitivus: added Alert widget
Goffi <goffi@goffi.org>
parents: 0
diff changeset
196 def __init__(self, title, message, style=['OK'], **kwargs):
a5c9603dac37 primitivus: added Alert widget
Goffi <goffi@goffi.org>
parents: 0
diff changeset
197 genericDialog.__init__(self, [urwid.Text(message, 'center')], title, style, ok_value=None, **kwargs)