"""
$Id: mythtvsettings.py,v 1.20 2006/08/14 07:57:43 frooby Exp $
Copyright (C) 2005 Tom Warkentin <tom@ixionstudios.com>
"""
from mythtvgui import Dialog
from singleton import getInstance
import mysql
import mythtv
import mythtvgui
import mythtvutil
import os
import string
import time
import traceback
import xbmc
import xbmcgui
def debug( str ):
mythtvutil.debug( mythtvutil.DEBUG_GUI, str )
def showWindow(loadingWin):
"""
Function to create the settings window.
"""
win = Window()
win.loadskin( "settings.xml" )
win.loadSettings()
win.refreshControls()
loadingWin.close()
win.doModal()
del win
class Window( mythtvgui.BaseWindow ):
def __init__( self ):
mythtvgui.BaseWindow.__init__( self )
self.dom = None
self.isDirty = 0
getInstance( mythtv.Settings )
def changeCheckmark( self, id ):
debug( "> mythtvsettings.Window.changeCheckmark" )
if id in ( 'mythtv_liveplayer', \
'mythtv_recplayer', \
'mythtv_recordlive'):
try:
debug( "validating checkmark" )
value = self.controls[id].control.getSelected()
except ValueError, ex:
Dialog().ok( \
mythtvutil.getLocalizedString( 27 ), \
mythtvutil.getLocalizedString( 30 ) )
value = None
if value != None:
debug( "stored value=[%s]"%value )
getInstance( mythtv.Settings ).setSetting( id, value )
# self.controls[id].control.setLabel( value )
# mark screens as dirty
self.isDirty = 1
debug( "< mythtvsettings.Window.changeCheckmark" )
def changeSettings( self, id ):
debug( "> mythtvsettings.Window.changeSettings" )
kbd = xbmc.Keyboard( getInstance( mythtv.Settings ).getSetting( id ) )
kbd.doModal()
if kbd.isConfirmed():
value = kbd.getText()
debug( "value=[%s]"%value )
if id in ( 'mythtv_port', \
'mythtv_statusport', \
'mythtv_protocol', \
'mythtv_minlivebufsize', \
'mythtv_tunewait', \
'mythtv_startpage', \
'mythtv_recordlength', \
'mysql_port' ):
try:
debug( "validating integer" )
int( value )
except ValueError, ex:
Dialog().ok( \
mythtvutil.getLocalizedString( 27 ), \
mythtvutil.getLocalizedString( 30 ) )
value = None
if value:
debug( "stored value=[%s]"%value )
getInstance( mythtv.Settings ).setSetting( id, value )
self.controls[id].control.setLabel( value )
# if configuring mythtv host and mysql host is not set, use
# mythtv host as default
if id == "mythtv_host":
mysqlHost = ""
try:
mysqlHost = getInstance( mythtv.Settings ).getSetting( "mysql_host" )
except IndexError, ex:
pass
if mysqlHost == "":
getInstance( mythtv.Settings ).setSetting( "mysql_host", value )
self.controls["mysql_host"].control.setLabel( value )
# mark screens as dirty
self.isDirty = 1
debug( "< mythtvsettings.Window.changeSettings" )
def loadSettings( self ):
debug( "> mythtvsettings.Window.loadSettings()" )
try:
getInstance( mythtv.Settings ).loadSettings()
getInstance( mythtv.Settings ).verifySettings()
except mythtv.SettingsException, ex:
Dialog().ok( \
mythtvutil.getLocalizedString( 27 ), \
str( ex ) + ' ' + mythtvutil.getLocalizedString( 36 ) )
getInstance( mythtv.Settings ).loadMergedDefaults()
self.isDirty = 1
pass
debug( "< mythtvsettings.Window.loadSettings()" )
def onActionHook( self, action ):
debug( "> mythtvsettings.Window.onActionHook( action=[%s] )"%action )
actionConsumed = 0
if self.isDirty != 0 and \
(action == mythtvgui.ACTION_PREVIOUS_MENU or \
action == mythtvgui.ACTION_PARENT_DIR):
if not Dialog().yesno( \
mythtvutil.getLocalizedString( 28 ), \
mythtvutil.getLocalizedString( 29 ) ):
# do not lose changes - consume the previous menu event
actionConsumed = 1
else:
# user agreed to lose changes - reload settings from file
try:
getInstance( mythtv.Settings ).loadSettings()
except mythtv.SettingsException, ex:
pass
debug( "< mythtvsettings.Window.onActionHook()" )
return actionConsumed
def onActionPostHook( self, action ):
# show the appropriate group of controls depending on which is in
# focus
if action == mythtvgui.ACTION_MOVE_UP or \
action == mythtvgui.ACTION_MOVE_DOWN or \
action == mythtvgui.ACTION_MOVE_LEFT or \
action == mythtvgui.ACTION_MOVE_RIGHT:
# give GUI time to process action
time.sleep( 0.10 )
id = self.getcontrolid( self.getFocus() )
if id in ( "menu_mythtv_mythtv", \
"menu_mysql_mythtv", \
"menu_paths_mythtv"):
self.showgroup( "mythtv" )
elif id in ("menu_mythtv_mysql", \
"menu_mysql_mysql", \
"menu_paths_mysql"):
self.showgroup( "mysql" )
elif id in ("menu_mythtv_paths", \
"menu_mysql_paths", \
"menu_paths_paths" ):
self.showgroup( "paths" )
def onControlHook( self, control ):
debug( "> mythtvsettings.Window.onControlHook()" )
id = self.getcontrolid( control )
#--------------------------------------------------------------------
# This is redundant but left in here because the XBMC emulator
# does not support Window.getFocus() yet.
if id in ( "menu_mythtv_mythtv", \
"menu_mysql_mythtv", \
"menu_paths_mythtv" ):
self.showgroup( "mythtv" )
elif id in ("menu_mythtv_mysql", \
"menu_mysql_mysql", \
"menu_paths_mysql" ):
self.showgroup( "mysql" )
elif id in ("menu_mythtv_paths", \
"menu_mysql_paths", \
"menu_paths_paths" ):
self.showgroup( "paths" )
#--------------------------------------------------------------------
elif id in ("menu_mythtv_test", \
"menu_mysql_test", \
"menu_paths_test" ):
self.testSettings()
elif id in ("menu_mythtv_save", \
"menu_mysql_save", \
"menu_paths_save" ):
self.saveSettings()
elif id in ("mythtv_host", \
"mythtv_port", \
"mythtv_statusport", \
"mythtv_protocol", \
"mythtv_minlivebufsize", \
"mythtv_tunewait", \
"mythtv_startpage", \
"mythtv_recordlength", \
"mysql_host", \
"mysql_port", \
"mysql_database", \
"mysql_user", \
"mysql_password", \
"paths_recordedprefix", \
"paths_livetvprefix", \
"paths_localcopypath" ):
self.changeSettings( id )
elif id in ("mythtv_recplayer", \
"mythtv_liveplayer", \
"mythtv_recordlive"):
self.changeCheckmark( id )
debug( "< mythtvsettings.Window.onControlHook()" )
return 1
def refreshControls( self ):
debug( "> mythtvsettings.Window.refreshControls" )
tagNames = [\
'mythtv_host','mythtv_port','mythtv_statusport','mythtv_protocol',\
'mythtv_minlivebufsize', 'mythtv_tunewait', 'mythtv_startpage', \
'mysql_host','mysql_port','mysql_database','mysql_user',\
'mysql_password','mythtv_recordlength',\
'paths_recordedprefix','paths_livetvprefix','paths_localcopypath']
s = getInstance( mythtv.Settings )
for tag in tagNames:
value = ""
try:
value = s.getSetting( tag )
except IndexError, ex:
pass
self.controls[tag].control.setLabel( value )
# get the checkmark tags
tagNames = ['mythtv_liveplayer', 'mythtv_recplayer', 'mythtv_recordlive']
for tag in tagNames:
value = False
try:
if s.getSetting( tag ) == "1":
value = True
else:
value = False
except IndexError, ex:
pass
self.controls[tag].control.setSelected( value )
debug( "< mythtvsettings.Window.refreshControls " )
def saveSettings( self ):
debug( "> mythtvsettings.Window.saveSettings" )
getInstance( mythtv.Settings ).saveSettings()
getInstance( mythtv.Settings ).loadSettings()
self.isDirty = 0
Dialog().ok( \
mythtvutil.getLocalizedString( 26 ), \
mythtvutil.getLocalizedString( 25 ) )
debug( "< mythtvsettings.Window.saveSettings" )
def testSettings( self ):
debug( "> mythtvsettings.Window.testSettings" )
errors = 0
try:
c = getInstance( mythtv.Connection )
c.getFreeSpace()
except Exception, ex:
errors += 1
Dialog().ok( \
mythtvutil.getLocalizedString( 27 ), \
mythtvutil.getLocalizedString( 31 ), \
str( ex ) )
traceback.print_exc()
try:
db = getInstance( mythtv.Database )
channels = db.getChannelList()
except Exception, ex:
errors += 1
Dialog().ok( \
mythtvutil.getLocalizedString( 27 ), \
mythtvutil.getLocalizedString( 32 ), \
str( ex ) )
traceback.print_exc()
if errors == 0:
Dialog().ok( \
mythtvutil.getLocalizedString( 26 ), \
mythtvutil.getLocalizedString( 33 ) )
debug( "< mythtvsettings.Window.testSettings" )
################################################################################
# FOR DEBUG ONLY
################################################################################
if __name__ == '__main__':
try:
loadingWin = xbmcgui.DialogProgress()
loadingWin.create("Settings","Loading Settings","Please Wait...")
mythtvutil.debugSetLevel( mythtvutil.DEBUG_ALL )
mythtvutil.initialize()
showWindow(loadingWin)
except Exception, ex:
traceback.print_exc()
Dialog().ok( "Exception", str( ex ) )
|