Port a few widgets to use new style properties.

This commit is contained in:
Marco Pesenti Gritti 2008-08-11 01:10:02 +02:00
parent 80190bf944
commit 204e4f233a
3 changed files with 67 additions and 75 deletions

View File

@ -425,13 +425,6 @@ class Activity(Window, gtk.Container):
'joined': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE, ([])) 'joined': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE, ([]))
} }
__gproperties__ = {
'active' : (bool, None, None, False,
gobject.PARAM_READWRITE),
'max-participants': (int, None, None, 0, 1000, 0,
gobject.PARAM_READWRITE)
}
def __init__(self, handle, create_jobject=True): def __init__(self, handle, create_jobject=True):
"""Initialise the Activity """Initialise the Activity
@ -570,24 +563,27 @@ class Activity(Window, gtk.Container):
# https://dev.laptop.org/ticket/3071 # https://dev.laptop.org/ticket/3071
datastore.write(self._jobject) datastore.write(self._jobject)
def do_set_property(self, pspec, value): def get_active(self):
if pspec.name == 'active': return self._active
if self._active != value:
self._active = value
if not self._active and self._jobject:
self.save()
elif pspec.name == 'max-participants':
self._max_participants = value
else:
Window.do_set_property(self, pspec, value)
def do_get_property(self, pspec): def set_active(self, active):
if pspec.name == 'active': if self._active != active:
return self._active self._active = active
elif pspec.name == 'max-participants': if not self._active and self._jobject:
return self._max_participants self.save()
else:
return Window.do_get_property(self, pspec) active = gobject.property(
type=bool, default=False, getter=get_active, setter=set_active)
def get_max_participants(self):
return self._max_participants
def set_max_participants(self, participants):
self._max_participants = participants
max_participants = gobject.property(
type=int, default=0, getter=get_max_participants,
setter=set_max_participants)
def get_id(self): def get_id(self):
"""Returns the activity id of the current instance of your activity. """Returns the activity id of the current instance of your activity.

View File

@ -21,10 +21,6 @@ import gtk
class ComboBox(gtk.ComboBox): class ComboBox(gtk.ComboBox):
__gtype_name__ = 'SugarComboBox' __gtype_name__ = 'SugarComboBox'
__gproperties__ = {
'value' : (object, None, None,
gobject.PARAM_READABLE)
}
def __init__(self): def __init__(self):
gtk.ComboBox.__init__(self) gtk.ComboBox.__init__(self)
@ -39,14 +35,14 @@ class ComboBox(gtk.ComboBox):
self.set_row_separator_func(self._is_separator) self.set_row_separator_func(self._is_separator)
def do_get_property(self, pspec): def get_value(self):
if pspec.name == 'value': row = self.get_active_item()
row = self.get_active_item() if not row:
if not row: return None
return None return row[0]
return row[0]
else: value = gobject.property(
return gtk.ComboBox.do_get_property(self, pspec) type=object, getter=get_value, setter=None)
def _get_real_name_from_theme(self, name, size): def _get_real_name_from_theme(self, name, size):
icon_theme = gtk.icon_theme_get_default() icon_theme = gtk.icon_theme_get_default()

View File

@ -293,17 +293,6 @@ class _IconBuffer(object):
class Icon(gtk.Image): class Icon(gtk.Image):
__gtype_name__ = 'SugarIcon' __gtype_name__ = 'SugarIcon'
__gproperties__ = {
'xo-color' : (object, None, None,
gobject.PARAM_WRITABLE),
'fill-color' : (object, None, None,
gobject.PARAM_READWRITE),
'stroke-color' : (object, None, None,
gobject.PARAM_READWRITE),
'badge-name' : (str, None, None, None,
gobject.PARAM_READWRITE)
}
def __init__(self, **kwargs): def __init__(self, **kwargs):
self._buffer = _IconBuffer() self._buffer = _IconBuffer()
@ -368,35 +357,46 @@ class Icon(gtk.Image):
cr.set_source_surface(surface, x, y) cr.set_source_surface(surface, x, y)
cr.paint() cr.paint()
def do_set_property(self, pspec, value): def set_xo_color(self, value):
if pspec.name == 'xo-color': if self._buffer.xo_color != value:
if self._buffer.xo_color != value: self._buffer.xo_color = value
self._buffer.xo_color = value self.queue_draw()
self.queue_draw()
elif pspec.name == 'fill-color':
if self._buffer.fill_color != value:
self._buffer.fill_color = value
self.queue_draw()
elif pspec.name == 'stroke-color':
if self._buffer.stroke_color != value:
self._buffer.stroke_color = value
self.queue_draw()
elif pspec.name == 'badge-name':
if self._buffer.badge_name != value:
self._buffer.badge_name = value
self.queue_resize()
else:
gtk.Image.do_set_property(self, pspec, value)
def do_get_property(self, pspec): xo_color = gobject.property(
if pspec.name == 'fill-color': type=object, getter=None, setter=set_xo_color)
return self._buffer.fill_color
elif pspec.name == 'stroke-color': def set_fill_color(self, value):
return self._buffer.stroke_color if self._buffer.fill_color != value:
elif pspec.name == 'badge-name': self._buffer.fill_color = value
return self._buffer.badge_name self.queue_draw()
else:
return gtk.Image.do_get_property(self, pspec) def get_fill_color(self):
return self._buffer.fill_color
fill_color = gobject.property(
type=object, getter=get_fill_color, setter=set_fill_color)
def set_stroke_color(self, value):
if self._buffer.stroke_color != value:
self._buffer.stroke_color = value
self.queue_draw()
def get_stroke_color(self):
return self._buffer.stroke_color
stroke_color = gobject.property(
type=object, getter=get_stroke_color, setter=set_stroke_color)
def set_badge_name(self, value):
if self._buffer.badge_name != value:
self._buffer.badge_name = value
self.queue_resize()
def get_badge_name(self):
return self._buffer.badge_name
badge_name = gobject.property(
type=str, getter=get_badge_name, setter=set_badge_name)
class CanvasIcon(hippo.CanvasBox, hippo.CanvasItem): class CanvasIcon(hippo.CanvasBox, hippo.CanvasItem):
__gtype_name__ = 'CanvasIcon' __gtype_name__ = 'CanvasIcon'