From 7a0d5d93984003d9d5964f593886dc6dee6dfb39 Mon Sep 17 00:00:00 2001 From: Simon Schampijer Date: Mon, 20 Jun 2011 17:48:51 +0200 Subject: [PATCH] Use 'focus-out' event instead of 'changed' event for title entry OLPC #10956, SL #2608 To determine if the title has changed we use the 'focus-out' event now instead of the 'changed' signal of the gtk.Entry. This removes races we had before. Signed-off-by: Daniel Drake Acked-By: Simon Schampijer Acked-By: Sascha Silbe --- src/sugar/activity/activity.py | 5 +++++ src/sugar/activity/widgets.py | 28 ++++++++++++++++------------ 2 files changed, 21 insertions(+), 12 deletions(-) diff --git a/src/sugar/activity/activity.py b/src/sugar/activity/activity.py index 31827da0..443799af 100644 --- a/src/sugar/activity/activity.py +++ b/src/sugar/activity/activity.py @@ -223,6 +223,9 @@ class Activity(Window, gtk.Container): __gsignals__ = { 'shared': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE, ([])), 'joined': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE, ([])), + # For internal use only, use can_close() if you want to perform extra + # checks before actually closing + '_closing': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE, ([])), } def __init__(self, handle, create_jobject=True): @@ -863,6 +866,8 @@ class Activity(Window, gtk.Container): if not self.can_close(): return + self.emit('_closing') + if skip_save or self._jobject is None or \ self.metadata.get('title_set_by_user', '0') == '1': if not self._closing: diff --git a/src/sugar/activity/widgets.py b/src/sugar/activity/widgets.py index 7166d3e2..e7a47cbc 100644 --- a/src/sugar/activity/widgets.py +++ b/src/sugar/activity/widgets.py @@ -16,7 +16,6 @@ # Boston, MA 02111-1307, USA. import gtk -import gobject import gettext import gconf @@ -186,32 +185,40 @@ class TitleEntry(gtk.ToolItem): def __init__(self, activity, **kwargs): gtk.ToolItem.__init__(self) self.set_expand(False) - self._update_title_sid = None self.entry = gtk.Entry(**kwargs) self.entry.set_size_request(int(gtk.gdk.screen_width() / 3), -1) self.entry.set_text(activity.metadata['title']) - self.entry.connect('changed', self.__title_changed_cb, activity) + self.entry.connect('focus-out-event', self.__title_changed_cb, activity) self.entry.show() self.add(self.entry) activity.metadata.connect('updated', self.__jobject_updated_cb) + activity.connect('_closing', self.__closing_cb) def modify_bg(self, state, color): gtk.ToolItem.modify_bg(self, state, color) self.entry.modify_bg(state, color) def __jobject_updated_cb(self, jobject): + if self.entry.flags() & gtk.HAS_FOCUS: + return + if self.entry.get_text() == jobject['title']: + return self.entry.set_text(jobject['title']) - def __title_changed_cb(self, entry, activity): - if self._update_title_sid is not None: - gobject.source_remove(self._update_title_sid) - self._update_title_sid = gobject.timeout_add_seconds( - 1, self.__update_title_cb, activity) + def __closing_cb(self, activity): + self.save_title(activity) + return False - def __update_title_cb(self, activity): + def __title_changed_cb(self, editable, event, activity): + self.save_title(activity) + return False + + def save_title(self, activity): title = self.entry.get_text() + if title == activity.metadata['title']: + return activity.metadata['title'] = title activity.metadata['title_set_by_user'] = '1' @@ -221,9 +228,6 @@ class TitleEntry(gtk.ToolItem): if shared_activity is not None: shared_activity.props.name = title - self._update_title_sid = None - return False - class ActivityToolbar(gtk.Toolbar): """The Activity toolbar with the Journal entry title, sharing,