[Pkg-sugar-commit] [sugar-toolkit] 01/04: Use 'focus-out' event instead of 'changed' event for title entry OLPC #10956, SL #2608
Jonas Smedegaard
dr at jones.dk
Thu Apr 16 18:52:34 UTC 2015
This is an automated email from the git hooks/post-receive script.
js pushed a commit to tag v0.92.3
in repository sugar-toolkit.
commit 746325106fb96fb9a4ad8fb45210dc1a60110ae8
Author: Simon Schampijer <simon at schampijer.de>
Date: Mon Jun 20 17:48:51 2011 +0200
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 <dsd at laptop.org>
Acked-By: Simon Schampijer <simon at laptop.org>
Acked-By: Sascha Silbe <silbe at activitycentral.com>
---
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 31827da..443799a 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 7166d3e..e7a47cb 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 __title_changed_cb(self, editable, event, activity):
+ self.save_title(activity)
+ return False
- def __update_title_cb(self, activity):
+ 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,
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-sugar/sugar-toolkit.git
More information about the pkg-sugar-commit
mailing list