Update of /cvsroot/freevo/freevo/src/plugins/idlebar
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv30607

Modified Files:
        __init__.py 
Added Files:
        cdstatus.py clock.py holidays.py logo.py mail.py tv.py 
        weather.py 
Log Message:
move plugins intro seperate files

--- NEW FILE: weather.py ---
# -*- coding: iso-8859-1 -*-
# -----------------------------------------------------------------------
# weather.py - IdleBarPlugin for showing weatcher status
# -----------------------------------------------------------------------
# $Id:
#
# -----------------------------------------------------------------------
# $Log:
#
#
# -----------------------------------------------------------------------
# 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
#
# ----------------------------------------------------------------------- */

import os
import time
import string

import gui
import config
import util.pymetar as pymetar
from plugins.idlebar import IdleBarPlugin

class PluginInterface(IdleBarPlugin):
    """
    Shows the current weather.

    Activate with:
    plugin.activate('idlebar.weather', level=30, args=('4-letter code', ))

    For weather station codes see: http://www.nws.noaa.gov/tg/siteloc.shtml
    You can also set the unit as second parameter in args ('C', 'F', or 'K')
    """
    def __init__(self, zone='CYYZ', units='C'):
        self.current = None, None

        IdleBarPlugin.__init__(self)
        self.TEMPUNITS = units
        self.METARCODE = zone
        self.WEATHERCACHE = config.FREEVO_CACHEDIR + '/weather'
        print
        print 'WARNING: the idlebar.weather plugin downloads new weather'
        print 'information inside the main loop. This bug makes all menu'
        print 'actions _very_ slow. Consider not using this plugin for higher'
        print 'speed.'
        print


    def checkweather(self):
        # We don't want to do this every 30 seconds, so we need
        # to cache the date somewhere.
        #
        # First check the age of the cache.
        #
        if (os.path.isfile(self.WEATHERCACHE) == 0 or \
            (abs(time.time() - os.path.getmtime(self.WEATHERCACHE)) > 3600)):
            try:
                rf=pymetar.ReportFetcher(self.METARCODE)
                rep=rf.FetchReport()
                rp=pymetar.ReportParser()
                pr=rp.ParseReport(rep)
                if (pr.getTemperatureCelsius()):
                    if self.TEMPUNITS == 'F':
                        temperature = '%2d' % pr.getTemperatureFahrenheit()
                    elif self.TEMPUNITS == 'K':
                        ktemp = pr.getTemperatureCelsius() + 273
                        temperature = '%3d' % ktemp
                    else:
                        temperature = '%2d' % pr.getTemperatureCelsius()
                else:
                    temperature = '?'  # Make it a string to match above.
                if pr.getPixmap():
                    icon = pr.getPixmap() + '.png'
                else:
                    icon = 'sun.png'
                cachefile = open(self.WEATHERCACHE,'w+')
                cachefile.write(temperature + '\n')
                cachefile.write(icon + '\n')
                cachefile.close()
            except:
                try:
                    # HTTP Problems, use cache. Wait till next try.
                    cachefile = open(self.WEATHERCACHE,'r')
                    newlist = map(string.rstrip, cachefile.readlines())
                    temperature,icon = newlist
                    cachefile.close()
                except IOError:
                    print 'WEATHER: error reading cache. Using fake weather.'
                    try:
                        cachefile = open(self.WEATHERCACHE,'w+')
                        cachefile.write('?' + '\n')
                        cachefile.write('sun.png' + '\n')
                        cachefile.close()
                    except IOError:
                        print 'You have no permission to write %s' % self.WEATHERCACHE
                    return '0', 'sun.png'


        else:
            cachefile = open(self.WEATHERCACHE,'r')
            newlist = map(string.rstrip, cachefile.readlines())
            temperature,icon = newlist
            cachefile.close()
        return temperature, icon

    def draw(self, width, height):
        t, ic = self.current
        temp,icon = self.checkweather()

        if temp == t and ic == icon:
            return self.NO_CHANGE

        self.clear()
        self.current = temp, icon

        icon = os.path.join(config.ICON_DIR, 'weather', icon)
        font  = gui.get_font('small0')
        i = gui.imagelib.load(icon, (None, None))
        self.objects.append(gui.Image(i, (0, 15)))

        temp = u'%s\xb0' % temp
        width = font.stringsize(temp)

        self.objects.append(gui.Text(temp, (15, 55-font.height), (width, font.height),
                                     font, 'left', 'top'))

        return width + 15

