Popdown when the toplevel of the parent item loses focus.

This commit is contained in:
Tomeu Vizoso 2007-07-09 14:26:41 +02:00
parent 8b72656ca4
commit a4f4d969fe
3 changed files with 47 additions and 23 deletions

View File

@ -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)

View File

@ -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,

View File

@ -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'