source: rhythmbox/__init__.py

debianmacno-cupsweb
Last change on this file was 30beeab, checked in by Jessica B. Hamrick <jhamrick@…>, 14 years ago

Remove "gutenbach-" from directory names and rename "gutenbach" to "gutenbach-server"

  • Property mode set to 100644
File size: 2.4 KB
RevLine 
[61c5043]1"""
2This module implements a Rhythmbox plugin that sends selected track to a
3printer queue. It's meant to be used with gutenbach, a music spooling printer
4server.
5
6The plugin uses lpr to send the files to gutenbach.
7"""
[7e6a613]8import gtk
[61c5043]9import rb
[7e6a613]10import subprocess
[61c5043]11import urllib
12import urlparse
[7e6a613]13
[0159c0a]14# UI Change is an extra item added to right-click menu when clicking on tracks
15popup_ui = """
[7e6a613]16<ui> 
17  <popup name="BrowserSourceViewPopup">
[0159c0a]18    <menuitem name="Gutenbach" action="SendToGutenbach"/>
[7e6a613]19  </popup>
20</ui>
21"""
[0159c0a]22class GutenbachPlugin(rb.Plugin):
[7e6a613]23    def __init__(self):
24        rb.Plugin.__init__(self)
25
26    def activate(self, shell):
[61c5043]27        """Adds a new item to the right-click menu which allows
28        sending music files to the gutenbach server.
29        """
[7e6a613]30        self.shell = shell
[0159c0a]31        # Create action for sending a track to gutenbach
32        action = gtk.Action('SendToGutenbach', _('Send to gutenbach'),
33                _("Queue selected tracks to the gutenbach server."),
[7e6a613]34                "")
[0159c0a]35        action.connect('activate', self.gutenbach_action, shell)
36        action_group = gtk.ActionGroup('GutenbachActionGroup')
[7e6a613]37        action_group.add_action(action)
38        manager = shell.get_ui_manager()
39        manager.insert_action_group(action_group)
[0159c0a]40        manager.add_ui_from_string(popup_ui)
41
42        # Default configuration options
[d566e6b]43        self.printer = "printername"
44        self.printer_host = "hostname"
[7e6a613]45
46    def deactivate(self, shell):
47        del self.shell
48
[0159c0a]49    def gutenbach_action(self, action, shell):
[61c5043]50        """An action called when the user clicks the right-click menu item
51        to send a track to gutenbach.
52        This function calls an instance of lpr for each file to be added.
53        """
[7e6a613]54        source = shell.get_property("selected-source")
[0159c0a]55        # For each track currently selected in the song browser
[7e6a613]56        for entry in source.get_entry_view().get_selected_entries():
[0159c0a]57            # Only play files that are stored on the user's computer
[7e6a613]58            uri = entry.get_playback_uri()
59            p = urlparse.urlparse(urllib.unquote(uri))
60            if p.scheme == "file":
61                path = p.path
[0159c0a]62                if self.printer_host:
63                    printer = '@'.join([self.printer, self.printer_host])
64                else:
65                    printer = self.printer
66                command = 'lpr -P %s "%s"' % (printer, path)
[61c5043]67                print "About to run command '%s'" % command
[7e6a613]68                subprocess.Popen(command, shell=True)
69
Note: See TracBrowser for help on using the repository browser.