--- NEW FILE: cdstatus.py ---
# -*- coding: iso-8859-1 -*-
# -----------------------------------------------------------------------
# cdstatus.py - IdleBarPlugin for showing cd status
# -----------------------------------------------------------------------
# $Id:
#
# -----------------------------------------------------------------------
# $Log:
#
#
# -----------------------------------------------------------------------
# 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
#
# ----------------------------------------------------------------------- */

import os

import gui
import config
from plugins.idlebar import IdleBarPlugin

class PluginInterface(IdleBarPlugin):
    """
    Show the status of all rom drives.

    Activate with:
    plugin.activate('idlebar.cdstatus')
    """
    def __init__(self):

        IdleBarPlugin.__init__(self)
        icondir = os.path.join(config.ICON_DIR, 'status')
        self.cdimages ={}
        self.cdimages ['audiocd']       = os.path.join(icondir, 'cd_audio.png')
        self.cdimages ['empty_cdrom'] = os.path.join(icondir, 'cd_inactive.png')
        self.cdimages ['images']      = os.path.join(icondir, 'cd_photo.png')
        self.cdimages ['video']       = os.path.join(icondir, 'cd_video.png')
        self.cdimages ['dvd']         = os.path.join(icondir, 'cd_video.png')
        self.cdimages ['burn']        = os.path.join(icondir, 'cd_burn.png')
        self.cdimages ['cdrip']       = os.path.join(icondir, 'cd_rip.png')
        self.cdimages ['mixed']       = os.path.join(icondir, 'cd_mixed.png')

    def draw(self, width, height):
        image = self.cdimages['empty_cdrom']

        self.clear()

        w = 0
        for media in config.REMOVABLE_MEDIA:
            image = self.cdimages['empty_cdrom']
            if media.type == 'empty_cdrom':
                image = self.cdimages['empty_cdrom']
            if media.type and self.cdimages.has_key(media.type):
                image = self.cdimages[media.type]
            else:
                image = self.cdimages['mixed']
            i = gui.imagelib.load(image, (None, None))

            w += i.width + 10

            self.objects.append(gui.Image(i, (w, (height-i.height)/2)))


        if w:
            w -= 10
        return w

--- NEW FILE: holidays.py ---
# -*- coding: iso-8859-1 -*-
# -----------------------------------------------------------------------
# holidays.py - IdleBarPlugin for displaying holidays
# -----------------------------------------------------------------------
# $Id:
#
# -----------------------------------------------------------------------
# $Log:
#
#
# -----------------------------------------------------------------------
# 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
#
# ----------------------------------------------------------------------- */

import os
import time

import gui
import config
from plugins.idlebar import IdleBarPlugin

