Ejemplo n.º 1
0
    def eventhandler(self, event=None, menuw=None):
        """
        eventhandler for the main menu. The menu must be regenerated
        when a disc in a rom drive changes
        """
        if plugin.isevent(event):
            if not menuw:
                menuw = self.menuw

            menu = menuw.menustack[1]

            sel = menu.choices.index(menu.selected)
            menuw.menustack[1].choices = self.main_menu_generate()
            if not menu.selected in menu.choices:
                if len( menu.choices ) > sel:
                    menu.selected = menu.choices[sel]
                elif menu.choices:
                    menu.selected = menu.choices[ -1 ]
                else:
                    menu.selected = None

            if menu == menuw.menustack[-1] and rc.focused_app() == menuw:
                menuw.init_page()
                menuw.refresh()
            # others may need this event, too
            return False

        if event in (PLAY_END, USER_END, STOP) and event.context != 'menu':
            if menuw:
                menuw.show()
            return True

        # give the event to the next eventhandler in the list
        return Item.eventhandler(self, event, menuw)
Ejemplo n.º 2
0
def check_cache_status():
    """
    check if cache got updated with helper while freevo is running
    """
    from menu import MenuWidget
    global __last_status_check__
    if not isinstance(rc.focused_app(), MenuWidget):
        return
    try:
        cachefile = os.path.join(config.FREEVO_CACHEDIR, 'mediainfo')
        if os.stat(cachefile)[stat.ST_MTIME] <= __last_status_check__:
            return
        if not __last_status_check__:
            __last_status_check__ = os.stat(cachefile)[stat.ST_MTIME]
            return
    except:
        __last_status_check__ = 1
        return

    __last_status_check__ = os.stat(cachefile)[stat.ST_MTIME]
    open_cache_files = []

    for cache in mmpython_cache, meta_cache:
        # save current cache
        cache.save_cache()
        # delete all info about loaded objects
        cache.current_objects = {}
        cache.current_cachefile = None
        cache.current_cachedir = None
        cache.cache_modified = False

        # file database
        for d in cache.all_directories:
            if d and not os.path.dirname(vfs.normalize(d)) in open_cache_files:
                open_cache_files.append(os.path.dirname(vfs.normalize(d)))
        cache.all_directories = {}

    # create ProgressBox for reloading
    from gui import ProgressBox
    box = ProgressBox(text=_('Reloading cache files, be patient...'),
                      full=len(open_cache_files))
    box.show()

    # reload already open cache files
    for d in open_cache_files:
        load_cache(d)
        box.tick()
    box.destroy()
Ejemplo n.º 3
0
def check_cache_status():
    """
    check if cache got updated with helper while freevo is running
    """
    from menu import MenuWidget
    global __last_status_check__
    if not isinstance(rc.focused_app(), MenuWidget):
        return
    try:
        cachefile = os.path.join(config.FREEVO_CACHEDIR, 'mediainfo')
        if os.stat(cachefile)[stat.ST_MTIME] <= __last_status_check__:
            return
        if not __last_status_check__:
            __last_status_check__ = os.stat(cachefile)[stat.ST_MTIME]
            return
    except:
        __last_status_check__ = 1
        return

    __last_status_check__ = os.stat(cachefile)[stat.ST_MTIME]
    open_cache_files = []

    for cache in mmpython_cache, meta_cache:
        # save current cache
        cache.save_cache()
        # delete all info about loaded objects
        cache.current_objects    = {}
        cache.current_cachefile  = None
        cache.current_cachedir   = None
        cache.cache_modified     = False

        # file database
        for d in cache.all_directories:
            if d and not os.path.dirname(vfs.normalize(d)) in open_cache_files:
                open_cache_files.append(os.path.dirname(vfs.normalize(d)))
        cache.all_directories  = {}

    # create ProgressBox for reloading
    from gui import ProgressBox
    box = ProgressBox(text=_('Reloading cache files, be patient...'), full=len(open_cache_files))
    box.show()

    # reload already open cache files
    for d in open_cache_files:
        load_cache(d)
        box.tick()
    box.destroy()
