Reload settings.xml programmatically
#1
Is it possible using python to reload the "resources/settings.xml" responsible for the settings GUI after the plugin has been loaded?
If I make changes to settings.xml, then the only way to see the changes is either to restart xbmc or at least disable and then re-enable the addon. I am seeking a way where I can reload the settings programmatically whenever I wish to from within my addon.
Reply
#2
Not tested, but I would expect you would do it the same way as with a skin - map a button (or, from Python, executebuiltin) to XBMC.ReloadSkin() so that the relevant xml file is reloaded - as detailed in the first post > http://forum.xbmc.org/showthread.php?tid=94438
Reply
#3
Hmmm... I added an action button to settings GUI:
Code:
<setting label="Refresh" type="action" action="XBMC.ReloadSkin()"/>
And when I choose it, it reload the skin as expected. However, the settings dialog is also closed. Also, if I am in the "Add-on information" screen and then choose "Configure" and choose that action button, it will reload the skin, close the dialog, and close the add-on information screen. I also just realized that if you show the context menu and choose "Add-on settings", then the settings.xml is automatically refreshed without needing to reload it. However, if I open the settings dialog through the "Configure" from "Add-on Information" screen, then it will not get reloaded automatically!

Regardless of all what is mentioned, what I wish for is a way to add an action button to "settings.xml" that if chosen, it will modify "settings.xml" and reload it to reflect the changes without closing the dialog (or at least reopen it again). Any workarounds or alternative solutions?
Reply
#4
Is it a service or a plugin?

The settings are read when the plugin/addon/service starts.

If your script is kept alive then you can create an xbmc.Monitor that calls a "read settings" function.

Thats what I do in the service.py for LazyTV.

Code:
class LazyMonitor(xbmc.Monitor):

    def __init__(self, *args, **kwargs):
        xbmc.Monitor.__init__(self)

    def onSettingsChanged(self):
        #update the settings
        grab_settings()
Reply
#5
It is a plugin in my case, but I guess what I am looking for doesn't change if I am to develop a service. I think what you suggested is something useful, but to a problem that is not the one I mentioned. Your suggestion is to detect and monitor the user changes to the settings "values".
What I am trying to achieve is unconventional. I am trying to change the "setting.xml" GUI by changing the XML using python when an action button is pressed inside the settings GUI, and then want that settings GUI to get refreshed to reflect the changes in GUI. What Unfledged suggested was the closest solution, but it unfortunately force-close the settings GUI.
Reply
#6
So far the closest solution I've come to is:
* I point the action button to my python script, then
* There I change the "settings.xml" GUI and write it back, then
* Call xbmcaddon.openSettings(), which will reopen the currently open dialog after reloading it
The drawbacks to this approach are:
* If there are categories in the settings dialog and the action button was in any category other than the first, then the dialog will reopen focusing on the first category (and not the one having the action button)
* Any new values entered before pressing the action button will be lost once you press it Sad
I welcome any improvements or alternatives.

Edit: the solution to the second drawback (lost values) is to add the close option to the action button (i.e. option="close"). This will cause the settings dialog to save and close, then your (my) script will reopen it with the refreshed GUI and saved values. What is only left is the first drawback.
Reply

Logout Mark Read Team Forum Stats Members Help
Reload settings.xml programmatically0