"""
$Id: default.py,v 1.11 2007/04/28 21:49:22 frooby Exp $
Copyright (C) 2005 Tom Warkentin <tom@ixionstudios.com>
"""
version="0.20.34"
import codecs
import xbmcgui
myprogress = xbmcgui.DialogProgress()
myprogress.create("XBMCMythTV v" + str(version))
myprogress.update(0,"Loading XBMCMythTV","Please Wait...","Importing mythtv.py")
import mythtvutil, traceback, string
# how many uP calls are there?
progressCount = 9
progressValue = 0
#***********************************************************************#
# Valid Debug Values: #
# DEBUG_NONE, DEBUG_MISC, DEBUG_GUI, DEBUG_DATABASE #
# DEBUG_MYTH, DEBUG_SKIN, DEBUG_OSD, DEBUG_ALL #
#***********************************************************************#
#debugLevel = mythtvutil.DEBUG_MYTH | mythtvutil.DEBUG_GUI # <-- Recommended debug level
#debugLevel = mythtvutil.DEBUG_MYTH
#debugLevel = mythtvutil.DEBUG_SKIN
debugLevel = mythtvutil.DEBUG_NONE
# [ Page ID, Description, Action, Control ID ]
pages = [[0,"Main","self.refresh()","refresh"],
[1,"LiveTV","mythtvlivetv.showWindow(self.loadingWin)","main_live_tv"],
[2,"Recorded Shows","mythtvrecordedshows.showWindow(self.loadingWin)","main_recorded_shows"],
[3,"Program Guide","mythtvguide.showWindow(self.loadingWin)","main_program_guide"],
[4,"Schedules","mythtvschedules.showWindow(self.loadingWin)","main_schedules"],
[5,"Upcoming Shows","mythtvupcoming.showWindow(self.loadingWin)","main_upcoming_shows"],
[6,"Settings","mythtvsettings.showWindow(self.loadingWin)","main_settings"]]
# Enter default start page in your settings using Page ID above
# Progress Was Cancelled!
def cL():
raise Exception, "XBMCMythTV Cancelled"
# update Progress Bar
def uP( txt ):
global progressValue, myprogress, progressCount, pages
try:
myprogress.update(progressValue,"Loading XBMCMythTV","Please Wait...",txt)
except:
myprogress.update(progressValue)
if myprogress.iscanceled():
cL()
progressValue += int( 100 / ( progressCount + ( len(pages) - 1) ) )
try:
uP("Importing mythtv.py")
import mythtv
uP("Importing System Libraries")
import os, sre, time, singleton
from datetime import datetime
uP("Importing mythtvgui.py")
from mythtvgui import Dialog
uP("Importing singleton.py")
from singleton import delInstance,getInstance
uP("")
import mythtvgui
uP("Importing Pages")
for mod in pages:
if int(mod[0]) == 0:
continue
exec("import %s" % string.replace(string.replace(mod[2],"self.loadingWin",""),".showWindow()","") )
uP("Importing %s" % mod[1] )
except Exception, ex:
traceback.print_exc()
myprogress.close()
del myprogress
Dialog().ok( mythtvutil.getLocalizedString( 27 ), str( ex ) )
def debug( str ):
mythtvutil.debug( mythtvutil.DEBUG_GUI, str )
#***************************************************************************#
class Window( mythtvgui.BaseWindow ):
def __init__( self ):
mythtvgui.BaseWindow.__init__( self )
self.loadingWin = xbmcgui.DialogProgress()
self.dbConnectTry = 0
self.db = None
self.conn = None
self.mythConnectTry = 0
def showIconImg( self, img, path="" ):
c = self.controls['popup_icon'].control
self.removeControl( c )
del c
x = int(self.getvalue( self.getoption( "popup_channel_x" ) ) )
y = int(self.getvalue( self.getoption( "popup_channel_y" ) ) )
w = int(self.getvalue( self.getoption( "popup_channel_w" ) ) )
h = int(self.getvalue( self.getoption( "popup_channel_h" ) ) )
myW = w * 1.172
myH = h * 0.95
debug("New Width: %s New Height: %s" %(str(myW),str(myH)) )
y -= (( myW - w ) / 2)
texture = img
tx = mythtvutil.findMediaFile( texture )
if tx == None:
tx = path + texture
c = xbmcgui.ControlImage( x, y, myW, myH, tx )
self.addControl( c )
self.controls['popup_icon'].control = c
def openStartPage( self ):
if startPage != 0:
myprogress.close()
if startPage < len(pages):
self.loadPage( startPage )
else:
debug ( "%s is not a valid Start Page ID" % str(startPage) )
def loadAction ( self, action ):
for p in pages:
if p[3] == action:
self.loadPage(p[0])
return 1
return 0
def loadPage( self, page, progressDialog = None ):
global pages
try:
print("Loading %s" % str(pages[page]) )
if int(page) > 0:
self.loadingWin.create(str( pages[page][1] ),"Loading %s" %str( pages[page][1] ),"Please Wait...","")
exec("%s" %pages[page][2])
if int(page) > 0:
self.refresh()
except Exception, ex:
debug("Failed to Load %s" %str(pages[page][1]) )
self.loadingWin.close()
traceback.print_exc()
def onControlHook( self, control ):
debug( "> mythtvmain.onControlHook( control=[%s] )"%control )
id = self.getcontrolid( control )
actionConsumed = self.loadAction( id )
debug( "< mythtvmain.onControlHook( control=[%s] )"%control )
return actionConsumed
## used so we can make sure they have a proper connection before continuing
def checkConnections( self ):
self.conn = getInstance( mythtv.Connection )
if self.conn.isConnected == 0:
self.conn.initialise()
if self.conn.isConnected == 0:
Dialog().ok( mythtvutil.getLocalizedString( 27 ), "MythTV Server Connection Failed.","XBMCMythTV is Unable to Continue" )
return False
self.db = getInstance( mythtv.Database )
if self.db.isConnected == 0:
self.db.initialise()
if self.db.isConnected == 0:
Dialog().ok( mythtvutil.getLocalizedString( 27 ), "Database Connection Failed.","XBMCMythTV is Unable to Continue" )
return False
def refresh( self ):
debug( "> default.Window.refresh()" )
try:
self.checkConnections()
theCards = self.db.getCaptureCards()
statusText = ""
cnt = 0
for theCardID in theCards:
if cnt < 3:
curStatus = self.conn.getEncoderStatus(theCardID)
self.controls['encoder_status' + str(cnt)].control.reset()
self.controls['encoder_status' + str(cnt)].control.addLabel( curStatus )
cnt += 1
space = self.conn.getFreeSpace()
self.controls['space_free'].control.setLabel( space[0] )
self.controls['space_total'].control.setLabel( space[1] )
self.controls['space_used'].control.setLabel( space[2] )
loads = self.conn.getLoad()
self.controls['load_avg_1min'].control.setLabel( str(loads[0]) )
self.controls['load_avg_5min'].control.setLabel( str(loads[1]) )
self.controls['load_avg_15min'].control.setLabel( str(loads[2]) )
self.controls['mythfilldatabase'].control.reset()
self.controls['mythfilldatabase'].control.addLabel( self.conn.getMythFillStatus() )
pendingRecordings = self.conn.getPendingRecordings()
ctl = self.controls['schedule'].control
ctl.reset()
try:
ctl.setPageControlVisible(False)
except:
pass
now = datetime.now().strftime( "%Y%m%d%H%M%S" )
totRecs = 0
for s in pendingRecordings:
if s.endtime() >= now:
totRecs += 1
ctl.addItem( "%s - Encoder %s - %s - %s-%s" % (time.strftime("%a %d/%m %I:%M%p",time.localtime(float(s.recstarttime()))),s.cardid(),s.channame(),s.title(), s.subtitle()) )
self.controls['schedule_lbl'].control.setLabel(
mythtvutil.getLocalizedString( 84 ) % \
totRecs )
self.controls['guidedata'].control.reset()
self.controls['guidedata'].control.addLabel( self.conn.getGuideData() )
except Exception, ex:
traceback.print_exc()
debug( "< default.Window.refresh()" )
#***************************************************************************#
# End Window Class #
#***************************************************************************#
try:
mythtvutil.debugSetLevel( debugLevel )
uP("Initializing...")
mythtvutil.initialize()
mythtvutil.debug( mythtvutil.DEBUG_ALL, ">> XBMCMythTV Version: %s <<"%version )
uP("Creating Main Window")
win = Window()
uP("Loading Skin")
win.loadskin( "home.xml" )
uP("Checking Settings")
try:
s = getInstance( mythtv.Settings )
s.loadSettings()
s.verifySettings()
startPage = int(s.getSetting( "mythtv_startpage" ))
except mythtv.SettingsException, ex:
startPage = 6
uP("Checking MythTV Connection")
if win.checkConnections() == False:
startPage = 6
uP("Done")
if startPage != 6:
win.refresh()
win.openStartPage()
# refesh AFTER settings have been checked to make sure connection OK
if startPage == 6:
win.refresh()
myprogress.close()
win.doModal()
delInstance( mythtv.Connection )
delInstance( mythtv.Database )
delInstance( mythtv.NMBService )
delInstance( mythtv.Settings )
delInstance( xbmcgui.Dialog )
delInstance( mythtvgui.ChannelIconCache )
delInstance( mythtvgui.ThumbnailCache )
del win
except Exception, ex:
traceback.print_exc()
myprogress.close()
Dialog().ok( mythtvutil.getLocalizedString( 27 ), str( ex ) )
# These objects must be destroyed here without calling getLocalizedString().
# Otherwise, they will get instantiated again.
delInstance( mythtvutil.XBMCLangInfo )
delInstance( mythtvutil.XBMCSettings )
delInstance( mythtvutil.LocalizedStrings )
|