[totem] Port all the Python plugins to libpeas 0.5.4



commit defd3ec6c6bb4dab310c47dbaa71eae2c6dc1e1d
Author: Philip Withnall <philip withnall collabora co uk>
Date:   Sun Aug 8 10:24:37 2010 +0100

    Port all the Python plugins to libpeas 0.5.4

 src/plugins/coherence_upnp/coherence_upnp.py |   14 +++++++-----
 src/plugins/dbus-service/dbus-service.py     |   12 ++++++----
 src/plugins/iplayer/iplayer.py               |   13 ++++++-----
 src/plugins/jamendo/jamendo.py               |   13 ++++++-----
 src/plugins/opensubtitles/opensubtitles.py   |   19 ++++++++---------
 src/plugins/pythonconsole/pythonconsole.py   |   29 ++++++++++++++-----------
 src/plugins/sample-python/sample-python.py   |    8 ++++--
 7 files changed, 59 insertions(+), 49 deletions(-)
---
diff --git a/src/plugins/coherence_upnp/coherence_upnp.py b/src/plugins/coherence_upnp/coherence_upnp.py
index e1517df..15f8cb8 100644
--- a/src/plugins/coherence_upnp/coherence_upnp.py
+++ b/src/plugins/coherence_upnp/coherence_upnp.py
@@ -18,7 +18,10 @@ _ = gettext.gettext
 class UPnPClient(gobject.GObject, Peas.Activatable):
     __gtype_name__ = 'UPnPClient'
 
+    object = gobject.property(type = gobject.GObject)
+
     def __init__ (self):
+        self.totem_object = self.object
         self.ui = TreeWidget()
         self.ui.window.set_shadow_type(gtk.SHADOW_IN)
         self.ui.cb_item_right_click = self.button_pressed
@@ -107,14 +110,13 @@ class UPnPClient(gobject.GObject, Peas.Activatable):
         else:
             self.context = self.context_no_delete
 
-    def do_activate (self, totem_object):
-        totem_object.add_sidebar_page ("upnp-coherence", _("Coherence DLNA/UPnP Client"), self.ui.window)
-        self.totem_object = totem_object
+    def do_activate (self):
+        self.totem_object.add_sidebar_page ("upnp-coherence", _("Coherence DLNA/UPnP Client"), self.ui.window)
 
         def load_and_play(url):
-            totem_object.add_to_playlist_and_play (url, '', True)
+            self.totem_object.add_to_playlist_and_play (url, '', True)
 
         self.ui.cb_item_dbl_click = load_and_play
 
-    def do_deactivate (self, totem_object):
-        totem_object.remove_sidebar_page ("upnp-coherence")
+    def do_deactivate (self):
+        self.totem_object.remove_sidebar_page ("upnp-coherence")
diff --git a/src/plugins/dbus-service/dbus-service.py b/src/plugins/dbus-service/dbus-service.py
index eeb3f9f..7d96ffa 100644
--- a/src/plugins/dbus-service/dbus-service.py
+++ b/src/plugins/dbus-service/dbus-service.py
@@ -30,15 +30,17 @@ from dbus.mainloop.glib import DBusGMainLoop
 class dbusservice(gobject.GObject, Peas.Activatable):
 	__gtype_name__ = 'dbusservice'
 
-	def do_activate(self, totem):
+	object = gobject.property(type = gobject.GObject)
+
+	def do_activate(self):
 		DBusGMainLoop(set_as_default = True)
 
 		name = dbus.service.BusName ('org.mpris.Totem', bus = dbus.SessionBus ())
-		self.root = Root (name, totem)
-		self.player = Player (name, totem)
-		self.track_list = TrackList (name, totem)
+		self.root = Root (name, self.object)
+		self.player = Player (name, self.object)
+		self.track_list = TrackList (name, self.object)
 
-	def do_deactivate(self, totem):
+	def do_deactivate(self):
 		self.root.disconnect() # ensure we don't leak our paths on the bus
 		self.player.disconnect()
 		self.track_list.disconnect()
