[rhythmbox/gobject-introspection: 20/34] port context pane plugin to gi, probably



commit 0e14c9b8a526f899d1248f2d421772c959d1c328
Author: Jonathan Matthew <jonathan d14n org>
Date:   Tue Jul 13 14:52:39 2010 +1000

    port context pane plugin to gi, probably

 plugins/context/context/AlbumTab.py    |   15 +++++---
 plugins/context/context/ArtistTab.py   |   15 +++++---
 plugins/context/context/ContextView.py |   53 ++++++++++++++++---------------
 plugins/context/context/LastFM.py      |    6 +--
 plugins/context/context/LyricsTab.py   |   16 +++++----
 plugins/context/context/__init__.py    |    7 ++--
 6 files changed, 60 insertions(+), 52 deletions(-)
---
diff --git a/plugins/context/context/AlbumTab.py b/plugins/context/context/AlbumTab.py
index cad4b29..50abccb 100644
--- a/plugins/context/context/AlbumTab.py
+++ b/plugins/context/context/AlbumTab.py
@@ -24,16 +24,19 @@
 # along with this program; if not, write to the Free Software
 # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA.
 
-import rb, rhythmdb
-import gtk, gobject
+import gobject
 import webkit
 import os
 import cgi
 import urllib
 from mako.template import Template
 import xml.dom.minidom as dom
+
 import LastFM
 
