"""
$Id: mythtvschedules.py,v 1.3 2006/03/19 00:35:24 frooby Exp $
"""
from mythtvgui import Dialog
from singleton import getInstance
import datetime
import mythtv
import mythtvgui
import mythtvscheduledetails
import mythtvstruct
import mythtvutil
import os
import sre
import string
import time
import traceback
import xbmcgui
import xbmc
def debug( str ):
mythtvutil.debug( mythtvutil.DEBUG_GUI, str )
def compareTypeAsc( x, y ):
if x.type() == y.type():
return cmp( x.title(), y.title() )
else:
return cmp( x.formattedType(), y.formattedType() )
def compareTypeDesc( y, x ):
if x.type() == y.type():
return cmp( x.title(), y.title() )
else:
return x.formattedType() < y.formattedType()
def compareTitleAsc( x, y ):
if x.title() == y.title():
return x.type() < y.type()
else:
return cmp( x.title(), y.title() )
def compareTitleDesc( y, x ):
if x.title() == y.title():
return x.type() < y.type()
else:
return cmp( x.title(), y.title() )
def showWindow(winDialog):
"""
Function to create the recording schedules window.
"""
debug( "> mythtvschedules.showWindow()" )
mythtvgui.checkSettings()
win = Window()
win.loadskin( "schedules.xml" )
win.loadData()
winDialog.close()
win.doModal()
del win
debug( "< mythtvschedules.showWindow()" )
class Window( mythtvgui.BaseWindow ):
def __init__( self ):
mythtvgui.BaseWindow.__init__( self )
self.schedules=[]
self.focusControl = None
def editSelected(self, control):
debug( "> mythtvschedules.Window.editSelected()" )
pos = control.getSelectedPosition()
if pos < len( self.schedules ):
# make a copy of the schedule
s = mythtvstruct.ScheduleFromQuery(
dict( self.schedules[pos].data().items() ) )
# launch the schedule details window
rc = mythtvscheduledetails.showWindow( s )
# check if we should refresh the list
if rc == 1:
self.loadData()
elif rc == 2:
self.schedules[pos] = s
debug( "> mythtvschedules.Window.editSelected()" )
def loadData( self ):
debug( '> mythtvschedules.Window.loadData()' )
self.schedules = []
xbmcgui.lock()
try:
listControl = self.controls["schedule_list"].control
listControl.reset()
db = getInstance( mythtv.Database )
self.schedules = db.getSchedule()
self.schedules.sort( compareTypeAsc )
for s in self.schedules:
item = xbmcgui.ListItem()
label = s.title()
if s.type() == 3: # channel
# item.setLabel2( s.formattedChannel() )
label += " (%s)"%s.formattedChannel()
else:
# item.setLabel2( s.formattedType() )
label += " (%s)"%s.formattedType()
item.setLabel( label )
listControl.addItem( item )
#self.updateShowDetails( 0 )
xbmcgui.unlock()
except:
xbmcgui.unlock()
raise
debug( '< mythtvschedules.Window.loadData()' )
def onActionHook( self, action ):
debug( "> mythtvschedules.Window.onActionHook( action=[%s] )"%action )
self.focusControl = self.getFocus()
if action == mythtvgui.ACTION_PREVIOUS_MENU:
try:
getInstance( mythtv.Settings ).saveSettings()
except:
pass
debug( "< mythtvschedules.Window.onActionHook()" )
return 0
def onActionPostHook( self, action ):
debug( "> mythtvschedules.Window.onActionPostHook( action=[%s] )"%action )
# 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 == "schedule_list":
# give gui time to update
time.sleep( 0.10 )
# get selected show and populate details
#self.updateShowDetails( self.focusControl.getSelectedPosition() )
debug( "< mythtvschedules.Window.onActionPostHook()" )
def onControlHook( self, control ):
debug( "> mythtvschedules.Window.onControlHook()" )
id = self.getcontrolid( control )
debug( "ID: %s" % id )
# if id == "view_by":
# self.viewBySelected()
if id == "schedule_list":
self.editSelected( control )
elif id == "refresh":
self.loadData()
debug( "< mythtvschedules.Window.onControlHook()" )
return 1
def populateScheduleDetails(self, show):
# populate title
self.controls['show_title'].control.reset()
self.controls['show_title'].control.addLabel( show.fullTitle() )
debug( "show_title=[%s]"%show.fullTitle() )
# populate air datea
self.controls['show_air_date'].control.setLabel( \
show.formattedAirDate() )
debug( "show_air_date=[%s]"%show.formattedAirDate() )
# populate channel
self.controls['show_channel'].control.setLabel( \
show.formattedChannel() )
debug( "show_channel=[%s]"%show.formattedChannel() )
# populate orig air
self.controls['show_orig_air'].control.setLabel( \
show.formattedOrigAirDate() )
debug( "show_orig_air=[%s]"%show.formattedOrigAirDate() )
# populate description
self.controls['show_descr'].control.reset()
self.controls['show_descr'].control.addLabel( \
show.formattedDescription() )
debug( "show_descr=[%s]"%show.formattedDescription() )
def updateShowDetails( self, pos ):
if pos < len( self.schedules ):
s = self.schedules[pos]
self.populateScheduleDetails(s)
if __name__ == "__main__":
try:
loadingWin = xbmcgui.DialogProgress()
loadingWin.create("Schedules","Loading Schedules","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 ) )
|