mythtvupcoming.py :  » Game-2D-3D » XBMC-MythTV » xbmcmythtv » Python Open Source

Home
Python Open Source
1.3.1.2 Python
2.Ajax
3.Aspect Oriented
4.Blog
5.Build
6.Business Application
7.Chart Report
8.Content Management Systems
9.Cryptographic
10.Database
11.Development
12.Editor
13.Email
14.ERP
15.Game 2D 3D
16.GIS
17.GUI
18.IDE
19.Installer
20.IRC
21.Issue Tracker
22.Language Interface
23.Log
24.Math
25.Media Sound Audio
26.Mobile
27.Network
28.Parser
29.PDF
30.Project Management
31.RSS
32.Search
33.Security
34.Template Engines
35.Test
36.UML
37.USB Serial
38.Web Frameworks
39.Web Server
40.Web Services
41.Web Unit
42.Wiki
43.Windows
44.XML
Python Open Source » Game 2D 3D » XBMC MythTV 
XBMC MythTV » xbmcmythtv » mythtvupcoming.py
"""
$Id: mythtvupcoming.py,v 1.8 2007/05/17 01:43:02 frooby Exp $

Copyright (C) 2005 Tom Warkentin <tom@ixionstudios.com>

"""
from datetime import datetime
from mythtvgui import Dialog
from singleton import getInstance
from time import strftime,strptime
import mythtv
import mythtvgui
import mythtvutil
import os
import sre
import time
import traceback
import xbmcgui

def debug( str ):
    mythtvutil.debug( mythtvutil.DEBUG_GUI, str )

def compareDateAsc( x, y ):
    if x.starttime() == y.starttime():
        return cmp( x.chanid(), y.chanid() )
    else:
        return cmp( x.starttime(), y.starttime() )

def compareDateDesc( y, x ):
    if x.starttime() == y.starttime():
        return cmp( x.chanid(), y.chanid() )
    else:
        return cmp( x.starttime(), y.starttime() )

def compareTitleAsc( x, y ):
    if x.title() == y.title():
        return cmp( x.starttime(), y.starttime() )
    else:
        return cmp( x.title(), y.title() )

def compareTitleDesc( y, x ):
    if x.title() == y.title():
        return cmp( x.starttime(), y.starttime() )
    else:
        return cmp( x.title(), y.title() )

def showWindow(winDialog):
    """
    Function to create the recorded show window.
    """
    debug( "> mythtvupcoming.showWindow()" )

    mythtvgui.checkSettings()
    win = Window()
    win.loadskin( "upcomingshows.xml" )
    win.loadList()
    winDialog.close()    
    win.doModal()
    del win

    debug( "< mythtvupcoming.showWindow()" )

class Window( mythtvgui.BaseWindow ):
    
    VIEW_BY_MIN         = 0     # must be smallest sequential value
    VIEW_BY_DATE_ASC    = 1
    VIEW_BY_DATE_DESC   = 2
    VIEW_BY_TITLE_ASC   = 3
    VIEW_BY_TITLE_DESC  = 4
    VIEW_BY_MAX         = 5     # must be largest sequential value

    def __init__( self ):
        mythtvgui.BaseWindow.__init__( self )
        self.recordings = []
        self.focusControl = None

        self.viewByLabel = { \
            self.VIEW_BY_DATE_ASC: 38, \
            self.VIEW_BY_TITLE_ASC: 39, \
            self.VIEW_BY_DATE_DESC: 69, \
            self.VIEW_BY_TITLE_DESC: 70 \
        }

        try:
            self.viewBy = \
                int(getInstance( mythtv.Settings ).getSetting( \
                    "upcoming_view_by" ))
        except IndexError, ie:
            self.viewBy = self.VIEW_BY_DATE_DESC
            getInstance( mythtv.Settings ).setSetting( \
                "upcoming_view_by", \
                "%d"%self.viewBy, \
                shouldCreate=1 )
            pass

    def buildListEntry( self, row ):
        debug( '> mythtvupcoming.Window.buildListEntry()' )
        entry = strftime("%a %d/%m %I:%M%p",time.localtime(float(row.recstarttime())))
        if row.cardid():
            entry += " - Encoder %s" % row.cardid()
        if row.channame():
            entry += " - %s" % row.channame()
        if row.title():
            entry += " - %s"%row.title()
        if row.subtitle() and not sre.match( '^\s+$', row.subtitle() ):
            entry += "-%s" %row.subtitle()
