rendered paste bodyimport rhythmdb, rb
import gobject, gtk
import time
import shutil
import gst
import thread
import gconf
from HoraConfigureDialog import HoraConfigureDialog
#from HoraSource import HoraSource
#< moch> just generate the output file when playback starts
#< kev> ok moch what im unclear on is how would i generate output from
# within my plugin?
#< moch> you could create a new rhythmdb entry type, and generate the
# output file in the get_playback_uri method for that type
gconf_keys = { 'offset' : '/apps/rhythmbox/plugins/hora/offset' }
class HoraPlugin(rb.Plugin):
def __init__(self):
rb.Plugin.__init__(self)
def activate(self, shell):
self.shell = shell
print "activating Hora python plugin"
self.db = shell.get_property("db")
print "register entry type"
self.entry_type = self.db.entry_register_type("HoraEntryType")
group = rb.rb_source_group_get_by_name("shared")
self.source = gobject.new (HoraSource,
shell=self.shell,
entry_type=self.entry_type,
source_group=group,
plugin=self,
name=_("Hora"))
self.shell.register_entry_type_for_source(self.source, self.entry_type)
self.shell.append_source (self.source, None)
self.entry_type.get_playback_uri = self.hora_get_playback_uri
print "loading icon and button"
icon_file_name = self.find_file("hora.svg")
iconsource = gtk.IconSource()
iconsource.set_filename(icon_file_name)
iconset = gtk.IconSet()
iconset.add_source(iconsource)
iconfactory = gtk.IconFactory()
iconfactory.add("hora-button", iconset)
iconfactory.add_default()
action = gtk.Action ('Hora',
_('Hora'),
_('Que hora Es?'),
"hora-button")
action.connect('activate', self.hora, shell)
self.action_group = gtk.ActionGroup('HoraActionGroup')
self.action_group.add_action(action)
ui_manager = shell.get_ui_manager()
ui_manager.insert_action_group(self.action_group, 0)
self.UI_ID = ui_manager.add_ui_from_string(ui_str)
ui_manager.ensure_update()
# add hora.ogg
uri = self.find_file("hora.ogg")
self.uri = "file://"+ uri
shell.add_uri(self.uri, "hora", "time library")
print "add", self.uri
def create_configure_dialog(self, dialog=None):
if not dialog:
builder_file = self.find_file("hora-prefs.ui")
dialog = HoraConfigureDialog (builder_file).get_dialog()
dialog.present()
return dialog
def deactivate(self, shell):
print "deactivating Hora python plugin"
ui_manager = shell.get_ui_manager()
ui_manager.remove_ui(self.UI_ID)
ui_manager.remove_action_group(self.action_group)
self.action_group = None
ui_manager.ensure_update()
self.db.entry_delete_by_type(self.entry_type)
self.db.commit()
self.db = None
self.entry_type = None
self.source.delete_thyself()
self.source = None
del self.shell
del self.UI_ID
def hora(self, event, shell):
print "add to queue: ", self.uri
shell.add_to_queue(self.uri)
def hora_get_playback_uri(self, entry):
#format time
HOUR = str(time.localtime().tm_hour)
#offset from system time
offset = gconf.client_get_default().get_string(gconf_keys['offset'])
if offset != "0":
if HOUR == "0":
HOUR = "12"
HOUR = int(HOUR) + int(offset)
HOUR = str(HOUR)
if len(HOUR) == 1:
HOUR = "0"+ HOUR
MIN = str(time.localtime().tm_min)
if len(MIN) == 1:
MIN = "0"+ MIN
#build audio file
fname = self.find_file("hora.ogg")
uri = fname
dest = open(uri,'wb')
HOUR_STR = "/audio/HRS"+ HOUR+ ".ogg.spx"
MIN_STR = "/audio/MIN"+ MIN+ ".ogg.spx"
fhour = self.find_file(HOUR_STR)
fmin = self.find_file(MIN_STR)
# copy file should be done with gst
print "copy %s to %s" % (fhour, dest)
shutil.copyfileobj(open(fhour,'rb'), dest)
print "copy %s to %s" % (fmin, dest)
shutil.copyfileobj(open(fmin,'rb'), dest)
dest.close()
url = "file://"+ fname
print url
return url
ui_str = \
"""<ui>
<menubar name="MenuBar">
<menu name="ControlMenu" action="Control">
<placeholder name="PluginPlaceholder">
<menuitem name="Hora" action="Hora"/>
</placeholder>
</menu>
</menubar>
<toolbar name="ToolBar">
<placeholder name="PluginPlaceholder">
<toolitem name="Hora" action="Hora"/>
</placeholder>
</toolbar>
</ui>"""