2023-03-09, 14:49
Hi, I want to add to my addon the capability to read the values of some Kodi settings from settings.xml when a custom window is open and then update them when a button in that window is clicked. The intention is to let my addon apply a 'recommended settings profile' easily when using my skin. So the logic is the custom window displays a list of settings where the current system value is different to the recommended. The user can toggle any off they don't wish to change, then they click the button to update the other settings.
script.py
Originally I decided to make two functions as part of my script.py called from my custom window like so:
get_default() worked fine, using a JSON calls to get the settings requiring update, and then I used window properties to display them in my custom window. But I would need to pass a dictionary of the settings to be changed from get_default to set_default, so I tried turning it into a class. and initated an instance of the class in my script.py main class __init__. However I realised my dictionary, self.settings_to_be_changed, could not be passed between the two methods, I think because each time I use RunScript, it starts a new copy of Python, so the instances are totally unrelated and objects cannot be shared between processes. Is that right?
monitor.py
I think for my Settings class to work as I need it, I need to include as a subclass it in my xbmc.Monitor class so it's persistently available and objects can be shared between the methods. Again I can get the first bit working fine, so it grabs the settings to be updated when my custom window becomes visible. But I'm not sure how to trigger the second part, self.set_default() when the button is clicked. Is there some sort of event I can listen for that a button has been clicked?
I thought if I push a notification when the button is clicked to say settings are being saved, I could 'listen' for this using onNotification() from xbmc.Monitor() but I now understand that this only listens for certain system json calls such as GUI.OnScreensaverActivated
script.py
Originally I decided to make two functions as part of my script.py called from my custom window like so:
<onload>RunScript(script.copacetic.helper,action=get_default)</onload>
<param name="button3_onclick" value="RunScript(script.copacetic.helper,action=set_default)" />
get_default() worked fine, using a JSON calls to get the settings requiring update, and then I used window properties to display them in my custom window. But I would need to pass a dictionary of the settings to be changed from get_default to set_default, so I tried turning it into a class. and initated an instance of the class in my script.py main class __init__. However I realised my dictionary, self.settings_to_be_changed, could not be passed between the two methods, I think because each time I use RunScript, it starts a new copy of Python, so the instances are totally unrelated and objects cannot be shared between processes. Is that right?
monitor.py
I think for my Settings class to work as I need it, I need to include as a subclass it in my xbmc.Monitor class so it's persistently available and objects can be shared between the methods. Again I can get the first bit working fine, so it grabs the settings to be updated when my custom window becomes visible. But I'm not sure how to trigger the second part, self.set_default() when the button is clicked. Is there some sort of event I can listen for that a button has been clicked?
I thought if I push a notification when the button is clicked to say settings are being saved, I could 'listen' for this using onNotification() from xbmc.Monitor() but I now understand that this only listens for certain system json calls such as GUI.OnScreensaverActivated