+from gi.repository import RhythmDB
+from gi.repository import Gtk
+
 class AlbumTab (gobject.GObject):
 
     __gsignals__ = {
@@ -48,14 +51,14 @@ class AlbumTab (gobject.GObject):
         self.db         = shell.get_property ('db') 
         self.buttons    = buttons
 
-        self.button     = gtk.ToggleButton (_("Albums"))
+        self.button     = Gtk.ToggleButton (label=_("Albums"))
         self.ds         = ds
         self.view       = view
         self.artist     = None
         self.active     = False
 
         self.button.show()
-        self.button.set_relief( gtk.RELIEF_NONE ) 
+        self.button.set_relief (Gtk.ReliefStyle.NONE)
         self.button.set_focus_on_click(False)
         self.button.connect ('clicked', 
             lambda button: self.emit ('switch-tab', 'album'))
@@ -75,8 +78,8 @@ class AlbumTab (gobject.GObject):
         if entry is None:
             return None
 
-        artist = self.db.entry_get (entry, rhythmdb.PROP_ARTIST)
-        album  = self.db.entry_get (entry, rhythmdb.PROP_ALBUM)
+        artist = self.db.entry_get (entry, RhythmDB.PropType.ARTIST)
+        album  = self.db.entry_get (entry, RhythmDB.PropType.ALBUM)
         if self.active and artist != self.artist:
             self.view.loading(artist)
             self.ds.fetch_album_list (artist)
diff --git a/plugins/context/context/ArtistTab.py b/plugins/context/context/ArtistTab.py
index 82c44bb..ed65c61 100644
--- a/plugins/context/context/ArtistTab.py
+++ b/plugins/context/context/ArtistTab.py
@@ -24,16 +24,19 @@
 # along with this program; if not, write to the Free Software
 # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA.
 
-import rb, rhythmdb
-import gtk, gobject
+import gobject
 import re, os
 import cgi
 import urllib
 import xml.dom.minidom as dom
-import LastFM
 
 import webkit
 from mako.template import Template
+
+import LastFM
+
+from gi.repository import Gtk
+from gi.repository import RhythmDB
     
 class ArtistTab (gobject.GObject):
     
@@ -49,14 +52,14 @@ class ArtistTab (gobject.GObject):
         self.db         = shell.get_property ('db') 
         self.buttons    = buttons
 
-        self.button     = gtk.ToggleButton (_("Artist"))
+        self.button     = Gtk.ToggleButton (label=_("Artist"))
         self.datasource = ds
         self.view       = view
         self.artist     = None
         self.active     = False
 
         self.button.show()
-        self.button.set_relief( gtk.RELIEF_NONE ) 
+        self.button.set_relief (Gtk.ReliefStyle.NONE)
         self.button.set_focus_on_click(False)
         self.button.connect ('clicked', 
             lambda button : self.emit('switch-tab', 'artist'))
@@ -78,7 +81,7 @@ class ArtistTab (gobject.GObject):
         if entry is None:
             print "Nothing playing"
             return None
-        artist = self.db.entry_get (entry, rhythmdb.PROP_ARTIST)
+        artist = self.db.entry_get (entry, RhythmDB.PropType.ARTIST)
 
         if self.active and self.artist != artist:
             self.datasource.fetch_artist_data (artist)
diff --git a/plugins/context/context/ContextView.py b/plugins/context/context/ContextView.py
index 160d385..e7705cf 100644
--- a/plugins/context/context/ContextView.py
+++ b/plugins/context/context/ContextView.py
@@ -24,9 +24,7 @@
 # along with this program; if not, write to the Free Software
 # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA.
 
-import rb, rhythmdb
-import gtk, gobject
-import pango
+import gobject
 import webkit
 import os
 
@@ -34,6 +32,10 @@ import ArtistTab as at
 import AlbumTab as abt
 import LyricsTab as lt
 
+from gi.repository import Gtk, Gdk, Pango
+from gi.repository import RB, RhythmDB
+import rb
+
 context_ui = """
 <ui>
     <toolbar name="ToolBar">
@@ -89,7 +91,7 @@ class ContextView (gobject.GObject):
         self.action = ('ToggleContextView','gtk-info', _('Toggle Conte_xt Pane'),
                         None, _('Change the visibility of the context pane'),
                         self.toggle_visibility, True)
-        self.action_group = gtk.ActionGroup('ContextPluginActions')
+        self.action_group = Gtk.ActionGroup(name='ContextPluginActions')
         self.action_group.add_toggle_actions([self.action])
         uim = self.shell.get_ui_manager()
         uim.insert_action_group (self.action_group, 0)
@@ -107,7 +109,7 @@ class ContextView (gobject.GObject):
         self.top_five = None
         self.tab = None
         if self.visible:
-            shell.remove_widget (self.vbox, rb.SHELL_UI_LOCATION_RIGHT_SIDEBAR)
+            shell.remove_widget (self.vbox, RB.ShellUILocation.RIGHT_SIDEBAR)
             self.visible = False
         uim = shell.get_ui_manager ()
         uim.remove_ui (self.ui_id)
@@ -134,10 +136,10 @@ class ContextView (gobject.GObject):
 
     def toggle_visibility (self, action):
         if not self.visible:
-            self.shell.add_widget (self.vbox, rb.SHELL_UI_LOCATION_RIGHT_SIDEBAR, expand=True)
+            self.shell.add_widget (self.vbox, RB.ShellUILocation.RIGHT_SIDEBAR, expand=True)
             self.visible = True
         else:
-            self.shell.remove_widget (self.vbox, rb.SHELL_UI_LOCATION_RIGHT_SIDEBAR)
+            self.shell.remove_widget (self.vbox, RB.ShellUILocation.RIGHT_SIDEBAR)
             self.visible = False
 
     def change_tab (self, tab, newtab):
@@ -189,7 +191,7 @@ class ContextView (gobject.GObject):
         if playing_entry is None:
             return
 
-        playing_artist = self.db.entry_get (playing_entry, rhythmdb.PROP_ARTIST)
+        playing_artist = self.db.entry_get (playing_entry, RhythmDB.PropType.ARTIST)
 
         if self.current_artist != playing_artist:
             self.current_artist = playing_artist.replace ('&', '&amp;')
@@ -203,7 +205,7 @@ class ContextView (gobject.GObject):
         # open HTTP URIs externally.  this isn't a web browser.
         if request.get_uri().startswith('http'):
             print "opening uri %s" % request.get_uri()
-            gtk.show_uri(self.shell.props.window.get_screen(), request.get_uri(), gtk.gdk.CURRENT_TIME)
+            Gtk.show_uri(self.shell.props.window.get_screen(), request.get_uri(), Gdk.CURRENT_TIME)
             return 1        # WEBKIT_NAVIGATION_RESPONSE_IGNORE
         else:
             return 0        # WEBKIT_NAVIGATION_RESPONSE_ACCEPT
@@ -216,32 +218,32 @@ class ContextView (gobject.GObject):
 
         font_size = style.font_desc.get_size()
         if style.font_desc.get_size_is_absolute() is False:
-            font_size /= pango.SCALE
+            font_size /= Pango.SCALE
         self.websettings.props.default_font_size = font_size
         self.websettings.props.default_font_family = style.font_desc.get_family()
         print "web view font settings: %s, %d" % (style.font_desc.get_family(), font_size)
 
     def init_gui(self):
-        self.vbox = gtk.VBox()
-        self.frame = gtk.Frame()
-        self.label = gtk.Label(_('Nothing Playing'))
-        self.frame.set_shadow_type(gtk.SHADOW_IN)
+        self.vbox = Gtk.VBox()
+        self.frame = Gtk.Frame()
+        self.label = Gtk.Label(str=_('Nothing Playing'))
+        self.frame.set_shadow_type(Gtk.ShadowType.IN)
         self.frame.set_label_align(0.0,0.0)
         self.frame.set_label_widget(self.label)
         self.label.set_use_markup(True)
         self.label.set_padding(0,4)
 
         #----- set up top 5 tree view -----#
-        self.top_five_list = gtk.ListStore (gobject.TYPE_STRING, gobject.TYPE_STRING)
-        self.top_five_view = gtk.TreeView(self.top_five_list)
+        self.top_five_list = Gtk.ListStore (gobject.TYPE_STRING, gobject.TYPE_STRING)
+        self.top_five_view = Gtk.TreeView(self.top_five_list)
 
-        self.top_five_tvc1 = gtk.TreeViewColumn()
-        self.top_five_tvc2 = gtk.TreeViewColumn()
+        self.top_five_tvc1 = Gtk.TreeViewColumn()
+        self.top_five_tvc2 = Gtk.TreeViewColumn()
 
         self.top_five_view.append_column(self.top_five_tvc1)
         self.top_five_view.append_column(self.top_five_tvc2)
 
-        self.crt = gtk.CellRendererText()
+        self.crt = Gtk.CellRendererText()
 
         self.top_five_tvc1.pack_start(self.crt, True)
         self.top_five_tvc2.pack_start(self.crt, True)
@@ -255,9 +257,9 @@ class ContextView (gobject.GObject):
         #---- set up webkit pane -----#
         self.webview = webkit.WebView()
         self.webview.connect("navigation-requested", self.navigation_request_cb)
-        self.scroll = gtk.ScrolledWindow()
-        self.scroll.set_policy(gtk.POLICY_NEVER, gtk.POLICY_AUTOMATIC)
-        self.scroll.set_shadow_type(gtk.SHADOW_IN)
+        self.scroll = Gtk.ScrolledWindow()
+        self.scroll.set_policy(Gtk.PolicyType.NEVER, Gtk.PolicyType.AUTOMATIC)
+        self.scroll.set_shadow_type(Gtk.ShadowType.IN)
         self.scroll.add (self.webview)
 
         # set up webkit settings to match gtk font settings
@@ -267,8 +269,8 @@ class ContextView (gobject.GObject):
         self.webview.connect("style-set", self.style_set_cb)
 
         #----- set up button group -----#
-        self.vbox2 = gtk.VBox()
-        self.buttons = gtk.HBox()
+        self.vbox2 = Gtk.VBox()
+        self.buttons = Gtk.HBox()
 
         #---- pack everything into side pane ----#
         self.vbox.pack_start  (self.frame, expand = False)
@@ -278,5 +280,4 @@ class ContextView (gobject.GObject):
 
         self.vbox.show_all()
         self.vbox.set_size_request(200, -1)
-        self.shell.add_widget (self.vbox, rb.SHELL_UI_LOCATION_RIGHT_SIDEBAR, expand=True)
-
+        self.shell.add_widget (self.vbox, RB.ShellUILocation.RIGHT_SIDEBAR, expand=True)
diff --git a/plugins/context/context/LastFM.py b/plugins/context/context/LastFM.py
index 02f3bf8..929f591 100644
--- a/plugins/context/context/LastFM.py
+++ b/plugins/context/context/LastFM.py
@@ -24,8 +24,7 @@
 # along with this program; if not, write to the Free Software
 # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA.
 
-import gobject
-import gconf
+from gi.repository import GConf
 
 # utility things for dealing with last.fm
 
@@ -41,9 +40,8 @@ NO_ACCOUNT_ERROR = _("This information is only available to last.fm users. Pleas
 USERNAME_GCONF_KEY = "/apps/rhythmbox/audioscrobbler/username"
 
 def user_has_account():
-    username = gconf.client_get_default().get_string(USERNAME_GCONF_KEY)
+    username = GConf.Client.get_default().get_string(USERNAME_GCONF_KEY)
     return (username is not None and username != "")
 
 def datasource_link(path):
     return "<a href='http://last.fm/'><img src='%s/img/lastfm.png'></a>" % path
-
diff --git a/plugins/context/context/LyricsTab.py b/plugins/context/context/LyricsTab.py
index 758aae7..6cad922 100644
--- a/plugins/context/context/LyricsTab.py
+++ b/plugins/context/context/LyricsTab.py
@@ -24,13 +24,15 @@
 # along with this program; if not, write to the Free Software
 # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA.
 
-import rb, rhythmdb
-import gtk, gobject
+import gobject
 import urllib
 import re, os
 import cgi
 from mako.template import Template
 
+from gi.repository import Gtk
+from gi.repository import RhythmDB
+
 class LyricsTab (gobject.GObject):
     
     __gsignals__ = {
@@ -45,12 +47,12 @@ class LyricsTab (gobject.GObject):
         self.db         = shell.get_property ('db') 
         self.toolbar    = toolbar
 
-        self.button     = gtk.ToggleButton (_("Lyrics"))
+        self.button     = Gtk.ToggleButton (label=_("Lyrics"))
         self.datasource = ds
         self.view       = view
         
         self.button.show()
-        self.button.set_relief( gtk.RELIEF_NONE ) 
+        self.button.set_relief (Gtk.ReliefStyle.NONE)
         self.button.set_focus_on_click(False)
         self.button.connect ('clicked', 
             lambda button: self.emit('switch-tab', 'lyrics'))
@@ -131,7 +133,7 @@ class LyricsView (gobject.GObject):
 class LyricsDataSource (gobject.GObject):
     
     __gsignals__ = {
-        'lyrics-ready' : (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, (rhythmdb.Entry, gobject.TYPE_STRING,)),
+        'lyrics-ready' : (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, (RhythmDB.Entry, gobject.TYPE_STRING,)),
     }
 
     def __init__ (self, db):
@@ -151,8 +153,8 @@ class LyricsDataSource (gobject.GObject):
             self.emit ('lyrics-ready', self.entry, lyrics)
 
     def get_title (self):
-        return self.db.entry_get(self.entry, rhythmdb.PROP_TITLE)
+        return self.db.entry_get(self.entry, RhythmDB.PropType.TITLE)
 
     def get_artist (self):
-        return self.db.entry_get(self.entry, rhythmdb.PROP_ARTIST)
+        return self.db.entry_get(self.entry, RhythmDB.PropType.ARTIST)
 
diff --git a/plugins/context/context/__init__.py b/plugins/context/context/__init__.py
index 0c0d9bc..ea275db 100644
--- a/plugins/context/context/__init__.py
+++ b/plugins/context/context/__init__.py
@@ -26,12 +26,13 @@
 
 # vim:shiftwidth=4:softtabstop=4:expandtab
 
-import rb, rhythmdb
 import ContextView as cv
 
-class ContextPlugin(rb.Plugin):
+from gi.repository import RB
+
+class ContextPlugin(RB.Plugin):
     def __init__ (self):
-        rb.Plugin.__init__ (self)
+        RB.Plugin.__init__ (self)
 
     def activate (self, shell):
         self.context_view = cv.ContextView (shell, self)



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