frontends (XMLUI): implementation of read_only attributes for widgets String, TextBox, Password and Bool

This commit is contained in:
Goffi 2014-06-25 14:01:56 +02:00
commit e002d55880
3 changed files with 60 additions and 16 deletions

View file

@ -46,7 +46,7 @@ class PrimitivusEmptyWidget(xmlui.EmptyWidget, urwid.Text):
class PrimitivusTextWidget(xmlui.TextWidget, urwid.Text):
def __init__(self, parent, value):
def __init__(self, parent, value, read_only=False):
urwid.Text.__init__(self, value)
@ -82,8 +82,14 @@ class PrimitivusDividerWidget(xmlui.DividerWidget, urwid.Divider):
class PrimitivusStringWidget(xmlui.StringWidget, sat_widgets.AdvancedEdit, PrimitivusEvents):
def __init__(self, parent, value):
def __init__(self, parent, value, read_only=False):
sat_widgets.AdvancedEdit.__init__(self, edit_text=value)
self.read_only = read_only
def selectable(self):
if self.read_only:
return False
return super(PrimitivusStringWidget, self).selectable()
def _xmluiSetValue(self, value):
self.set_edit_text(value)
@ -94,8 +100,14 @@ class PrimitivusStringWidget(xmlui.StringWidget, sat_widgets.AdvancedEdit, Primi
class PrimitivusPasswordWidget(xmlui.PasswordWidget, sat_widgets.Password, PrimitivusEvents):
def __init__(self, parent, value):
def __init__(self, parent, value, read_only=False):
sat_widgets.Password.__init__(self, edit_text=value)
self.read_only = read_only
def selectable(self):
if self.read_only:
return False
return super(PrimitivusPasswordWidget, self).selectable()
def _xmluiSetValue(self, value):
self.set_edit_text(value)
@ -106,8 +118,14 @@ class PrimitivusPasswordWidget(xmlui.PasswordWidget, sat_widgets.Password, Primi
class PrimitivusTextBoxWidget(xmlui.TextBoxWidget, sat_widgets.AdvancedEdit, PrimitivusEvents):
def __init__(self, parent, value):
def __init__(self, parent, value, read_only=False):
sat_widgets.AdvancedEdit.__init__(self, edit_text=value, multiline=True)
self.read_only = read_only
def selectable(self):
if self.read_only:
return False
return super(PrimitivusTextBoxWidget, self).selectable()
def _xmluiSetValue(self, value):
self.set_edit_text(value)
@ -118,8 +136,14 @@ class PrimitivusTextBoxWidget(xmlui.TextBoxWidget, sat_widgets.AdvancedEdit, Pri
class PrimitivusBoolWidget(xmlui.BoolWidget, urwid.CheckBox, PrimitivusEvents):
def __init__(self, parent, state):
def __init__(self, parent, state, read_only=False):
urwid.CheckBox.__init__(self, '', state=state)
self.read_only = read_only
def selectable(self):
if self.read_only:
return False
return super(PrimitivusBoolWidget, self).selectable()
def _xmluiSetValue(self, value):
self.set_state(value == "true")

View file

@ -191,6 +191,16 @@ class XMLUI(object):
raise ValueError(_("XMLUI can have only one main container"))
self._main_cont = value
def _isAttrSet(self, name, node):
"""Returnw widget boolean attribute status
@param name: name of the attribute (e.g. "read_only")
@param node: Node instance
@return (bool): True if widget's attribute is set ("true")
"""
read_only = node.getAttribute(name) or "false"
return read_only.lower().strip() == "true"
def _parseChilds(self, parent, current_node, wanted = ('container',), data = None):
""" Recursively parse childNodes of an elemen
@param parent: widget container with '_xmluiAppend' method
@ -289,16 +299,16 @@ class XMLUI(object):
style = node.getAttribute("style") or 'line'
ctrl = self.widget_factory.createDividerWidget(parent, style)
elif type_=="string":
ctrl = self.widget_factory.createStringWidget(parent, value)
ctrl = self.widget_factory.createStringWidget(parent, value, self._isAttrSet("read_only", node))
self.ctrl_list[name] = ({'type':type_, 'control':ctrl})
elif type_=="password":
ctrl = self.widget_factory.createPasswordWidget(parent, value)
ctrl = self.widget_factory.createPasswordWidget(parent, value, self._isAttrSet("read_only", node))
self.ctrl_list[name] = ({'type':type_, 'control':ctrl})
elif type_=="textbox":
ctrl = self.widget_factory.createTextBoxWidget(parent, value)
ctrl = self.widget_factory.createTextBoxWidget(parent, value, self._isAttrSet("read_only", node))
self.ctrl_list[name] = ({'type':type_, 'control':ctrl})
elif type_=="bool":
ctrl = self.widget_factory.createBoolWidget(parent, value=='true')
ctrl = self.widget_factory.createBoolWidget(parent, value=='true', self._isAttrSet("read_only", node))
self.ctrl_list[name] = ({'type':type_, 'control':ctrl})
elif type_ == "list":
style = [] if node.getAttribute("multi") == 'yes' else ['single']

View file

@ -82,31 +82,41 @@ class DividerWidget(WixWidget, xmlui.DividerWidget, wx.StaticLine):
class StringWidget(EventWidget, ValueWidget, xmlui.StringWidget, wx.TextCtrl):
_xmlui_change_event = wx.EVT_TEXT
def __init__(self, parent, value):
wx.TextCtrl.__init__(self, parent, -1, value)
def __init__(self, parent, value, read_only=False):
style = wx.TE_READONLY if read_only else 0
wx.TextCtrl.__init__(self, parent, -1, value, style=style)
self._xmlui_proportion = 1
class PasswordWidget(EventWidget, ValueWidget, xmlui.PasswordWidget, wx.TextCtrl):
_xmlui_change_event = wx.EVT_TEXT
def __init__(self, parent, value):
wx.TextCtrl.__init__(self, parent, -1, value, style=wx.TE_PASSWORD)
def __init__(self, parent, value, read_only=False):
style = wx.TE_PASSWORD
if read_only:
style |= wx.TE_READONLY
wx.TextCtrl.__init__(self, parent, -1, value, style=style)
self._xmlui_proportion = 1
class TextBoxWidget(EventWidget, ValueWidget, xmlui.TextBoxWidget, wx.TextCtrl):
_xmlui_change_event = wx.EVT_TEXT
def __init__(self, parent, value):
wx.TextCtrl.__init__(self, parent, -1, value, style=wx.TE_MULTILINE)
def __init__(self, parent, value, read_only=False):
style = wx.TE_MULTILINE
if read_only:
style |= wx.TE_READONLY
wx.TextCtrl.__init__(self, parent, -1, value, style=style)
self._xmlui_proportion = 1
class BoolWidget(EventWidget, ValueWidget, xmlui.BoolWidget, wx.CheckBox):
_xmlui_change_event = wx.EVT_CHECKBOX
def __init__(self, parent, state):
def __init__(self, parent, state, read_only=False):
style = wx.CHK_2STATE
if read_only:
style |= wx.TE_READONLY
wx.CheckBox.__init__(self, parent, -1, "", style=wx.CHK_2STATE)
self.SetValue(state)
self._xmlui_proportion = 1