예제 #1
0
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()
예제 #2
0
    def draw_info(self, gooms):
        """
        Draw the info
        @param gooms: Goom surface
        """
        logger.log( 9, 'draw_info()')
        if self.infodata is not None:
            (s, info, font, x, y, w, h) = self.infodata
            if time.time() - self.m_timer > self.m_timeout:
                self.infodata = None
                s.fill(0)
                return

            osd.drawstringframed(info, 0, 0, w, h, font, mode='hard', layer=s)
            gooms.blit(s, (x, y))
예제 #3
0
    def set_message(self, message, timeout=5):
        """
        Pass a message to the screen.

        @message: text to draw
        @timeout: how long to display
        """

        font = skin.get_font('detachbar')
        w = font.stringsize(message)
        h = font.height
        x = 10
        y = 10

        s = Surface((w,h), 0, 32)

        osd.drawstringframed(message, 0, 0, w, h, font,
                             mode='hard', layer=s)

        self.m_timer   = time.time()
        self.m_timeout = timeout
        self.message   = (s, x, y, w, h)
예제 #4
0
    def set_info(self, info, timeout=5):
        """
        Pass a info message on to the screen.

        @param info: text to draw
        @param timeout: how long to display
        """
        _debug_('set_info(info=%r, timeout==%r)' % (info, timeout), 2)

        font = skin.get_font('widget')
        w = font.stringsize(info)
        h = font.height
        x = config.OSD_OVERSCAN_LEFT + 5
        y = config.OSD_OVERSCAN_TOP + 5

        s = Surface((w, h), 0, 32)

        osd.drawstringframed(info, 0, 0, w, h, font, mode='hard', layer=s)

        self.m_timer = time.time()
        self.m_timeout = timeout
        self.info = (s, x, y, w, h)
예제 #5
0
    def show(self, force_redraw=False):
        """
        the main drawing function
        """
        if osd.must_lock:
            # only lock s_alpha layer, because only there
            # are pixel operations (round rectangle)
            self.s_alpha.lock()

        if force_redraw:
            _debug_('show, force update', 2)
            self.update_bg = (0, 0, osd.width, osd.height)
            self.update_alpha = []
            self.update_content = []

        update_area = self.update_alpha

        # if the background has some changes ...
        if self.update_bg:
            ux1, uy1, ux2, uy2 = self.update_bg
            for x1, y1, x2, y2, image in self.drawlist.bgimages:
                if not (x2 < ux1 or y2 < uy1 or x1 > ux2 or y1 > uy2):
                    self.s_bg.blit(image, (ux1, uy1),
                                   (ux1 - x1, uy1 - y1, ux2 - ux1, uy2 - uy1))
            update_area.append(self.update_bg)

        # rectangles
        if update_area:
            self.s_alpha.fill((0, 0, 0, 0))
            for x1, y1, x2, y2, bgcolor, size, color, radius in self.drawlist.rectangles:
                # only redraw if necessary
                if self.in_update(x1, y1, x2, y2, update_area):
                    # if the radius and the border is not inside the update area,
                    # use drawbox, it's faster
                    if self.in_update(x1 + size + radius,
                                      y1 + size + radius,
                                      x2 - size - radius,
                                      y2 - size - radius,
                                      update_area,
                                      full=True):
                        osd.drawroundbox(x1,
                                         y1,
                                         x2,
                                         y2,
                                         color=bgcolor,
                                         layer=self.s_alpha)
                    else:
                        osd.drawroundbox(x1,
                                         y1,
                                         x2,
                                         y2,
                                         color=bgcolor,
                                         border_size=size,
                                         border_color=color,
                                         radius=radius,
                                         layer=self.s_alpha)
            # and than blit only the changed parts of the screen
            try:
                for x0, y0, x1, y1 in update_area:
                    self.s_content.blit(self.s_bg, (x0, y0),
                                        (x0, y0, x1 - x0, y1 - y0))
                    self.s_content.blit(self.s_alpha, (x0, y0),
                                        (x0, y0, x1 - x0, y1 - y0))
            except:
                pass

        update_area += self.update_content

        layer = self.s_screen
        for x0, y0, x1, y1 in update_area:
            layer.blit(self.s_content, (x0, y0), (x0, y0, x1 - x0, y1 - y0))

        # if something changed redraw all content objects
        if update_area:
            ux1, uy1, ux2, uy2 = osd.width, osd.height, 0, 0
            for a in update_area:
                ux1 = min(ux1, a[0])
                uy1 = min(uy1, a[1])
                ux2 = max(ux2, a[2])
                uy2 = max(uy2, a[3])

            for x1, y1, x2, y2, image in self.drawlist.images:
                if self.in_update(x1, y1, x2, y2, update_area):
                    layer.blit(image, (ux1, uy1),
                               (ux1 - x1, uy1 - y1, ux2 - ux1, uy2 - uy1))

            for x1, y1, x2, y2, text, font, height, align_h, align_v, mode, \
                    ellipses, dim in self.drawlist.text:
                if self.in_update(x1, y1, x2, y2, update_area):
                    osd.drawstringframed(text,
                                         x1,
                                         y1,
                                         x2 - x1,
                                         height,
                                         font,
                                         align_h=align_h,
                                         align_v=align_v,
                                         mode=mode,
                                         ellipses=ellipses,
                                         dim=dim,
                                         layer=layer)

        if self.drawlist.skin_area:
            for area in self.drawlist.skin_area:
                x, y, w, h, name = area
                osd.drawbox(x, y, x + w, y + h, 1, osd.COL_WHITE, 0, layer)
                osd.drawstring(name,
                               x + 1,
                               y + 1,
                               fgcolor=osd.COL_WHITE,
                               bgcolor=osd.COL_BLUE,
                               layer=layer)
                update_area.append((x, y, x + w, y + h))

        if not update_area:
            return None

        rect = (osd.width, osd.height, 0, 0)
        for u in update_area:
            osd.screenblit(layer, (u[0], u[1]),
                           (u[0], u[1], u[2] - u[0], u[3] - u[1]))
            rect = (min(u[0], rect[0]), min(u[1], rect[1]), max(u[2], rect[2]),
                    max(u[3], rect[3]))
        rect = (rect[0], rect[1], rect[2] - rect[0], rect[3] - rect[1])

        if osd.must_lock:
            self.s_alpha.unlock()

        return rect
