[kupfer: 33/51] kupferui: Update (show preferences etc) to use correct screen



commit b990bcbb3e998568b3e6b7f1bfa7c2834ca4c973
Author: Ulrik Sverdrup <ulrik sverdrup gmail com>
Date:   Mon Mar 28 16:51:47 2011 +0200

    kupferui: Update (show preferences etc) to use correct screen

 kupfer/kupferui.py              |   26 +++++++++++++-------------
 kupfer/obj/special.py           |    2 +-
 kupfer/plugin/core/contents.py  |    6 +++---
 kupfer/plugin/kupfer_plugins.py |    2 +-
 kupfer/ui/browser.py            |   31 ++++++++++++++++++-------------
 5 files changed, 36 insertions(+), 31 deletions(-)
---
diff --git a/kupfer/kupferui.py b/kupfer/kupferui.py
index 947e565..7010020 100644
--- a/kupfer/kupferui.py
+++ b/kupfer/kupferui.py
@@ -5,11 +5,11 @@ import gtk
 
 from kupfer import utils, version
 
-def _get_time(ctx):
-	return ctx.environment.get_timestamp() if ctx else \
+def _get_time(ctxenv):
+	return ctxenv.get_timestamp() if ctxenv else \
 			gtk.get_current_event_time()
 
-def show_help(ctx=None):
+def show_help(ctxenv=None):
 	"""
 	Show Kupfer help pages, if possible
 	"""
@@ -18,7 +18,7 @@ def show_help(ctx=None):
 
 _about_dialog = None
 
-def show_about_dialog(ctx=None):
+def show_about_dialog(ctxenv=None):
 	"""
 	create an about dialog and show it
 	"""
@@ -48,8 +48,8 @@ def show_about_dialog(ctx=None):
 		# do not delete window on close
 		ab.connect("delete-event", lambda *ign: True)
 		_about_dialog = ab
-	if ctx:
-		ctx.environment.present_window(ab)
+	if ctxenv:
+		ctxenv.present_window(ab)
 	else:
 		ab.present()
 
@@ -57,16 +57,16 @@ def _response_callback(dialog, response_id):
 	dialog.hide()
 
 
-def show_preferences(ctx=None):
+def show_preferences(ctxenv):
 	from kupfer.ui import preferences
 	win = preferences.GetPreferencesWindowController()
-	if ctx:
-		win.show_on_screen(ctx.environment.get_timestamp(),
-		                   ctx.environment.get_screen())
+	if ctxenv:
+		win.show_on_screen(ctxenv.get_timestamp(),
+		                   ctxenv.get_screen())
 	else:
-		win.show(_get_time(ctx))
+		win.show(_get_time(ctxenv))
 
-def show_plugin_info(plugin_id, ctx=None):
+def show_plugin_info(plugin_id, ctxenv=None):
 	from kupfer.ui import preferences
 	prefs = preferences.GetPreferencesWindowController()
-	prefs.show_focus_plugin(plugin_id, _get_time(ctx))
+	prefs.show_focus_plugin(plugin_id, _get_time(ctxenv))
diff --git a/kupfer/obj/special.py b/kupfer/obj/special.py
index 3216dee..55ed7c1 100644
--- a/kupfer/obj/special.py
+++ b/kupfer/obj/special.py
@@ -19,7 +19,7 @@ class PleaseConfigureLeaf(RunnableLeaf):
 		return True
 
 	def run(self, ctx):
-		kupferui.show_plugin_info(self.object, ctx)
+		kupferui.show_plugin_info(self.object, ctx.environment)
 
 	def get_icon_name(self):
 		return "preferences-desktop"
diff --git a/kupfer/plugin/core/contents.py b/kupfer/plugin/core/contents.py
index e185f60..87cf651 100644
--- a/kupfer/plugin/core/contents.py
+++ b/kupfer/plugin/core/contents.py
@@ -54,7 +54,7 @@ class About (RunnableLeaf):
 	def wants_context(self):
 		return True
 	def run(self, ctx):
-		kupferui.show_about_dialog(ctx)
+		kupferui.show_about_dialog(ctx.environment)
 	def get_description(self):
 		return _("Show information about Kupfer authors and license")
 	def get_icon_name(self):
@@ -67,7 +67,7 @@ class Help (RunnableLeaf):
 	def wants_context(self):
 		return True
 	def run(self, ctx):
