Refine code.
authorHuang Peng <shawn.p.huang@gmail.com>
Tue, 19 Aug 2008 00:44:23 +0000 (08:44 +0800)
committerHuang Peng <shawn.p.huang@gmail.com>
Tue, 19 Aug 2008 00:44:23 +0000 (08:44 +0800)
ibus/property.py

index 7b43c07..1f8e3f9 100644 (file)
@@ -49,105 +49,121 @@ PROP_STATE_INCONSISTENT = 2
 class Property(object):
     def __init__(self, name,
                         type = PROP_TYPE_NORMAL,
-                        label = "",
-                        icon = "",
-                        tooltip = "",
+                        label = u"",
+                        icon = u"",
+                        tooltip = u"",
                         sensitive = True,
                         visible = True,
                         state = PROP_STATE_UNCHECKED):
         super(Property, self).__init__()
-        self._name = name
-        self._type = type
-        self._label = label
-        self._icon = icon
-        self._tooltip = tooltip
-        self._sensitive = sensitive
-        self._visible = visible
-        self._state = state
-        self._sub_props = PropList()
+        self.__name = name
+        self.__type = type
+        self.label = label
+        self.icon = icon
+        self.tooltip = tooltip
+        self.sensitive = sensitive
+        self.visible = visible
+        self.state = state
+        self.sub_props = PropList()
 
     def set_sub_props(self, props):
-        self._sub_props = props
+        self.__sub_props = props
 
     def get_sub_props(self):
-        return self._sub_props
+        return self.__sub_props
 
     def get_name(self):
-        return self._name
+        return self.__name
 
     def get_type(self):
-        return self._type
+        return self.__type
 
     def set_label(self, label):
-        self._label = label
+        self.__label = label
 
     def get_label(self):
-        return self._label
+        return self.__label
+
+    def set_icon(self, icon):
+        self.__icon = icon
+
+    def get_icon(self):
+        return self.__icon
 
     def set_tooltip(self, tooltip):
-        self._tooltip = tooltip
+        self.__tooltip = tooltip
 
     def get_tooltip(self):
-        return self._tooltip
+        return self.__tooltip
 
     def set_state(self, state):
-        self._state = state
+        self.__state = state
 
     def get_state(self):
-        return self._state
+        return self.__state
 
     def set_sensitive(self, sensitive):
-        self._sensitive = sensitive
+        self.__sensitive = sensitive
 
     def get_sensitive(self):
-        return self._sensitive
+        return self.__sensitive
 
     def set_visible(self, visible):
-        self._visible = visible
+        self.__visible = visible
 
     def get_visible(self):
-        return self._visible
+        return self.__visible
+
+    name        = property(get_name)
+    type        = property(get_type)
+    label       = property(get_label, set_label)
+    icon        = property(get_icon, set_icon)
+    tooltip     = property(get_tooltip, set_tooltip)
+    state       = property(get_state, set_state)
+    sensitive   = property(get_sensitive, set_sensitive)
+    visible     = property(get_visible, set_visible)
+    sub_props   = property(get_sub_props, set_sub_props)
 
     def is_same(self, prop, test_all = True):
-        if self._name != prop._name or self._type != prop._type:
+        if self.__name != prop.__name or self.__type != prop.__type:
             return False
         if not test_all:
             return True
-        if self._label != prop._label or \
-            self._icon != prop._icon or \
-            self._tooltip != prop._tooltip or \
-            self._sensitive != prop._sensitive or \
-            self._visible != prop._visible or \
-            self._state != prop._state:
+        if self.__label != prop.__label or \
+            self.__icon != prop.__icon or \
+            self.__tooltip != prop.__tooltip or \
+            self.__sensitive != prop.__sensitive or \
+            self.__visible != prop.__visible or \
+            self.__state != prop.__state:
             return False
-        return self._sub_props.is_same(prop._sub_props, test_all)
+        return self.__sub_props.is_same(prop.__sub_props, test_all)
 
 
     def to_dbus_value(self):
-        sub_props = self._sub_props.to_dbus_value()
-        values = (dbus.String(self._name),
-                dbus.Int32(self._type),
-                dbus.String(self._label),
-                dbus.String(self._icon),
-                dbus.String(self._tooltip),
-                dbus.Boolean(self._sensitive),
-                dbus.Boolean(self._visible),
-                dbus.Int32(self._state),
+        sub_props = self.__sub_props.to_dbus_value()
+        values = (dbus.String(self.__name),
+                dbus.Int32(self.__type),
+                dbus.String(self.__label),
+                dbus.String(self.__icon),
+                dbus.String(self.__tooltip),
+                dbus.Boolean(self.__sensitive),
+                dbus.Boolean(self.__visible),
+                dbus.Int32(self.__state),
                 sub_props)
         return dbus.Struct(values)
 
     def from_dbus_value(self, value):
-        self._name, \
-        self._type, \
-        self._label, \
-        self._icon, \
-        self._tooltip, \
-        self._sensitive, \
-        self._visible, \
-        self._state, \
+        self.__name, \
+        self.__type, \
+        self.__label, \
+        self.__icon, \
+        self.__tooltip, \
+        self.__sensitive, \
+        self.__visible, \
+        self.__state, \
         props = value
 
-        self._sub_props = prop_list_from_dbus_value(props)
+        self.__sub_props = prop_list_from_dbus_value(props)
 
 def property_from_dbus_value(value):
     p = Property("")
@@ -157,19 +173,19 @@ def property_from_dbus_value(value):
 class PropList(object):
     def __init__(self):
         super(PropList, self).__init__()
-        self._props = []
+        self.__props = []
 
     def append(self, prop):
-        self._props.append(prop)
+        self.__props.append(prop)
 
     def prepand(self, prop):
-        self._props.insert(0, prop)
+        self.__props.insert(0, prop)
 
     def insert(self, index, prop):
-        self._props.insert(index, prop)
+        self.__props.insert(index, prop)
 
     def get_properties(self):
-        return self._props[:]
+        return self.__props[:]
 
     def is_same(self, props, test_all = True):
         if len(props.get_properties()) != len(self.get_properties()):
@@ -181,20 +197,20 @@ class PropList(object):
         return False
 
     def to_dbus_value(self):
-        props = map(lambda p: p.to_dbus_value(), self._props)
+        props = map(lambda p: p.to_dbus_value(), self.__props)
         return dbus.Array(props, signature = "v")
 
     def from_dbus_value(self, value):
         props = []
         for p in value:
             props.append(property_from_dbus_value(p))
-        self._props = props
+        self.__props = props
 
     def __iter__(self):
-        return self._props.__iter__()
+        return self.__props.__iter__()
 
     def __getitem__(self, i):
-        return self._props.__getitem__(i)
+        return self.__props.__getitem__(i)
 
 def prop_list_from_dbus_value(value):
     props = PropList()
@@ -203,14 +219,14 @@ def prop_list_from_dbus_value(value):
 
 def test():
     props = PropList()
-    props.append(Property("a"))
-    props.append(Property("b"))
-    props.append(Property("c"))
-    props.append(Property("d"))
+    props.append(Property(u"a"))
+    props.append(Property(u"b"))
+    props.append(Property(u"c"))
+    props.append(Property(u"d"))
     value = props.to_dbus_value()
     print prop_list_from_dbus_value(value)
 
-    p = Property("z")
+    p = Property(u"z")
     p.set_sub_props(props)
     props = PropList()
     props.append(p)