source: gutenbach-rhythmbox-plugin/__init__.py @ d566e6b

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

-Updated the README.
-Changed "pikamp3" to "printername" and "lbsg.mit.edu" to "hostname" in init.py

  • Property mode set to 100644
File size: 1.9 KB
Line 
1import rb
2import gtk
3import urlparse
4import urllib
5import subprocess
6
7# UI Change is an extra item added to right-click menu when clicking on tracks
8popup_ui = """
9<ui> 
10  <popup name="BrowserSourceViewPopup">
11    <menuitem name="Gutenbach" action="SendToGutenbach"/>
12  </popup>
13</ui>
14"""
15class GutenbachPlugin(rb.Plugin):
16    def __init__(self):
17        rb.Plugin.__init__(self)
18
19    def activate(self, shell):
20        self.shell = shell
21        # Create action for sending a track to gutenbach
22        action = gtk.Action('SendToGutenbach', _('Send to gutenbach'),
23                _("Queue selected tracks to the gutenbach server."),
24                "")
25        action.connect('activate', self.gutenbach_action, shell)
26        action_group = gtk.ActionGroup('GutenbachActionGroup')
27        action_group.add_action(action)
28        manager = shell.get_ui_manager()
29        manager.insert_action_group(action_group)
30        manager.add_ui_from_string(popup_ui)
31
32        # Default configuration options
33        self.printer = "printername"
34        self.printer_host = "hostname"
35
36    def deactivate(self, shell):
37        del self.shell
38
39    def gutenbach_action(self, action, shell):
40        source = shell.get_property("selected-source")
41        # For each track currently selected in the song browser
42        for entry in source.get_entry_view().get_selected_entries():
43            # Only play files that are stored on the user's computer
44            uri = entry.get_playback_uri()
45            p = urlparse.urlparse(urllib.unquote(uri))
46            if p.scheme == "file":
47                path = p.path
48                if self.printer_host:
49                    printer = '@'.join([self.printer, self.printer_host])
50                else:
51                    printer = self.printer
52                command = 'lpr -P %s "%s"' % (printer, path)
53                print command
54                subprocess.Popen(command, shell=True)
55
Note: See TracBrowser for help on using the repository browser.