Commits

Rhys !  committed f560078

added sidebar

  • Participants
  • Parent commits c535f43

Comments (0)

Files changed (2)

 from __future__ import with_statement
 
 import os, re, urllib, webbrowser
-import gtk
+import gtk, gio
 #import gconf
 import rhythmdb, rb
 
       <menuitem name="LyrclViewSongLyrics" action="LyrclViewSongLyrics"/>
     </menu>
   </menubar>
+  <toolbar name="ToolBar">
+    <toolitem name="LyrclViewSidebar" action="LyrclViewSidebar" />
+  </toolbar>
 </ui>
 """
 
         self.edit.props.sensitive = False
         self.edit.connect('clicked', self.edit_callback)
 
-        discard = gtk.Button(_("_Search again"))
-        discard.connect('clicked', lambda w: self.get_lyrics(force_refresh=True))
+        self.discard = gtk.Button(_("_Search again"))
+        self.discard.connect('clicked', lambda w: self.get_lyrics(force_refresh=True))
 
         hbox = gtk.HButtonBox()
         hbox.props.spacing = 6
         hbox.props.layout_style = gtk.BUTTONBOX_END
         
         hbox.add(self.edit)
-        hbox.add(discard)
+        hbox.add(self.discard)
         
         return hbox
 
         self.props.title = 'lyrcl // ' + self.c_song.artist + ': ' + self.c_song.title
         self.get_lyrics()
 
+class LyricSidebar(LyricsShowyThing):
+    def __init__(self, db, shell, playing_entry):
+        super(self.__class__, self).__init__()
+
+        self.shell = shell
+        self.visible = False
+        self.c_song = CurrentSong(db)
+        
+        buttons = self.prep_buttons()
+        buttons.props.spacing = 2
+        buttons.props.layout_style = gtk.BUTTONBOX_SPREAD
+        self.edit.props.relief = gtk.RELIEF_NONE
+        self.discard.props.relief = gtk.RELIEF_NONE
+        self.discard.props.sensitive = False
+
+        self.vbox, self.buffer = self.create_lyrics_view()
+        self.vbox.pack_start(buttons, expand=False, fill=True)
+        self.vbox.props.spacing = 0
+
+        self.vbox.props.width_request = 300
+        self.vbox.props.height_request = -1
+        self.vbox.show_all()
+        
+        if playing_entry:
+            self.song_changed(playing_entry)
+
+    def song_changed(self, entry):
+        self.discard.props.sensitive = True
+        self.c_song.refresh(entry)
+        if self.visible:
+            self.get_lyrics()
+
+    def toggle_visibility(self):
+        if self.visible:
+            self.shell.remove_widget(self.vbox, rb.SHELL_UI_LOCATION_RIGHT_SIDEBAR)
+            self.visible = False
+        else:
+            self.shell.add_widget(self.vbox, rb.SHELL_UI_LOCATION_RIGHT_SIDEBAR, expand=True)
+            self.visible = True
+            if self.c_song.entry:
+                self.get_lyrics()
+
+    def destroy(self):
+        self.vbox.destroy()
+
 class LyricsDisplayPlugin(rb.Plugin):
-    def __init__ (self):
+    def __init__(self):
         super(self.__class__, self).__init__()
         self.window = None
+        self.sidebar = None
 
     def activate(self, shell):
         self.action = gtk.Action('LyrclViewSongLyrics', _('Song L_yrics'),
                       _('Display lyrics for the playing song'),
-                      'rb-song-lyrics')
+                      None)
         self.activate_id = self.action.connect('activate', self.show_song_lyrics, shell)
         
+        self.sidebar_action = gtk.ToggleAction('LyrclViewSidebar', _('Lyrics Sidebar'),
+            _('Show/hide the lyrics sidebar'), None)
+        self.sidebar_action.props.gicon = gio.FileIcon(gio.File('icon.svg'))
+        self.sidebar_action.connect('activate', self.toggle_sidebar, shell)
+        
         self.action_group = gtk.ActionGroup('LyrclPluginActions')
         self.action_group.add_action_with_accel(self.action, "<control>L")
+        self.action_group.add_action(self.sidebar_action)
         
         uim = shell.get_ui_manager()
         uim.insert_action_group(self.action_group, 0)
 
         self.action_group = None
         self.action = None
+        self.sidebar_action = None
 
         sp = shell.get_player()
         sp.disconnect(self.ppc_id)
             self.window.destroy()
             self.window = None
 
+        if self.sidebar is not None:
+            self.sidebar.destroy()
+            self.sidebar = None
+
     def song_changed(self, entry):
         if self.window is not None:
             self.window.song_changed(entry)
+        if self.sidebar is not None:
+            self.sidebar.song_changed(entry)
 
     def playing_property_changed(self, player, uri, prop, old_val, new_val):
         if (prop == STREAM_SONG_TITLE):
     def create_song_info(self, shell, song_info, is_multiple):
         if is_multiple is False:
             LyricPane(self.db, song_info)
+
+    def toggle_sidebar(self, action, shell):
+        if self.sidebar is None:
+            self.sidebar = LyricSidebar(self.db, shell, self.playing_entry())
+        self.sidebar.toggle_visibility()
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<!-- Created with Inkscape (http://www.inkscape.org/) -->
+
+<svg
+   xmlns:dc="http://purl.org/dc/elements/1.1/"
+   xmlns:cc="http://creativecommons.org/ns#"
+   xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
+   xmlns:svg="http://www.w3.org/2000/svg"
+   xmlns="http://www.w3.org/2000/svg"
+   xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
+   xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
+   width="16"
+   height="16"
+   id="svg2"
+   version="1.1"
+   inkscape:version="0.48.2 r9819"
+   sodipodi:docname="song-icon.svg"
+   inkscape:export-filename="/home/aiden/Projects/Graphics/Lyrcl/song-icon.png"
+   inkscape:export-xdpi="90"
+   inkscape:export-ydpi="90">
+  <defs
+     id="defs4" />
+  <sodipodi:namedview
+     id="base"
+     pagecolor="#ffffff"
+     bordercolor="#666666"
+     borderopacity="1.0"
+     inkscape:pageopacity="0.0"
+     inkscape:pageshadow="2"
+     inkscape:zoom="1.4"
+     inkscape:cx="-203.33765"
+     inkscape:cy="115.85348"
+     inkscape:document-units="px"
+     inkscape:current-layer="layer1"
+     showgrid="false"
+     fit-margin-top="5"
+     fit-margin-left="5"
+     fit-margin-right="5"
+     fit-margin-bottom="5"
+     inkscape:window-width="1920"
+     inkscape:window-height="1056"
+     inkscape:window-x="0"
+     inkscape:window-y="24"
+     inkscape:window-maximized="1" />
+  <metadata
+     id="metadata7">
+    <rdf:RDF>
+      <cc:Work
+         rdf:about="">
+        <dc:format>image/svg+xml</dc:format>
+        <dc:type
+           rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
+        <dc:title />
+      </cc:Work>
+    </rdf:RDF>
+  </metadata>
+  <g
+     inkscape:label="Layer 1"
+     inkscape:groupmode="layer"
+     id="layer1"
+     transform="translate(-227.35446,-350.04011)">
+    <path
+       style="fill:#000000;stroke:#000000;stroke-width:0.91150409px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
+       d="m 234.87178,351.18295 0.11511,10.41608 c -2.84351,-1.46041 -5.76304,0.20029 -5.52455,1.89905 0.43101,3.06992 6.33022,2.28391 6.33022,0.0575 l 0,-7.66491 c 2.96926,1.18685 4.29203,3.98627 3.74058,5.93849 2.51884,-1.8761 3.25457,-3.62835 -4.66135,-10.64622 z"
+       id="path3007"
+       inkscape:connector-curvature="0"
+       sodipodi:nodetypes="ccsscccc" />
+  </g>
+</svg>