comparison urwid_satext/sat_widgets.py @ 69:b39c81cdd863

removed __valid_text: urwid now manage basestring subclasses, it's not necessary anymore
author Goffi <goffi@goffi.org>
date Tue, 24 Dec 2013 15:09:21 +0100
parents 5c28bb50ae0d
children 24d49f1d735f
comparison
equal deleted inserted replaced
68:5c28bb50ae0d 69:b39c81cdd863
190 @select_attr: attrbute to use when selected 190 @select_attr: attrbute to use when selected
191 @param selected: is the text selected ?""" 191 @param selected: is the text selected ?"""
192 self.focus_attr = focus_attr 192 self.focus_attr = focus_attr
193 self.__selected = False 193 self.__selected = False
194 self.__was_focused = False 194 self.__was_focused = False
195 self.header = self.__valid_text(header) 195 self.header = header
196 self.default_txt = self.__valid_text(text) 196 self.default_txt = text
197 urwid.WidgetWrap.__init__(self, urwid.Text("",align=align)) 197 urwid.WidgetWrap.__init__(self, urwid.Text("",align=align))
198 self.setSelectedText(selected_text) 198 self.setSelectedText(selected_text)
199 self.setState(selected) 199 self.setState(selected)
200
201 def __valid_text(self, text):
202 """Tmp method needed until dbus and urwid are more friends"""
203 if isinstance(text, ListOption):
204 return text
205 if isinstance(text,basestring):
206 return unicode(text)
207 elif isinstance(text,tuple):
208 return (unicode(text[0]),text[1])
209 elif isinstance(text,list):
210 for idx in range(len(text)):
211 elem = text[idx]
212 if isinstance(elem,basestring):
213 text[idx] = unicode(elem)
214 if isinstance(elem,tuple):
215 text[idx] = (unicode(elem[0]),elem[1])
216 else:
217 warning (_('WARNING: unknown text type'))
218 return text
219 200
220 def getValue(self): 201 def getValue(self):
221 if isinstance(self.default_txt,basestring): 202 if isinstance(self.default_txt,basestring):
222 return self.default_txt 203 return self.default_txt
223 list_attr = self.default_txt if isinstance(self.default_txt, list) else [self.default_txt] 204 list_attr = self.default_txt if isinstance(self.default_txt, list) else [self.default_txt]
233 """for compatibility with urwid.Text""" 214 """for compatibility with urwid.Text"""
234 return self.getValue() 215 return self.getValue()
235 216
236 def set_text(self, text): 217 def set_text(self, text):
237 """/!\ set_text doesn't change self.selected_txt !""" 218 """/!\ set_text doesn't change self.selected_txt !"""
238 self.default_txt = self.__valid_text(text) 219 self.default_txt = text
239 self.setState(self.__selected,invisible=True) 220 self.setState(self.__selected,invisible=True)
240 221
241 def setSelectedText(self, text=None): 222 def setSelectedText(self, text=None):
242 """Text to display when selected 223 """Text to display when selected
243 @text: text as in urwid.Text or None for default value""" 224 @text: text as in urwid.Text or None for default value"""
244 if text == None: 225 if text == None:
245 text = ('selected',self.getValue()) 226 text = ('selected',self.getValue())
246 self.selected_txt = self.__valid_text(text) 227 self.selected_txt = text
247 if self.__selected: 228 if self.__selected:
248 self.setState(self.__selected) 229 self.setState(self.__selected)
249 230
250 231
251 def __set_txt(self): 232 def __set_txt(self):