Use button_press virtual method instead of the connect_after hacks.

This commit is contained in:
Marco Pesenti Gritti 2007-03-09 13:12:52 +01:00
parent 2d9a06ec9a
commit 66e341c58e
3 changed files with 7 additions and 13 deletions

View File

@ -176,7 +176,6 @@ class CanvasIcon(hippo.CanvasBox, hippo.CanvasItem):
hippo.CanvasBox.__init__(self, **kwargs) hippo.CanvasBox.__init__(self, **kwargs)
self.connect_after('button-press-event', self._button_press_event_cb)
self.connect_after('motion-notify-event', self._motion_notify_event_cb) self.connect_after('motion-notify-event', self._motion_notify_event_cb)
def _clear_buffers(self): def _clear_buffers(self):
@ -326,9 +325,9 @@ class CanvasIcon(hippo.CanvasBox, hippo.CanvasItem):
[width, height] = self._get_icon_size() [width, height] = self._get_icon_size()
return height return height
def _button_press_event_cb(self, item, event): def do_button_press_event(self, event):
item.emit_activated() item.emit_activated()
return False return True
def get_popup(self): def get_popup(self):
if self._tooltip: if self._tooltip:

View File

@ -27,7 +27,7 @@ from sugar.graphics import color
STANDARD_SIZE = 0 STANDARD_SIZE = 0
SMALL_SIZE = 1 SMALL_SIZE = 1
class IconButton(CanvasIcon): class IconButton(CanvasIcon, hippo.CanvasItem):
__gtype_name__ = 'SugarIconButton' __gtype_name__ = 'SugarIconButton'
__gproperties__ = { __gproperties__ = {
@ -45,9 +45,6 @@ class IconButton(CanvasIcon):
self._set_size(STANDARD_SIZE) self._set_size(STANDARD_SIZE)
self.connect_after('button-press-event',
self._icon_button_button_press_event_cb)
def _set_size(self, size): def _set_size(self, size):
if size == SMALL_SIZE: if size == SMALL_SIZE:
self.props.box_width = -1 self.props.box_width = -1
@ -72,7 +69,7 @@ class IconButton(CanvasIcon):
else: else:
return CanvasIcon.do_get_property(self, pspec) return CanvasIcon.do_get_property(self, pspec)
def _icon_button_button_press_event_cb(self, widget, event): def do_button_press_event(self, event):
if self._active: if self._active:
self.emit_activated() self.emit_activated()
return True return True

View File

@ -16,11 +16,12 @@
# Boston, MA 02111-1307, USA. # Boston, MA 02111-1307, USA.
import gobject import gobject
import hippo
from sugar.graphics.iconbutton import IconButton from sugar.graphics.iconbutton import IconButton
from sugar.graphics import color from sugar.graphics import color
class ToggleIconButton(IconButton): class ToggleIconButton(IconButton, hippo.CanvasItem):
__gtype_name__ = 'SugarToggleIconButton' __gtype_name__ = 'SugarToggleIconButton'
__gproperties__ = { __gproperties__ = {
@ -33,9 +34,6 @@ class ToggleIconButton(IconButton):
IconButton.__init__(self, **kwargs) IconButton.__init__(self, **kwargs)
self.connect('button-press-event',
self._toggle_icon_button_press_event_cb)
def _get_bg_color(self): def _get_bg_color(self):
if self._toggled: if self._toggled:
col = color.TOGGLE_BUTTON_BACKGROUND col = color.TOGGLE_BUTTON_BACKGROUND
@ -60,7 +58,7 @@ class ToggleIconButton(IconButton):
return IconButton.do_get_property(self, pspec) return IconButton.do_get_property(self, pspec)
def _toggle_icon_button_press_event_cb(self, widget, event): def do_button_press_event(self, event):
self.props.toggled = not self._toggled self.props.toggled = not self._toggled
return True return True