-		kupferui.show_help(ctx)
+		kupferui.show_help(ctx.environment)
 	def get_description(self):
 		return _("Get help with Kupfer")
 	def get_icon_name(self):
@@ -80,7 +80,7 @@ class Preferences (RunnableLeaf):
 	def wants_context(self):
 		return True
 	def run(self, ctx):
-		kupferui.show_preferences(ctx)
+		kupferui.show_preferences(ctx.environment)
 	def get_description(self):
 		return _("Show preferences window for Kupfer")
 	def get_icon_name(self):
diff --git a/kupfer/plugin/kupfer_plugins.py b/kupfer/plugin/kupfer_plugins.py
index 18eaa82..fa972b0 100644
--- a/kupfer/plugin/kupfer_plugins.py
+++ b/kupfer/plugin/kupfer_plugins.py
@@ -24,7 +24,7 @@ class ShowInfo (Action):
 
 	def activate(self, leaf, ctx):
 		plugin_id = leaf.object["name"]
-		kupferui.show_plugin_info(plugin_id, ctx)
+		kupferui.show_plugin_info(plugin_id, ctx.environment)
 
 	def get_description(self):
 		pass
diff --git a/kupfer/ui/browser.py b/kupfer/ui/browser.py
index cba429d..2ea0401 100644
--- a/kupfer/ui/browser.py
+++ b/kupfer/ui/browser.py
@@ -1338,11 +1338,11 @@ class Interface (gobject.GObject):
 		self.data_controller.find_object("qpfer:quit")
 
 	def show_help(self):
-		kupferui.show_help()
+		kupferui.show_help(self._make_gui_ctx())
 		self.emit("launched-action")
 
 	def show_preferences(self):
-		kupferui.show_preferences()
+		kupferui.show_preferences(self._make_gui_ctx())
 		self.emit("launched-action")
 
 	def compose_action(self):
@@ -1491,7 +1491,7 @@ class Interface (gobject.GObject):
 		self.data_controller.browse_down(pane, alternate=alternate)
 
 	def _make_gui_ctx(self):
-		timestamp = uievents.current_event_time()
+		timestamp = gtk.get_current_event_time()
 		return uievents.gui_context_from_widget(timestamp, self._widget)
 
 	def _activate(self, widget, current):
@@ -1784,27 +1784,32 @@ class WindowController (pretty.OutputMixin):
 		menu = gtk.Menu()
 		menu.set_name("kupfer-menu")
 
-		def menu_callback(menuitem, callback):
-			callback()
-			if context_menu:
-				self.put_away()
-			return True
-
 		def submenu_callback(menuitem, callback):
 			callback()
 			return True
 
-		def add_menu_item(icon, callback, label=None):
+		def add_menu_item(icon, callback, label=None, with_ctx=True):
+			def mitem_handler(menuitem, callback):
+				if with_ctx:
+					time = gtk.get_current_event_time()
+					ui_ctx = uievents.gui_context_from_widget(time, menuitem)
+					callback(ui_ctx)
+				else:
+					callback()
+				if context_menu:
+					self.put_away()
+				return True
+
 			mitem = None
 			if label and not icon:
 				mitem = gtk.MenuItem(label=label)
 			else:
 				mitem = gtk.ImageMenuItem(icon)
-			mitem.connect("activate", menu_callback, callback)
+			mitem.connect("activate", mitem_handler, callback)
 			menu.append(mitem)
 
 		if context_menu:
-			add_menu_item(gtk.STOCK_CLOSE, self.put_away)
+			add_menu_item(gtk.STOCK_CLOSE, self.put_away, with_ctx=False)
 		else:
 			add_menu_item(None, self.activate, _("Show Main Interface"))
 		menu.append(gtk.SeparatorMenuItem())
@@ -1819,7 +1824,7 @@ class WindowController (pretty.OutputMixin):
 		add_menu_item(gtk.STOCK_HELP, kupferui.show_help)
 		add_menu_item(gtk.STOCK_ABOUT, kupferui.show_about_dialog)
 		menu.append(gtk.SeparatorMenuItem())
-		add_menu_item(gtk.STOCK_QUIT, self.quit)
+		add_menu_item(gtk.STOCK_QUIT, self.quit, with_ctx=False)
 		menu.show_all()
 
 		return menu



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]