class PluginInterface(IdleBarPlugin):
    """
    Display some holidays in the idlebar

    This plugin checks if the current date is a holiday and will
    display a specified icon for that holiday. If no holiday is found,
    nothing will be displayed. If you use the idlebar, you should activate
    this plugin, most of the time you won't see it.

    You can customize the list of holidays with the variable HOLIDAYS in
    local_config.py. The default value is:

    [ ('01-01',  'newyear.png'),
      ('02-14',  'valentine.png'),
      ('05-07',  'freevo_bday.png'),
      ('07-03',  'usa_flag.png'),
      ('07-04',  'usa_flag.png'),
      ('10-30',  'ghost.png'),
      ('10-31',  'pumpkin.png'),
      ('12-21',  'snowman.png'),
      ('12-25',  'christmas.png')]
    """
    def __init__(self):
        IdleBarPlugin.__init__(self)
        self.icon = ''

    def config(self):
        return [ ('HOLIDAYS', [ ('01-01',  'newyear.png'),
                                ('02-14',  'valentine.png'),
                                ('05-07',  'freevo_bday.png'),
                                ('07-03',  'usa_flag.png'),
                                ('07-04',  'usa_flag.png'),
                                ('10-30',  'ghost.png'),
                                ('10-31',  'pumpkin.png'),
                                ('12-21',  'snowman.png'),
                                ('12-25',  'christmas.png')],
                  'list of holidays this plugin knows') ]

    def get_holiday_icon(self):
        # Creates a string which looks like "07-04" meaning July 04
        todays_date = time.strftime('%m-%d')

        for i in config.HOLIDAYS:
            holiday, icon = i
            if todays_date == holiday:
                return os.path.join(config.ICON_DIR, 'holidays', icon)


    def draw(self, width, height):
        icon = self.get_holiday_icon()

        if icon == self.icon:
            return self.NO_CHANGE

        if icon:
            self.icon = icon
            self.clear()
            i = gui.imagelib.load(icon, (None, None))
            self.objects.append(gui.Image(i, (0, (height-i.height)/2)))

            return i.width

        return 0

--- NEW FILE: clock.py ---
# -*- coding: iso-8859-1 -*-
# -----------------------------------------------------------------------
# clock.py - IdleBar clock
# -----------------------------------------------------------------------
# $Id:
#
# -----------------------------------------------------------------------
# $Log:
#
#
# -----------------------------------------------------------------------
# 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
#
# ----------------------------------------------------------------------- */

import time

import gui
from plugins.idlebar import IdleBarPlugin

class PluginInterface(IdleBarPlugin):
    """
    Shows the current time.

    Activate with:
    plugin.activate('idlebar.clock',   level=50)
    Note: The clock will always be displayed on the right side of
    the idlebar.
    """
    def __init__(self, format=''):
        IdleBarPlugin.__init__(self)
        if format == '': # No overiding of the default value
            if time.strftime('%P') =='':
                format ='%a %H:%M'
            else:
                format ='%a %I:%M %P'

        self.format = format
        self.object = None
        self.align  = 'right'
        self.width  = 0
        self.text   = ''

    def draw(self, width, height):
        clock  = time.strftime(self.format)

        if self.objects and self.text == clock:
            return self.NO_CHANGE

        self.clear()

        font  = gui.get_font('clock')
        width = min(width, font.stringsize(clock))

        txt = gui.Text(clock, (0, 0), (width, height), font,
                       align_v='center', align_h='right')
        self.objects.append(txt)
        self.text = clock
        return width

--- NEW FILE: mail.py ---
# -*- coding: iso-8859-1 -*-
# -----------------------------------------------------------------------
# mail.py - IdleBarPlugin for showing mbox status
# -----------------------------------------------------------------------
# $Id:
#
# -----------------------------------------------------------------------
# $Log:
#
#
# -----------------------------------------------------------------------
# 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
#
# ----------------------------------------------------------------------- */

import os
import mailbox

import gui
import config
from plugins.idlebar import IdleBarPlugin

class PluginInterface(IdleBarPlugin):
    """
    Shows if new mail is in the mailbox.

    Activate with:
    plugin.activate('idlebar.mail',    level=10, args=('path to mailbox', ))

    """
    def __init__(self, mailbox):
        IdleBarPlugin.__init__(self)
        self.mails = -1
        self.NO_MAILIMAGE = os.path.join(config.ICON_DIR, 'status/newmail_dimmed.png')
        self.MAILIMAGE = os.path.join(config.ICON_DIR, 'status/newmail_active.png')
        self.MAILBOX = mailbox

    def checkmail(self):
        if not self.MAILBOX:
            return 0
        if os.path.isfile(self.MAILBOX):
            mb = mailbox.UnixMailbox (file(self.MAILBOX,'r'))
            msg = mb.next()
            count = 0
            while msg is not None:
                count = count + 1
                msg = mb.next()
            return count
        else:
            return 0

    def draw(self, width, height):
        mails = self.checkmail()

        if self.mails == mails:
            return self.NO_CHANGE

        self.mails = mails
        self.clear()

        if mails > 0:
            m = gui.imagelib.load(self.MAILIMAGE, (None, None))
        else:
            m = gui.imagelib.load(self.NO_MAILIMAGE, (None, None))

        self.objects.append(gui.Image(m, (0, (height-m.height)/2)))

        return m.width