Ejemplo n.º 4
0
    def eventhandler(self, event):
        """
        event handling function for the main loop
        """
        if event == OS_EVENT_POPEN2:
            logger.debug('popen2 %s', event.arg[1])
            event.arg[0].child = util.popen3.Popen3(event.arg[1])
            return

        logger.log(9, 'handling event %s', str(event))
        for p in self.eventlistener_plugins:
            p.eventhandler(event=event)

        if event == FUNCTION_CALL:
            event.arg()

        elif event.handler:
            event.handler(event=event)

        # Pass the event to the dialog subsystem first incase a dialog is being displayed.
        elif dialog.handle_event(event):
            return

        # Send events to either the current app or the menu handler
        elif rc.focused_app():
            consumed = False
            app = rc.focused_app()
            try:
                if config.DEBUG_TIME:
                    t1 = time.clock()

                if hasattr(app, 'eventhandler'):
                    consumed = app.eventhandler(event)
                else:
                    consumed = app(event)

                if config.DEBUG_TIME:
                    print time.clock() - t1

                if not consumed:
                    for p in self.eventhandler_plugins:
                        if p.eventhandler(event=event):
                            break
                    else:
                        logger.log(9, 'no eventhandler for event %s', event)

            except SystemExit:
                logger.debug('SystemExit re-raised')
                raise

            except:
                if config.FREEVO_EVENTHANDLER_SANDBOX:
                    traceback.print_exc()
                    from gui import ConfirmBox
                    pop = ConfirmBox(text=_(
                        "Event '%s' crashed\n\n" +
                        "Please take a look at the logfile and report" +
                        "the bug to the Freevo mailing list. The state" +
                        "of Freevo may be corrupt now and this error" +
                        "could cause more errors until you restart" +
                        "Freevo.\n\n" + "Logfile: %s\n\n") %
                                     (event, config.logfile),
                                     width=osd.width -
                                     (config.OSD_OVERSCAN_LEFT +
                                      config.OSD_OVERSCAN_RIGHT) - 50,
                                     handler=shutdown,
                                     handler_message=_('shutting down...'))
                    pop.b0.set_text(_('Shutdown'))
                    pop.b0.toggle_selected()
                    pop.b1.set_text(_('Continue'))
                    pop.b1.toggle_selected()
                    pop.show()
                else:
                    raise
        else:
            logger.debug('no target for events given')
Ejemplo n.º 5
0
    def eventhandler(self, event):
        """
        event handling function for the main loop
        """
        if event == OS_EVENT_POPEN2:
            logger.debug('popen2 %s', event.arg[1])
            event.arg[0].child = util.popen3.Popen3(event.arg[1])
            return

        logger.log( 9, 'handling event %s', str(event))
        for p in self.eventlistener_plugins:
            p.eventhandler(event=event)

        if event == FUNCTION_CALL:
            event.arg()

        elif event.handler:
            event.handler(event=event)

        # Pass the event to the dialog subsystem first incase a dialog is being displayed.
        elif dialog.handle_event(event):
            return

        # Send events to either the current app or the menu handler
        elif rc.focused_app():
            consumed = False
            app = rc.focused_app()
            try:
                if config.DEBUG_TIME:
                    t1 = time.clock()

                if hasattr(app, 'eventhandler'):
                    consumed = app.eventhandler(event)
                else:
                    consumed = app(event)

                if config.DEBUG_TIME:
                    print time.clock() - t1

                if not consumed:
                    for p in self.eventhandler_plugins:
                        if p.eventhandler(event=event):
                            break
                    else:
                        logger.log( 9, 'no eventhandler for event %s', event)

            except SystemExit:
                logger.debug('SystemExit re-raised')
                raise

            except:
                if config.FREEVO_EVENTHANDLER_SANDBOX:
                    traceback.print_exc()
                    from gui import ConfirmBox
                    pop = ConfirmBox(
                        text=_("Event '%s' crashed\n\n" +
                            "Please take a look at the logfile and report" +
                            "the bug to the Freevo mailing list. The state" +
                            "of Freevo may be corrupt now and this error" +
                            "could cause more errors until you restart" +
                            "Freevo.\n\n" +
                            "Logfile: %s\n\n") %
                        (event, config.logfile),
                        width=osd.width-(config.OSD_OVERSCAN_LEFT+config.OSD_OVERSCAN_RIGHT)-50,
                        handler=shutdown,
                        handler_message = _('shutting down...'))
                    pop.b0.set_text(_('Shutdown'))
                    pop.b0.toggle_selected()
                    pop.b1.set_text(_('Continue'))
                    pop.b1.toggle_selected()
                    pop.show()
                else:
                    raise
        else:
            logger.debug('no target for events given')