"""
$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 ) )
|