def play(self, item, menuw): _debug_('play(item=%r, menuw=%r)' % (item, menuw), 2) self.item = item self.filename = item.filename self.command = item.command self.mode = item.mode self.menuw = menuw if not os.path.isfile(self.filename): osd.clearscreen() osd.drawstring(_('File "%s" not found!') % self.filename, 30, 280) osd.update() time.sleep(2.0) self.menuw.refresh() return 0 if plugin.getbyname('MIXER'): plugin.getbyname('MIXER').reset() if plugin.is_active('joy'): try: plugin.getbyname('JOY').enable(FALSE) except Exception, e: _debug_('getbyname(\'JOY\')', e, DWARNING)
def __run__(self): _debug_('__run__()', 2) current_saver = None index = 0 plugins_count = len(self.plugins) _debug_('found %s screensaver(s)' % plugins_count) while not self.stop_screensaver: # No current screensaver so select one of the installed screensaver # plugins at random # if current_saver is None: if plugins_count == 1: current_saver = self.plugins[0] elif plugins_count > 1 and plugins_count <= 4: current_saver = self.plugins[index] index += 1 if index >= plugins_count: index = 0 elif plugins_count > 4: index = random.randint(0, len(self.plugins) - 1) current_saver = self.plugins[index] # No screensaver found just sleep for 200ms if current_saver is None: time.sleep(0.200) else: self.__run_screensaver__(current_saver) self.screensaver_showing = False skin.force_redraw = True skin.redraw() osd.update() _debug_('Screensaver thread stopped')
def __run_screensaver__(self, screensaver): _debug_( '__run_screensaver__(screensaver=%r)' % (screensaver.plugin_name, ), 2) try: fps = screensaver.start(osd.width, osd.height) max_iterations = int(self.cycle_time / (1.0 / fps)) iteration = 0 clock = pygame.time.Clock() while (not self.stop_screensaver) and (iteration < max_iterations): # Draw the screen and update the display screensaver.draw(osd.screen) pygame.display.flip() clock.tick(fps) iteration += 1 screensaver.stop() except: print 'Screensaver %s crashed!' % screensaver.plugin_name traceback.print_exc() # Remove the broken screensaver so we don't try to run it again self.plugins.remove(screensaver) osd.clearscreen(osd.COL_BLACK) osd.update()
def enable_dpms(self): self.dpms_enabled = True self.timer.stop() osd.clearscreen(osd.COL_BLACK) osd.update() logger.debug('Forced DPMS OFF') os.system('xset dpms force off')
def play(self, item, menuw): logger.log( 9, 'play(item=%r, menuw=%r)', item, menuw) self.item = item self.filename = item.filename self.command = item.command self.mode = item.mode self.menuw = menuw if not os.path.isfile(self.filename): osd.clearscreen() osd.drawstring(_('File "%s" not found!') % self.filename, 30, 280) osd.update() time.sleep(2.0) self.menuw.refresh() return 0 if plugin.getbyname('MIXER'): plugin.getbyname('MIXER').reset() if plugin.is_active('joy'): try: plugin.getbyname('JOY').disable() except Exception, why: logger.warning('getbyname("JOY"): %s', why)
def __draw(self, screensaver, time_per_frame, iteration, max_iterations): s = time.time() try: screensaver.draw(osd.screen) pygame.display.flip() except: iteration = max_iterations print 'Screensaver %s crashed!' % screensaver.plugin_name traceback.print_exc() # Remove the broken screensaver so we don't try to run it again self.plugins.remove(screensaver) e = time.time() t = e - s iteration += 1 if iteration < max_iterations: d = time_per_frame - t if d < 0.0: d = time_per_frame self.timer = kaa.OneShotTimer(self.__draw, screensaver, time_per_frame, iteration, max_iterations) self.timer.start(d) else: try: screensaver.stop() except: print 'Screensaver %s crashed when stopping' % screensaver.plugin_name osd.clearscreen(osd.COL_BLACK) osd.update() self.__next()
def goom_surface_update(self): """ The timer handler Uses a state machine to control the display of the cover image """ #_debug_('goom_surface_update()') try: # draw the cover if not self.running: return False if self.mode == MpvMode.FULL: if self.message_counter == 0: print('%s.message=%r' % (self.__class__, self.message)) if self.message: self.set_message(self.message) self.message_counter = (self.message_counter + 1) % config.MPLAYERVIS_MSG_FRAMES gooms = self.goom.process() # write the goom surface to the display if self.mode == MpvMode.FULL: zoom = 2 ** config.MPLAYERVIS_FULL_ZOOM for i in range(config.MPLAYERVIS_FULL_ZOOM): gooms = transform.scale2x(gooms) self.rect.width = gooms.get_width() self.rect.height = gooms.get_height() #print 'zoom=%r %r rect=%r' % (zoom, range(config.MPLAYERVIS_FULL_ZOOM), self.rect) #DJW elif self.mode == MpvMode.DOCK: zoom = 2 ** config.MPLAYERVIS_DOCK_ZOOM for i in range(config.MPLAYERVIS_DOCK_ZOOM): gooms = transform.scale2x(gooms) self.rect.width = gooms.get_width() self.rect.height = gooms.get_height() #print 'zoom=%r %r rect=%r' % (zoom, range(config.MPLAYERVIS_DOCK_ZOOM), self.rect) #DJW if self.showfps: self.goom.fps = self.clock.get_fps() else: self.goom.fps = -1 if self.coversurf: self.state() if self.alpha > 0: s, x, y = self.coversurf logger.log( 9, 'self.alpha=%r', self.alpha) s.set_alpha(self.alpha) logger.log( 9, 'gooms.blit(s=%r, (x=%r, y=%r))', s, x, y) gooms.blit(s, (x, y)) if self.mode == MpvMode.FULL: self.draw_info(gooms) osd.putsurface(gooms, self.rect.left, self.rect.top) osd.update(self.rect) self.clock.tick() return True except Exception, why: traceback.print_exc() logger.warning(why)
def __cleanup_freevo(): import osd import plugin import rc import util.mediainfo osd = osd.get_singleton() util.mediainfo.sync() if not config.HELPER: if not osd.active: # this function is called from the signal # handler, but we are dead already. sys.exit(0) osd.clearscreen(color=osd.COL_BLACK) osd.drawstringframed(_('shutting down...'), 0, 0, osd.width, osd.height, osd.getfont(config.OSD_DEFAULT_FONTNAME, config.OSD_DEFAULT_FONTSIZE), fgcolor=osd.COL_ORANGE, align_h='center', align_v='center') osd.update() time.sleep(0.5) # shutdown all daemon plugins plugin.shutdown() # shutdown registered callbacks rc.shutdown() if not config.HELPER: # shutdown the screen osd.clearscreen(color=osd.COL_BLACK) osd.shutdown()
def do_slide_step(self, transition): self.steps += 1 if self.steps == TRANSITION_STEPS: self.timer.stop() self.timer = None self.next_screen.set_alpha(255) osd.main_layer.blit(self.next_screen, (0,0)) osd.update() self.transitioning = False return osd.main_layer.fill(0) if transition == TRANSITION_IN: r = self.current_screen.get_rect() self.current_screen.set_alpha((255 * (TRANSITION_STEPS - self.steps) / TRANSITION_STEPS)) osd.main_layer.blit(self.current_screen, (0,0), r) r = self.next_screen.get_rect() r.width = (r.width * self.steps) / TRANSITION_STEPS osd.main_layer.blit(self.next_screen, (self.next_screen.get_width() - r.width,0), r) else: self.next_screen.set_alpha((255 * self.steps)/TRANSITION_STEPS) r = self.next_screen.get_rect() osd.main_layer.blit(self.next_screen, (0,0), r) r = self.current_screen.get_rect() r.width = (r.width * (TRANSITION_STEPS - self.steps)) / TRANSITION_STEPS osd.main_layer.blit(self.current_screen, (self.current_screen.get_width() - r.width,0), r) osd.update()
def clear(self, osd_update=True): """ Clean the screen """ logger.debug('Skin.clear(osd_update=%r)', osd_update) self.force_redraw = True osd.clearscreen(osd.COL_BLACK) if osd_update: osd.update()
def clear(self, osd_update=True): """ clean the screen """ _debug_('clear: %s' % osd_update, 2) self.force_redraw = True osd.clearscreen(osd.COL_BLACK) if osd_update: osd.update()
def RunCmd(self, arg=None, menuw=None): popup_string=_("Starting Web Browser...") pop = PopupBox(text=popup_string) pop.show() osd.stopdisplay() os.system('mozilla-firebird') osd.restartdisplay() osd.update() pop.destroy() osd.update()
def stop_saver(self): logger.log( 9, 'stop_saver()') if self.timer is not None: self.disable_dpms() self.dpms_timer.stop() self.timer.stop() self.screensaver_showing = False skin.redraw() osd.screensaver_running = False osd.update() logger.debug('Screensaver thread stopped')
def do_blend_step(self, transition): self.steps += 1 if self.steps == TRANSITION_STEPS: self.timer.stop() self.timer = None self.next_screen.set_alpha(255) osd.main_layer.blit(self.next_screen, (0,0)) osd.update() self.transitioning = False return osd.main_layer.blit(self.current_screen, (0,0)) self.next_screen.set_alpha((255 * self.steps) / TRANSITION_STEPS) osd.main_layer.blit(self.next_screen, (0,0)) osd.update()
def poll(self, current_time): """ override to get extra performance """ if self.next_update < current_time: self.next_update = current_time + self.interval gooms = pygoom.get_surface() # draw blending if self.coversurf: self.blend += self.blend_step if self.blend > self.max_blend: self.blend = self.max_blend elif self.blend < 0: self.blend = 0 self.max_blend = 120 if time.time() - self.c_timer > self.timeout: if self.timeout == self.c_timeout: self.timeout = self.v_timeout else: self.timeout = self.c_timeout self.c_timer = time.time() self.blend_step = - self.blend_step if self.blend > 0: s, x, y = self.coversurf s.set_alpha(self.blend) gooms.blit(s, (x, y)) # draw message if self.message: s, x, y, w, h = self.message if time.time() - self.m_timer > self.m_timeout: self.message = False s.fill(0) gooms.blit(s, (x,y)) osd.putsurface(gooms, self.rect.left, self.rect.top) osd.update(self.rect)
def timerhandler(self): """ The timer handler Uses a state machine """ #_debug_('timerhandler()', 2) # draw the cover if not self.running: return self.running gooms = pygoom.get_surface() if self.coversurf: self.state() if self.alpha > 0: s, x, y = self.coversurf _debug_('self.alpha=%r' % (self.alpha, ), 2) s.set_alpha(self.alpha) _debug_('gooms.blit(s=%r, (x=%r, y=%r))' % (s, x, y), 2) gooms.blit(s, (x, y)) # draw the info if not self.running: return self.running if self.info: s, x, y, w, h = self.info if time.time() - self.m_timer > self.m_timeout: self.info = False s.fill(0) _debug_('gooms.blit(s=%r, (x=%r, y=%r))' % (s, x, y), 2) gooms.blit(s, (x, y)) osd.putsurface(gooms, self.rect.left, self.rect.top) osd.update(self.rect) return self.running
def shutdown(menuw=None, mode=None, exit=False): """ Function to shut down freevo or the whole system. This system will be shut down when argshutdown is True, restarted when argrestart is true, else only Freevo will be stopped. """ logger.debug('shutdown(menuw=%r, mode=%r, exit=%r)', menuw, mode, exit) if ShutdownModes.shutdown_in_progress: logger.debug('shutdown in progress') return ShutdownModes.shutdown_in_progress = True import osd import plugin import rc import util.mediainfo osd = osd.get_singleton() util.mediainfo.sync() if not osd.active: # this function is called from the signal handler, but we are dead # already. sys.exit(0) skin.get_singleton().suspend() osd.clearscreen(color=osd.COL_BLACK) if mode == ShutdownModes.SYSTEM_SHUTDOWN: msg = _('Shutting down...') elif mode == ShutdownModes.SYSTEM_RESTART: msg = _('Restarting...') else: msg = _('Exiting...') osd.drawstringframed(msg, 0, 0, osd.width, osd.height, osd.getfont(config.OSD_DEFAULT_FONTNAME, config.OSD_DEFAULT_FONTSIZE), fgcolor=osd.COL_ORANGE, align_h='center', align_v='center') osd.update() time.sleep(0.5) if mode == ShutdownModes.SYSTEM_SHUTDOWN or mode == ShutdownModes.SYSTEM_RESTART: # shutdown dual head for mga if config.CONF.display == 'mga': os.system('%s runapp matroxset -f /dev/fb1 -m 0' % os.environ['FREEVO_SCRIPT']) time.sleep(1) os.system('%s runapp matroxset -f /dev/fb0 -m 1' % os.environ['FREEVO_SCRIPT']) time.sleep(1) logger.debug('sys:plugin.shutdown()') plugin.shutdown() logger.debug('sys:rc.shutdown()') rc.shutdown() #if config.CONF.display == 'mga': logger.debug('sys:osd.shutdown()') osd.shutdown() if mode == ShutdownModes.SYSTEM_SHUTDOWN: logger.debug('os.system(%r)', config.SYS_SHUTDOWN_CMD) os.system(config.SYS_SHUTDOWN_CMD) elif ShutdownModes.SYSTEM_RESTART: logger.debug('os.system(%r)', config.SYS_RESTART_CMD) os.system(config.SYS_RESTART_CMD) # this closes the log logger.debug('sys:config.shutdown()') config.shutdown() # let freevo be killed by init, looks nicer for mga print 'Freevo shutdown' while True: time.sleep(1) # # Exit Freevo # # shutdown any daemon plugins that need it. logger.debug('plugin.shutdown()') plugin.shutdown() # shutdown registered callbacks logger.debug('rc.shutdown()') rc.shutdown() # SDL must be shutdown to restore video modes etc logger.log( 9, 'osd.clearscreen(color=osd.COL_BLACK)') osd.clearscreen(color=osd.COL_BLACK) logger.debug('osd.shutdown()') osd.shutdown() logger.debug('config.shutdown()') config.shutdown() if exit: # really exit, we are called by the signal handler logger.debug('raise SystemExit') raise SystemExit # We must use spawn instead of os.system here because the python interpreter # lock is held by os.system until the command returns, which prevents receiving # any signals. logger.log( 9, '%s --stop', os.environ['FREEVO_SCRIPT']) os.spawnlp(os.P_NOWAIT, os.environ['FREEVO_SCRIPT'], os.environ['FREEVO_SCRIPT'], '--stop') # Just wait until we're dead. SDL cannot be polled here anyway. while True: time.sleep(1)
def shutdown(menuw=None, argshutdown=None, argrestart=None, exit=False): """ Function to shut down freevo or the whole system. This system will be shut down when argshutdown is True, restarted when argrestart is true, else only Freevo will be stopped. """ import osd import plugin import rc import util.mediainfo osd = osd.get_singleton() util.mediainfo.sync() if not osd.active: # this function is called from the signal handler, but # we are dead already. sys.exit(0) osd.clearscreen(color=osd.COL_BLACK) osd.drawstringframed(_('shutting down...'), 0, 0, osd.width, osd.height, osd.getfont(config.OSD_DEFAULT_FONTNAME, config.OSD_DEFAULT_FONTSIZE), fgcolor=osd.COL_ORANGE, align_h='center', align_v='center') osd.update() time.sleep(0.5) if argshutdown or argrestart: # shutdown dual head for mga if config.CONF.display == 'mga': os.system('%s runapp matroxset -f /dev/fb1 -m 0' % \ os.environ['FREEVO_SCRIPT']) time.sleep(1) os.system('%s runapp matroxset -f /dev/fb0 -m 1' % \ os.environ['FREEVO_SCRIPT']) time.sleep(1) plugin.shutdown() rc.shutdown() osd.shutdown() if argshutdown and not argrestart: os.system(config.SHUTDOWN_SYS_CMD) elif argrestart and not argshutdown: os.system(config.RESTART_SYS_CMD) # let freevo be killed by init, looks nicer for mga while 1: time.sleep(1) return # # Exit Freevo # # Shutdown any daemon plugins that need it. plugin.shutdown() # Shutdown all children still running rc.shutdown() # SDL must be shutdown to restore video modes etc osd.clearscreen(color=osd.COL_BLACK) osd.shutdown() if exit: # realy exit, we are called by the signal handler sys.exit(0) os.system('%s stop' % os.environ['FREEVO_SCRIPT']) # Just wait until we're dead. SDL cannot be polled here anyway. while 1: time.sleep(1)
osd.drawstring(_('Function: %s') % funcname, 70, 190, fgcolor=osd.COL_ORANGE) osd.drawstring(_('Text: %s') % text, 70, 220, fgcolor=osd.COL_ORANGE) osd.drawstring(str(sys.exc_info()[1]), 70, 280, fgcolor=osd.COL_ORANGE) osd.drawstring(_('Please see the logfiles for more info'), 70, 350, fgcolor=osd.COL_ORANGE) osd.drawstring(_('Exit in %s seconds') % i, 70, 410, fgcolor=osd.COL_ORANGE) osd.update() time.sleep(1) except: pass traceback.print_exc() # Shutdown the application, but not the system even if that is # enabled shutdown()
def draw(self, type, object, menu=None): """ draw the object. object may be a menu widget, a table for the tv menu are an audio item for the audio player """ if isinstance(object, GUIObject): # handling for gui objects: are they visible? what about children? if not object.visible: return draw_allowed = True for child in object.children: draw_allowed = draw_allowed and not child.visible if not draw_allowed: self.force_redraw = True return settings = self.settings if type == 'menu': menu = object.menustack[-1] if menu.skin_settings: settings = menu.skin_settings # XXX FIXME if len(object.menustack) == 1: menu.item_types = 'main' style = self.get_display_style(menu) else: try: if not object.visible: return except AttributeError: pass style = self.get_display_style(type) if self.last_draw[0] != type: self.force_redraw = True self.all_areas = getattr(self, '%s_areas' % type) self.last_draw = type, object, menu try: self.screen.clear() for a in self.all_areas: a.draw(settings, object, menu, style, type, self.force_redraw) osd.update([self.screen.show(self.force_redraw)]) self.force_redraw = False except UnicodeError, e: print '******************************************************************' print 'Unicode Error: %s' % e print 'Please report the following lines to the freevo mailing list' print 'or with the subject \'[Freevo-Bugreport\] Unicode\' to' print '[email protected].' print print traceback.print_exc() print print type, object if type == 'menu': for i in object.menustack[-1].choices: print i print raise UnicodeError, e
def draw(self, type, object, menu=None, transition=TRANSITION_NONE): """ Draw the object. object may be a menu widget, a table for the tv menu or an audio item for the audio player. """ logger.log( 9, 'Skin.draw(type=%r, object=%r, menu=%r)', type, object, menu) if self.suspended: return if isinstance(object, GUIObject): # handling for gui objects: are they visible? what about children? if not object.visible: return draw_allowed = True for child in object.children: draw_allowed = draw_allowed and not child.visible if not draw_allowed: self.force_redraw = True return settings = self.settings old_screen = None if type == 'menu': if menu is None: menu = object.menustack[-1] if menu.selected and hasattr(menu.selected, 'skin_settings') and menu.selected.skin_settings: settings = menu.selected.skin_settings elif menu.skin_settings: settings = menu.skin_settings # XXX FIXME if len(object.menustack) == 1: menu.item_types = 'main' style = self.get_display_style(menu) else: try: if not object.visible: return except AttributeError: pass if hasattr(object, 'skin_settings') and object.skin_settings: settings = object.skin_settings style = self.get_display_style(type) if self.last_draw[0] != type: self.force_redraw = True self.all_areas = getattr(self, '%s_areas' % type) self.last_draw = type, object, menu try: self.screen.clear() for a in self.all_areas: a.draw(settings, object, menu, style, type, self.force_redraw) if self.transitioning: ml = osd.main_layer osd.main_layer = self.next_screen self.screen.show(self.force_redraw) osd.main_layer = ml else: if not config.SKIN_USE_PAGE_TRANSITIONS and transition == TRANSITION_PAGE: transition = TRANSITION_NONE if transition and config.SKIN_USE_SCREEN_TRANSITIONS: self.do_transition(transition) else: osd.update([self.screen.show(self.force_redraw)]) self.force_redraw = False except UnicodeError, e: print '******************************************************************' print 'Unicode Error: %s' % e print 'Please report the following lines to the freevo users mailing list' print 'https://lists.sourceforge.net/lists/listinfo/freevo-users' print print traceback.print_exc() print print type, object if type == 'menu': for i in object.menustack[-1].choices: print i print raise UnicodeError, e
except Exception, why: logger.fatal('Crash!', exc_info=True) try: tb = sys.exc_info()[2] fname, lineno, funcname, text = traceback.extract_tb(tb)[-1] if config.FREEVO_EVENTHANDLER_SANDBOX: secs = 5 else: secs = 1 for i in range(secs, 0, -1): osd.clearscreen(color=osd.COL_BLACK) osd.drawstring(_('Freevo crashed!'), 70, 70, fgcolor=osd.COL_ORANGE) osd.drawstring(_('Filename: %s') % fname, 70, 130, fgcolor=osd.COL_ORANGE) osd.drawstring(_('Lineno: %s') % lineno, 70, 160, fgcolor=osd.COL_ORANGE) osd.drawstring(_('Function: %s') % funcname, 70, 190, fgcolor=osd.COL_ORANGE) osd.drawstring(_('Text: %s') % text, 70, 220, fgcolor=osd.COL_ORANGE) osd.drawstring(str(sys.exc_info()[1]), 70, 280, fgcolor=osd.COL_ORANGE) osd.drawstring(_('Please see the logfiles for more info'), 70, 350, fgcolor=osd.COL_ORANGE) osd.drawstring(_('Exit in %s seconds') % i, 70, 410, fgcolor=osd.COL_ORANGE) osd.update() time.sleep(1) except: pass traceback.print_exc() # Shutdown the application, but not the system even if that is # enabled shutdown()