[rhythmbox] Port context pane plugin to GI



commit d7ccbb3057a07164695f0c81b4a0194af37e3dcb
Author: Jonathan Matthew <jonathan d14n org>
Date:   Fri Feb 4 23:03:44 2011 +1000

    Port context pane plugin to GI
    
    Some parts by Bastien Nocera.

 plugins/context/context/AlbumTab.py    |   20 +++++----
 plugins/context/context/ArtistTab.py   |   20 +++++----
 plugins/context/context/ContextView.py |   73 +++++++++++++++++---------------
 plugins/context/context/LastFM.py      |    6 +--
 plugins/context/context/LinksTab.py    |   18 ++++----
 plugins/context/context/LyricsTab.py   |   19 +++++----
 plugins/context/context/__init__.py    |    7 ++-
 7 files changed, 90 insertions(+), 73 deletions(-)
---
diff --git a/plugins/context/context/AlbumTab.py b/plugins/context/context/AlbumTab.py
index cad4b29..236ac30 100644
--- a/plugins/context/context/AlbumTab.py
+++ b/plugins/context/context/AlbumTab.py
@@ -24,16 +24,20 @@
 # 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 webkit
+import gobject
 import os
 import cgi
 import urllib
 from mako.template import Template
 import xml.dom.minidom as dom
+
 import LastFM
 
