source: rhythmbox/__init__.py @ 7b63831

debianmacno-cupsweb
Last change on this file since 7b63831 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
Line 
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"""
8import gtk
9import rb
10import subprocess
11import urllib
12import urlparse
13
14# UI Change is an extra item added to right-click menu when clicking on tracks
15popup_ui = """
16<ui> 
17  <popup name="BrowserSourceViewPopup">
18    <menuitem name="Gutenbach" action="SendToGutenbach"/>
19  </popup>
20</ui>
21"""
22class GutenbachPlugin(rb.Plugin):
23    def __init__(self):
24        rb.Plugin.__init__(self)
25
26    def activate(self, shell):
27        """Adds a new item to the right-click menu which allows
28        sending music files to the gutenbach server.
29        """
30        self.shell = shell
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."),
34                "")
35        action.connect('activate', self.gutenbach_action, shell)
36        action_group = gtk.ActionGroup('GutenbachActionGroup')
37        action_group.add_action(action)
38        manager = shell.get_ui_manager()
39        manager.insert_action_group(action_group)
40        manager.add_ui_from_string(popup_ui)
41
42        # Default configuration options
43        self.printer = "printername"
44        self.printer_host = "hostname"
45
46    def deactivate(self, shell):
47        del self.shell
48
49    def gutenbach_action(self, action, shell):
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        """
54        source = shell.get_property("selected-source")
55        # For each track currently selected in the song browser
56        for entry in source.get_entry_view().get_selected_entries():
57            # Only play files that are stored on the user's computer
58            uri = entry.get_playback_uri()
59            p = urlparse.urlparse(urllib.unquote(uri))
60            if p.scheme == "file":
61                path = p.path
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)
67                print "About to run command '%s'" % command
68                subprocess.Popen(command, shell=True)
69
Note: See TracBrowser for help on using the repository browser.