3 ATTR_TYPE_UNDERLINE
= 1
4 ATTR_TYPE_FOREGROUND
= 2
5 ATTR_TYPE_BACKGROUND
= 3
8 def __init__ (self
, type, value
, start_index
, end_index
):
11 self
._start
_index
= start_index
12 self
._end
_index
= end_index
14 def to_dbus_value (self
):
15 values
= [dbus
.UInt32 (self
._type
),
16 dbus
.UInt32 (self
._value
),
17 dbus
.UInt32 (self
._start
_index
),
18 dbus
.UInt32 (self
._end
_index
)]
19 return dbus
.Array (values
, signature
="u")
21 def from_dbus_value (self
, value
):
22 if not isinstance (value
, dbus
.Array
):
23 raise dbus
.Exception ("Attribute must be dbus.Array (uuuu)")
25 if len (value
) != 4 or not all (map (lambda x
: isinstance (x
, dbus
.UInt32
), value
)):
26 raise dbus
.Exception ("Attribute must be dbus.Array (uuuu)")
29 self
._value
= value
[1]
30 self
._start
_index
= value
[2]
31 self
._end
_index
= value
[3]
33 def attribute_from_dbus_value (value
):
34 attribute
= Attribute (0, 0, 0, 0)
35 attribute
.from_dbus_value (value
)
38 class AttributeUnderline (Attribute
):
39 def __init__(self
, value
, start_index
, end_index
):
40 Attribute
.__init
__ (self
, ATTR_TYPE_UNDERLINE
, value
, start_index
, end_index
)
42 class AttributeForeground (Attribute
):
43 def __init__(self
, value
, start_index
, end_index
):
44 Attribute
.__init
__ (self
, ATTR_TYPE_FOREGROUND
, value
, start_index
, end_index
)
46 class AttributeBackground (Attribute
):
47 def __init__(self
, value
, start_index
, end_index
):
48 Attribute
.__init
__ (self
, ATTR_TYPE_BACKGROUND
, value
, start_index
, end_index
)
50 def ARGB (a
, r
, g
, b
):
51 return ((a
& 0xff)<<24) + ((r
& 0xff) << 16) + ((g
& 0xff) << 8) + (b
& 0xff)
54 return ARGB (255, r
, g
, b
)
57 def __init__ (self
, attrs
= []):
62 def append (self
, attr
):
63 assert isinstance (attr
, Attribute
)
64 self
._attrs
.append (attr
)
66 def to_dbus_value (self
):
67 array
= dbus
.Array (signature
= "v")
68 for attr
in self
._attrs
:
69 array
.append (attr
.to_dbus_value ())
72 def from_dbus_value (self
, value
):
74 if not isinstance (value
, dbus
.Array
):
75 raise IBusException ("AttrList must from dbus.Array (uuuu)")
78 attr
= attribute_from_dbus_value (v
)
84 return self
._attrs
.__iter
__ ()
86 def attr_list_from_dbus_value (value
):
88 attrs
.from_dbus_value (value
)