Need help conceptualising a solution to my problem
#1
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:

xml:

<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
Reply
#2
(2023-03-09, 14:49)realcopacetic Wrote: 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


Your second question sounds similar to mine with regards to the limitations of onNotification  Since you have your own Window class I would think you can use the onAction callback function.  For your first question, you can pass parameters with runScript like so:

RunScript(%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)' %   ("plugin.video.myplugin", "context", pctitle, itemurl, season_text, episode_text, playcount, pcseries, mtype, contenturl, dcmInfo_text, icon, movieset, taglist)

This is a bit of an extreme example but just showing how I am passing a bunch of variables (static values and Python variables) between scripts in Kodi.  Here's a thread which details more.

I hope this helps.


Jeff
Running with the Mezzmo Kodi addon.  The easier way to share your media with multiple Kodi clients.
Service.autostop , CBC Sports, Kodi Selective Cleaner and Mezzmo Kodi addon author.
Reply
#3
Thanks @jbinkley60  it's good to know that's possible. I may try reverting and seeing how well it works. 

For now I kept the two functions in a class as part of my monitor class. To trigger the second method when the button is pressed I'm doing this. It seems to work well enough:

button onclick --> Skin.ToggleSetting(run_set_default)

Then in my Monitor() loop, I check on each run through if that condition is true to run the script and toggle the setting using xbmc.executebuiltin(action).

It seems to work but it's probably a lot of unnecessary checking for something relatively simple so I may try to pass a variable between scripts.
Reply
#4
(2023-03-09, 19:03)realcopacetic Wrote: Thanks @jbinkley60  it's good to know that's possible. I may try reverting and seeing how well it works. 

For now I kept the two functions in a class as part of my monitor class. To trigger the second method when the button is pressed I'm doing this. It seems to work well enough:

button onclick --> Skin.ToggleSetting(run_set_default)

Then in my Monitor() loop, I check on each run through if that condition is true to run the script and toggle the setting using xbmc.executebuiltin(action).

It seems to work but it's probably a lot of unnecessary checking for something relatively simple so I may try to pass a variable between scripts.

Ok, good luck.  When you get to a point you are willing to share, I'd like to see your window code.  I may have to create a window class for what I want to do and try to catch keystrokes (vs a button)  so I'd like to see something which is working.  For passing RunScript arguments my large addon has a special Python file called by addon.xml and it takes many different runScript commands from different parts of the addon and parses them based upon sys.argv[1] and other passed variables.  It works pretty well. You can see it here beginning on line 639


Thanks,

Jeff
Running with the Mezzmo Kodi addon.  The easier way to share your media with multiple Kodi clients.
Service.autostop , CBC Sports, Kodi Selective Cleaner and Mezzmo Kodi addon author.
Reply
#5
My script is public @jbinkley60, don't have a window class yet but reading up one the threads and documentation you shared I think this could be what I need to remove some of the hacks in my skin. Will message you if I get anywhere with it!

https://github.com/realcopacetic/script....tic.helper
Reply
#6
You might want to have a look at the kutils module library in Kodi repo.  I think it has a lot of the capability you are looking for.

scott s.
.
Reply

Logout Mark Read Team Forum Stats Members Help
Need help conceptualising a solution to my problem0