-
-
Notifications
You must be signed in to change notification settings - Fork 6.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[addon] support to set binary add-on instance settings by python #23648
base: master
Are you sure you want to change the base?
Conversation
throw XBMCAddon::WrongTypeException("Invalid setting type"); | ||
|
||
if (value) | ||
CServiceBroker::GetAddonMgr().PublishInstanceAdded(pAddon->ID(), instance); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will this callback to the PVR add-on? It is important that it does as otherwise the add-on cannot handle settings changes. Ideally each changed setting would callback to SetInstanceSetting()
for the add-on implementing the interface kodi::addon::IAddonInstance.
IT's also possible this happens for free as part of the regular settings interface.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will this callback to the PVR add-on? It is important that it does as otherwise the add-on cannot handle settings changes. Ideally each changed setting would callback to
SetInstanceSetting()
for the add-on implementing the interface kodi::addon::IAddonInstance.IT's also possible this happens for free as part of the regular settings interface.
The callback mainly works to the CPVRClients, where then call the PVR add-ons and only needed on add or disable/enable. SetInstanceSetting()
now becomes called if instance already know on add-on.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great, this should mean that the dynamic settings in pvr.iptvsimple should work ok now.
@matthuisman can you build this PR yourself? Or will I build it for you? I'd like you to test this to make sure this functionality is working again in Omega. Thanks in advance.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@phunkyfish
i dont have the env setup to create builds sorry. If you can get me an x86_64 windows I can test.
We want to make sure that we can force IPTV Simple to reload its playlists right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@phunkyfish i dont have the env setup to create builds sorry. If you can get me an x86_64 windows I can test. We want to make sure that we can force IPTV Simple to reload its playlists right?
This mainly to change the use state about the instance, e.g. the disable/enable. Normally should the add-on handle setting changes by self, if he see a change within in his settings. But optionally can the python also do a hacky disable and enable again to force a reload.
This looks like it should solve #22779 |
373d36d
to
2099ec8
Compare
Yes this should fix the issue. @phunkyfish have updated, should be now a bit better. The The Also found here a small bug as the instance id not given to it: xbmc/xbmc/addons/settings/AddonSettings.cpp Line 442 in f5ab9fd
|
2099ec8
to
fb1346d
Compare
Thanks a lot @enen92! Have updated the text, also removed the spaces on the value text, added they some years ago, but makes not really sense to use. |
cea05b4
to
6cef00c
Compare
Have added now also a second commit where allow it within old setting functions, not sure to make, as they are set as deprecated. Further can the python add-on open the instance settings dialog direct. |
xbmc/interfaces/legacy/Addon.cpp
Outdated
} | ||
|
||
String Addon::getSetting(const char* id) | ||
String Addon::getSetting(const char* id, unsigned int instance /* = 0*/) | ||
{ | ||
return pAddon->GetSetting(id); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NOTE: Have forgot to give "instance" here, but not updated now, as the support there maybe becomes removed again.
Will this remove the confusing debug message when the resource/instance-setting.xml is read here since it shouldn't have these values. https://github.com/xbmc/xbmc/blob/8de133330cc47e1d4809f271118b8ac2fb3701eb/xbmc/addons/settings/AddonSettings.cpp#L226C55-L226C55
|
Ah, thanks. Yes this comes on Debug some times and not needed. /*!
\brief Gets the setting with the given identifier.
\param id Setting identifier
\param[in] notPresentPossible If is set, error messages are ignored because the given setting
might not actually exist.
Can refer to background settings related to Kodi, which may be
added later, e.g. to an add-on.
\return Setting object with the given identifier or nullptr if the identifier is unknown
*/
std::shared_ptr<CSetting> GetSetting(const std::string &id, bool notPresentPossible = false) const; |
Thanks this has bugged me since I first saw them. Perhaps in a future PR this could lead new to new settings type for removed variables, instead of having to hide them. |
6cef00c
to
ad14c91
Compare
Updated it, should work now, had recently thrown a bug where name and enable/disable were not saved. I have removed my changes in the old python API because they are deprecated. Setting the settings is now also possible in the Python addon class directly via From my side it should be ready, which is why I removed the WIP. Take a look and say what you think. |
xbmc/interfaces/legacy/Addon.h
Outdated
/// settings.setInt('m3uPathType', 0) | ||
/// settings.setString('m3uPath', '/SOME_PATH_OF_YOU') | ||
/// ... | ||
/// addon.setInstanceIdState(newinstanceid, True, 'Example by Python added') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this string meaningful for any actual feature or is it just some optional string?
I feel it is just used for some logging or so. If that's the case I'd suggest to drop it. It should be the add-on in charge of logging stuff
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See above this:
/// @param name [opt] string or unicode - The instance name used inside Kodi
/// @warning Needs on new added instances set.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Got it by the screenshots you posted. Maybe rename the example as "Example instance created from python" (reads a bit better)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also @warning Needs on new added instances set.
-> "Required when creating a new settings instance" ?
xbmc/addons/Addon.cpp
Outdated
bool CAddon::GetKodiInstanceSetting(AddonInstanceId id, | ||
bool& enabled, | ||
std::string& name, | ||
bool presenceValidated) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is the presenceValidated mandatory? Why not return false if the setting does not exist?
I'd say it makes the api a bit cumbersome for no reason
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can remove as value, thought only for cases if in future this becomes called on place where needs the presence of settings.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please remove if possible
/// ~~~~~~~~~~~~~ | ||
/// | ||
getFreeNewInstanceId(); | ||
#else |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here. Why not simply id = addon.Instance()
?
Cleaner
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thats as addon.instance()
I see really confusing, as I expect then a handling class and not an identifier as return.
Maybe another, but has not found a good name for it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed, maybe createInstance()
?
Can you give an example of how this would work? |
getKnownInstanceIds returns a single [ID] that represents the single settings This may already be the case :) Not a huge deal to be honest. just makes the calling code a bit easier Im happy enough to do:
|
i cant review because from first implementation in kodi of "multiple instances binary addons" i never understand his purpose and how works and if it works for PVR only or all binary, then with the scripts in the description its not clear to me what are you doing.. |
The instances really only refer to binary add-ons and currently only used in PVR with independent settings of it. The background to Python is that an add-on may be able to change the settings of a PVR add-on. E.g. in pvr.iptvsimple where a python script can then set everything suitable for multiple PVR stream backend servers by adding these necessary instances with the associated settings to the binary add-on. |
yes i more or less understand that script above change some settings of an "instance" (you create always a new one?) |
c201c98
to
259bb1e
Compare
Hi @matthuisman is not directly so easy, a add-on can still have both, within id 0 are general settings of add-on where relates to all instances on it. All numbers higher 0 then relates to instance only. The
Hello @CastagnaIT, yes you right, there should be some documentations about to know what exactly is the background about. Will look in next time what would be the best about and to add documentations. The "Edit add-on settings" there relates as button to global general settings of PVR add-on (only visible if add-on have a standard "settings.xml", they below are the independent instance settings on the add-on, the last added by the python script. Python can then with his new API then add, delete or edit all instances, they from user or they added from him in script. About "they are indipendent like a service?" not directly, the add-on is like a app, it runs all instances independent from each other in own processes, but everything in same base and can if needed also interact between (the PVR add-on only loaded one time). |
#ifdef DOXYGEN_SHOULD_USE_THIS | ||
/// | ||
/// \ingroup python_xbmcaddon | ||
/// @brief \python_func{ xbmcaddon.Addon([id]).setInstanceState(id, enabled, [name]) } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is the name set when change the state on the instance and not right when the instance is created? Can it be moved to getFreeNewInstanceId()?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is a big hen and egg problem, by getFreeNewInstanceId()
is and can the instance not created, as the needed settings for it not available and PVR system then start works where always ends in errors, thats why it only give a free id.
The fields about "enabled" and "name" are parts only handled by Kodi itself, about "enabled" is easy to understand why, about name relates to the name used on the GUI in Kodi (see picture above).
The setInstanceState
needs be called on new added instances, thats why name needed on it, or can be called too on already present ones to change name and/or enable / disable it, thats why name declared optional.
Maybe the function can become another name. Have you a idea about?
Another solution can be, but then it becomes hacky and needs more functions and much changes to add:
Function | Hacky description |
---|---|
settings = addon.createInstanceSettings(enabled, name) |
It returns the settings class and not an id - The enabled and name needs temporary stored somewhere - access to CSettingsBase in Kodi no more enough and needs access to CAddonSettings as this handle the id. |
settings.setAddedInstanceReady() oraddon.setAddedInstanceReady(settings) |
Something needs always done to report Kodi that new instance is ready to start and thats PVR system does it Maybe it can optionally also be done by the settings class destructor, but then Python needs to do destruct it and never stores it somewhere. |
id = settings.getInstanceId() |
New function then needed for the cases if python needs the id byself to store something about for him himself or for the future works. |
addon.setInstanceState(id, enabled) |
To allow on already present ones the enable / disable |
addon.setInstanceName(id, name) |
To allow on already present ones the name change |
state = settings.getInstanceState() andstate = addon.getInstanceState(id) |
For the sake of form, to have the counterpart to the “set”. |
name = settings.getInstanceName() andname = addon.getInstanceName(id) |
For the sake of form, to have the counterpart to the “set”. |
About this it seems then also more hard to understand what does somewhere what.
…d either Previously, there were always calls to Kodi's own add-on instance settings in the debug log, since these cannot be known anyway, it makes no sense to set a log message.
This makes it possible to call up an instance setting immediately without first showing the selection dialog.
Before was the instance id not given on "m_addon->SaveSettings(...)" call.
This allow a python script to edit add-on instance settings where used within PVR add-ons. To prevent conflicts by user set within Kodi's GUI are the by python created ones starting with id >1000. By a small python script has it works for tests.
259bb1e
to
9a590a2
Compare
@enen92 based on the above example code can you explain how it should be in order to be able to be able to get this code in a mergeable state. Maybe even re-write the code snippet above and then we can see if that is possible, or if we need to make trade-offs somewhere. Thanks! |
Description
This allow a python script to edit add-on instance settings where used within PVR add-ons.
To prevent conflicts by user set within Kodi's GUI are the by python created ones starting with id >1000.
Motivation and context
How has this been tested?
By a small python script has it works for tests.
If the instance already present is it enough to call:
By this the add-on becomes the
ADDON_STATUS SetInstanceSetting(const std::string& settingName, const kodi::addon::CSettingValue& settingValue)
call.What is the effect on users?
Screenshots (if appropriate):
Types of change
Checklist: