(2020-08-29, 00:31)ronie Wrote: [ -> ]onAction can only be used by scripts who create their own window.
the purpose of onAction is to capture actions that are send to that window.
what i think you could do is create a service addon that uses the onNotification
method of the xbmc.Monitor() class.
that way you can receive a notification whever on update to your database occurs.
python:
import xbmc
class Main():
def __init__(self):
self.Monitor = MyMonitor()
while not self.Monitor.abortRequested():
xbmc.sleep(100)
class MyMonitor(xbmc.Monitor):
def __init__(self):
xbmc.Monitor.__init__(self)
def onNotification(self, sender, method, data):
print(sender)
print(method)
print(data)
if __name__ == '__main__':
Main()
an example of the sender, method and data this will capture:
Code:
xbmc
VideoLibrary.OnUpdate
{"item":{"id":40,"type":"movie"},"playcount":1}
Thanks so much for this but I've determined that I am going to need to use another context menu item button. It has to do with differences in the list item objectID between when it displays in a playlist via a Kodi listitem vs. a full sync of the uPNP server with the Kodi database. The objectIDs are different and Kodi has no way to determine that.
I've inherited this code and realized they had created a context menu item called Details which was nothing more than the function which already exists in the context menu as Info that calls XBMC.Action(Info). So I am reusing / renaming it and changing the function of the menu items.
Here's the code and it is working pretty well:
if playcount == 0:
li.addContextMenuItems([ (addon.getLocalizedString(30347), 'Container.Refresh'), \
(addon.getLocalizedString(30346), 'Action(ParentDir)'), (addon.getLocalizedString(30372), \
'XBMC.RunScript(special://home/addons/plugin.video.mezzmo/resources/lib/playcount.py, \
{},{}, {}, {}, {}, {}, {})'.format(mtitle, itemurl, season_text, episode_text, playcount, \
album_text, pcdbfile)) ])
elif playcount > 0:
li.addContextMenuItems([ (addon.getLocalizedString(30347), 'Container.Refresh'), \
(addon.getLocalizedString(30346), 'Action(ParentDir)'), (addon.getLocalizedString(30373), \
'XBMC.RunScript(special://home/addons/plugin.video.mezzmo/resources/lib/playcount.py, \
{},{}, {}, {}, {}, {}, {})'.format(mtitle, itemurl, season_text, episode_text, playcount, \
album_text, pcdbfile)) ])
I've been reading through the documentation on the addContextMenuItems function and from what I can tell I can't just call a function in my plugin with it, is that correct ? I'd like to do something maybe cleaner like:
import playcount
if playcount == 0:
li.addContextMenuItems([ (addon.getLocalizedString(30347), 'Container.Refresh'), \
(addon.getLocalizedString(30346), 'Action(ParentDir)'), (addon.getLocalizedString(30372), \
'playcount.updateKodiPlaycount( mtitle, itemurl, season_text, episode_text, playcount, \
album_text, pcdbfile)') ])
elif playcount > 0:
li.addContextMenuItems([ (addon.getLocalizedString(30347), 'Container.Refresh'), \
(addon.getLocalizedString(30346), 'Action(ParentDir)'), (addon.getLocalizedString(30373), \
'playcount.updateKodiPlaycount( mtitle, itemurl, season_text, episode_text, playcount, \
album_text, pcdbfile)') ])
where playcount.updateKodiPlaycount is the function which updates the database and the uPNP server. The documentation seems to indicate I can only call a script like above and not another function within the plugin.. Am I missing something or I am reading it right and that is correct that I can't call a function already in my plugin ?