#        start = strptime( row.starttime(), "%Y%m%d%H%M%S" )
#        entry = strftime( "%m/%d %I:%M %p", start ) + "   "
#        if row.title():
#            entry += row.title()
#        if row.subtitle() and not sre.match( '^\s+$', row.subtitle() ):
#            entry += " - " + row.subtitle()
#
        debug( '< mythtvupcoming.Window.buildListEntry()' )
        return entry

    def loadList( self ):
        debug( '> mythtvupcoming.Window.loadList()' )

        c = getInstance( mythtv.Connection )
        recordings = c.getPendingRecordings()

        if self.viewBy == self.VIEW_BY_DATE_ASC:
            recordings.sort( compareDateAsc )
        elif self.viewBy == self.VIEW_BY_DATE_DESC:
            recordings.sort( compareDateDesc )
        elif self.viewBy == self.VIEW_BY_TITLE_ASC:
            recordings.sort( compareTitleAsc )
        elif self.viewBy == self.VIEW_BY_TITLE_DESC:
            recordings.sort( compareTitleDesc )

        ctl = self.controls["show_list"].control

        xbmcgui.lock()
        try:
            self.controls["view_by"].control.setLabel( \
                mythtvutil.getLocalizedString( self.viewByLabel[self.viewBy] ) )

            ctl.reset()
            self.recordings = []
            now = datetime.now().strftime( "%Y%m%d%H%M%S" )
            for r in recordings:
                if r.endtime() >= now:
                    ctl.addItem( self.buildListEntry( r ) )
                    self.recordings.append( r )
            if len( self.recordings ) > 0:
                self.populateShowDetails( 0 )
            xbmcgui.unlock()
        except:
            xbmcgui.unlock()
            raise

        try:
            freeSpace = getInstance( "mythtv.Connection" ).getFreeSpace()
            self.controls['free_space'].control.setLabel( freeSpace[0] )
        except Exception, ex:
            self.controls['free_space'].control.setLabel( \
                mythtvutil.getLocalizedString( 45 ) )

        debug( '< mythtvupcoming.Window.loadList()' )

    def onActionHook( self, action ):
        debug( "> mythtvupcoming.Window.onActionHook( action=[%s] )"%action )
        self.focusControl = self.getFocus()

        if action == mythtvgui.ACTION_PREVIOUS_MENU:
            getInstance( mythtv.Settings ).saveSettings()
        debug( "< mythtvupcoming.Window.onActionHook()" )
        return 0

    def onActionPostHook( self, action ):
        debug( "> mythtvupcoming.Window.onActionPostHook()" )
        # check if the action was to move up or down
        if action == mythtvgui.ACTION_MOVE_UP or \
            action == mythtvgui.ACTION_MOVE_DOWN or \
            action == mythtvgui.ACTION_SCROLL_UP or \
            action == mythtvgui.ACTION_SCROLL_DOWN:

            # check if the control in focus is the show list
            id = self.getcontrolid( self.focusControl )
            if id == "show_list":
                # give gui time to update
                time.sleep( 0.10 )

                # get selected show and populate details
                self.populateShowDetails(
                    self.focusControl.getSelectedPosition() )
        debug( "< mythtvupcoming.Window.onActionPostHook()" )

    def onControlHook( self, control ):
        debug( "> mythtvupcoming.Window.onControlHook()" )
        id = self.getcontrolid( control )

        if id == "view_by":
            self.viewBySelected()
        elif id == "show_list":
            self.showSelected( control )
        elif id == "refresh":
            self.loadList()
        debug( "< mythtvupcoming.Window.onControlHook()" )
        return 1

    def populateShowDetails( self, pos ):
        debug( "> mythtvupcoming.Window.populateShowDetails( pos=%d)"%pos )

        if pos < len( self.recordings ):
            row = self.recordings[pos]

            # populate title
            self.controls['show_title'].control.reset()
            title = row.fullTitle()
            self.controls['show_title'].control.addLabel( title )
            debug( "show_title=[%s]"%title )

            # populate air date
            self.controls['show_air_date'].control.setLabel( \
                row.formattedAirDate() )
            debug( "show_air_date=[%s]"%row.formattedAirDate() )

            # populate channel
            self.controls['show_channel'].control.setLabel( \
                row.formattedChannel() )
            debug( "show_channel=[%s]"%row.formattedChannel() )

            # populate orig air
            self.controls['show_orig_air'].control.setLabel( \
                row.formattedOrigAirDate() )
            debug( "show_orig_air=[%s]"%row.formattedOrigAirDate() )

            # populate description
            self.controls['show_descr'].control.reset()
            self.controls['show_descr'].control.addLabel( \
                row.formattedDescription() )
            debug( "show_descr=[%s]"%row.formattedDescription() )

            # populate notes
            self.controls['show_notes'].control.reset()
            self.controls['show_notes'].control.addLabel( \
                row.translatedRecStatus() )
            debug( "show_notes=[%s]"%row.translatedRecStatus() )

        debug( "< mythtvupcoming.Window.populateShowDetails( pos=%d)"%pos )

    def showSelected( self, control ):
        debug( "> mythtvupcoming.Window.showSelected()" )

        pos = control.getSelectedPosition()
        if pos < len( self.recordings ):
            #rc = mythtvrecordedshowdetails.showWindow(self.recordings[pos])
            rc = 0
            # refresh list if show was deleted
            if rc == 1:
                self.loadList()

        debug( "< mythtvupcoming.Window.showSelected()" )

    def viewBySelected( self ):
        debug( "> mythtvupcoming.Window.viewBySelected()" )

        # switch to next view by
        self.viewBy += 1
        if self.viewBy >= self.VIEW_BY_MAX:
            self.viewBy = self.VIEW_BY_MIN+1

        # store the setting change
        getInstance( mythtv.Settings ).setSetting( \
            "upcoming_view_by", \
            "%d"%self.viewBy, \
            shouldCreate=1 )

        # refresh the listing
        self.loadList()

        debug( "< mythtvupcoming.Window.viewBySelected()" )

if __name__ == "__main__":
    try:
        loadingWin = xbmcgui.DialogProgress()
        loadingWin.create("Upcoming Shows","Loading Upcoming Shows","Please Wait...")    
        mythtvutil.debugSetLevel( mythtvutil.DEBUG_GUI | mythtvutil.DEBUG_MYTH )
        mythtvutil.initialize()
        showWindow(loadingWin)

    except Exception, ex:
        traceback.print_exc()
        Dialog().ok( mythtvutil.getLocalizedString( 27 ), str( ex ) )

www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.