def __init__(self): """initialise the DaemonPlugin interface""" logger.log(9, 'detachbar.PluginInterface.__init__()') plugin.DaemonPlugin.__init__(self) self.plugin_name = 'audio.detachbar' self.player = None self.timer = Timer(self._timer_handler) self.event = EventHandler(self._event_handler) self.event.register() self.state = BAR_NOTSET self.update(BAR_HIDE) # tunables self.wait_timeout = 3 # 3 seconds till we hide the bar
def __init__(self, standalone=False): """ init the upsoon plugin """ _debug_('upsoon.PluginInterface.__init__()', 2) plugin.DaemonPlugin.__init__(self) plugin.register(self, 'upsoon') self.standalone = standalone self.lock = thread.allocate_lock() self.running = True self.timer = Timer(self.timer_handler).start(15) self.event = EventHandler(self.event_handler) #self.event.register(('VIDEO_START', 'VIDEO_END')) self.event.register() self.recordclient = RecordClient() self.fc = FreevoChannels() self.rdev = config.RADIO_DEVICE self.next_program = None self.seconds_before_announce = 120 self.seconds_before_start = 60 self.pending_lockfile = config.FREEVO_CACHEDIR + '/record.soon' self.tv_lockfile = None # lockfile of recordserver self.stopped = None # flag that tells upsoon what stopped
def __init__(self, standalone=False): """ init the upsoon plugin """ logger.log( 9, 'upsoon.PluginInterface.__init__()') plugin.DaemonPlugin.__init__(self) plugin.register(self, 'upsoon') self.standalone = standalone self.lock = thread.allocate_lock() self.running = True self.timer = Timer(self.timer_handler).start(15) self.event = EventHandler(self.event_handler) #self.event.register(('VIDEO_START', 'VIDEO_END')) self.event.register() self.recordclient = RecordClient() self.fc = FreevoChannels() self.rdev = config.RADIO_DEVICE self.next_program = None self.announced = False self.seconds_before_announce = config.TV_UPSOON_ANNOUNCE self.seconds_before_start = config.TV_UPSOON_BEFORE_START self.pending_lockfile = config.FREEVO_CACHEDIR + '/record.soon' self.tv_lockfile = None # lockfile of recordserver self.stopped = None # flag that tells upsoon what stopped if os.path.exists(self.pending_lockfile): os.remove(self.pending_lockfile) logger.debug('%r lockfile removed', self.pending_lockfile)
class Master(object): """ Master Monitor. This monitor will connect to the db and will call all monitors with the changes. This class will make sure they don't re-query all at once and have a small delay between them to keep the load down. """ def __init__(self, db): self.monitors = [] self.timer = Timer(self.check) db.signals['changed'].connect(self.changed) def connect(self, monitor): """ Connect a new monitor. """ self.monitors.append((weakref(monitor), [ False, [] ])) def changed(self, changes): """ Database callback with changed ids. """ if len(changes) == 1 and changes[0][0] == 'media': for m, c in self.monitors: c[0] = True for m, c in self.monitors: c[1].extend(changes) if not self.timer.active: # TODO: should use scheduler to get interval self.timer.start(0.02) def check(self): """ Timed callback to call the connected monitor update functions. """ if not self.monitors: return False monitor, (force, changes) = self.monitors.pop(0) if monitor == None: return True if changes or force: monitor.check(changes) self.monitors.append((monitor, [ False, [] ])) return len(changes) > 0 or force
class Master(object): """ Master Monitor. This monitor will connect to the db and will call all monitors with the changes. This class will make sure they don't re-query all at once and have a small delay between them to keep the load down. """ def __init__(self, db): self.monitors = [] self.timer = Timer(self.check) db.signals['changed'].connect(self.changed) def connect(self, monitor): """ Connect a new monitor. """ self.monitors.append((weakref(monitor), [False, []])) def changed(self, changes): """ Database callback with changed ids. """ if len(changes) == 1 and changes[0][0] == 'media': for m, c in self.monitors: c[0] = True for m, c in self.monitors: c[1].extend(changes) if not self.timer.active: # TODO: should use scheduler to get interval self.timer.start(0.02) def check(self): """ Timed callback to call the connected monitor update functions. """ if not self.monitors: return False monitor, (force, changes) = self.monitors.pop(0) if monitor == None: return True if changes or force: monitor.check(changes) self.monitors.append((monitor, [False, []])) return len(changes) > 0 or force
def __init__(self): """initialise the DaemonPlugin interface""" logger.log( 9, 'detachbar.PluginInterface.__init__()') plugin.DaemonPlugin.__init__(self) self.plugin_name = 'audio.detachbar' self.player = None self.timer = Timer(self._timer_handler) self.event = EventHandler(self._event_handler) self.event.register() self.state = BAR_NOTSET self.update(BAR_HIDE) # tunables self.wait_timeout = 3 # 3 seconds till we hide the bar
def __init__(self, x, y, width, height, title=None, coverfilename=None): """ Initialise the MPlayer Visualization Goom """ logger.debug('%s.__init__(x=%r y=%r width=%r height=%r coverfilename=%r)', self.__class__, x, y, width, height, coverfilename) self.mode = MpvMode(config.MPLAYERVIS_MODE) self.coverfilename = coverfilename self.showfps = False if not os.path.exists(MMAP_FILE): f = open(MMAP_FILE, 'w') s = str(chr(0)) * 2064 f.write(s) f.close() #pygoom.debug(2) BaseAnimation.__init__(self, (x, y, width, height), fps=100, bg_update=False, bg_redraw=False) # goom doesn't handle Unicode, so make it a string self.goom = pygoom.PyGoom(width, height, MMAP_FILE, songtitle=self.to_str(title) or '') self.infodata = None self.width = width self.height = height self.fade_step = config.MPLAYERVIS_FADE_STEP self.init_counter = self.fade_step * config.MPLAYERVIS_INIT_COUNTER self.fade_in_wait_counter = self.fade_step * config.MPLAYERVIS_FADE_IN_WAIT_COUNTER self.fade_out_wait_counter = self.fade_step * config.MPLAYERVIS_FADE_OUT_WAIT_COUNTER self.fade_counter = self.fade_step * config.MPLAYERVIS_FADE_COUNTER self.fade_machine = { 'init': self.init_state, 'fade_out_wait': self.fade_out_wait_state, 'fade_out': self.fade_out_state, 'fade_in_wait': self.fade_in_wait_state, 'fade_in': self.fade_in_state, } self.state = self.fade_machine['init'] self.counter = self.init_counter self.fader = lambda n, m: int(float(n-m)/float(2)) self.alpha = self.set_alpha(self.counter, 0) self.clock = Clock() self.running = False self.timer = Timer(self.goom_surface_update) self.last_time = 0 self.message_counter = 1 # skip message at start self.message = ''
def __init__(self, x, y, width, height, coverfile=None): """ Initialise the MPlayer Visualization Goom """ _debug_( '__init__(x=%r y=%r width=%r height=%r coverfile=%r)' % (x, y, width, height, coverfile), 2) self.coverfile = coverfile BaseAnimation.__init__(self, (x, y, width, height), fps=100, bg_update=False, bg_redraw=False) _debug_('pygoom.set_exportfile(mmap_file=%r)' % (mmap_file), 2) pygoom.set_exportfile(mmap_file) _debug_( 'pygoom.set_resolution(width=%r, height=%r, 0)' % (width, height), 2) pygoom.set_resolution(width, height, 0) self.fade_step = config.MPLAYERVIS_FADE_STEP self.init_counter = self.fade_step * config.MPLAYERVIS_INIT_COUNTER self.fade_in_wait_counter = self.fade_step * config.MPLAYERVIS_FADE_IN_WAIT_COUNTER self.fade_out_wait_counter = self.fade_step * config.MPLAYERVIS_FADE_OUT_WAIT_COUNTER self.fade_counter = self.fade_step * config.MPLAYERVIS_FADE_COUNTER self.fade_machine = { 'init': self.init_state, 'fade_out_wait': self.fade_out_wait_state, 'fade_out': self.fade_out_state, 'fade_in_wait': self.fade_in_wait_state, 'fade_in': self.fade_in_state, } self.state = self.fade_machine['init'] self.counter = self.init_counter self.fader = lambda n, m: int(float(n - m) / float(2)) self.alpha = self.set_alpha(self.counter, 0) self.running = True Timer(self.timerhandler).start(0.1) self.last_time = 0
def __init__(self, db): self.monitors = [] self.timer = Timer(self.check) db.signals['changed'].connect(self.changed)
class PluginInterface(plugin.DaemonPlugin): """ This plugin enables a small bar showing information about audio being played when detached with the detach plugin. If the idlebar is loaded and there is enough space left there, this plugin will draw itself there, otherwise it will draw at the right bottom of the screen. A dot (graphvis) diagram of the states the bar has dot -Tpng -odetach.png detach.dot | digraph finite_state_machine { | rankdir=TB; | size="8,5" | node [shape = doublecircle]; Hide; | node [shape = circle]; | { rank = same; "Wait"; "Show"; } | Hide -> Show [ label = "detach(start timer)" ]; | Show -> Wait [ label = "play_end" ]; | Show -> Hide [ label = "stop(stop timer)" ]; | Wait -> Hide [ label = "stop(stop timer)" ]; | Show -> Show [ label = "play_start" ]; | Wait -> Show [ label = "play_start" ]; | Wait -> Hide [ label = "timeout(stop timer)" ]; | } """ detached = False def __init__(self): """initialise the DaemonPlugin interface""" logger.log( 9, 'detachbar.PluginInterface.__init__()') plugin.DaemonPlugin.__init__(self) self.plugin_name = 'audio.detachbar' self.player = None self.timer = Timer(self._timer_handler) self.event = EventHandler(self._event_handler) self.event.register() self.state = BAR_NOTSET self.update(BAR_HIDE) # tunables self.wait_timeout = 3 # 3 seconds till we hide the bar def _event_handler(self, event): logger.log( 9, '_event_handler(event=%s)', event) if plugin.isevent(event) == 'DETACH': PluginInterface.detached = True self.update(BAR_SHOW) elif plugin.isevent(event) == 'ATTACH': PluginInterface.detached = False self.update(BAR_HIDE) elif event == STOP: PluginInterface.detached = False self.update(BAR_HIDE) elif event == BUTTON and event.arg == 'STOP': PluginInterface.detached = False self.update(BAR_HIDE) elif PluginInterface.detached: if event == PLAY_START: self.update(BAR_SHOW) elif event == PLAY_END: self.update(BAR_WAIT) def _timer_handler(self): logger.log( 9, '_timer_handler()') self.update() def update(self, state=None): """ update the bar according to bar state """ logger.log( 8, 'update()') if state is not None: if state == BAR_SHOW: self.show() self.timer.start(1.0) elif state == BAR_HIDE: self.timer.stop() self.hide() elif state == BAR_WAIT: self.time = time.time() self.state = state if self.state == BAR_SHOW: skin.redraw() elif self.state == BAR_HIDE: skin.redraw() elif self.state == BAR_WAIT: if self.time and (time.time() - self.time) > self.wait_timeout: self.update(BAR_HIDE) def show(self): """ used when showing for the first time """ logger.log( 9, 'show()') self.player = audio.player.get() if self.player: self.getinfo() def hide(self): """ used when hiding the bar """ logger.log( 9, 'hide()') self.render = [] self.player = None self.time = None self.bar = None def stop(self): """ stops the player, waiting for timeout """ logger.log( 9, 'stop()') #self.state = BAR_WAIT #self.time = time.time() def draw(self, (type, object), osd): """ draws the bar called from the skin's redraw method """ logger.log( 8, 'draw((type=%r, object=%r), osd=%r)', type, object, osd) if self.player is None: return #if self.state == BAR_WAIT: # # when idle, wait for a new player # if audio.player.get(): # self.show() #elif self.state == BAR_SHOW: # if self.player and not self.player.running: # # player stopped, we also stop # # and wait for a new one # self.player = None # self.stop() # return # if type == 'player': # # Oops, showing the player again, stop me # self.stop() # self.hide() # return font = osd.get_font('detachbar') if font == osd.get_font('default'): font = osd.get_font('info value') self.calculatesizes(osd, font) if self.image: x = self.x - self.h width = self.w + 70 - 10 else: x = self.x width = self.w if not self.idlebar: y = self.y - 10 height = self.h osd.drawroundbox(x, y, width, height, (0xf0ffffffL, 5, 0xb0000000L, 10)) if self.image: osd.draw_image(self.image, (x+5, self.y, 50, 50)) y = self.t_y for r in self.render: osd.write_text(r, font, None, self.t_x, y, self.t_w, self.font_h, 'center', 'center') y += self.font_h try: if self.player.item.length: progress = '%s/%s' % (self.formattime(self.player.item.elapsed), self.formattime(self.player.item.length)) else: progress = '%s' % self.formattime(self.player.item.elapsed) except AttributeError: progress = '' osd.write_text(progress, font, None, self.t_x, y, self.t_w, self.font_h, 'center', 'center')
class PluginInterface(plugin.DaemonPlugin): """ This plugin enables a small bar showing information about audio being played when detached with the detach plugin. If the idlebar is loaded and there is enough space left there, this plugin will draw itself there, otherwise it will draw at the right bottom of the screen. A dot (graphvis) diagram of the states the bar has dot -Tpng -odetach.png detach.dot | digraph finite_state_machine { | rankdir=TB; | size="8,5" | node [shape = doublecircle]; Hide; | node [shape = circle]; | { rank = same; "Wait"; "Show"; } | Hide -> Show [ label = "detach(start timer)" ]; | Show -> Wait [ label = "play_end" ]; | Show -> Hide [ label = "stop(stop timer)" ]; | Wait -> Hide [ label = "stop(stop timer)" ]; | Show -> Show [ label = "play_start" ]; | Wait -> Show [ label = "play_start" ]; | Wait -> Hide [ label = "timeout(stop timer)" ]; | } """ detached = False def __init__(self): """initialise the DaemonPlugin interface""" logger.log(9, 'detachbar.PluginInterface.__init__()') plugin.DaemonPlugin.__init__(self) self.plugin_name = 'audio.detachbar' self.player = None self.timer = Timer(self._timer_handler) self.event = EventHandler(self._event_handler) self.event.register() self.state = BAR_NOTSET self.update(BAR_HIDE) # tunables self.wait_timeout = 3 # 3 seconds till we hide the bar def _event_handler(self, event): logger.log(9, '_event_handler(event=%s)', event) if plugin.isevent(event) == 'DETACH': PluginInterface.detached = True self.update(BAR_SHOW) elif plugin.isevent(event) == 'ATTACH': PluginInterface.detached = False self.update(BAR_HIDE) elif event == STOP: PluginInterface.detached = False self.update(BAR_HIDE) elif event == BUTTON and event.arg == 'STOP': PluginInterface.detached = False self.update(BAR_HIDE) elif PluginInterface.detached: if event == PLAY_START: self.update(BAR_SHOW) elif event == PLAY_END: self.update(BAR_WAIT) def _timer_handler(self): logger.log(9, '_timer_handler()') self.update() def update(self, state=None): """ update the bar according to bar state """ logger.log(8, 'update()') if state is not None: if state == BAR_SHOW: self.show() self.timer.start(1.0) elif state == BAR_HIDE: self.timer.stop() self.hide() elif state == BAR_WAIT: self.time = time.time() self.state = state if self.state == BAR_SHOW: skin.redraw() elif self.state == BAR_HIDE: skin.redraw() elif self.state == BAR_WAIT: if self.time and (time.time() - self.time) > self.wait_timeout: self.update(BAR_HIDE) def show(self): """ used when showing for the first time """ logger.log(9, 'show()') self.player = audio.player.get() if self.player: self.getinfo() def hide(self): """ used when hiding the bar """ logger.log(9, 'hide()') self.render = [] self.player = None self.time = None self.bar = None def stop(self): """ stops the player, waiting for timeout """ logger.log(9, 'stop()') #self.state = BAR_WAIT #self.time = time.time() def draw(self, (type, object), osd): """ draws the bar called from the skin's redraw method """ logger.log(8, 'draw((type=%r, object=%r), osd=%r)', type, object, osd) if self.player is None: return #if self.state == BAR_WAIT: # # when idle, wait for a new player # if audio.player.get(): # self.show() #elif self.state == BAR_SHOW: # if self.player and not self.player.running: # # player stopped, we also stop # # and wait for a new one # self.player = None # self.stop() # return # if type == 'player': # # Oops, showing the player again, stop me # self.stop() # self.hide() # return font = osd.get_font('detachbar') if font == osd.get_font('default'): font = osd.get_font('info value') self.calculatesizes(osd, font) if self.image: x = self.x - self.h width = self.w + 70 - 10 else: x = self.x width = self.w if not self.idlebar: y = self.y - 10 height = self.h osd.drawroundbox(x, y, width, height, (0xf0ffffffL, 5, 0xb0000000L, 10)) if self.image: osd.draw_image(self.image, (x + 5, self.y, 50, 50)) y = self.t_y for r in self.render: osd.write_text(r, font, None, self.t_x, y, self.t_w, self.font_h, 'center', 'center') y += self.font_h try: if self.player.item.length: progress = '%s/%s' % (self.formattime( self.player.item.elapsed), self.formattime(self.player.item.length)) else: progress = '%s' % self.formattime(self.player.item.elapsed) except AttributeError: progress = '' osd.write_text(progress, font, None, self.t_x, y, self.t_w, self.font_h, 'center', 'center')