def set_screen_background(self): """ Update the background """ logger.log( 9, 'set_screen_background()') if not self.background: self.background = osd.get_singleton().getsurface(rect=self.rect) self.updates = [] elif len(self.updates) > 0: # find the topleft corner x = self.rect.right y = self.rect.bottom for i in self.updates: x = min(x, i.left) y = min(y, i.top) # find the total rect of the collisions upd = Rect(x, y, 0, 0) upd.unionall_ip(self.updates) self.updates = [] x = upd[0] - self.rect.left y = upd[1] - self.rect.top bg_tmp = osd.get_singleton().getsurface(rect=upd) self.background.blit(bg_tmp, (x, y)) self.surface.blit(self.background, (0,0))
def render(self, surface, value_dict): percent = min(1.0, max(0, eval(self.expr, value_dict))) if self.vertical: im_x = 0 x = self.x w = self.w h = int(float(self.h) * percent) im_y = self.h - h y = self.y + im_y else: im_x = 0 im_y = 0 x = self.x y = self.y w = int(float(self.w) * percent) h = self.h osd.get_singleton().drawsurface(self.image_surface, x=im_x, y=im_y, bbx=x, bby=y, bbw=w, bbh=h, layer=surface)
def render(self, surface, value_dict): if eval(self.expr, value_dict): osd.get_singleton().drawsurface(self.image_surface, bbx=self.x, bby=self.y, bbw=self.w, bbh=self.h, layer=surface)
def remove(self): """ Flags the animation to be removed from the animation list """ logger.log( 9, 'remove()') self.active = False # set the org. bg if we use this if self.bg_update: osd.get_singleton().putsurface(self.background, self.rect.left, self.rect.top) osd.get_singleton().update([self.rect]) self.delete = True
def render(self, surface, value_dict): to_render = self.expr % value_dict osd.get_singleton().drawstringframed(to_render, self.x, self.y, self.w, self.h, self.font, self.fgcolor, self.bgcolor, self.halign, self.valign, layer=surface)
def __init__(self): """ init the keyboard event handler """ _debug_('Keyboard.__init__()', 2) import osd self.callback = osd.get_singleton()._cb
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 __init__(self, items=None, left=None, top=None, width=100, height=200, bg_color=None, fg_color=None, selected_bg_color=None, selected_fg_color=None, border=None, bd_color=None, bd_width=None, show_h_scrollbar=None, show_v_scrollbar=None): self.items = items self.show_h_scrollbar = show_h_scrollbar self.show_v_scrollbar = show_v_scrollbar if self.show_h_scrollbar != 0 and not self.show_h_scrollbar: self.show_h_scrollbar = 0 if self.show_v_scrollbar != 0 and not self.show_v_scrollbar: self.show_v_scrollbar = 1 dummy_surface = osd.get_singleton().Surface((1,1), 0, 32) RegionScroller.__init__(self, dummy_surface, left, top, width, height, bg_color, fg_color, border, bd_color, bd_width, self.show_h_scrollbar, self.show_v_scrollbar) self.set_surface(self.osd.Surface(self.get_size(), 0, 32)) self.h_margin = 2 self.v_margin = 2 self.items_height = Button('foo').height self.x_scroll_interval = 25 self.y_scroll_interval = self.items_height if not self.items: self.items = [] if self.items: self.set_items(self.items)
def __init__(self, app, mplayer): self.RE_TIME = re.compile("^A: *([0-9]+)").match self.RE_START = re.compile("^Starting playback\.\.\.").match self.RE_EXIT = re.compile("^Exiting\.\.\. \((.*)\)$").match self.item = mplayer.item self.mplayer = mplayer self.exit_type = None # DVD items also store mplayer_audio_broken to check if you can # start them with -alang or not if hasattr(self.item, 'mplayer_audio_broken') or self.item.mode != 'dvd': self.check_audio = 0 else: self.check_audio = 1 import osd self.osd = osd.get_singleton() self.osdfont = self.osd.getfont(config.OSD_DEFAULT_FONTNAME, config.OSD_DEFAULT_FONTSIZE) # check for mplayer plugins self.stdout_plugins = [] self.elapsed_plugins = [] for p in plugin.get('mplayer_video'): if hasattr(p, 'stdout'): self.stdout_plugins.append(p) if hasattr(p, 'elapsed'): self.elapsed_plugins.append(p) # init the child (== start the threads) childapp.ChildApp2.__init__(self, app)
def __init__(self, command, mplayer): self.RE_TIME = re.compile("^[AV]: *([0-9]+)").match self.RE_VO = re.compile("^VO: \[.+\] \d+x\d+ => (\d+)x(\d+)").match self.RE_START = re.compile("^Starting playback\.\.\.").match self.RE_EXIT = re.compile("^Exiting\.\.\. \((.*)\)$").match self.item = mplayer.item self.mplayer = mplayer self.exit_type = None # DVD items also store mplayer_audio_broken to check if you can # start them with -alang or not if hasattr(self.item, 'mplayer_audio_broken') or self.item.mode != 'dvd': self.check_audio = 0 else: self.check_audio = 1 import osd self.osd = osd.get_singleton() self.osdfont = self.osd.getfont(config.OSD_DEFAULT_FONTNAME, config.OSD_DEFAULT_FONTSIZE) # check for mplayer plugins self.stdout_plugins = [] self.elapsed_plugins = [] for p in plugin.get('mplayer_video'): if hasattr(p, 'stdout'): self.stdout_plugins.append(p) if hasattr(p, 'elapsed'): self.elapsed_plugins.append(p) self.output_event = threading.Event() self.get_property_ans = None # init the child (== start the threads) childapp.ChildApp2.__init__(self, command, callback_use_rc=False)
def __init__(self): #print '__init__(self)' GUIObject.__init__(self) self.osd_mode = 0 # Draw file info on the image self.zoom = 0 # Image zoom self.zoom_btns = { str(IMAGE_NO_ZOOM): 0, str(IMAGE_ZOOM_GRID1): 1, str(IMAGE_ZOOM_GRID2): 2, str(IMAGE_ZOOM_GRID3): 3, str(IMAGE_ZOOM_GRID4): 4, str(IMAGE_ZOOM_GRID5): 5, str(IMAGE_ZOOM_GRID6): 6, str(IMAGE_ZOOM_GRID7): 7, str(IMAGE_ZOOM_GRID8): 8, str(IMAGE_ZOOM_GRID9): 9 } self.slideshow = True self.app_mode = 'image' self.last_image = (None, None) self.osd = osd.get_singleton() self.signal_registered = False self.free_cache()
def __init__(self, left=0, top=0, width=0, height=0, bg_color=None, fg_color=None): self.left = left or 0 self.top = top or 0 self.width = width or 0 self.height = height or 0 try: self.rect = Rect(self.left, self.top, self.width, self.height) except TypeError: logger.debug('Invalid Rect: left=%r, top=%r, width=%r, height=%r', left, top, width, height) self.osd = osd.get_singleton() self.label = None self.icon = None self.surface = None self.bg_surface = None self.bg_image = None self.parent = None self.children = [] self.enabled = 1 self.visible = 1 self.selected = 0 self.rect = pygame.Rect(0, 0, 0, 0) self.refresh_abs_position() self.rect.width = self.width self.rect.height = self.height self.bg_color = bg_color self.fg_color = fg_color self.event_context = None style = skin.get_singleton().get_popupbox_style(self) self.content_layout, self.background_layout = style self.skin_info_widget = self.content_layout.types['widget'] self.skin_info_font = self.skin_info_widget.font self.h_margin = self.content_layout.spacing self.v_margin = self.content_layout.spacing ci = self.content_layout.types['widget'].rectangle self.bg_color = self.bg_color or Color(ci.bgcolor) self.fg_color = self.fg_color or Color(ci.color) self.set_v_align(Align.NONE) self.set_h_align(Align.NONE)
def __init__(self, command, mplayer): self.RE_TIME = re.compile("^[AV]: *([0-9]+)").match self.RE_VO = re.compile("^VO: \[.+\] \d+x\d+ => (\d+)x(\d+)").match self.RE_START = re.compile("^Starting playback\.\.\.").match self.RE_EXIT = re.compile("^Exiting\.\.\. \((.*)\)$").match self.item = mplayer.item self.mplayer = mplayer self.exit_type = None # DVD items also store mplayer_audio_broken to check if you can # start them with -alang or not if hasattr(self.item, 'mplayer_audio_broken') or self.item.mode != 'dvd': self.check_audio = 0 else: self.check_audio = 1 import osd self.osd = osd.get_singleton() self.osdfont = self.osd.getfont(config.OSD_DEFAULT_FONTNAME, config.OSD_DEFAULT_FONTSIZE) # check for mplayer plugins self.stdout_plugins = [] self.elapsed_plugins = [] for p in plugin.get('mplayer_video'): if hasattr(p, 'stdout'): self.stdout_plugins.append(p) if hasattr(p, 'elapsed'): self.elapsed_plugins.append(p) self.output_event = threading.Event() self.get_property_ans = None if config.MPLAYER_RATE_SET_FROM_VIDEO: # we set a monitor's refresh rate that matches the FPS of the movie screen = xrandr.get_current_screen() # first we save the current rate self.rate = screen.get_current_rate() logger.info('Current refresh rate: %s', self.rate) fps = self.item.getattr('fps') if fps: # get the rate mapping rate = config.MPLAYER_RATE_MAP[fps] if rate: screen.set_refresh_rate(rate[1]) screen.apply_config() else: logger.warning('Unable to set refresh rate to %s', fps) else: logger.warning('Unknown refresh rate: %s', fps) # init the child (== start the threads) childapp.ChildApp2.__init__(self, command, callback_use_rc=False)
def __init__(self): super(X11GraphicsDisplay, self).__init__() if config.OSD_SINGLE_WINDOW: self.window = X11Window(size=(1,1), parent=osd.get_singleton().display_window, mouse_events=False, key_events=False) else: self.window = X11Window(size=(1,1), title='Freevo OSD', mouse_events=False, key_events=False) self.window.set_decorated(False) self.window.signals['expose_event'].connect(self.__redraw) self.image = None
def __init__(self, in_color=None): self.red = 0 self.green = 0 self.blue = 0 self.alpha = 0 self.osd = osd.get_singleton() if in_color: self.set_color(in_color)
def __init__(self): if reason: self.reason = reason else: self.display = X11GraphicsDisplay() dialog.set_overlay_display(self.display) singleton = osd.get_singleton() if singleton: singleton.shutdown = osd_shutdown plugin.Plugin.__init__(self)
def mod_name(self, arg=None, menuw=None): """ Modify name This opens a input box to ask the user for a new name for this favorite. The default name of a favorite is the name of the program. """ logger.log( 9, 'mod_name(arg=%r, menuw=%r)', arg, menuw) self.menuw = menuw InputBox(text=_('Alter Name'), handler=self.alter_name, \ width=osd.get_singleton().width - config.OSD_OVERSCAN_LEFT - 20, input_text=self.name).show()
def mod_name(self, arg=None, menuw=None): """ Modify name This opens a input box to ask the user for a new name for this favorite. The default name of a favorite is the name of the program. """ logger.log(9, 'mod_name(arg=%r, menuw=%r)', arg, menuw) self.menuw = menuw InputBox(text=_('Alter Name'), handler=self.alter_name, \ width=osd.get_singleton().width - config.OSD_OVERSCAN_LEFT - 20, input_text=self.name).show()
def parse_plugins2(): """ The idea is to extract the PluginInterface class or classes from the source module and then to import it and extract the __doc__ string from the Class and the config() from the class instance. This does't quite work, neither does import PluginInterface from <m> as <a> nor do any of the import methods that I've tried. I've left this code in to remind any that this techique does work in all cases, it does work in come cases and from the freevo prompt. """ import time import pygame from screensaver import ScreenSaverPlugin from idlebar import IdleBarPlugin from util import Rendezvous import osd osd = osd.get_singleton() all_plugins = [] print "FREEVO_PYTHON", os.environ["FREEVO_PYTHON"] print "PYTHONPATH", os.environ["PYTHONPATH"] for file in util.recursefolders(os.environ["FREEVO_PYTHON"], 1, "*.py", 1): if file.find("plugin.py") > 0: continue data = open(file, "r").read() for plugin_interface in find_plugin_interface(data): if not plugin_interface: print "Can't find interface in %s" % file continue try: exec plugin_interface except Exception, e: print "Error:1:%s: %s" % (file, e) break print "<<<%s>>>" % file print PluginInterface.__bases__ for base in PluginInterface.__bases__: print base.__name__ print PluginInterface.__doc__ try: interface = PluginInterface() print interface.config() except Exception, e: print "Error:2:%s: %s" % (file, e) continue interface = None PluginInterface = None
def parse_plugins2(): """ The idea is to extract the PluginInterface class or classes from the source module and then to import it and extract the __doc__ string from the Class and the config() from the class instance. This does't quite work, neither does import PluginInterface from <m> as <a> nor do any of the import methods that I've tried. I've left this code in to remind any that this techique does work in all cases, it does work in come cases and from the freevo prompt. """ import time import pygame from screensaver import ScreenSaverPlugin from idlebar import IdleBarPlugin from util import Rendezvous import osd osd = osd.get_singleton() all_plugins = [] print 'FREEVO_PYTHON', os.environ['FREEVO_PYTHON'] print 'PYTHONPATH', os.environ['PYTHONPATH'] for file in util.recursefolders(os.environ['FREEVO_PYTHON'], 1, '*.py', 1): if file.find('plugin.py') > 0: continue data = open(file, 'r').read() for plugin_interface in find_plugin_interface(data): if not plugin_interface: print 'Can\'t find interface in %s' % file continue try: exec plugin_interface except Exception, e: print 'Error:1:%s: %s' % (file, e) break print '<<<%s>>>' % file print PluginInterface.__bases__ for base in PluginInterface.__bases__: print base.__name__ print PluginInterface.__doc__ try: interface = PluginInterface() print interface.config() except Exception, e: print 'Error:2:%s: %s' % (file, e) continue interface = None PluginInterface = None
def update_wait(self): """ This is used while starting freevo """ if osd._singleton == None: return if self.osd == None: self.osd = osd.get_singleton() rc.unregister(self.update) self.update = self.update_enabled rc.register(self.update, True, 0)
def __draw_state_screen(self): osd_obj = osd.get_singleton() percent = 0.0 channel = self.__get_display_channel() if self.state == STATE_IDLE: state_string = None elif self.state == STATE_TUNING: state_string = _('Tuning to %s' % self.last_channel) elif self.state == STATE_BUFFERING: state_string = _('Buffering %s' % self.last_channel) percent = float(WAIT_FOR_DATA_COUNT - self.wait_for_data_count ) / float(WAIT_FOR_DATA_COUNT) elif self.state == STATE_PLAYING: state_string = _('Playing %s' % self.last_channel) percent = 1.0 osd_obj.clearscreen(color=osd_obj.COL_BLACK) if state_string: y = (config.CONF.height / 2) - config.OSD_DEFAULT_FONTSIZE h = -1 font = osd_obj.getfont(config.OSD_DEFAULT_FONTNAME, config.OSD_DEFAULT_FONTSIZE) osd_obj.drawstringframed(state_string, 0, y, config.CONF.width, h, font, fgcolor=osd_obj.COL_ORANGE, align_h='center') x = config.CONF.width / 4 w = x * 2 y = (config.CONF.height / 2) + config.OSD_DEFAULT_FONTSIZE h = int(20.0 * (float(config.CONF.height) / 600.0)) osd_obj.drawbox(x - 2, y - 2, x + w + 2, y + h + 2, color=osd_obj.COL_ORANGE) w = int(float(w) * percent) osd_obj.drawbox(x, y, x + w, y + h, color=osd_obj.COL_ORANGE, fill=1) osd_obj.update()
def render(self, surface, value_dict): percent = min(1.0, max(0, eval(self.expr, value_dict))) if self.vertical: im_x = 0 x = self.x w = self.w h = int(float(self.h) * percent) im_y = self.h - h y = self.y + im_y else: im_x = 0 im_y = 0 x = self.x y = self.y w = int(float(self.w) * percent) h = self.h osd.get_singleton().drawsurface(self.image_surface,x=im_x, y=im_y, bbx=x, bby=y, bbw=w, bbh=h, layer=surface)
def update_wait(self): """ This is used while starting freevo """ if osd._singleton == None: return if self.osd == None: self.osd = osd.get_singleton() if self.timer: self.timer.stop() self.update = self.update_enabled self.timer = kaa.Timer(self.update) self.timer.start(0.01)
def __init__(self, sstype, ssarg1, ssarg2=None): plugin.DaemonPlugin.__init__(self) self.plugin_name = 'SCREENSAVER' self.event_listener = TRUE self.poll_menu_only = TRUE self.last_event = 0 self.screensaver_showing = FALSE self.vitem = None self.pl = None self.menuw = None self.poll_interval = config.SSAVER_POLL self.saver_delay = config.SSAVER_DELAY self.saver_type = sstype self.arg1 = ssarg1 self.arg2 = ssarg2 self.osd = osd.get_singleton()
def __init__(self, sstype, ssarg1, ssarg2=None): plugin.DaemonPlugin.__init__(self) self.plugin_name = 'SCREENSAVER' self.event_listener = TRUE self.poll_menu_only = TRUE self.last_event = 0 self.screensaver_showing = FALSE self.vitem = None self.pl = None self.menuw = None self.poll_interval = 10 * config.SSAVER_POLL self.saver_delay = config.SSAVER_DELAY self.saver_type = sstype self.arg1 = ssarg1 self.arg2 = ssarg2 self.osd = osd.get_singleton()
def __init__(self, left=0, top=0, width=0, height=0, bg_color=None, fg_color=None): self.osd = osd.get_singleton() self.label = None self.icon = None self.surface = None self.bg_surface = None self.bg_image = None self.parent = None self.children = [] self.enabled = 1 self.visible = 1 self.selected = 0 self.left = left self.top = top self.width = width self.height = height self.bg_color = bg_color self.fg_color = fg_color self.event_context = None style = skin.get_singleton().get_popupbox_style(self) self.content_layout, self.background_layout = style self.skin_info_widget = self.content_layout.types['widget'] self.skin_info_font = self.skin_info_widget.font self.h_margin = self.content_layout.spacing self.v_margin = self.content_layout.spacing ci = self.content_layout.types['widget'].rectangle self.bg_color = self.bg_color or Color(ci.bgcolor) self.fg_color = self.fg_color or Color(ci.color) self.set_v_align(Align.NONE) self.set_h_align(Align.NONE)
def __init__(self): logger.log( 9, 'ImageViewer.__init__()') GUIObject.__init__(self) self.osd_mode = 0 # Draw file info on the image self.zoom = 0 # Image zoom self.zoom_btns = { str(IMAGE_NO_ZOOM):0, str(IMAGE_ZOOM_GRID1):1, str(IMAGE_ZOOM_GRID2):2, str(IMAGE_ZOOM_GRID3):3, str(IMAGE_ZOOM_GRID4):4, str(IMAGE_ZOOM_GRID5):5, str(IMAGE_ZOOM_GRID6):6, str(IMAGE_ZOOM_GRID7):7, str(IMAGE_ZOOM_GRID8):8, str(IMAGE_ZOOM_GRID9):9 } self.slideshow = config.IMAGEVIEWER_AUTOPLAY self.duration = config.IMAGEVIEWER_DURATION self.event_context = 'image' self.last_image = (None, None) self.render = render.get_singleton() self.osd = osd.get_singleton() self.osd_height = self.osd.height self.osd_width = self.osd.width * float(config.OSD_PIXEL_ASPECT) self.timer = None self.blend = None self.__added_app = False self.free_cache()
import codecs import urllib #regular expression import re #freevo modules import config, menu, rc, plugin, skin, osd, util from gui import PopupBox, AlertBox, ConfirmBox from item import Item from video import VideoItem #get the singletons so we get skin info and access the osd skin = skin.get_singleton() osd = osd.get_singleton() class PluginInterface(plugin.MainMenuPlugin): """ A plugin to obtain TV streams on Freevo To activate, put the following lines in local_conf.py: | plugin.activate('tv.freeboxtv', level=45) | PLUGIN_FREEBOXTV_LOCATION = "http://mafreebox.freebox.fr/freeboxtv/playlist.m3u" | plugin.activate('video.vlc') | | # ================ | # VLC Settings | # ================
def build(self, arg=None, menuw=None): """ build the items for the archive """ logger.log(9, 'build(arg=%r, menuw=%r)', arg, menuw) osd.get_singleton().busyicon.wait(config.OSD_BUSYICON_TIMER[0]) archive = None try: if zipfile.is_zipfile(self.archive): archive = zipfile.ZipFile(self.archive, 'r') files = archive.infolist() elif tarfile.is_tarfile(self.archive): archive = tarfile.open(self.archive, 'r') files = archive.getmembers() elif ARCHIVE_RAR_AVAILABLE and rarfile.is_rarfile(self.archive): archive = rarfile.RarFile(self.archive, 'r') files = archive.infolist() else: # fallback, nothing to do, not an archive super(DirItem, self).build(arg, menuw) return except (ZipError, RarError, TarError) as exc: _debug_('Archive %s error: %s' % (self.archive, exc), 1) self.valid = False osd.get_singleton().busyicon.stop() DirItem.build(self, arg, menuw) return # display the msg box pop = None to_extract = 0 xfiles = [] for f in files: logger.debug('testing for %s', os.path.join(self.dir, get_filename(f))) if not os.path.exists(os.path.join(self.dir, get_filename(f))): logger.debug('%s not found, will extract', os.path.join(self.dir, get_filename(f))) xfiles.append(f) if len(xfiles) > 8 and skin.active(): pop = CacheProgressDialog( _('Extracting from archive, be patient...'), len(xfiles)) pop.show() elif len(xfiles) > config.OSD_BUSYICON_TIMER[1]: # many files, just show the busy icon now osd.get_singleton().busyicon.wait(0) # extract one file at the time, bump the progress bar for each file extracted for f in xfiles: archive.extract(f, self.dir) if pop: pop.processed_file() # get rid of the msg box if pop: pop.hide() # stop the timer. If the icons is drawn, it will stay there # until the osd is redrawn, if not, we don't need it to pop # up the next milliseconds osd.get_singleton().busyicon.stop() exclude = '' if self.cover: # we do not want to include the cover img we just created # we store original config.IMAGE_EXCLUDE first, then set it to cover exclude = config.IMAGE_EXCLUDE config.IMAGE_EXCLUDE = ['cover'] # now we let the base class handle the tmp directory DirItem.build(self, arg, menuw) if self.cover: # and now we restore original cover.IMAGE_RESTORE config.IMAGE_EXCLUDE = exclude
def prepare(self): self.image_surface = osd.get_singleton().loadbitmap(self.image)
def build(self, arg=None, menuw=None): """ build the items for the directory """ self.menuw = menuw self.playlist = [] self.play_items = [] self.dir_items = [] self.pl_items = [] if self.media: self.media.mount() if hasattr(self, '__dirwatcher_last_time__'): del self.__dirwatcher_last_time__ if arg == 'update': if not self.menu.choices: selected_pos = -1 else: # store the current selected item selected_id = self.menu.selected.id() selected_pos = self.menu.choices.index(self.menu.selected) if hasattr(self.menu, 'skin_default_has_description'): del self.menu.skin_default_has_description if hasattr(self.menu, 'skin_default_no_images'): del self.menu.skin_default_no_images if hasattr(self.menu, 'skin_force_text_view'): del self.menu.skin_force_text_view elif not os.path.exists(self.dir): AlertBox(text=_('Directory does not exist')).show() return display_type = self.display_type if self.display_type == 'tv': display_type = 'video' if arg and arg.startswith('playlist:'): if arg.endswith(':random'): Playlist(playlist=[(self.dir, 0)], parent=self, display_type=display_type, random=True).play(menuw=menuw) elif arg.endswith(':recursive'): Playlist(playlist=[(self.dir, 1)], parent=self, display_type=display_type, random=False).play(menuw=menuw) elif arg.endswith(':random_recursive'): Playlist(playlist=[(self.dir, 1)], parent=self, display_type=display_type, random=True).play(menuw=menuw) return if config.OSD_BUSYICON_TIMER: osd.get_singleton().busyicon.wait(config.OSD_BUSYICON_TIMER[0]) files = vfs.listdir(self.dir, include_overlay=True) num_changes = mediainfo.check_cache(self.dir) pop = None callback = None if skin.active(): if (num_changes > 10) or (num_changes and self.media): if self.media: pop = ProgressBox(text=_('Scanning disc, be patient...'), full=num_changes) else: pop = ProgressBox( text=_('Scanning directory, be patient...'), full=num_changes) pop.show() callback = pop.tick elif config.OSD_BUSYICON_TIMER and len( files) > config.OSD_BUSYICON_TIMER[1]: # many files, just show the busy icon now osd.get_singleton().busyicon.wait(0) if num_changes > 0: mediainfo.cache_dir(self.dir, callback=callback) # # build items # # build play_items, pl_items and dir_items for p in plugin.mimetype(display_type): for i in p.get(self, files): if i.type == 'playlist': self.pl_items.append(i) elif i.type == 'dir': self.dir_items.append(i) else: self.play_items.append(i) # normal DirItems for filename in files: if os.path.isdir(filename): d = DirItem(filename, self, display_type=self.display_type) self.dir_items.append(d) # remove same beginning from all play_items if self.DIRECTORY_SMART_NAMES: substr = '' if len(self.play_items) > 4 and len(self.play_items[0].name) > 5: substr = self.play_items[0].name[:-5].lower() for i in self.play_items[1:]: if len(i.name) > 5: substr = util.find_start_string(i.name.lower(), substr) if not substr or len(substr) < 10: break else: break else: for i in self.play_items: i.name = util.remove_start_string(i.name, substr) # # sort all items # # sort directories if self.DIRECTORY_SMART_SORT: self.dir_items.sort(lambda l, o: util.smartsort(l.dir, o.dir)) else: self.dir_items.sort(lambda l, o: cmp(l.dir.upper(), o.dir.upper())) # sort playlist self.pl_items.sort(lambda l, o: cmp(l.name.upper(), o.name.upper())) # sort normal items if self.DIRECTORY_SORT_BY_DATE: self.play_items.sort(lambda l, o: cmp( l.sort('date').upper(), o.sort('date').upper())) elif self['%s_advanced_sort' % display_type]: self.play_items.sort(lambda l, o: cmp( l.sort('advanced').upper(), o.sort('advanced').upper())) else: self.play_items.sort(lambda l, o: cmp(l.sort().upper(), o.sort().upper())) if self['num_dir_items'] != len(self.dir_items): self['num_dir_items'] = len(self.dir_items) if self['num_%s_items' % display_type] != len(self.play_items) + len(self.pl_items): self['num_%s_items' % display_type] = len(self.play_items) + len(self.pl_items) if self.DIRECTORY_REVERSE_SORT: self.dir_items.reverse() self.play_items.reverse() self.pl_items.reverse() # delete pl_items if they should not be displayed if self.display_type and not self.display_type in self.DIRECTORY_ADD_PLAYLIST_FILES: self.pl_items = [] # add all playable items to the playlist of the directory # to play one files after the other if not self.display_type or self.display_type in self.DIRECTORY_CREATE_PLAYLIST: self.playlist = self.play_items # build a list of all items items = self.dir_items + self.pl_items + self.play_items # random playlist (only active for audio) if self.display_type and self.display_type in self.DIRECTORY_ADD_RANDOM_PLAYLIST \ and len(self.play_items) > 1: pl = Playlist(_('Random playlist'), self.play_items, self, random=True) pl.autoplay = True items = [pl] + items if pop: pop.destroy() # closing the poup will rebuild the menu which may umount # the drive if self.media: self.media.mount() if config.OSD_BUSYICON_TIMER: # stop the timer. If the icons is drawn, it will stay there # until the osd is redrawn, if not, we don't need it to pop # up the next milliseconds osd.get_singleton().busyicon.stop() # # action # if arg == 'update': # update because of dirwatcher changes self.menu.choices = items if selected_pos != -1: for i in items: if Unicode(i.id()) == Unicode(selected_id): self.menu.selected = i break else: # item is gone now, try to the selection close # to the old item pos = max(0, min(selected_pos - 1, len(items) - 1)) if items: self.menu.selected = items[pos] else: self.menu.selected = None if self.menuw: if self.menu.selected and selected_pos != -1: self.menuw.rebuild_page() else: self.menuw.init_page() self.menuw.refresh() elif len(items) == 1 and items[0].actions() and \ self.DIRECTORY_AUTOPLAY_SINGLE_ITEM: # autoplay items[0].actions()[0][0](menuw=menuw) elif arg == 'play' and self.play_items: # called by play function self.playlist = self.play_items Playlist.play(self, menuw=menuw) else: # normal menu build item_menu = menu.Menu( self.name, items, reload_func=self.reload, item_types=self.skin_display_type, force_skin_layout=self.DIRECTORY_FORCE_SKIN_LAYOUT) if self.skin_fxd: item_menu.skin_settings = skin.load(self.skin_fxd) menuw.pushmenu(item_menu) dirwatcher.cwd(menuw, self, item_menu, self.dir) self.menu = item_menu self.menuw = menuw
def snapshot(videofile, imagefile=None, pos=None, update=True, popup=None): """ make a snapshot of the videofile at position pos to imagefile """ from subprocess import Popen, PIPE import kaa.imlib2 as Image import vfs import gui.PopupBox import osd # skip broken symlinks if os.path.islink(videofile) and not os.path.exists(videofile): return if not imagefile: imagefile = vfs.getoverlay(videofile + '.raw') if not update and os.path.isfile(imagefile) and \ os.stat(videofile)[ST_MTIME] <= os.stat(imagefile)[ST_MTIME]: return if imagefile.endswith('.raw'): imagefile += '.tmp' if popup: pop = gui.PopupBox( text='Creating thumbnail for "%s"...' % Unicode(os.path.basename(videofile)), width=osd.get_singleton().width - (config.OSD_OVERSCAN_LEFT + config.OSD_OVERSCAN_RIGHT) - 80) pop.show() args = [config.MPLAYER_CMD, videofile, imagefile] if pos != None: args.append(str(pos)) command = [ os.environ['FREEVO_SCRIPT'], '--execute=%s' % os.path.abspath(__file__) ] + args logger.debug(' '.join(command)) p = Popen(command, stdin=PIPE, stdout=PIPE, stderr=PIPE, close_fds=True) (stdout, stderr) = p.communicate() if p.returncode: for line in stdout.split(): logger.debug(line) for line in stderr.split(): logger.info(line) if vfs.isfile(imagefile): try: image = Image.open(imagefile) if image.width > 255 or image.height > 255: image.thumbnail((255, 255)) mode = image.mode if mode == 'P': mode = 'RGB' if image.width * 3 > image.height * 4: # fix image with blank bars to be 4:3 nh = (image.width * 3) / 4 ni = Image.new((image.width, nh), from_format=image.mode) ni.draw_rectangle((0, 0), (image.width, nh), (0, 0, 0, 255), True) ni.blend(image, dst_pos=(0, (nh - image.height) / 2)) image = ni elif image.width * 3 < image.height * 4: # strange aspect, let's guess it's 4:3 new_size = (image.width, (image.width * 3) / 4) image = image.scale((new_size)) # crop some pixels, looks better that way image = image.crop((4, 3), (image.width - 8, image.height - 6)) mode = image.mode # Pygame can't handle BGRA images if mode == 'BGRA': mode = 'RGBA' if imagefile.endswith('.raw.tmp'): f = vfs.open(imagefile[:-4], 'w') data = (str(image.get_raw_data(format=mode)), image.size, mode) f.write('FRI%s%s%5s' % (chr(image.width), chr(image.height), mode)) f.write(data[0]) f.close() os.unlink(imagefile) else: image.save(imagefile) except (OSError, IOError), why: logger.error('snapshot: %s', why)
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 __init__(self): super(OSDGraphicsDisplay, self).__init__() self.osd = osd.get_singleton() self.last_dialog = None
def get_osd(self): """ Helper for getting osd singleton """ _debug_('get_osd()', 2) return osd.get_singleton()
def snapshot(videofile, imagefile=None, pos=None, update=True, popup=None): """ make a snapshot of the videofile at position pos to imagefile """ from subprocess import Popen, PIPE import kaa.imlib2 as Image import vfs import gui.PopupBox import osd # skip broken symlinks if os.path.islink(videofile) and not os.path.exists(videofile): return if not imagefile: imagefile = vfs.getoverlay(videofile + '.raw') if not update and os.path.isfile(imagefile) and \ os.stat(videofile)[ST_MTIME] <= os.stat(imagefile)[ST_MTIME]: return if imagefile.endswith('.raw'): imagefile += '.tmp' if popup: pop = gui.PopupBox(text='Creating thumbnail for "%s"...' % Unicode(os.path.basename(videofile)), width=osd.get_singleton().width-(config.OSD_OVERSCAN_LEFT+config.OSD_OVERSCAN_RIGHT)-80) pop.show() args = [ config.MPLAYER_CMD, videofile, imagefile ] if pos != None: args.append(str(pos)) command = [os.environ['FREEVO_SCRIPT'], '--execute=%s' % os.path.abspath(__file__) ] + args logger.debug(' '.join(command)) p = Popen(command, stdin=PIPE, stdout=PIPE, stderr=PIPE, close_fds=True) (stdout, stderr) = p.communicate() if p.returncode: for line in stdout.split(): logger.debug(line) for line in stderr.split(): logger.info(line) if vfs.isfile(imagefile): try: image = Image.open(imagefile) if image.width > 255 or image.height > 255: image.thumbnail((255,255)) mode = image.mode if mode == 'P': mode = 'RGB' if image.width * 3 > image.height * 4: # fix image with blank bars to be 4:3 nh = (image.width*3)/4 ni = Image.new((image.width, nh), from_format=image.mode) ni.draw_rectangle((0,0), (image.width, nh), (0,0,0,255), True) ni.blend(image, dst_pos=(0,(nh- image.height) / 2)) image = ni elif image.width * 3 < image.height * 4: # strange aspect, let's guess it's 4:3 new_size = (image.width, (image.width*3)/4) image = image.scale((new_size)) # crop some pixels, looks better that way image = image.crop((4, 3), (image.width-8, image.height-6)) mode = image.mode # Pygame can't handle BGRA images if mode == 'BGRA': mode = 'RGBA' if imagefile.endswith('.raw.tmp'): f = vfs.open(imagefile[:-4], 'w') data = (str(image.get_raw_data(format=mode)), image.size, mode) f.write('FRI%s%s%5s' % (chr(image.width), chr(image.height), mode)) f.write(data[0]) f.close() os.unlink(imagefile) else: image.save(imagefile) except (OSError, IOError), why: logger.error('snapshot: %s', why)
def snapshot(videofile, imagefile=None, pos=None, update=True, popup=None): """ make a snapshot of the videofile at position pos to imagefile """ import config import popen3 import kaa.imlib2 as Image import util import vfs import gui.PopupBox import osd if not imagefile: imagefile = vfs.getoverlay(videofile + '.raw') if not update and os.path.isfile(imagefile) and \ os.stat(videofile)[ST_MTIME] <= os.stat(imagefile)[ST_MTIME]: return if imagefile.endswith('.raw'): imagefile += '.tmp' if popup: pop = gui.PopupBox(text='Creating thumbnail for \'%s\'...' % \ Unicode(os.path.basename(videofile)), width=osd.get_singleton().width-config.OSD_OVERSCAN_X*2-80) pop.show() args = [ config.MPLAYER_CMD, videofile, imagefile ] if pos != None: args.append(str(pos)) out = popen3.stdout([os.environ['FREEVO_SCRIPT'], 'execute', os.path.abspath(__file__) ] + args) if out: for line in out: print line if vfs.isfile(imagefile): try: image = Image.open(imagefile) if image.width > 255 or image.height > 255: image.thumbnail((255,255)) if image.mode == 'P': image.mode = 'RGB' if image.width * 3 > image.height * 4: # fix image with blank bars to be 4:3 nh = (image.width*3)/4 ni = Image.new((image.width, nh), from_format = image.mode) ni.draw_rectangle((0,0), (image.width, nh), (0,0,0,255), True) ni.blend(image, dst_pos=(0,(nh- image.height) / 2)) image = ni elif image.width * 3 < image.height * 4: # strange aspect, let's guess it's 4:3 new_size = (image.width, (image.width*3)/4) image = image.scale((new_size)) # crop some pixels, looks better that way image = image.crop((4, 3), (image.width-8, image.height-6)) # Pygame can't handle BGRA images if image.mode == 'BGRA': image.mode = 'RGBA' if imagefile.endswith('.raw.tmp'): f = vfs.open(imagefile[:-4], 'w') data = (str(image.get_raw_data(format=image.mode)), image.size, image.mode) f.write('FRI%s%s%5s' % (chr(image.width), chr(image.height), image.mode)) f.write(data[0]) f.close() os.unlink(imagefile) else: image.save(imagefile) except (OSError, IOError), e: print 'snapshot:', e
def prepare(self): # Load background image self.surface = osd.get_singleton().loadbitmap(self.background) for obj in self.objects: obj.prepare()
def build(self, arg=None, menuw=None): """ build the items for the archive """ logger.log(9, 'build(arg=%r, menuw=%r)', arg, menuw) osd.get_singleton().busyicon.wait(config.OSD_BUSYICON_TIMER[0]) archive = None try: if zipfile.is_zipfile(self.archive): archive = zipfile.ZipFile(self.archive, 'r') files = archive.infolist() elif tarfile.is_tarfile(self.archive): archive = tarfile.open(self.archive, 'r') files = archive.getmembers() elif ARCHIVE_RAR_AVAILABLE and rarfile.is_rarfile(self.archive): archive = rarfile.RarFile(self.archive, 'r') files = archive.infolist() else: # fallback, nothing to do, not an archive super(DirItem, self).build(arg, menuw) return except (ZipError, RarError, TarError) as exc: logger.warning('Archive %s error: %s', self.archive, exc) self.valid = False osd.get_singleton().busyicon.stop() DirItem.build(self, arg, menuw) return # display the msg box pop = None to_extract = 0 xfiles = [] for f in files: logger.debug('testing for %s', os.path.join(self.dir, get_filename(f))) if not os.path.exists(os.path.join(self.dir, get_filename(f))): logger.debug('%s not found, will extract', os.path.join(self.dir, get_filename(f))) xfiles.append(f) if len(xfiles) > 8 and skin.active(): pop = CacheProgressDialog(_('Extracting from archive, be patient...'), len(xfiles)) pop.show() elif len(xfiles) > config.OSD_BUSYICON_TIMER[1]: # many files, just show the busy icon now osd.get_singleton().busyicon.wait(0) # extract one file at the time, bump the progress bar for each file extracted for f in xfiles: archive.extract(f, self.dir) if pop: pop.processed_file() # get rid of the msg box if pop: pop.hide() # stop the timer. If the icons is drawn, it will stay there # until the osd is redrawn, if not, we don't need it to pop # up the next milliseconds osd.get_singleton().busyicon.stop() exclude = '' if self.cover: # we do not want to include the cover img we just created # we store original config.IMAGE_EXCLUDE first, then set it to cover exclude = config.IMAGE_EXCLUDE config.IMAGE_EXCLUDE = ['cover'] # now we let the base class handle the tmp directory DirItem.build(self, arg, menuw) if self.cover: # and now we restore original cover.IMAGE_RESTORE config.IMAGE_EXCLUDE = exclude
def get_osd(self): """ Helper for getting osd singleton """ logger.log( 9, 'get_osd()') return osd.get_singleton()