Changeset 9fed25d


Ignore:
Timestamp:
Mar 5, 2011, 9:00:50 PM (14 years ago)
Author:
Danny <danny@…>
Branches:
master
Children:
e541733
Parents:
a50d28b
git-author:
Danny <danny@…> (03/05/11 21:00:50)
git-committer:
Danny <danny@…> (03/05/11 21:00:50)
Message:

Plugin now remembers and populates fields with last host and queue

Location:
rhythmbox
Files:
1 added
2 deleted
2 edited

Legend:

Unmodified
Added
Removed
  • rhythmbox/__init__.py

    r30beeab r9fed25d  
    1 """
    2 This module implements a Rhythmbox plugin that sends selected track to a
    3 printer queue. It's meant to be used with gutenbach, a music spooling printer
    4 server.
     1from __future__ import division
    52
    6 The plugin uses lpr to send the files to gutenbach.
    7 """
    8 import gtk
    93import rb
     4import gtk, gtk.glade, gconf
     5import gobject
     6import sys, os
     7import locale, datetime, time
    108import subprocess
    119import urllib
    1210import urlparse
    1311
    14 # UI Change is an extra item added to right-click menu when clicking on tracks
    15 popup_ui = """
     12#fade_steps = 50
     13
     14ui_str = '''
    1615<ui>
    1716  <popup name="BrowserSourceViewPopup">
    18     <menuitem name="Gutenbach" action="SendToGutenbach"/>
     17    <menuitem name="Gutenbach" action="GutenbachDialog"/>
    1918  </popup>
    2019</ui>
    21 """
     20'''
     21
    2222class GutenbachPlugin(rb.Plugin):
    23     def __init__(self):
    24         rb.Plugin.__init__(self)
     23    def __init__ (self):
     24        rb.Plugin.__init__ (self)
    2525
    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         """
     26    def activate (self, shell):
     27        data = dict()
     28        manager = shell.get_player().get_property('ui-manager')
    3029        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)
     30        action = gtk.Action('GutenbachDialog', _('_Send to gutenbach'), _('Spool song to gutenbach server'), None);
     31        action.connect('activate', self.show_conf_dialog)
     32        data['action_group'] = gtk.ActionGroup('GutenbachGroup')
     33        data['action_group'].add_action(action)
     34        manager.insert_action_group(data['action_group'], 0)
    4135
    42         # Default configuration options
    43         self.printer = "printername"
    44         self.printer_host = "hostname"
     36        data['ui_id'] = manager.add_ui_from_string(ui_str)
     37        manager.ensure_update()
     38        shell.set_data('GutenbachInfo', data)
     39
     40
    4541
    4642    def deactivate(self, shell):
     43        self.toolbar.remove(self.separator)
     44        data = shell.get_data('GutenbachInfo')
     45        manager = shell.get_player().get_property('ui-manager')
     46        manager.remove_ui(data['ui_id'])
     47        del self.player
     48        del self.separator
     49        del self.toolbar
    4750        del self.shell
    4851
    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")
     52    def show_conf_dialog(self, action):
     53        self.wTree = gtk.glade.XML(self.find_file('gutenbach-rhythmbox-2.glade'))
     54        widgets = {}
     55        widgets['gutenbach-dialog'] = self.wTree.get_widget('gutenbach-dialog')
     56        dic = {
     57            "on_gutenbach-ok_clicked" : self.process,
     58            "on_windowMain_destroy" : self.quit,
     59            }
     60
     61        self.wTree.signal_autoconnect( dic )
     62
     63        # Fix proper Dialog placements
     64        widgets['gutenbach-dialog'].set_transient_for(self.shell.props.window)
     65
     66        def gconf_path(key):
     67            return '%s%s' % (gconf_plugin_path, key)
     68
     69
     70        widget = None
     71        try:
     72                memf = open('savedqueue','r+')
     73        except IOError:
     74                memf = file('savedqueue', 'wt')
     75                memf.close()
     76        memf = open('savedqueue','r+')
     77        memLine = memf.readline()
     78        if memLine != "":
     79                left = memLine
     80                right = memf.readline()
     81                self.wTree.get_widget("gutenbach-printer-entry").set_text(left.rstrip('\n'))
     82                self.wTree.get_widget("gutenbach-host-entry").set_text(right.rstrip('\n'))
     83        memf.close()
     84        widgets['gutenbach-dialog'].run()
     85        self.process(widget)
     86        widgets['gutenbach-dialog'].destroy()
     87    def process(self, widget):
     88        memf = open('savedqueue','r+')
     89        printerMem = (self.wTree.get_widget("gutenbach-printer-entry").get_text())
     90        hostMem = (self.wTree.get_widget("gutenbach-host-entry").get_text())
     91        memf.write(printerMem)
     92        memf.write("\n")
     93        memf.write(hostMem)
     94        memf.write("\n")
     95        memf.close();
     96        self.process_songs(printerMem, hostMem)
     97     # stuff that does things 
     98    def process_songs(self, printer, host):
     99        source = self.shell.get_property("selected-source")
    55100        # For each track currently selected in the song browser
    56101        for entry in source.get_entry_view().get_selected_entries():
     
    60105            if p.scheme == "file":
    61106                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)
     107                if host:
     108                    print "there is a host"
     109                   # printer = '@'.join([printer, printer_host])
     110       
     111                printer = printer
     112                #command = 'gbr "%s"' % (path)
     113                command = 'lpr -H%s -P%s "%s"' % (host,printer, path)
    67114                print "About to run command '%s'" % command
    68115                subprocess.Popen(command, shell=True)
    69 
     116    def quit(self, widget):
     117        return
     118                         
  • rhythmbox/gutenbach.rb-plugin

    r30beeab r9fed25d  
    33Module=gutenbach
    44IAge=1
    5 Name=gutenbach
    6 Description="Print" tunes to the gutenbach server
    7 Authors=Nimrod Gileadi <nimrodg@mit.edu>
     5Name=Gutenbach
     6Description=Enable printing to a Gutenbach queue
     7Authors=Kyle Brogle <broglek@bu.edu>
     8Copyright=Copyright © 2010 Kyle Brogle
     9Website=http://gutenbach.mit.edu
Note: See TracChangeset for help on using the changeset viewer.