--- NEW FILE: tv.py ---
# -*- coding: iso-8859-1 -*-
# -----------------------------------------------------------------------
# tv.py - IdleBarPlugin for information about XMLTV-listings
# -----------------------------------------------------------------------
# $Id:
#
# -----------------------------------------------------------------------
# $Log:
#
#
# -----------------------------------------------------------------------
# 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
#
# ----------------------------------------------------------------------- */
import os

import gui
import config
import util.tv_util as tv_util
from plugins.idlebar import IdleBarPlugin


class PluginInterface(IdleBarPlugin):
    """
    Informs you, when the xmltv-listings expires.

    Activate with:
    plugin.activate('idlebar.tv', level=20, args=(listings_threshold,))
    listings_threshold must be a number in hours.  For example if you put
    args=(12, ) then 12 hours befor your xmltv listings run out the tv icon
    will present a warning.  Once your xmltv data is expired it will present
    a more severe warning.  If no args are given then no warnings will be
    given.
    """
    def __init__(self, listings_threshold=-1):
        IdleBarPlugin.__init__(self)

        self.listings_threshold = listings_threshold
        self.next_guide_check   = 0
        self.listings_expire    = 0
        self.tvlockfile         = config.FREEVO_CACHEDIR + '/record'
        self.status             = None

        self.TVLOCKED     = 'television_active.png'
        self.TVFREE       = 'television_inactive.png'
        self.NEAR_EXPIRED = 'television_near_expired.png'
        self.EXPIRED      = 'television_expired.png'


    def clear(self):
        IdleBarPlugin.clear(self)
        self.status = None


    def checktv(self):
        if os.path.exists(self.tvlockfile):
            return 1
        return 0


    def draw(self, width, height):
        status = 'inactive'
        if self.checktv() == 1:
            status = 'active'

        if self.listings_threshold != -1:
            now = time.time()

            if now > self.next_guide_check:
                self.listings_expire = tv_util.when_listings_expire()
                # check again in 10 minutes
                self.next_guide_check = now + 10*60

            if self.listings_expire <= self.listings_threshold:
                status = 'near_expired'

            if self.listings_expire == 0:
                status = 'expired'

        if self.status == status:
            return self.NO_CHANGE

        self.clear()
        self.status = status
        icon = gui.get_icon('status/television_%s' % status)
        i = gui.imagelib.load(icon, (None, None))


        self.objects.append(gui.Image(i, (0, (height-i.height)/2)))
        return i.width

Index: __init__.py
===================================================================
RCS file: /cvsroot/freevo/freevo/src/plugins/idlebar/__init__.py,v
retrieving revision 1.29
retrieving revision 1.30
diff -C2 -d -r1.29 -r1.30
*** __init__.py 8 Sep 2004 08:33:13 -0000       1.29
--- __init__.py 14 Sep 2004 14:00:39 -0000      1.30
***************
*** 5,21 ****
  # $Id$
  #
- # Documentation moved to the corresponding classes, so that the help
- # interface returns something usefull.
- # Available plugins:
- #       idlebar
- #       idlebar.clock
- #       idlebar.cdstatus
- #       idlebar.mail
- #       idlebar.tv
- #       idlebar.weather
- #       idlebar.holidays
- #
  # -----------------------------------------------------------------------
  # $Log$
  # Revision 1.29  2004/09/08 08:33:13  dischi
  # patch from Viggo Fredriksen to reactivate the plugins
--- 5,13 ----
  # $Id$
  #
  # -----------------------------------------------------------------------
  # $Log$
+ # Revision 1.30  2004/09/14 14:00:39  dischi
+ # move plugins intro seperate files
+ #
  # Revision 1.29  2004/09/08 08:33:13  dischi
  # patch from Viggo Fredriksen to reactivate the plugins