diff --git a/src/plugins/iplayer/iplayer.py b/src/plugins/iplayer/iplayer.py
index a79dcec..525485a 100644
--- a/src/plugins/iplayer/iplayer.py
+++ b/src/plugins/iplayer/iplayer.py
@@ -16,14 +16,16 @@ _ = gettext.gettext
 class IplayerPlugin (gobject.GObject, Peas.Activatable):
 	__gtype_name__ = 'IplayerPlugin'
 
+	object = gobject.property(type = gobject.GObject)
+
 	def __init__ (self):
 		self.debug = False
-		self.totem = None
+		self.totem = self.object
 		self.programme_download_lock = threading.Lock ()
 
-	def do_activate (self, totem_object):
+	def do_activate (self):
 		# Build the interface
-		builder = Totem.plugin_load_interface ("iplayer", "iplayer.ui", True, totem_object.get_main_window (), self)
+		builder = Totem.plugin_load_interface ("iplayer", "iplayer.ui", True, self.totem.get_main_window (), self)
 		container = builder.get_object ('iplayer_vbox')
 
 		self.tv_tree_store = builder.get_object ('iplayer_programme_store')
@@ -31,7 +33,6 @@ class IplayerPlugin (gobject.GObject, Peas.Activatable):
 		programme_list.connect ('row-expanded', self._row_expanded_cb)
 		programme_list.connect ('row-activated', self._row_activated_cb)
 
-		self.totem = totem_object
 		container.show_all ()
 
 		self.tv = iplayer2.feed ('tv')
@@ -42,8 +43,8 @@ class IplayerPlugin (gobject.GObject, Peas.Activatable):
 		# Get the channel category listings
 		self.populate_channel_list (self.tv, self.tv_tree_store)
 
-	def do_deactivate (self, totem_object):
-		totem_object.remove_sidebar_page ("iplayer")
+	def do_deactivate (self):
+		self.totem.remove_sidebar_page ("iplayer")
 
 	def populate_channel_list (self, feed, tree_store):
 		if self.debug:
diff --git a/src/plugins/jamendo/jamendo.py b/src/plugins/jamendo/jamendo.py
index 9c06583..e0db439 100644
--- a/src/plugins/jamendo/jamendo.py
+++ b/src/plugins/jamendo/jamendo.py
@@ -67,6 +67,8 @@ gconf_key = '/apps/totem/plugins/jamendo'
 class JamendoPlugin(gobject.GObject, Peas.Activatable, PeasUI.Configurable):
     __gtype_name__ = 'JamendoPlugin'
 
+    object = gobject.property(type = gobject.GObject)
+
     """
     Jamendo totem plugin GUI.
     """
@@ -79,16 +81,16 @@ class JamendoPlugin(gobject.GObject, Peas.Activatable, PeasUI.Configurable):
     def __init__(self):
         self.debug = True
         self.gstreamer_plugins_present = True
-        self.totem = None
+        self.totem = self.object
         self.gconf = GConf.Client.get_default()
         self.init_settings()
 
-    def do_activate(self, totem_object):
+    def do_activate(self):
         """
         Plugin activation.
         """
         # Initialise the interface
-        builder = Totem.plugin_load_interface ("jamendo", "jamendo.ui", True, totem_object.get_main_window (), self)
+        builder = Totem.plugin_load_interface ("jamendo", "jamendo.ui", True, self.totem.get_main_window (), self)
         self.popup = builder.get_object('popup_menu')
         container = builder.get_object('container')
         self.notebook = builder.get_object('notebook')
@@ -120,16 +122,15 @@ class JamendoPlugin(gobject.GObject, Peas.Activatable, PeasUI.Configurable):
         builder.get_object('add_to_playlist').connect('activate', self.on_add_to_playlist_activate)
         builder.get_object('jamendo_album_page').connect('activate', self.on_open_jamendo_album_page_activate)
 
-        self.totem = totem_object
         self.reset()
         container.show_all()
         self.totem.add_sidebar_page("jamendo", _("Jamendo"), container)
 
-    def do_deactivate(self, totem_object):
+    def do_deactivate(self):
         """
         Plugin deactivation.
         """
