Update of /cvsroot/freevo/freevo/WIP/RobShortt
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv9304

Added Files:
        directfb_osd.py 
Log Message:
I did this a long time ago, dunno if it still works.


--- NEW FILE: directfb_osd.py ---

#if 0 /*
# -----------------------------------------------------------------------
# directfb_osd.py - Implementation of an OSD using DirectFB
# -----------------------------------------------------------------------
# $Id: directfb_osd.py,v 1.1 2004/07/17 01:04:41 rshortt Exp $
#
# Notes:
# Todo:
#
# -----------------------------------------------------------------------
# $Log: directfb_osd.py,v $
# Revision 1.1  2004/07/17 01:04:41  rshortt
# I did this a long time ago, dunno if it still works.
#
#
#
# -----------------------------------------------------------------------
# Freevo - A Home Theater PC framework
# Copyright (C) 2002 Krister Lagerstrom, et al.
# Please see the file freevo/Docs/CREDITS for a complete list of authors.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of MER-
# CHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
# Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
# ----------------------------------------------------------------------- */
#endif

import time, re, string, pyosd
from directfb import *

import config, plugin
from event import *


OSD_MESSAGE_FONT    = '/opt/freevo/share/fonts/VeraBd.ttf'
OSD_MESSAGE_COLOR   = '#D3D3D3'  # LightGray
OSD_MESSAGE_TIMEOUT = 3          # 3 seconds


class PluginInterface(plugin.DaemonPlugin):
    """
    """
    def __init__(self):
        """
        init the osd
        """
        plugin.DaemonPlugin.__init__(self)
        self.plugin_name = 'OSD_MESSAGE'

        self.message = ''
        # (0%) -> (100%)
        self.re_percent = re.compile(r' [0-9][0-9]?[0-9]?%')

        self.dfb = DirectFB()
        caps = self.dfb.getCardCapabilities()
        self.dfb_layer = self.dfb.getDisplayLayer(0)
        self.dfb_layer.setCooperativeLevel( DLSCL_ADMINISTRATIVE )     

        if ( not ((caps[2] & DSBLIT_BLEND_ALPHACHANNEL) and
              (caps[2] & DSBLIT_BLEND_COLORALPHA  ))):
            self.dfb_layer.setConfiguration( flags = DLCONF_BUFFERMODE, 
                                             buffermode = DLBM_BACKSYSTEM )

        layer_config = self.dfb_layer.getConfiguration()
        self.dfb_layer.enableCursor(0)
        self.font = self.dfb.createFont( OSD_MESSAGE_FONT, 
                                         height=layer_config['width']/30 )
        fontheight = self.font.getHeight()

        self.osd_width = layer_config['width'] - config.OSD_OVERSCAN_X
        self.osd_height = layer_config['height'] - config.OSD_OVERSCAN_Y

        print 'osd_width: %s' % self.osd_width
        print 'osd_height: %s' % self.osd_height

        self.osd = self.dfb_layer.createWindow( caps=DWCAPS_ALPHACHANNEL, 
                                                width=self.osd_width, 
                                                height=self.osd_height, 
                                                posx=config.OSD_OVERSCAN_X/2, 
                                                posy=config.OSD_OVERSCAN_Y/2 )

        self.osd_surface = self.osd.getSurface()
        self.osd.setOpacity( 0xFF )
        # buffer = osd.createEventBuffer()

        # self.osd_surface.setFont( font )
        # self.osd_surface.setColor( 0xFF, 0xFF, 0xFF, 0xFF )
        # self.osd_surface.drawString( "TEST OSD MESSAGE", osd_width/3, 
2*osd_height/3);
        # self.osd_surface.flip( 0 )

        self.dfb_id = osd.getID()
        # self.osd.attachEventBuffer(buffer)
        # self.osd.requestFocus()
        self.osd.raiseToTop()


    def draw_osd(self):
        """
        Display a message on the screen.
        """

        if not self.message == '' :
            re_percent = self.re_percent.search(self.message)

            if re_percent :
                # A percentage was sent
                label   = self.message[0:re_percent.start() - 1]
                percent = int(self.message[re_percent.start() + 1:re_percent.end() - 
1])

                if label in SLIDER :
                    type = pyosd.TYPE_SLIDER
                else :
                    type = pyosd.TYPE_PERCENT
                
                if percent < 0 :
                    percent = 0
                elif percent > 100 :
                    percent = 100

                # Display it on the bottom of the screen
                self.osd.set_pos(pyosd.POS_BOT)
                # First line is the label with the value
                self.osd.display('%s (%d%%)' % (_(label), percent), pyosd.TYPE_STRING, 
line=0)
                # Second line is the progress bar
                self.osd.display(percent, type, line=1)

            else :
                # This is text, display it on top
                self.osd.set_pos(pyosd.POS_TOP)
                if re.search('\n', self.message) :
                    # If message contains one or more \n, display two first lines.
                    s_msg = self.message.split('\n')
                    self.osd.display(s_msg[0], pyosd.TYPE_STRING, line=0)
                    self.osd.display(s_msg[1], pyosd.TYPE_STRING, line=1)
                else :
                    # If not, display only the first line
                    self.osd.display(self.message, pyosd.TYPE_STRING, line=0)
                    self.osd.display('', pyosd.TYPE_STRING, line=1)

    def eventhandler(self, event, menuw=None):
        """
        Do something when receiving an event
        """

        _debug_('%s: %s app got %s event' % (time.time(), self.plugin_name, event))
        if event == OSD_MESSAGE :
            self.poll_counter = 1
            self.message = event.arg
            self.draw_osd()




-------------------------------------------------------
This SF.Net email is sponsored by BEA Weblogic Workshop
FREE Java Enterprise J2EE developer tools!
Get your free copy of BEA WebLogic Workshop 8.1 today.
http://ads.osdn.com/?ad_id=4721&alloc_id=10040&op=click
_______________________________________________
Freevo-cvslog mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/freevo-cvslog

Reply via email to