diff --git a/default.py b/default.py index a5fa6300..7572a409 100644 --- a/default.py +++ b/default.py @@ -105,13 +105,6 @@ def __init__(self): if self.TYPE=="shortcuts": # We're just going to choose a shortcut, and save its details to the given # skin labels - xbmcgui.Window( 10000 ).clearProperty( "skinshortcuts-overrides-script" ) - xbmcgui.Window( 10000 ).clearProperty( "skinshortcuts-overrides-script-data" ) - xbmcgui.Window( 10000 ).clearProperty( "skinshortcuts-overrides-skin" ) - xbmcgui.Window( 10000 ).clearProperty( "skinshortcuts-overrides-skin-data" ) - xbmcgui.Window( 10000 ).clearProperty( "skinshortcuts-overrides-user" ) - xbmcgui.Window( 10000 ).clearProperty( "skinshortcuts-overrides-user-data" ) - xbmcgui.Window( 10000 ).clearProperty( "skinshortcutsAdditionalProperties" ) selectedShortcut = LIBRARY.selectShortcut( "", custom = self.CUSTOM, showNone = self.NONE ) @@ -216,7 +209,6 @@ def _check_Window_Properties( self ): # Check if the user has changed skin or profile if self.WINDOW.getProperty("skinsettings-currentSkin-Path") and self.WINDOW.getProperty("skinsettings-currentProfile-Path"): if self.WINDOW.getProperty("skinsettings-currentSkin-Path") != xbmc.getSkinDir().encode( 'utf-8' ) or self.WINDOW.getProperty("skinsettings-currentProfile-Path") != __profilepath__.encode( 'utf-8' ): - self.reset_window_properties() self.WINDOW.setProperty("skinsettings-currentSkin-Path", xbmc.getSkinDir() ) self.WINDOW.setProperty("skinsettings-currentProfile-Path", __profilepath__ ) else: @@ -422,9 +414,6 @@ def _reset_all_shortcuts( self ): # Update home window property (used to automatically refresh type=settings) xbmcgui.Window( 10000 ).setProperty( "skinshortcuts",strftime( "%Y%m%d%H%M%S",gmtime() ) ) - - # Reset all window properties (so menus will be reloaded) - self.reset_window_properties() # ---------------- @@ -539,34 +528,6 @@ def _get_customised_settings_string( self, group ): return "::MENUNAME::" - def reset_window_properties( self ): - xbmcgui.Window( 10000 ).clearProperty( "skinshortcuts-overrides-skin" ) - xbmcgui.Window( 10000 ).clearProperty( "skinshortcutsAdditionalProperties" ) - #xbmcgui.Window( 10000 ).clearProperty( "skinshortcuts-mainmenu" ) - #listitems = DATA._get_shortcuts( "mainmenu" ) - #for item in listitems: - # # Get labelID so we can check shortcuts for this menu item - # groupName = item[0].replace(" ", "").lower().encode('utf-8') - # - # # Localize strings - # if not item[0].find( "::SCRIPT::" ) == -1: - # groupName = DATA.createNiceName( item[0][10:] ).encode('utf-8') - # elif not item[0].find( "::LOCAL::" ) == -1: - # groupName = DATA.createNiceName( item[0][9:] ).encode('utf-8') - # - # # Clear the property - # xbmcgui.Window( 10000 ).clearProperty( "skinshortcuts-" + groupName ) - # - # # Clear any additional submenus - # i = 0 - # finished = False - # while finished == False: - # i = i + 1 - # if xbmcgui.Window( 10000 ).getProperty( "skinshortcuts-" + groupName + "." + str( i ) ): - # xbmcgui.Window( 10000 ).clearProperty( "skinshortcuts-" + groupName + "." + str( i ) ) - # else: - # finished = True - def _hidesubmenu( self, menuid ): count = 0 while xbmc.getCondVisibility( "!IsEmpty(Container(" + menuid + ").ListItem(" + str( count ) + ").Property(isSubmenu))" ): diff --git a/resources/language/English/strings.po b/resources/language/English/strings.po index f96980c9..ef3e1773 100644 --- a/resources/language/English/strings.po +++ b/resources/language/English/strings.po @@ -413,3 +413,7 @@ msgstr "" msgctxt "#32097" msgid "Unable to save menu" msgstr "" + +msgctxt "#32098" +msgid "Writing menu..." +msgstr "" diff --git a/resources/lib/datafunctions.py b/resources/lib/datafunctions.py index feabf88f..56e1dbf2 100644 --- a/resources/lib/datafunctions.py +++ b/resources/lib/datafunctions.py @@ -3,7 +3,6 @@ import xbmc, xbmcaddon, xbmcgui, xbmcvfs, urllib import xml.etree.ElementTree as xmltree import hashlib, hashlist -import cPickle as pickle from xml.dom.minidom import parse from traceback import print_exc from htmlentitydefs import name2codepoint @@ -50,7 +49,10 @@ def log(txt): class DataFunctions(): def __init__(self): - pass + self.overrides = {} + + self.widgetNameAndType = {} + self.backgroundName = {} def _get_labelID( self, labelID, action, getDefaultID = False, includeAddOnID = True ): @@ -387,92 +389,64 @@ def _get_icon_overrides( self, tree, icon, group, labelID, setToDefault = True ) def _get_overrides_script( self ): - # If we haven't already loaded skin overrides, or if the skin has changed, load the overrides file - if not xbmcgui.Window( 10000 ).getProperty( "skinshortcuts-overrides-script-data" ) or not xbmcgui.Window( 10000 ).getProperty( "skinshortcuts-overrides-script" ) == __defaultpath__: - xbmcgui.Window( 10000 ).setProperty( "skinshortcuts-overrides-script", __defaultpath__ ) - overridepath = os.path.join( __defaultpath__ , "overrides.xml" ) - try: - tree = xmltree.parse( overridepath ) - self._save_hash( overridepath, xbmcvfs.File( overridepath ).read() ) - xbmcgui.Window( 10000 ).setProperty( "skinshortcuts-overrides-script-data", pickle.dumps( tree ) ) - return tree - except: - if xbmcvfs.exists( overridepath ): - # Unable to parse script overrides.xml - log( "Unable to parse script overrides.xml. Invalid xml?" ) - self._save_hash( overridepath, xbmcvfs.File( overridePath ).read() ) - else: - # No script overrides.xml - self._save_hash( overridepath, None ) - xbmcgui.Window( 10000 ).setProperty( "skinshortcuts-overrides-script-data", "No overrides" ) - return None - - # Return the overrides - returnData = xbmcgui.Window( 10000 ).getProperty( "skinshortcuts-overrides-script-data" ) - if returnData == "No overrides": - return None - else: - return pickle.loads( returnData ) + # Get overrides.xml provided by script + if "script" in self.overrides: + return self.overrides[ "script" ] + overridePath = os.path.join( __defaultpath__, "overrides.xml" ) + try: + tree = xmltree.parse( overridePath ) + self._save_hash( overridePath, xbmcvfs.File( overridePath ).read() ) + self.overrides[ "script" ] = tree + return tree + except: + if xbmcvfs.exists( overridePath ): + log( "Unable to parse script overrides.xml. Invalid xml?" ) + self._save_hash( overridePath, xbmcvfs.File( overridePath ).read() ) + else: + self._save_hash( overridePath, None ) + self.overrides[ "script" ] = None + return None def _get_overrides_skin( self ): - # If we haven't already loaded skin overrides, or if the skin has changed, load the overrides file - if not xbmcgui.Window( 10000 ).getProperty( "skinshortcuts-overrides-skin-data" ) or not xbmcgui.Window( 10000 ).getProperty( "skinshortcuts-overrides-skin" ) == __skinpath__: - xbmcgui.Window( 10000 ).setProperty( "skinshortcuts-overrides-skin", __skinpath__ ) - overridepath = os.path.join( __skinpath__ , "overrides.xml" ) - try: - tree = xmltree.parse( overridepath ) - self._save_hash( overridepath, xbmcvfs.File( overridepath ).read() ) - xbmcgui.Window( 10000 ).setProperty( "skinshortcuts-overrides-skin-data", pickle.dumps( tree ) ) - return tree - except: - if xbmcvfs.exists( overridepath ): - # Unable to parse skin overrides.xml - log( "Unable to parse skin overrides.xml. Invalid xml?" ) - self._save_hash( overridepath, xbmcvfs.File( overridePath ).read() ) - else: - # No skin overrides.xml - self._save_hash( overridepath, None ) - xbmcgui.Window( 10000 ).setProperty( "skinshortcuts-overrides-skin-data", "No overrides" ) - return None - - # Return the overrides - returnData = xbmcgui.Window( 10000 ).getProperty( "skinshortcuts-overrides-skin-data" ) - if returnData == "No overrides": - return None - else: - return pickle.loads( returnData ) + # Get overrides.xml provided by skin + if "skin" in self.overrides: + return self.overrides[ "skin" ] + overridePath = os.path.join( __skinpath__, "overrides.xml" ) + try: + tree = xmltree.parse( overridePath ) + self._save_hash( overridePath, xbmcvfs.File( overridePath ).read() ) + self.overrides[ "skin" ] = tree + return tree + except: + if xbmcvfs.exists( overridePath ): + log( "Unable to parse skin overrides.xml. Invalid xml?" ) + self._save_hash( overridePath, xbmcvfs.File( overridePath ).read() ) + else: + self._save_hash( overridePath, None ) + self.overrides[ "skin" ] = None + return None def _get_overrides_user( self, profileDir = "special://profile" ): - # If we haven't already loaded user overrides - profileDir = profileDir.encode( "utf-8" ) - if not xbmcgui.Window( 10000 ).getProperty( "skinshortcuts-overrides-user-data" + profileDir ) or not xbmcgui.Window( 10000 ).getProperty( "skinshortcuts-overrides-user" + profileDir ) == __profilepath__: - xbmcgui.Window( 10000 ).setProperty( "skinshortcuts-overrides-user" + profileDir, profileDir ) - overridepath = os.path.join( profileDir , "overrides.xml" ) - try: - tree = xmltree.parse( overridepath ) - self._save_hash( overridepath, xbmcvfs.File( overridepath ).read() ) - xbmcgui.Window( 10000 ).setProperty( "skinshortcuts-overrides-user-data" + profileDir, pickle.dumps( tree ) ) - return tree - except: - if xbmcvfs.exists( overridepath ): - # Unable to parse user overrides.xml - log( "Unable to parse user overrides.xml. Invalid xml?" ) - self._save_hash( overridepath, xbmcvfs.File( overridePath ).read() ) - else: - # No user overrides.xml - self._save_hash( overridepath, None ) - self._save_hash( overridepath, None ) - xbmcgui.Window( 10000 ).setProperty( "skinshortcuts-overrides-user-data" + profileDir, "No overrides" ) - return None - - # Return the overrides - returnData = xbmcgui.Window( 10000 ).getProperty( "skinshortcuts-overrides-user-data" + profileDir ) - if returnData == "No overrides": + # Get overrides.xml provided by user + if "user" in self.overrides: + return self.overrides[ "user" ] + + overridePath = os.path.join( profileDir, "overrides.xml" ) + try: + tree = xmltree.parse( overridePath ) + self._save_hash( overridePath, xbmcvfs.File( overridePath ).read() ) + self.overrides[ "user" ] = tree + return tree + except: + if xbmcvfs.exists( overridePath ): + log( "Unable to parse user overrides.xml. Invalid xml?" ) + self._save_hash( overridePath, xbmcvfs.File( overridePath ).read() ) + else: + self._save_hash( overridePath, None ) + self.overrides[ "user" ] = None return None - else: - return pickle.loads( returnData ) def _get_additionalproperties( self, profileDir ): @@ -549,24 +523,36 @@ def _get_additionalproperties( self, profileDir ): return returnVal def _getWidgetNameAndType( self, widgetID ): + if widgetID in self.widgetNameAndType: + return self.widgetNameAndType[ widgetID ] + tree = self._get_overrides_skin() if tree is not None: for elem in tree.findall( "widget" ): if elem.text == widgetID: if "type" in elem.attrib: - return [elem.attrib.get( "label" ), elem.attrib.get( "type" )] + returnList = [elem.attrib.get( "label" ), elem.attrib.get( "type" )] else: - return [ elem.attrib.get( "label" ), None ] + returnList = [ elem.attrib.get( "label" ), None ] + self.widgetNameAndType[ widgetID ] = returnList + return returnList + self.widgetNameAndType[ widgetID ] = None return None def _getBackgroundName( self, backgroundID ): + if backgroundID in self.backgroundName: + return self.backgroundName[ backgroundID ] + tree = self._get_overrides_skin() if tree is not None: for elem in tree.findall( "background" ): if elem.text == backgroundID: - return elem.attrib.get( "label" ) + returnString = elem.attrib.get( "label" ) + self.backgroundName[ backgroundID ] = returnString + return returnString + self.backgroundName[ backgroundID ] = None return None def _reset_backgroundandwidgets( self ): diff --git a/resources/lib/gui.py b/resources/lib/gui.py index 38355447..6908077a 100644 --- a/resources/lib/gui.py +++ b/resources/lib/gui.py @@ -73,13 +73,6 @@ def __init__( self, *args, **kwargs ): log( 'Management module loaded' ) def onInit( self ): - xbmcgui.Window( 10000 ).clearProperty( "skinshortcuts-overrides-script" ) - xbmcgui.Window( 10000 ).clearProperty( "skinshortcuts-overrides-script-data" ) - xbmcgui.Window( 10000 ).clearProperty( "skinshortcuts-overrides-skin" ) - xbmcgui.Window( 10000 ).clearProperty( "skinshortcuts-overrides-skin-data" ) - xbmcgui.Window( 10000 ).clearProperty( "skinshortcuts-overrides-user" ) - xbmcgui.Window( 10000 ).clearProperty( "skinshortcuts-overrides-user-data" ) - xbmcgui.Window( 10000 ).clearProperty( "skinshortcutsAdditionalProperties" ) if self.group == '': self._close() else: diff --git a/resources/lib/xmlfunctions.py b/resources/lib/xmlfunctions.py index 777dbc72..d613ce9c 100644 --- a/resources/lib/xmlfunctions.py +++ b/resources/lib/xmlfunctions.py @@ -91,16 +91,6 @@ def buildMenu( self, mainmenuID, groups, numLevels, buildMode, options, weEnable log( "Failed to write menu" ) print_exc() complete = False - - - # Clear window properties for overrides, widgets, backgrounds, properties - xbmcgui.Window( 10000 ).clearProperty( "skinshortcuts-overrides-script" ) - xbmcgui.Window( 10000 ).clearProperty( "skinshortcuts-overrides-script-data" ) - xbmcgui.Window( 10000 ).clearProperty( "skinshortcuts-overrides-skin" ) - xbmcgui.Window( 10000 ).clearProperty( "skinshortcuts-overrides-skin-data" ) - xbmcgui.Window( 10000 ).clearProperty( "skinshortcuts-overrides-user" ) - xbmcgui.Window( 10000 ).clearProperty( "skinshortcuts-overrides-user-data" ) - xbmcgui.Window( 10000 ).clearProperty( "skinshortcutsAdditionalProperties" ) # Mark that we're no longer running, clear the progress dialog xbmcgui.Window( 10000 ).clearProperty( "skinshortcuts-isrunning" ) @@ -539,7 +529,7 @@ def writexml( self, profilelist, mainmenuID, groups, numLevels, buildMode, progr # Build any 'Other' templates Template.writeOthers() - progress.update( 100 ) + progress.update( 100, message = __language__( 32098 ) ) # Get the skins addon.xml file addonpath = xbmc.translatePath( os.path.join( "special://skin/", 'addon.xml').encode("utf-8") ).decode("utf-8")