-        totem_object.remove_sidebar_page("jamendo")
+        self.totem.remove_sidebar_page("jamendo")
 
     def do_create_configure_widget(self):
         """
diff --git a/src/plugins/opensubtitles/opensubtitles.py b/src/plugins/opensubtitles/opensubtitles.py
index 6cae53d..cf767e4 100644
--- a/src/plugins/opensubtitles/opensubtitles.py
+++ b/src/plugins/opensubtitles/opensubtitles.py
@@ -297,24 +297,23 @@ class OpenSubtitlesModel(object):
 class OpenSubtitles(gobject.GObject, Peas.Activatable):
     __gtype_name__ = 'OpenSubtitles'
 
+    object = gobject.property(type = gobject.GObject)
+
     def __init__(self):
         self.dialog = None
+        self.totem = self.object
         self.gconf_client = GConf.Client.get_default()
         self.GCONF_BASE_DIR = "/apps/totem/plugins/opensubtitles/"
         self.GCONF_LANGUAGE = "language"
 
     # totem.Plugin methods
 
-    def do_activate(self, totem_object):
+    def do_activate(self):
         """
         Called when the plugin is activated.
         Here the sidebar page is initialized(set up the treeview, connect 
         the callbacks, ...) and added to totem.
-
-        @param totem_object:
-        @type  totem_object: {totem.TotemObject}
         """
-        self.totem = totem_object
 	self.filename = None
 
         self.manager = self.totem.get_ui_manager()
@@ -327,7 +326,7 @@ class OpenSubtitles(gobject.GObject, Peas.Activatable):
         server = xmlrpclib.Server('http://api.opensubtitles.org/xml-rpc')
         self.model = OpenSubtitlesModel(server)
 
-    def do_deactivate(self, totem):
+    def do_deactivate(self):
         if self.dialog:
             self.dialog.destroy()
 	    self.dialog = None
@@ -336,8 +335,8 @@ class OpenSubtitles(gobject.GObject, Peas.Activatable):
 
     # UI related code
 
-    def os_build_dialog(self, action, totem_object):
-        builder = Totem.plugin_load_interface ("opensubtitles", "opensubtitles.ui", True, totem_object.get_main_window (), self)
+    def os_build_dialog(self, action):
+        builder = Totem.plugin_load_interface ("opensubtitles", "opensubtitles.ui", True, self.totem.get_main_window (), self)
 
         # Obtain all the widgets we need to initialize
         combobox =       builder.get_object('language_combobox')
@@ -403,9 +402,9 @@ class OpenSubtitles(gobject.GObject, Peas.Activatable):
         self.treeview.get_selection().connect('changed', self.on_treeview__row_change)
         self.treeview.connect('row-activated', self.on_treeview__row_activate)
 
-    def os_show_dialog(self, action, totem_object):
+    def os_show_dialog(self, action):
         if not self.dialog:
-            self.os_build_dialog(action, totem_object)
+            self.os_build_dialog(action)
 
         filename = self.totem.get_current_mrl()
         if not self.model.results or filename != self.filename:
diff --git a/src/plugins/pythonconsole/pythonconsole.py b/src/plugins/pythonconsole/pythonconsole.py
index 84971e4..f02461e 100644
--- a/src/plugins/pythonconsole/pythonconsole.py
+++ b/src/plugins/pythonconsole/pythonconsole.py
@@ -69,13 +69,16 @@ ui_str = """
 class PythonConsolePlugin(gobject.GObject, Peas.Activatable):
 	__gtype_name__ = 'PythonConsolePlugin'
 
+	object = gobject.property(type = gobject.GObject)
+
 	def __init__(self):
+		self.totem = self.object
 		self.window = None
 	
-	def do_activate(self, totem_object):
+	def do_activate(self):
 
 		data = dict()
-		manager = totem_object.get_ui_manager()
+		manager = self.totem.get_ui_manager()
 
 		data['action_group'] = Gtk.ActionGroup(name = 'Python')
 		
