[kupfer: 29/53] windows: Port to wants_context



commit b647719c3d55ec2adbd06b47d291acbdd6a207c1
Author: Ulrik Sverdrup <ulrik sverdrup gmail com>
Date:   Thu Mar 24 17:22:37 2011 +0100

    windows: Port to wants_context

 kupfer/plugin/windows.py |   38 ++++++++++++++++++++++----------------
 1 files changed, 22 insertions(+), 16 deletions(-)
---
diff --git a/kupfer/plugin/windows.py b/kupfer/plugin/windows.py
index 62a662f..090d383 100644
--- a/kupfer/plugin/windows.py
+++ b/kupfer/plugin/windows.py
@@ -8,14 +8,10 @@ import gtk
 import wnck
 
 from kupfer.objects import Leaf, Action, Source
-from kupfer.ui import uievents
 from kupfer.weaklib import gobject_connect_weakly
 from kupfer.obj.helplib import PicklingHelperMixin
 
 
-def _get_current_event_time():
-	return uievents.current_event_time()
-
 class WindowLeaf (Leaf):
 	def get_actions(self):
 		yield WindowActivateWorkspace()
@@ -109,10 +105,12 @@ class NextWindow (WindowLeaf):
 class WindowActivateWorkspace (Action):
 	def __init__(self, name=_("Go To")):
 		super(WindowActivateWorkspace, self).__init__(name)
-	def activate (self, leaf):
+	def wants_context(self):
+		return True
+	def activate (self, leaf, ctx):
 		window = leaf.object
 		workspace = window.get_workspace()
-		time = _get_current_event_time()
+		time = ctx.environment.get_timestamp()
 		workspace.activate(time)
 		window.activate(time)
 	def get_description(self):
@@ -124,11 +122,14 @@ class WindowMoveToWorkspace (Action):
 	def __init__(self):
 		Action.__init__(self, _("Move To..."))
 
-	def activate(self, leaf, iobj):
+	def wants_context(self):
+		return True
+
+	def activate(self, leaf, iobj, ctx):
 		window = leaf.object
 		workspace = iobj.object
 		window.move_to_workspace(workspace)
-		time = _get_current_event_time()
+		time = ctx.environment.get_timestamp()
 		workspace.activate(time)
 		window.activate(time)
 
@@ -157,8 +158,11 @@ class WindowAction (Action):
 	def repr_key(self):
 		return self.action
 
-	def activate(self, leaf):
-		time = self._get_time() if self.time else None
+	def wants_context(self):
+		return True
+
+	def activate(self, leaf, ctx):
+		time = self._get_time(ctx) if self.time else None
 		self._perform_action(self.action, leaf, time)
 
 	@classmethod
@@ -171,10 +175,10 @@ class WindowAction (Action):
 			action_method()
 
 	@classmethod
-	def _get_time(cls):
+	def _get_time(cls, ctx):
 		# @time will be != 0 if we are "inside"
 		# a current gtk event
-		return _get_current_event_time()
+		return ctx.environment.get_timestamp()
 
 	def get_icon_name(self):
 		if not self.icon_name:
@@ -195,10 +199,10 @@ class ToggleAction (WindowAction):
 		self.predicate = predicate
 		self.uaction = uaction
 
-	def activate(self, leaf):
+	def activate(self, leaf, ctx):
 		if self.predicate(leaf.object):
 			# only use time on the disable action
-			time = self._get_time() if self.time else None
+			time = self._get_time(ctx) if self.time else None
 			self._perform_action(self.uaction, leaf, time)
 		else:
 			self._perform_action(self.action, leaf)
@@ -260,9 +264,11 @@ class ActivateWorkspace (Action):
 	def __init__(self):
 		Action.__init__(self, _("Go To"))
 
-	def activate (self, leaf):
+	def wants_context(self):
+		return True
+	def activate (self, leaf, ctx):
 		workspace = leaf.object
-		time = _get_current_event_time()
+		time = ctx.environment.get_timestamp()
 		workspace.activate(time)
 
 	def get_description(self):



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