***************
*** 85,104 ****
  # ----------------------------------------------------------------------- */
  
! 
  import time
- import os
- import sys
- import string
- import types
- import mailbox
- import re
  import locale
  
  import config
  import plugin
- import util.tv_util as tv_util
- import util.pymetar as pymetar
  import gui
- import gui.imagelib
  import eventhandler
  from event import *
--- 77,88 ----
  # ----------------------------------------------------------------------- */
  
! # python modules
  import time
  import locale
  
+ # freevo modules
  import config
  import plugin
  import gui
  import eventhandler
  from event import *
***************
*** 309,725 ****
              o.unparent()
          self.objects = []
- 
- 
- 
- 
- class clock(IdleBarPlugin):
-     """
-     Shows the current time.
- 
-     Activate with:
-     plugin.activate('idlebar.clock',   level=50)
-     Note: The clock will always be displayed on the right side of
-     the idlebar.
-     """
-     def __init__(self, format=''):
-         IdleBarPlugin.__init__(self)
-       if format == '': # No overiding of the default value
-           if time.strftime('%P') =='':
-                 format ='%a %H:%M'
-             else:
-                 format ='%a %I:%M %P'
-         self.format = format
-         self.object = None
-         self.align  = 'right'
-         self.width  = 0
-         self.text   = ''
- 
-     def draw(self, width, height):
-         clock  = time.strftime(self.format)
- 
-         if self.objects and self.text == clock:
-             return self.NO_CHANGE
- 
-         self.clear()
- 
-         font  = gui.get_font('clock')
-         width = min(width, font.stringsize(clock))
- 
-         txt = gui.Text(clock, (0, 0), (width, height), font,
-                        align_v='center', align_h='right')
-         self.objects.append(txt)
-         self.text = clock
-         return width
- 
- 
- 
- class cdstatus(IdleBarPlugin):
-     """
-     Show the status of all rom drives.
- 
-     Activate with:
-     plugin.activate('idlebar.cdstatus')
-     """
-     def __init__(self):
- 
-         IdleBarPlugin.__init__(self)
-         icondir = os.path.join(config.ICON_DIR, 'status')
-         self.cdimages ={}
-         self.cdimages ['audiocd']       = os.path.join(icondir, 'cd_audio.png')
-         self.cdimages ['empty_cdrom'] = os.path.join(icondir, 'cd_inactive.png')
-         self.cdimages ['images']      = os.path.join(icondir, 'cd_photo.png')
-         self.cdimages ['video']       = os.path.join(icondir, 'cd_video.png')
-         self.cdimages ['dvd']         = os.path.join(icondir, 'cd_video.png')
-         self.cdimages ['burn']        = os.path.join(icondir, 'cd_burn.png')
-         self.cdimages ['cdrip']       = os.path.join(icondir, 'cd_rip.png')
-         self.cdimages ['mixed']       = os.path.join(icondir, 'cd_mixed.png')
- 
-     def draw(self, width, height):
-         image = self.cdimages['empty_cdrom']
- 
-         self.clear()
- 
-         w = 0
-         for media in config.REMOVABLE_MEDIA:
-             image = self.cdimages['empty_cdrom']
-             if media.type == 'empty_cdrom':
-                 image = self.cdimages['empty_cdrom']
-             if media.type and self.cdimages.has_key(media.type):
-                 image = self.cdimages[media.type]
-             else:
-                 image = self.cdimages['mixed']
-             i = gui.imagelib.load(image, (None, None))
- 
-             w += i.width + 10
- 
-             self.objects.append(gui.Image(i, (w, (height-i.height)/2)))
- 
- 
-         if w:
-             w -= 10
-         return w
- 
- 
- class mail(IdleBarPlugin):
-     """
-     Shows if new mail is in the mailbox.
- 
-     Activate with:
-     plugin.activate('idlebar.mail',    level=10, args=('path to mailbox', ))
- 
-     """
-     def __init__(self, mailbox):
-         IdleBarPlugin.__init__(self)
-         self.mails = -1
-         self.NO_MAILIMAGE = os.path.join(config.ICON_DIR, 
'status/newmail_dimmed.png')
-         self.MAILIMAGE = os.path.join(config.ICON_DIR, 'status/newmail_active.png')
-         self.MAILBOX = mailbox
- 
-     def checkmail(self):
-         if not self.MAILBOX:
-             return 0
-         if os.path.isfile(self.MAILBOX):
-             mb = mailbox.UnixMailbox (file(self.MAILBOX,'r'))
-             msg = mb.next()
-             count = 0
-             while msg is not None:
-                 count = count + 1
-                 msg = mb.next()
-             return count
-         else:
-             return 0
- 
-     def draw(self, width, height):
-         mails = self.checkmail()
- 
-         if self.mails == mails:
-             return self.NO_CHANGE
- 
-         self.mails = mails
-         self.clear()
- 
-         if mails > 0:
-             m = gui.imagelib.load(self.MAILIMAGE, (None, None))
-         else:
-             m = gui.imagelib.load(self.NO_MAILIMAGE, (None, None))
- 
-         self.objects.append(gui.Image(m, (0, (height-m.height)/2)))
- 
-         return m.width
- 
- 
- 
- 
- class tv(IdleBarPlugin):
-     """
-     Informs you, when the xmltv-listings expires.
- 
-     Activate with:
-     plugin.activate('idlebar.tv', level=20, args=(listings_threshold,))
-     listings_threshold must be a number in hours.  For example if you put
-     args=(12, ) then 12 hours befor your xmltv listings run out the tv icon
-     will present a warning.  Once your xmltv data is expired it will present
-     a more severe warning.  If no args are given then no warnings will be
-     given.
-     """
-     def __init__(self, listings_threshold=-1):
-         IdleBarPlugin.__init__(self)
- 
-         self.listings_threshold = listings_threshold
-         self.next_guide_check   = 0
-         self.listings_expire    = 0
-         self.tvlockfile         = config.FREEVO_CACHEDIR + '/record'
-         self.status             = None
- 
-         self.TVLOCKED     = 'television_active.png'
-         self.TVFREE       = 'television_inactive.png'
-         self.NEAR_EXPIRED = 'television_near_expired.png'
-         self.EXPIRED      = 'television_expired.png'
- 
- 
-     def clear(self):
-         IdleBarPlugin.clear(self)
-         self.status = None
- 
- 
-     def checktv(self):
-         if os.path.exists(self.tvlockfile):
-             return 1
-         return 0
- 
- 
-     def draw(self, width, height):
-         status = 'inactive'
-         if self.checktv() == 1:
-             status = 'active'
- 
-         if self.listings_threshold != -1:
-             now = time.time()
- 
-             if now > self.next_guide_check:
-                 self.listings_expire = tv_util.when_listings_expire()
-                 # check again in 10 minutes
-                 self.next_guide_check = now + 10*60
- 
-             if self.listings_expire <= self.listings_threshold:
-                 status = 'near_expired'
- 
-             if self.listings_expire == 0:
-                 status = 'expired'
- 
-         if self.status == status:
-             return self.NO_CHANGE
- 
-         self.clear()
-         self.status = status
-         icon = gui.get_icon('status/television_%s' % status)
-         i = gui.imagelib.load(icon, (None, None))
- 
- 
-         self.objects.append(gui.Image(i, (0, (height-i.height)/2)))
-         return i.width
- 
- 
- 
- class weather(IdleBarPlugin):
-     """
-     Shows the current weather.
- 
-     Activate with:
-     plugin.activate('idlebar.weather', level=30, args=('4-letter code', ))
- 
-     For weather station codes see: http://www.nws.noaa.gov/tg/siteloc.shtml
-     You can also set the unit as second parameter in args ('C', 'F', or 'K')
-     """
-     def __init__(self, zone='CYYZ', units='C'):
-         self.current = None, None
- 
-         IdleBarPlugin.__init__(self)
-         self.TEMPUNITS = units
-         self.METARCODE = zone
-         self.WEATHERCACHE = config.FREEVO_CACHEDIR + '/weather'
-         print
-         print 'WARNING: the idlebar.weather plugin downloads new weather'
-         print 'information inside the main loop. This bug makes all menu'
-         print 'actions _very_ slow. Consider not using this plugin for higher'
-         print 'speed.'
-         print
- 
- 
-     def checkweather(self):
-         # We don't want to do this every 30 seconds, so we need
-         # to cache the date somewhere.
-         #
-         # First check the age of the cache.
-         #
-         if (os.path.isfile(self.WEATHERCACHE) == 0 or \
-             (abs(time.time() - os.path.getmtime(self.WEATHERCACHE)) > 3600)):
-             try:
-                 rf=pymetar.ReportFetcher(self.METARCODE)
-                 rep=rf.FetchReport()
-                 rp=pymetar.ReportParser()
-                 pr=rp.ParseReport(rep)
-                 if (pr.getTemperatureCelsius()):
-                     if self.TEMPUNITS == 'F':
-                         temperature = '%2d' % pr.getTemperatureFahrenheit()
-                     elif self.TEMPUNITS == 'K':
-                         ktemp = pr.getTemperatureCelsius() + 273
-                         temperature = '%3d' % ktemp
-                     else:
-                         temperature = '%2d' % pr.getTemperatureCelsius()
-                 else:
-                     temperature = '?'  # Make it a string to match above.
-                 if pr.getPixmap():
-                     icon = pr.getPixmap() + '.png'
-                 else:
-                     icon = 'sun.png'
-                 cachefile = open(self.WEATHERCACHE,'w+')
-                 cachefile.write(temperature + '\n')
-                 cachefile.write(icon + '\n')
-                 cachefile.close()
-             except:
-                 try:
-                     # HTTP Problems, use cache. Wait till next try.
-                     cachefile = open(self.WEATHERCACHE,'r')
-                     newlist = map(string.rstrip, cachefile.readlines())
-                     temperature,icon = newlist
-                     cachefile.close()
-                 except IOError:
-                     print 'WEATHER: error reading cache. Using fake weather.'
-                     try:
-                         cachefile = open(self.WEATHERCACHE,'w+')
-                         cachefile.write('?' + '\n')
-                         cachefile.write('sun.png' + '\n')
-                         cachefile.close()
-                     except IOError:
-                         print 'You have no permission to write %s' % 
self.WEATHERCACHE
-                     return '0', 'sun.png'
- 
- 
-         else:
-             cachefile = open(self.WEATHERCACHE,'r')
-             newlist = map(string.rstrip, cachefile.readlines())
-             temperature,icon = newlist
-             cachefile.close()
-         return temperature, icon
- 
-     def draw(self, width, height):
-         t, ic = self.current
-         temp,icon = self.checkweather()
- 
-         if temp == t and ic == icon:
-             return self.NO_CHANGE
- 
-         self.clear()
-         self.current = temp, icon
- 
-         icon = os.path.join(config.ICON_DIR, 'weather', icon)
-         font  = gui.get_font('small0')
-         i = gui.imagelib.load(icon, (None, None))
-         self.objects.append(gui.Image(i, (0, 15)))
- 
-         temp = u'%s\xb0' % temp
-         width = font.stringsize(temp)
- 
-         self.objects.append(gui.Text(temp, (15, 55-font.height), (width, 
font.height),
-                                      font, 'left', 'top'))
- 
-         return width + 15
- 
- 
- class holidays(IdleBarPlugin):
-     """
-     Display some holidays in the idlebar
- 
-     This plugin checks if the current date is a holiday and will
-     display a specified icon for that holiday. If no holiday is found,
-     nothing will be displayed. If you use the idlebar, you should activate
-     this plugin, most of the time you won't see it.
- 
-     You can customize the list of holidays with the variable HOLIDAYS in
-     local_config.py. The default value is:
- 
-     [ ('01-01',  'newyear.png'),
-       ('02-14',  'valentine.png'),
-       ('05-07',  'freevo_bday.png'),
-       ('07-03',  'usa_flag.png'),
-       ('07-04',  'usa_flag.png'),
-       ('10-30',  'ghost.png'),
-       ('10-31',  'pumpkin.png'),
-       ('12-21',  'snowman.png'),
-       ('12-25',  'christmas.png')]
-     """
-     def __init__(self):
-         IdleBarPlugin.__init__(self)
-         self.icon = ''
- 
-     def config(self):
-         return [ ('HOLIDAYS', [ ('01-01',  'newyear.png'),
-                                 ('02-14',  'valentine.png'),
-                                 ('05-07',  'freevo_bday.png'),
-                                 ('07-03',  'usa_flag.png'),
-                                 ('07-04',  'usa_flag.png'),
-                                 ('10-30',  'ghost.png'),
-                                 ('10-31',  'pumpkin.png'),
-                                 ('12-21',  'snowman.png'),
-                                 ('12-25',  'christmas.png')],
-                   'list of holidays this plugin knows') ]
- 
-     def get_holiday_icon(self):
-         # Creates a string which looks like "07-04" meaning July 04
-         todays_date = time.strftime('%m-%d')
- 
-         for i in config.HOLIDAYS:
-             holiday, icon = i
-             if todays_date == holiday:
-                 return os.path.join(config.ICON_DIR, 'holidays', icon)
- 
- 
-     def draw(self, width, height):
-         icon = self.get_holiday_icon()
- 
-         if icon == self.icon:
-             return self.NO_CHANGE
- 
-         if icon:
-             self.icon = icon
-             self.clear()
-             i = gui.imagelib.load(icon, (None, None))
-             self.objects.append(gui.Image(i, (0, (height-i.height)/2)))
- 
-             return i.width
- 
-         return 0
- 
- 
- 
- class logo(IdleBarPlugin):
-     """
-     Display the freevo logo in the idlebar
-     """
-     def __init__(self, image=None):
-         IdleBarPlugin.__init__(self)
-         self.image  = image
-         self.file   = file
-         self.object = None
- 
- 
-     def draw(self, width, height):
-         if not self.image:
-             image = gui.get_image('logo')
-         else:
-             image = os.path.join(config.IMAGE_DIR, self.image)
- 
-         if self.objects and self.file == image:
-             return self.NO_CHANGE
- 
-         self.file = image
-         self.clear()
- 
-         i = gui.imagelib.load(image, (None, height + 10))
-         if not i:
-             return 0
- 
-         self.objects.append(gui.Image(i, (0, 0)))
- 
-         return i.width
--- 293,294 ----

