mythtvscheduledetails.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 » mythtvscheduledetails.py
"""
$Id: mythtvscheduledetails.py,v 1.6 2007/05/15 06:44:29 frooby Exp $

"""
from mythtvgui import Dialog
from singleton import getInstance
import codecs
import mythtv
import mythtvgui
import mythtvstruct
import mythtvutil
import os
import singleton
import sre
import time
import traceback
import xbmc
import xbmcgui

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

def showWindow( schedule ):
    """
    Function to create the recording schedule details window.

    Returns:
    - 1 if show was deleted
    - 0 otherwise
    """

    debug( "> mythtvscheduledetails.showWindow()" )
    retVal = 0

    win = Window()
    win.loadskin( "scheduledetails.xml" )
    win.loadDetails( schedule )
    win.doModal()
    retVal = win.shouldRefresh
    del win

    debug( "< mythtvscheduledetails.showWindow() => [%d]"%retVal )
    return retVal

class Window( mythtvgui.BaseWindow ):
    
    def __init__( self ):
        mythtvgui.BaseWindow.__init__( self )
        self.shouldRefresh = 0

    def delete( self ):
        debug( '> mythtvscheduledetails.Window.delete()' )

        if self.schedule.recordid():
            # we have a recordid so it exists in database
            rc = Dialog().yesno( \
                mythtvutil.getLocalizedString( 28 ), \
                mythtvutil.getLocalizedString( 157 ) )
            if rc:
                # delete the schedule
                db = getInstance( mythtv.Database )
                db.deleteSchedule( self.schedule )
                self.shouldRefresh = 1

                # notify backend to reschedule
                conn = getInstance( mythtv.Connection )
                conn.rescheduleNotify()

                # close the window
                self.close()
        else:
            # no recordid so this is a new one - just close window
            self.close()

        debug( '< mythtvscheduledetails.Window.delete()' )

    def getIntValue( self, id, min=None, max=None ):
        debug( '> mythtvscheduledetails.Window.getIntValue()' )

        kbd = xbmc.Keyboard( self.schedule.data()[id] )
        kbd.doModal()
        if kbd.isConfirmed():
            value = kbd.getText()
            intVal = None
            debug( "value=[%s]"%value )

            try:
                debug( "validating integer" )
                intVal = int( value )
            except ValueError, ex:
                Dialog().ok(
                    mythtvutil.getLocalizedString( 27 ),
                    mythtvutil.getLocalizedString( 30 ) )
                value = None
            if intVal and min != None and intVal < min:
                Dialog().ok(
                    mythtvutil.getLocalizedString( 27 ),
                    mythtvutil.getLocalizedString( 154 )%min )
                value = None
            if intVal and max != None and intVal > max:
                Dialog().ok(
                    mythtvutil.getLocalizedString( 27 ),
                    mythtvutil.getLocalizedString( 155 )%max )
                value = None
            if value:
                value = "%d"%int(value)
                debug( "stored value=[%s]"%value )
                self.schedule.data()[id] = value
                self.controls[id].control.setLabel( value )

        debug( '< mythtvscheduledetails.Window.getIntValue()' )
        
    def getListValue( self, id, choices, isLocalized=True ):
        debug( '> mythtvscheduledetails.Window.getListValue()' )

        valueList = []
        keyList = []
        if type(choices) is dict:
            for k,v in choices.items():
                keyList.append( str(k) )
                if isLocalized:
                    if choices == mythtvstruct.gRecSchedTypeLongTrans and \
                        k == 3:
                        valueList.append(
                            str(mythtvutil.getLocalizedString( v )%
                                self.schedule.channum()) )
                    else:
                        valueList.append(
                            str(mythtvutil.getLocalizedString( v )) )
                else:
                    valueList.append( str(v) )
        elif type(choices) is list:
            valueList = choices
            keyList = choices
        pos = xbmcgui.Dialog().select(
            mythtvutil.getLocalizedString( 156 ),
            valueList )
        if pos != None:
            debug( "pos=[%d]"%pos )
            self.schedule.data()[id] = keyList[pos]
            self.controls[id].control.setLabel( valueList[pos] )

        debug( '< mythtvscheduledetails.Window.getListValue()' )
        
    def loadDetails( self, schedule ):
        debug( '> mythtvscheduledetails.Window.loadDetails()' )
        self.schedule = schedule
        self.populateDetails( self.schedule )
        debug( '< mythtvscheduledetails.Window.loadDetails()' )

    def onControlHook( self, control ):
        debug( "> mythtvscheduledetails.Window.onControlHook()" )

        id = self.getcontrolid( control )

        if id == "save":
            self.save()
        elif id == "delete":
            self.delete()
        elif id == "refresh":
            self.refresh()
        elif id in ('autoexpire',
                    'autocommflag',
                    'maxnewest'):
            self.controls[id].control.setSelected(
                not int(self.schedule.data()[id]) )
            self.schedule.data()[id] = "%d"%(not int(self.schedule.data()[id]))
            debug( "id=[%s] value=[%s]"%(id,self.schedule.data()[id]) )
        elif id == 'recpriority':
            self.getIntValue( id, -99, 99 )
        elif id == 'maxepisodes':
            self.getIntValue( id, 0 )
        elif id == 'startoffset':
            self.getIntValue( id, -60, 60 )
        elif id == 'endoffset':
            self.getIntValue( id, -60, 60 )
        elif id == 'type':
            self.getListValue( id, mythtvstruct.gRecSchedTypeLongTrans )
        elif id == 'dupin':
            self.getListValue( id, mythtvstruct.gRecSchedDupInTrans )
        elif id == 'dupmethod':
            self.getListValue( id, mythtvstruct.gRecSchedDupMethodTrans )
        elif id == 'profile':
            profileList = [ \
                'Default', 'Live TV', 'High Quality', 'Low Quality' ]
            self.getListValue( id, profileList, isLocalized=False )
        elif id == 'recgroup':
            recgroupList = [ 'Default' ]
            self.getListValue( id, recgroupList, isLocalized=False )

        debug( "< mythtvscheduledetails.Window.onControlHook()" )
        return 1

    def populateDetails( self, s ):
        debug( "> mythtvscheduledetails.Window.populateDetails()" )

        fmt = mythtvutil.getLocalizedString( 121 )
        try:
            self.controls['window_title'].control.setLabel( fmt%s.title() )
        except:
            pass
        try:
            if s.chanid() > 0:
                self.controls['channel'].control.setLabel( s.formattedChannel() )
            else:
                self.controls['channel'].control.setLabel(
                    mythtvutil.getLocalizedString( 46 ) )
        except:
            pass
        try:
            self.controls['date'].control.setLabel( s.formattedStartDate() )
        except:
            pass
        
        try:
            self.controls['time'].control.setLabel( s.formattedTime() )
        except:
            pass
        debug( "getting icon cache" )
        cic = getInstance( mythtvgui.ChannelIconCache )
        debug( "finding file for [%s]"%s )
        
        shost = str(getInstance( mythtv.Settings ).getSetting( "mythtv_host" ))
        file = mythtvgui.picBase + 'channels\\' + str(s.channum()) + mythtvgui.picType
        if not os.path.exists(file):
            file = None
            if s.icon():
                try:
                    file = cic.findFile( s, shost)
                except:
                    debug(" populateDetails: nothing assigned to file")
            
        if file != None:
            debug( "file=[%s]"%file )
            if file:
                c = self.controls['channel_icon'].control
                self.removeControl( c )
                del c
                debug( "deleted old control" )
                c = xbmcgui.ControlImage(
                    int(self.getoption('channel_x')),
                    int(self.getoption('channel_y')),
                    int(self.getoption('channel_w')),
                    int(self.getoption('channel_h')),
                    file )
                debug( "created control" )
                self.addControl( c )
                debug( "added control" )
                self.controls['channel_icon'].control = c
            
        if s.type() == 3:   # channel
            self.controls['type'].control.setLabel(
                s.formattedTypeLong()%s.channum() )
        else:
            self.controls['type'].control.setLabel( s.formattedTypeLong() )

        self.controls['profile'].control.setLabel( s.profile() )

        value = "%d"%s.recpriority()
        self.controls['recpriority'].control.setLabel( value )

        self.controls['recgroup'].control.setLabel( s.recgroup() )

        self.controls['autoexpire'].control.setSelected( s.autoexpire() )

        self.controls['autocommflag'].control.setSelected( s.autocommflag() )

        self.controls['maxnewest'].control.setSelected( s.maxnewest() )

        value = "%d"%s.maxepisodes()
        self.controls['maxepisodes'].control.setLabel( value )

        self.controls['dupin'].control.setLabel( s.formattedDuplicateIn() )

        self.controls['dupmethod'].control.setLabel(
            s.formattedDuplicateMethod() )

        value = "%d"%s.startoffset()
        self.controls['startoffset'].control.setLabel( value )

        value = "%d"%s.endoffset()
        self.controls['endoffset'].control.setLabel( "%d"%s.endoffset() )

        debug( "< mythtvscheduledetails.Window.populateDetails()" )

    def refresh( self ):
        debug( "> mythtvscheduledetails.Window.refresh()" )

        if self.schedule.recordid():
            # parent window should refresh as well
            self.shouldRefresh = 1

            # retrieve the schedule details
            scheds = getInstance( mythtv.Database ).getSchedule(
                self.schedule.recordid() )
            if len( scheds ) == 1:
                self.schedule = scheds[0]
                self.loadDetails( self.schedule )
            else:
                # recording schedule no longer exists
                Dialog().ok(
                    mythtvutil.getLocalizedString( 26 ),
                    mythtvutil.getLocalizedString( 122 ) )
                self.close()

        debug( "< mythtvscheduledetails.Window.refresh()" )

    def save( self ):
        debug( "> mythtvscheduledetails.Window.save()" )
        if not self.schedule.subtitle():
            self.schedule.data()['subtitle'] = ""
        if not self.schedule.category():
            self.schedule.data()['category'] = ""
        if not self.schedule.description():
            self.schedule.data()['description'] = ""
        getInstance( mythtv.Database ).saveSchedule( self.schedule )
        self.shouldRefresh = 2
        getInstance( mythtv.Connection ).rescheduleNotify( self.schedule )
        Dialog().ok(
            mythtvutil.getLocalizedString( 26 ),
            mythtvutil.getLocalizedString( 158 ) )
        debug( "< mythtvscheduledetails.Window.save()" )

if __name__ == "__main__":
    import mythtvstruct

    try:
        mythtvutil.debugSetLevel( mythtvutil.DEBUG_GUI | mythtvutil.DEBUG_MISC )
        mythtvutil.initialize()

        s = getInstance( mythtv.Database ).getSchedule( 72 )
        debug( "title=[%s]"%s[0].title() )
        debug( "subtitle=[%s]"%s[0].subtitle() )
        showWindow( s[0] )

    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.