예제 #6
0
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)
예제 #7
0
    def show(self, force_redraw=False):
        """
        the main drawing function
        """
        logger.log( 8, 'show(force_redraw=%r)', force_redraw)
        if osd.must_lock:
            # only lock s_alpha layer, because only there
            # are pixel operations (round rectangle)
            self.s_alpha.lock()

        if force_redraw:
            logger.log( 9, 'show, force update')
            self.update_bg      = (0, 0, osd.width, osd.height)
            self.update_alpha   = []
            self.update_content = []

        update_area = self.update_alpha

        # if the background has some changes ...
        if self.update_bg:
            ux1, uy1, ux2, uy2 = self.update_bg
            for x1, y1, x2, y2, image in self.drawlist.bgimages:
                if not (x2 < ux1 or y2 < uy1 or x1 > ux2 or y1 > uy2):
                    self.s_bg.blit(image, (ux1, uy1), (ux1-x1, uy1-y1, ux2-ux1, uy2-uy1))
            update_area.append(self.update_bg)

        # rectangles
        if update_area:
            self.s_alpha.fill((0,0,0,0))
            for x1, y1, x2, y2, bgcolor, size, color, radius in self.drawlist.rectangles:
                # only redraw if necessary
                if self.in_update(x1, y1, x2, y2, update_area):
                    # if the radius and the border is not inside the update area,
                    # use drawbox, it's faster
                    if self.in_update(x1+size+radius, y1+size+radius, x2-size-radius,
                                      y2-size-radius, update_area, full=True):
                        osd.drawroundbox(x1, y1, x2, y2, color=bgcolor,
                                         layer=self.s_alpha)
                    else:
                        osd.drawroundbox(x1, y1, x2, y2, color=bgcolor,
                                         border_size=size, border_color=color,
                                         radius=radius, layer=self.s_alpha)
            # and than blit only the changed parts of the screen
            try:
                for x0, y0, x1, y1 in update_area:
                    self.s_content.blit(self.s_bg, (x0, y0), (x0, y0, x1-x0, y1-y0))
                    self.s_content.blit(self.s_alpha, (x0, y0), (x0, y0, x1-x0, y1-y0))
            except:
                pass

        update_area += self.update_content

        layer = self.s_screen
        for x0, y0, x1, y1 in update_area:
            layer.blit(self.s_content, (x0, y0), (x0, y0, x1-x0, y1-y0))

        # if something changed redraw all content objects
        if update_area:
            ux1, uy1, ux2, uy2 = osd.width, osd.height, 0, 0
            for a in update_area:
                ux1 = min(ux1, a[0])
                uy1 = min(uy1, a[1])
                ux2 = max(ux2, a[2])
                uy2 = max(uy2, a[3])

            for x1, y1, x2, y2, image in self.drawlist.images:
                if self.in_update(x1, y1, x2, y2, update_area):
                    layer.blit(image, (ux1, uy1), (ux1-x1, uy1-y1, ux2-ux1, uy2-uy1))

            for x1, y1, x2, y2, text, font, height, align_h, align_v, mode, \
                    ellipses, dim in self.drawlist.text:
                if self.in_update(x1, y1, x2, y2, update_area):
                    osd.drawstringframed(text, x1, y1, x2 - x1, height, font,
                                         align_h = align_h,
                                         align_v = align_v, mode=mode,
                                         ellipses=ellipses, dim=dim, layer=layer)

        if self.drawlist.skin_area:
            for area in self.drawlist.skin_area:
                x,y,w,h,name = area
                osd.drawbox(x,y,x + w, y +h, 1, osd.COL_WHITE, 0, layer)
                osd.drawstring(name, x + 1, y + 1, fgcolor=osd.COL_WHITE, bgcolor=osd.COL_BLUE, layer=layer)
                update_area.append((x,y,x+w,y+h))

        if not update_area:
            return None

        rect = (osd.width, osd.height, 0, 0)
        for u in update_area:
            osd.screenblit(layer, (u[0], u[1]), (u[0], u[1], u[2]-u[0], u[3]-u[1]))
            rect = ( min(u[0], rect[0]), min(u[1], rect[1]),
                     max(u[2], rect[2]), max(u[3], rect[3]))
        rect = (rect[0], rect[1], rect[2]-rect[0], rect[3]-rect[1])

        if osd.must_lock:
            self.s_alpha.unlock()

        return rect
예제 #8
0
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)