From 28f10bf1428dc5d1e87517c43f550142f7e8ae01 Mon Sep 17 00:00:00 2001 From: Tomeu Vizoso Date: Thu, 15 Feb 2007 19:18:15 +0100 Subject: [PATCH] OptionMenu fixes and API updates. --- sugar/graphics/entry.py | 4 ++-- sugar/graphics/optionmenu.py | 26 +++++++++++++++++--------- sugar/graphics/toolbar.py | 3 ++- 3 files changed, 21 insertions(+), 12 deletions(-) diff --git a/sugar/graphics/entry.py b/sugar/graphics/entry.py index fcaa3c59..8a799400 100644 --- a/sugar/graphics/entry.py +++ b/sugar/graphics/entry.py @@ -46,14 +46,14 @@ class Entry(hippo.CanvasBox, hippo.CanvasItem): self._buttons = {} self._round_box = RoundBox() - self._round_box.props.border_color = Color.FRAME_BORDER.get_int() + self._round_box.props.border_color = color.FRAME_BORDER.get_int() self.append(self._round_box, hippo.PACK_EXPAND) self._entry = self.create_entry() self._entry.props.has_frame = False self._update_colors(focused=False) self._entry.modify_text(gtk.STATE_SELECTED, - Color.BLACK.get_gdk_color()) + color.BLACK.get_gdk_color()) self._entry.connect('focus-in-event', self._entry_focus_in_event_cb) self._entry.connect('focus-out-event', self._entry_focus_out_event_cb) self._entry.connect('activate', self._entry_activate_cb) diff --git a/sugar/graphics/optionmenu.py b/sugar/graphics/optionmenu.py index 72ea678c..11179dbb 100644 --- a/sugar/graphics/optionmenu.py +++ b/sugar/graphics/optionmenu.py @@ -33,7 +33,7 @@ class Menu(hippo.CanvasBox, hippo.CanvasItem): __gtype_name__ = 'SugarMenu' __gsignals__ = { - 'action': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE, ([int])) + 'action': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE, ([object])) } def __init__(self): @@ -60,7 +60,8 @@ class Menu(hippo.CanvasBox, hippo.CanvasItem): canvas_text.props.font_desc = font.DEFAULT.get_pango_desc() box.append(canvas_text) - box.connect('button-press-event', self._button_press_event_cb, action_id) + box.connect('button-press-event', self._button_press_event_cb, + [action_id, label]) self.append(box) def add_separator(self): @@ -81,8 +82,8 @@ class Menu(hippo.CanvasBox, hippo.CanvasItem): self._window.destroy() self._window = None - def _button_press_event_cb(self, item, event, option_id): - self.emit('action', option_id) + def _button_press_event_cb(self, item, event, data): + self.emit('action', data) self.hide() def is_visible(self): @@ -119,12 +120,13 @@ class OptionMenu(hippo.CanvasBox, hippo.CanvasItem): button.props.scale = style.small_icon_scale button.props.yalign = hippo.ALIGNMENT_CENTER button.props.xalign = hippo.ALIGNMENT_START - button.connect('activated', self._button_activated_cb) self._round_box.append(button) self._menu = Menu() self._menu.connect('action', self._menu_action_cb) + self.connect('button-press-event', self._button_press_event_cb) + def do_set_property(self, pspec, value): if pspec.name == 'value': self._value = value @@ -134,12 +136,16 @@ class OptionMenu(hippo.CanvasBox, hippo.CanvasItem): return self._value def add_option(self, action_id, label, icon_name=None, icon_color=None): + if not self._value: + self._value = action_id + self._canvas_text.props.text = label + self._menu.add_item(action_id, label, icon_name, icon_color) def add_separator(self): self._menu.add_separator() - def _button_activated_cb(self, button): + def _button_press_event_cb(self, box, event): if self._menu.is_visible(): self._menu.hide() else: @@ -149,7 +155,9 @@ class OptionMenu(hippo.CanvasBox, hippo.CanvasItem): self._menu.props.box_width = self.get_width_request() self._menu.show(x, y + height) - def _menu_action_cb(self, menu, option_id): - if option_id != self._value: - self._value = option_id + def _menu_action_cb(self, menu, data): + [action_id, label] = data + if action_id != self._value: + self._value = action_id + self._canvas_text.props.text = label self.emit('changed') diff --git a/sugar/graphics/toolbar.py b/sugar/graphics/toolbar.py index 5cd0f65d..56e50e31 100644 --- a/sugar/graphics/toolbar.py +++ b/sugar/graphics/toolbar.py @@ -6,4 +6,5 @@ class Toolbar(hippo.CanvasBox): def __init__(self, orientation=hippo.ORIENTATION_HORIZONTAL): hippo.CanvasBox.__init__(self, orientation=orientation, - background_color=0x414141ff) + background_color=0x414141ff, + spacing=15)