5 # Copyright (c) 2007-2008 Huang Peng <shawn.p.huang@gmail.com>
7 # This library is free software; you can redistribute it and/or
8 # modify it under the terms of the GNU Lesser General Public
9 # License as published by the Free Software Foundation; either
10 # version 2 of the License, or (at your option) any later version.
12 # This library is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU Lesser General Public License for more details.
17 # You should have received a copy of the GNU Lesser General Public
18 # License along with this program; if not, write to the
19 # Free Software Foundation, Inc., 59 Temple Place, Suite 330,
20 # Boston, MA 02111-1307 USA
26 "PROP_TYPE_SEPARATOR",
28 "PROP_STATE_UNCHECKED",
30 "PROP_STATE_INCONSISTENT",
33 "property_from_dbus_value",
34 "prop_list_from_dbus_value",
43 PROP_TYPE_SEPARATOR
= 4
45 PROP_STATE_UNCHECKED
= 0
46 PROP_STATE_CHECKED
= 1
47 PROP_STATE_INCONSISTENT
= 2
50 def __init__ (self
, name
,
51 type = PROP_TYPE_NORMAL
,
57 state
= PROP_STATE_UNCHECKED
):
62 self
._tooltip
= tooltip
63 self
._sensitive
= sensitive
64 self
._visible
= visible
66 self
._sub
_props
= PropList ()
68 def set_sub_props (self
, props
):
69 self
._sub
_props
= props
71 def get_sub_props (self
):
72 return self
._sub
_props
74 def is_same (self
, prop
, test_all
= True):
75 if self
._name
!= prop
._name
or self
._type
!= prop
._type
:
79 if self
._label
!= prop
._label
or \
80 self
._icon
!= prop
._icon
or \
81 self
._tooltip
!= prop
._tooltip
or \
82 self
._sensitive
!= prop
._sensitive
or \
83 self
._visible
!= prop
._visible
or \
84 self
._state
!= prop
._state
:
86 return self
._sub
_props
.is_same (prop
._sub
_props
, test_all
)
89 def to_dbus_value (self
):
90 sub_props
= self
._sub
_props
.to_dbus_value ()
91 values
= (dbus
.String (self
._name
),
92 dbus
.Int32 (self
._type
),
93 dbus
.String (self
._label
),
94 dbus
.String (self
._icon
),
95 dbus
.String (self
._tooltip
),
96 dbus
.Boolean (self
._sensitive
),
97 dbus
.Boolean (self
._visible
),
98 dbus
.Int32 (self
._state
),
100 return dbus
.Struct (values
)
102 def from_dbus_value (self
, value
):
113 self
._sub
_props
= prop_list_from_dbus_value (props
)
115 def property_from_dbus_value (value
):
117 p
.from_dbus_value (value
)
124 def append (self
, prop
):
125 self
._props
.append (prop
)
127 def prepand (self
, prop
):
128 self
._props
.insert (0, prop
)
130 def insert (self
, index
, prop
):
131 self
._props
.insert (index
, prop
)
133 def get_properties (self
):
134 return self
._props
[:]
136 def is_same (self
, props
, test_all
= True):
137 if len (props
.get_properties ()) != len (self
.get_properties ()):
140 for a
, b
in zip (self
.get_properties(), props
.get_properties ()):
141 if not a
.is_same (b
, test_all
):
145 def to_dbus_value (self
):
146 props
= map (lambda p
: p
.to_dbus_value (), self
._props
)
147 return dbus
.Array (props
, signature
= "v")
149 def from_dbus_value (self
, value
):
152 props
.append (property_from_dbus_value (p
))
156 return self
._props
.__iter
__ ()
158 def prop_list_from_dbus_value (value
):
160 props
.from_dbus_value (value
)
165 props
.append (Property ("a"))
166 props
.append (Property ("b"))
167 props
.append (Property ("c"))
168 props
.append (Property ("d"))
169 value
= props
.to_dbus_value ()
170 print prop_list_from_dbus_value (value
)
173 p
.set_sub_props (props
)
176 value
= props
.to_dbus_value ()
177 print prop_list_from_dbus_value (value
)
179 if __name__
== "__main__":