+import rb
+from gi.repository import RB
+from gi.repository import Gtk
+from gi.repository import WebKit
+
 class AlbumTab (gobject.GObject):
 
     __gsignals__ = {
@@ -48,18 +52,18 @@ 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'))
-        buttons.pack_start (self.button, True, True)
+        buttons.pack_start (self.button, True, True, 0)
 
     def activate (self):
         self.button.set_active(True)
@@ -75,8 +79,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 = entry.get_string (RB.RhythmDBPropType.ARTIST)
+        album  = entry.get_string (RB.RhythmDBPropType.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..f944908 100644
--- a/plugins/context/context/ArtistTab.py
+++ b/plugins/context/context/ArtistTab.py
@@ -24,16 +24,20 @@
 # 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 rb
+import LastFM
+
+from gi.repository import WebKit
+from gi.repository import Gtk
+from gi.repository import RB
     
 class ArtistTab (gobject.GObject):
     
@@ -49,18 +53,18 @@ 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'))
-        buttons.pack_start (self.button, True, True)
+        buttons.pack_start (self.button, True, True, 0)
 
     def activate (self):
         print "activating Artist Tab"
@@ -78,7 +82,7 @@ class ArtistTab (gobject.GObject):
         if entry is None:
             print "Nothing playing"
             return None
-        artist = self.db.entry_get (entry, rhythmdb.PROP_ARTIST)
+        artist = entry.get_string (RB.RhythmDBPropType.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 ab65927..ac042ab 100644
--- a/plugins/context/context/ContextView.py
+++ b/plugins/context/context/ContextView.py
@@ -24,10 +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, gio
-import pango
-import webkit
+import gobject, gio
 import os
 
 import ArtistTab as at
@@ -35,6 +32,11 @@ import AlbumTab as abt
 import LyricsTab as lt
 import LinksTab as lit
 
+import rb
+from gi.repository import Gtk, Gdk, Pango
+from gi.repository import RB
+from gi.repository import WebKit
+
 context_ui = """
 <ui>
     <toolbar name="ToolBar">
@@ -90,7 +92,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)
@@ -108,7 +110,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)
@@ -135,10 +137,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):
@@ -175,10 +177,12 @@ class ContextView (gobject.GObject):
                 self.top_five_list.append(["%d. " % (i+1), ""])
         else:
             num_tracks = len(top_tracks)
+            ## empty liststore
+            self.top_five_list.clear()
             for i in range (0, 5):
                 if i >= num_tracks : track = ""
                 else : track = top_tracks[i]
-                self.top_five_list[(i,)] = ("%d. " % (i+1), track)
+                self.top_five_list.append(["%d. " % (i+1), str(track)])
 
     def playing_changed_cb (self, playing, user_data):
         # this sometimes happens on a streaming thread, so we need to
@@ -193,7 +197,7 @@ class ContextView (gobject.GObject):
         if playing_entry is None:
             return
 
-        playing_artist = self.db.entry_get (playing_entry, rhythmdb.PROP_ARTIST)
+        playing_artist = playing_entry.get_string(RB.RhythmDBPropType.ARTIST)
 
         if self.current_artist != playing_artist:
             self.current_artist = playing_artist.replace ('&', '&amp;')
@@ -221,36 +225,38 @@ class ContextView (gobject.GObject):
         self.apply_font_settings()
 
     def apply_font_settings(self):
-        style = self.webview.style
+        # FIXME apply font style
+        # style = self.webview.style
+        return
 
         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(_('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.new_with_model(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)
@@ -262,30 +268,29 @@ class ContextView (gobject.GObject):
         self.frame.add (self.top_five_view)
 
         #---- set up webkit pane -----#
-        self.webview = webkit.WebView()
+        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
-        self.websettings = webkit.WebSettings()
+        self.websettings = WebKit.WebSettings()
         self.webview.set_settings(self.websettings)
         self.apply_font_settings()
         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)
-        self.vbox2.pack_start (self.buttons, expand = False)
-        self.vbox2.pack_start (self.scroll, expand = True)
-        self.vbox.pack_start  (self.vbox2, expand = True)
+        self.vbox.pack_start  (self.frame, False, True, 0)
+        self.vbox2.pack_start (self.buttons, False, True, 0)
+        self.vbox2.pack_start (self.scroll, True, True, 0)
+        self.vbox.pack_start  (self.vbox2, True, True, 0)
 
         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, True, 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/LinksTab.py b/plugins/context/context/LinksTab.py
index d801ee7..96cfa05 100644
--- a/plugins/context/context/LinksTab.py
+++ b/plugins/context/context/LinksTab.py
@@ -24,15 +24,17 @@
 # along with this program; if not, write to the Free Software
 # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA.
 
-import rhythmdb
-import gtk, gobject
+import gobject
 import os
 import cgi
 import urllib
 
+from gi.repository import Gtk
+from gi.repository import RB
+from gi.repository import WebKit
+
 from gettext import gettext as _
 
-import webkit
 from mako.template import Template
 
 
@@ -50,18 +52,18 @@ class LinksTab (gobject.GObject):
         self.db         = shell.get_property ('db')
         self.buttons    = buttons
 
-        self.button     = gtk.ToggleButton (_("Links"))
+        self.button     = Gtk.ToggleButton (label=_("Links"))
         self.datasource = ds
         self.view       = view
         self.artist     = None
         self.album      = None
 
         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', 'links'))
-        buttons.pack_start (self.button, True, True)
+        buttons.pack_start (self.button, True, True, 0)
 
     def activate (self):
         print "activating Links Tab"
@@ -77,8 +79,8 @@ class LinksTab (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 = entry.get_string (RB.RhythmDBPropType.ARTIST)
+        album = entry.get_string (RB.RhythmDBPropType.ALBUM)
         self.artist = artist
         self.album = album
 
diff --git a/plugins/context/context/LyricsTab.py b/plugins/context/context/LyricsTab.py
index 758aae7..92cd4a7 100644
--- a/plugins/context/context/LyricsTab.py
+++ b/plugins/context/context/LyricsTab.py
@@ -24,13 +24,16 @@
 # 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
 
+import rb
+from gi.repository import Gtk
+from gi.repository import RB
+
 class LyricsTab (gobject.GObject):
     
     __gsignals__ = {
@@ -45,16 +48,16 @@ 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'))
-        toolbar.pack_start (self.button, True, True)
+        toolbar.pack_start (self.button, True, True, 0)
 
     def activate (self):
         print "activating Lyrics Tab"
@@ -131,7 +134,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, (RB.RhythmDBEntry, gobject.TYPE_STRING,)),
     }
 
     def __init__ (self, db):
@@ -151,8 +154,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.entry.get_string (RB.RhythmDBPropType.TITLE)
 
     def get_artist (self):
-        return self.db.entry_get(self.entry, rhythmdb.PROP_ARTIST)
+        return self.entry.get_string (RB.RhythmDBPropType.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]