2
# -*- coding: utf-8 -*-
6
__authors__ = ["Jan Jokela <janjokela@gmail.com>"]
7
__licenses__ = ["LICENSE.LGPL"]
8
__description__ = "Base class for widgets"
13
from theme import Theme
14
from style import Style
16
STATE_NORMAL = 'STATE_NORMAL'
17
STATE_HIGHLIGHT = 'STATE_HIGHLIGHT'
18
STATE_ACTIVE = 'STATE_ACTIVE'
19
STATE_SELECTED = 'STATE_SELECTED'
20
STATE_INSENSITIVE = 'STATE_INSENSITIVE'
22
class Widget(clutter.Group):
24
Base class for Glitter widgets.
26
A widget inherits from a clutter group actor, which means each and every
27
widget can have children added or removed, working as a scenegraph.
28
Moreover, all the remaining underlying clutter API is exposed.
30
The widget object also holds widget specific properties like current state
37
'state-changed': (gobject.SIGNAL_RUN_LAST,
39
(gobject.TYPE_PYOBJECT,)),
40
'style-changed': (gobject.SIGNAL_RUN_LAST,
42
(gobject.TYPE_PYOBJECT,))
46
""" Initialize widget """
48
super(Widget, self).__init__()
50
self._state = STATE_NORMAL
56
def _init_style(self):
57
""" Initialize widget style """
59
theme = Theme.get_default()
63
# Widget styles are a merge of the respective state styles for the
64
# widget and all its subclasses
66
while issubclass(base, Widget):
67
module_name = base.__name__
68
for state in (STATE_NORMAL, STATE_HIGHLIGHT, STATE_ACTIVE,
69
STATE_SELECTED, STATE_INSENSITIVE):
70
style = theme.get_style(module_name, state)
71
if state in self._styles and style:
72
self._styles[state] = self._styles[state].merge(style)
74
#self._styles[state] = style
75
if state != STATE_NORMAL:
76
self._styles[state] = self._styles[STATE_NORMAL].merge(style)
78
self._styles[state] = style
81
self._style = self._styles[self.state]
83
def _update_style(self, props=None):
84
""" Metaclass for style updates """
89
""" Retrieve widget state """
93
def set_state(self, state):
94
""" Sets the state for the widget and emits a 'state-changed' signal
97
state -- enum(STATE_NORMAL, STATE_HIGHLIGHT, STATE_ACTIVE,
98
STATE_SELECTED, STATE_INSENSITIVE)
101
if self._state != state:
103
self.emit('state-changed', state)
105
state = property(get_state, set_state)
108
""" Retrieve widget style """
112
def set_style(self, style):
113
""" Sets the style for the widget and emits a 'style-changed' signal
116
style -- (glitter.Style)
119
if self._style != style:
121
self.emit('style-changed', style)
123
style = property(get_style, set_style)
125
def do_state_changed(self, previous_state):
126
""" Widget state changed """
128
self.style = self._styles[self.state]
130
def do_style_changed(self, previous_style):
131
""" Widget style changed """
133
self._update_style(self.style)