From a4f4d969fea4787aaecf8cafd1095a412d01a432 Mon Sep 17 00:00:00 2001 From: Tomeu Vizoso Date: Mon, 9 Jul 2007 14:26:41 +0200 Subject: [PATCH 1/2] Popdown when the toplevel of the parent item loses focus. --- sugar/datastore/datastore.py | 11 +++++-- sugar/datastore/dbus_helpers.py | 2 +- sugar/graphics/palette.py | 57 +++++++++++++++++++++------------ 3 files changed, 47 insertions(+), 23 deletions(-) diff --git a/sugar/datastore/datastore.py b/sugar/datastore/datastore.py index 4acfd861..26ea49ea 100644 --- a/sugar/datastore/datastore.py +++ b/sugar/datastore/datastore.py @@ -99,14 +99,21 @@ def create(): def write(ds_object, reply_handler=None, error_handler=None): logging.debug('datastore.write') + + properties = ds_object.metadata.get_dictionary().copy() + # The title property should be sent as a 'text' property so it gets indexed + if properties.has_key('title'): + properties['title:text'] = properties['title'] + del properties['title'] + if ds_object.object_id: dbus_helpers.update(ds_object.object_id, - ds_object.metadata.get_dictionary(), + properties, ds_object.file_path, reply_handler=reply_handler, error_handler=error_handler) else: - ds_object.object_id = dbus_helpers.create(ds_object.metadata.get_dictionary(), + ds_object.object_id = dbus_helpers.create(properties, ds_object.file_path) # TODO: register the object for updates logging.debug('Written object %s to the datastore.' % ds_object.object_id) diff --git a/sugar/datastore/dbus_helpers.py b/sugar/datastore/dbus_helpers.py index 18c20ea7..2ce00909 100644 --- a/sugar/datastore/dbus_helpers.py +++ b/sugar/datastore/dbus_helpers.py @@ -37,7 +37,7 @@ def create(properties, filename): return object_id def update(uid, properties, filename, reply_handler=None, error_handler=None): - logging.debug('dbus_helpers.update: %s, %s' % (uid, filename)) + logging.debug('dbus_helpers.update: %s, %s, %s' % (uid, filename, properties)) if reply_handler and error_handler: _data_store.update(uid, dbus.Dictionary(properties), filename, reply_handler=reply_handler, diff --git a/sugar/graphics/palette.py b/sugar/graphics/palette.py index c241def4..b15f473f 100644 --- a/sugar/graphics/palette.py +++ b/sugar/graphics/palette.py @@ -146,7 +146,9 @@ class Palette(gobject.GObject): def do_set_property(self, pspec, value): if pspec.name == 'invoker': self._invoker = value - self._invoker.add_listener(self) + self._invoker.connect('mouse-enter', self._invoker_mouse_enter_cb) + self._invoker.connect('mouse-leave', self._invoker_mouse_leave_cb) + self._invoker.connect('focus-out', self._invoker_focus_out_cb) elif pspec.name == 'position': self._position = value else: @@ -237,6 +239,8 @@ class Palette(gobject.GObject): if not self._in_screen(x, y): x, y = self._get_position(_TOP_RIGHT) + self._invoker.connect_to_parent() + self._palette_popup_sid = _palette_observer.connect('popup', self._palette_observer_popup_cb) self._menu.popup(x, y) @@ -268,12 +272,15 @@ class Palette(gobject.GObject): else: self._hide() - def invoker_mouse_enter(self): + def _invoker_mouse_enter_cb(self, invoker): self.popup() - def invoker_mouse_leave(self): + def _invoker_mouse_leave_cb(self, invoker): self.popdown() + def _invoker_focus_out_cb(self, invoker): + self._hide() + def _enter_notify_event_cb(self, widget, event): if event.detail == gtk.gdk.NOTIFY_NONLINEAR: self._popdown_anim.stop() @@ -382,26 +389,30 @@ class _PopdownAnimation(animator.Animation): if current == 1.0: self._palette._hide() -class Invoker(object): +class Invoker(gobject.GObject): + __gtype_name__ = 'SugarPaletteInvoker' + + __gsignals__ = { + 'mouse-enter': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE, ([])), + 'mouse-leave': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE, ([])), + 'focus-out': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE, ([])) + } + def __init__(self): - self._listeners = [] - - def add_listener(self, listener): - self._listeners.append(listener) - - def notify_mouse_enter(self): - for listener in self._listeners: - listener.invoker_mouse_enter() - - def notify_mouse_leave(self): - for listener in self._listeners: - listener.invoker_mouse_leave() + gobject.GObject.__init__(self) def get_screen_area(self): width = gtk.gdk.screen_width() height = gtk.gdk.screen_height() return gtk.gdk.Rectangle(0, 0, width, height) + def connect_to_parent(self): + window = self.get_toplevel() + window.connect('focus-out-event', self._window_focus_out_event_cb) + + def _window_focus_out_event_cb(self, widget, event): + self.emit('focus-out') + class WidgetInvoker(Invoker): def __init__(self, widget): Invoker.__init__(self) @@ -422,10 +433,13 @@ class WidgetInvoker(Invoker): return gtk.gdk.Rectangle(x, y, width, height) def _enter_notify_event_cb(self, widget, event): - self.notify_mouse_enter() + self.emit('mouse-enter') def _leave_notify_event_cb(self, widget, event): - self.notify_mouse_leave() + self.emit('mouse-leave') + + def get_toplevel(self): + return self._widget.get_toplevel() class CanvasInvoker(Invoker): def __init__(self, item): @@ -446,12 +460,15 @@ class CanvasInvoker(Invoker): def _motion_notify_event_cb(self, button, event): if event.detail == hippo.MOTION_DETAIL_ENTER: - self.notify_mouse_enter() + self.emit('mouse-enter') elif event.detail == hippo.MOTION_DETAIL_LEAVE: - self.notify_mouse_leave() + self.emit('mouse-leave') return False + def get_toplevel(self): + return hippo.get_canvas_for_item(self._item).get_toplevel() + class _PaletteObserver(gobject.GObject): __gtype_name__ = 'SugarPaletteObserver' From e068a61e99607af041d9287714a858c5ca52c9cd Mon Sep 17 00:00:00 2001 From: Tomeu Vizoso Date: Mon, 9 Jul 2007 14:44:55 +0200 Subject: [PATCH 2/2] Update NEWS. --- NEWS | 2 ++ 1 file changed, 2 insertions(+) diff --git a/NEWS b/NEWS index 5b0e8fcf..260c6108 100644 --- a/NEWS +++ b/NEWS @@ -1,3 +1,5 @@ +* #1872, #1934: Hide palettes when closing activities or switching views. (tomeu) + Snapshot f8cf7ff1ce * Hide palettes when buttons are clicked. (edsiper)