--- NEW FILE: logo.py ---
# -*- coding: iso-8859-1 -*-
# -----------------------------------------------------------------------
# logo.py - IdleBarPlugin for showing a freevo logo
# -----------------------------------------------------------------------
# $Id:
#
# -----------------------------------------------------------------------
# $Log:
#
#
# -----------------------------------------------------------------------
# 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
#
# ----------------------------------------------------------------------- */

import os

import gui
import config
from plugins.idlebar import IdleBarPlugin

class PluginInterface(IdleBarPlugin):
    """
    Display the freevo logo in the idlebar
    """
    def __init__(self, image=None):
        IdleBarPlugin.__init__(self)
        self.image  = image
        self.file   = file
        self.object = None


    def draw(self, width, height):
        if not self.image:
            image = gui.get_image('logo')
        else:
            image = os.path.join(config.IMAGE_DIR, self.image)

        if self.objects and self.file == image:
            return self.NO_CHANGE

        self.file = image
        self.clear()

        i = gui.imagelib.load(image, (None, height + 10))
        if not i:
            return 0

        self.objects.append(gui.Image(i, (0, 0)))

        return i.width



-------------------------------------------------------
This SF.Net email is sponsored by: YOU BE THE JUDGE. Be one of 170
Project Admins to receive an Apple iPod Mini FREE for your judgement on
who ports your project to Linux PPC the best. Sponsored by IBM. 
Deadline: Sept. 13. Go here: http://sf.net/ppc_contest.php
_______________________________________________
Freevo-cvslog mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/freevo-cvslog

Reply via email to