Index: channels/timer.py ================================================================== --- channels/timer.py +++ channels/timer.py @@ -3,23 +3,23 @@ # title: Recording timer # description: Schedules play/record events for bookmarked radio stations. # type: feature # category: hook # depends: kronos -# version: 0.5 +# version: 0.6 # config: - # priority: optional # support: unsupported # -# Okay, while programming this, I missed the broadcast I wanted to hear. Again(!) -# But still this is a useful extension, as it allows recording and playing specific -# stations at a programmed time and interval. It accepts a natural language time -# string when registering a stream. (Via streams menu > extension > add timer) +# Provides an internal timer, to configure recording and playback times/intervals +# for stations. It accepts a natural language time string when registering a stream. +# +# Context menu > Extension > Add timer # # Programmed events are visible in "timer" under the "bookmarks" channel. Times # are stored in the description field, and can thus be edited. However, after editing -# times manually, streamtuner2 must be restarted for the changes to take effect. +# times manually, streamtuner2 must be restarted for any changes to take effect. # from config import * from channels import * @@ -37,18 +37,15 @@ # plugin info module = "timer" title = "Timer" meta = plugin_meta() - # configuration settings timefield = "playing" - # kronos scheduler list sched = None - # prepare gui def __init__(self, parent): @@ -66,13 +63,15 @@ self.bookmarks.streams["timer"] = [{"title":"--- timer events ---"}] self.bookmarks.add_category("timer") self.streams = self.bookmarks.streams["timer"] # widgets - parent.add_signals.update({ - "timer_ok": self.add_timer, - "timer_cancel": lambda w,*a: self.parent.timer_dialog.hide() or 1, + uikit.add_signals(parent, { + ("timer_ok", "clicked"): self.add_timer, + ("timer_cancel", "clicked"): self.hide, + ("timer_dialog", "close"): self.hide, + ("timer_dialog", "delete-event"): self.hide, }) # prepare spool self.sched = kronos.ThreadedScheduler() for row in self.streams: @@ -84,10 +83,14 @@ # display GUI for setting timespec def edit_timer(self, *w): self.parent.timer_dialog.show() self.parent.timer_value.set_text("Fri,Sat 20:00-21:00 play") + # done + def hide(self, *w): + return self.parent.timer_dialog.hide() + # close dialog,get data def add_timer(self, *w): self.parent.timer_dialog.hide() row = self.parent.row() row = copy.copy(row) Index: uikit.py ================================================================== --- uikit.py +++ uikit.py @@ -27,13 +27,12 @@ import os.path import copy import sys import re import base64 -import zlib import inspect -from compat2and3 import unicode, xrange, PY3 +from compat2and3 import unicode, xrange, PY3, gzip_decode # gtk version (2=gtk2, 3=gtk3, 7=tk;) ver = 2 # if running on Python3 or with commandline flag @@ -57,11 +56,11 @@ GdkPixbuf = gtk.gdk empty_pixbuf = GdkPixbuf.Pixbuf(gtk.gdk.COLORSPACE_RGB,True,8,16,16) empty_pixbuf.fill(0xFFFFFFFF) # prepare gtkbuilder data -ui_xml = get_data("gtk3.xml.zlib", decode=True, z=True) or get_data("gtk3.xml", decode=True) +ui_xml = get_data("gtk3.xml.gz", decode=True, gz=True) #or get_data("gtk3.xml", decode=True) if ver == 2: ui_xml = ui_xml.replace('version="3.0"', 'version="2.16"') @@ -449,10 +448,17 @@ def msg(text, style=gtk.MESSAGE_INFO, buttons=gtk.BUTTONS_CLOSE): m = gtk.MessageDialog(None, 0, style, buttons, message_format=text) m.show() m.connect("response", lambda *w: m.destroy()) + + # manual signal binding with a dict of { (widget, signal): callback } + @staticmethod + def add_signals(builder, map): + for (widget,signal),func in map.items(): + builder.get_widget(widget).connect(signal, func) + # Pixbug loader (from inline string, as in `logo.png`) @staticmethod def pixbuf(buf, fmt="png", decode=True, gzip=False): if not buf or len(buf) < 16: @@ -464,11 +470,11 @@ else: p = GdkPixbuf.PixbufLoader() if decode and re.match("^[\w+/=\s]+$", str(buf)): buf = base64.b64decode(buf) # inline encoding if gzip: - buf = zlib.decompress(buf) + buf = gzip_decode(buf) if buf: p.write(buf) pix = p.get_pixbuf() p.close() return pix