source: gutenbach-rhythmbox-plugin/__init__.py @ 0159c0a

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

-Changed the name from pikamp3 to gutenbach.
-Added comments.
-Moved printername and hostname to constructor.
-Created UI XML file for future preferences dialogue.

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