Skip to content

Commit

Permalink
Merge pull request #34 from Ignoble61/build-rewrite
Browse files Browse the repository at this point in the history
More menu build speed improvements
  • Loading branch information
BobCratchett committed Jul 28, 2015
2 parents 5e9741a + 6a8be9f commit 935388a
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 141 deletions.
39 changes: 0 additions & 39 deletions default.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 )

Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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()


# ----------------
Expand Down Expand Up @@ -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))" ):
Expand Down
4 changes: 4 additions & 0 deletions resources/language/English/strings.po
Original file line number Diff line number Diff line change
Expand Up @@ -413,3 +413,7 @@ msgstr ""
msgctxt "#32097"
msgid "Unable to save menu"
msgstr ""

msgctxt "#32098"
msgid "Writing menu..."
msgstr ""
154 changes: 70 additions & 84 deletions resources/lib/datafunctions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 ):
Expand Down Expand Up @@ -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 ):
Expand Down Expand Up @@ -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 ):
Expand Down
7 changes: 0 additions & 7 deletions resources/lib/gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
12 changes: 1 addition & 11 deletions resources/lib/xmlfunctions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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" )
Expand Down Expand Up @@ -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")
Expand Down

0 comments on commit 935388a

Please sign in to comment.