Skip to content

Commit

Permalink
[skin] improvize callbacks function
Browse files Browse the repository at this point in the history
-rename name callbacks --> onLoadCallbacks
-remove self
-add global variable runCallbacks
-change call function(run only once)
-add object check
  • Loading branch information
Dima73 committed Jan 22, 2025
1 parent 99a4d76 commit 10d1d6a
Showing 1 changed file with 11 additions and 12 deletions.
23 changes: 11 additions & 12 deletions lib/python/skin.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@

currentPrimarySkin = None
currentDisplaySkin = None
callbacks = []
onLoadCallbacks = []
runCallbacks = False

# Skins are loaded in order of priority. Skin with highest priority is
Expand All @@ -72,8 +72,7 @@


def InitSkins():
global currentPrimarySkin, currentDisplaySkin
runCallbacks = False
global currentPrimarySkin, currentDisplaySkin, runCallbacks
# Add the emergency skin. This skin should provide enough functionality
# to enable basic GUI functions to work.
loadSkin(EMERGENCY_SKIN, scope=SCOPE_CURRENT_SKIN, desktop=getDesktop(GUI_SKIN_ID), screenID=GUI_SKIN_ID)
Expand Down Expand Up @@ -110,7 +109,11 @@ def InitSkins():
result = loadSkin(name, scope=SCOPE_CURRENT_SKIN, desktop=getDesktop(GUI_SKIN_ID), screenID=GUI_SKIN_ID)
if result is None:
loadSkin(USER_SKIN, scope=SCOPE_CURRENT_SKIN, desktop=getDesktop(GUI_SKIN_ID), screenID=GUI_SKIN_ID)
runCallbacks = True
if not runCallbacks:
runCallbacks = True
for method in onLoadCallbacks:
if callable(method):
method()

# Temporary entry point for older versions of StartEnigma.py.
#
Expand Down Expand Up @@ -154,10 +157,6 @@ def loadSkin(filename, scope=SCOPE_SKIN, desktop=getDesktop(GUI_SKIN_ID), screen
# Element is not a screen or windowstyle element so no need for it any longer.
reloadWindowStyles() # Reload the window style to ensure all skin changes are taken into account.
print("[Skin] Loading skin file '%s' complete." % filename)
if runCallbacks:
for method in self.callbacks:
if method:
method()
return True
except xml.etree.ElementTree.ParseError as err:
fd.seek(0)
Expand Down Expand Up @@ -204,13 +203,13 @@ def reloadSkins():


def addCallback(callback):
if callback not in callbacks:
callbacks.append(callback)
if callback not in onLoadCallbacks:
onLoadCallbacks.append(callback)


def removeCallback(callback):
if callback in self.callbacks:
callbacks.remove(callback)
if callback in onLoadCallbacks:
onLoadCallbacks.remove(callback)


class SkinError(Exception):
Expand Down

0 comments on commit 10d1d6a

Please sign in to comment.