@@ -85,13 +88,13 @@ class PythonConsolePlugin(gobject.GObject, Peas.Activatable):
 		action = Gtk.Action(name = 'PythonConsole', label = _('_Python Console'),
 		                    tooltip = _("Show Totem's Python console"),
 		                    stock_id = 'gnome-mime-text-x-python')
-		action.connect('activate', self.show_console, totem_object)
+		action.connect('activate', self.show_console)
 		data['action_group'].add_action(action)
 
 		action = Gtk.Action(name = 'PythonDebugger', label = _('Python Debugger'),
 				    tooltip = _("Enable remote Python debugging with rpdb2"))
 		if have_rpdb2:
-			action.connect('activate', self.enable_debugging, totem_object)
+			action.connect('activate', self.enable_debugging)
 		else:
 			action.set_visible(False)
 		data['action_group'].add_action(action)
@@ -100,14 +103,14 @@ class PythonConsolePlugin(gobject.GObject, Peas.Activatable):
 		data['ui_id'] = manager.add_ui_from_string(ui_str)
 		manager.ensure_update()
 		
-		totem_object.set_data('PythonConsolePluginInfo', data)
+		self.totem.set_data('PythonConsolePluginInfo', data)
 	
-	def show_console(self, action, totem_object):
+	def show_console(self, action):
 		if not self.window:
 			console = PythonConsole(namespace = {'__builtins__' : __builtins__,
 			                                     'Totem' : Totem,
-                               		                     'totem_object' : totem_object},
-						             destroy_cb = self.destroy_console)
+			                                     'totem_object' : self.totem},
+			                                     destroy_cb = self.destroy_console)
 
 			console.set_size_request(600, 400)
 			console.eval('print "%s" %% totem_object' % _("You can access the Totem.Object through " \
@@ -122,7 +125,7 @@ class PythonConsolePlugin(gobject.GObject, Peas.Activatable):
 			self.window.show_all()
 			self.window.grab_focus()
 
-	def enable_debugging(self, action, totem_object):
+	def enable_debugging(self, action):
 		msg = _("After you press OK, Totem will wait until you connect to it with winpdb or rpdb2. If you have not set a debugger password in GConf, it will use the default password ('totem').")
 		dialog = Gtk.MessageDialog(None, 0, Gtk.MessageType.INFO, Gtk.ButtonType.OK_CANCEL, msg)
 		if dialog.run() == Gtk.ResponseType.OK:
@@ -139,15 +142,15 @@ class PythonConsolePlugin(gobject.GObject, Peas.Activatable):
 		self.window.destroy()
 		self.window = None
 
-	def do_deactivate(self, totem_object):
-		data = totem_object.get_data('PythonConsolePluginInfo')
+	def do_deactivate(self):
+		data = self.totem.get_data('PythonConsolePluginInfo')
 
-		manager = totem_object.get_ui_manager()
+		manager = self.totem.get_ui_manager()
 		manager.remove_ui(data['ui_id'])
 		manager.remove_action_group(data['action_group'])
 		manager.ensure_update()
 
-		totem_object.set_data('PythonConsolePluginInfo', None)
+		self.totem.set_data('PythonConsolePluginInfo', None)
 		
 		if self.window is not None:
 			self.window.destroy()
diff --git a/src/plugins/sample-python/sample-python.py b/src/plugins/sample-python/sample-python.py
index 5b67255..3956cf8 100644
--- a/src/plugins/sample-python/sample-python.py
+++ b/src/plugins/sample-python/sample-python.py
@@ -7,9 +7,11 @@ from gi.repository import Totem
 class SamplePython(gobject.GObject, Peas.Activatable):
 	__gtype_name__ = 'SamplePython'
 
-	def do_activate(self, totem):
+	object = gobject.property(type = gobject.GObject)
+
+	def do_activate(self):
 		print "Activating sample Python plugin"
-		totem.action_fullscreen_toggle()
+		self.object.action_fullscreen_toggle()
 	
-	def do_deactivate(self, totem):
+	def do_deactivate(self):
 		print "Deactivating sample Python plugin"



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