How to make a progress indicator in my add-on
#1
Hi there!

I am trying to get the infamous texturecache.py (by Millhouse https://forum.kodi.tv/showthread.php?tid=158373) incorporated into my addon, so that I can run it in Kodi for Windows.  Previously I was running Kodi in LibreElec, so I had SSH access to run the py script.

This is in Python3 Kodi 19.

I was calling the textures.py in my Tools section:

self.addDirectoryItem("System : Click to Run Textures -c", 'tools_textures_c', 'tools.png', 'DefaultAddonProgram.png')

The command I use is to run textures.py is:

if action == 'tools_textures_c':
     if not control.yesnoDialog('Are you sure you want to run Textures c?', '', ''): return
     import xbmc
     xbmc.executebuiltin('System.Exec(C:\Kodi\portable_data\texturecache.py c)')
     control.notification(message='Textures c has completed!')

It works but since the script takes up to an hour to run sometimes, I would really like to have some sort of progress indicator, similar to the one that runs when you clean the movies Database.

Is that possible?  If so, what code do I use?

Thanks!!
Ken
Reply
#2
OK I have made some headway but still hitting raodbloacks.  

This code:
cpp:
        elif action == 'tools_textures_c':
            if not control.yesnoDialog('Are you sure you want to run Textures c?', '', ''): return
            import xbmc, xbmcgui
            from resources.lib.modules import texturecache
            running_dialog = xbmcgui.DialogProgressBG()
            running_dialog.update(0, 'Running "texturecache.py". Please wait.')
            list_of_arguments = ['c']
            counter = 0
            for argument in list_of_arguments:
                texturecache.main([argument])
                counter += 1
                running_dialog.update(int(counter / len(list_of_arguments)* 100), 'Running "texturecache.py %s". Please wait.' % argument)
            control.notification(message='Textures c has completed!')

gives this error:

2022-03-22 17:31:46.878 T:6312    ERROR <general>: EXCEPTION: Dialog not created.
2022-03-22 17:31:46.879 T:6312    ERROR <general>: EXCEPTION Thrown (PythonToCppException) : -->Python callback/script returned the following error<--
                                                    - NOTE: IGNORING THIS CAN LEAD TO MEMORY LEAKS!
                                                   Error Type: <class 'RuntimeError'>
                                                   Error Contents: Dialog not created.
                                                   Traceback (most recent call last):
                                                     File "C:\Kodi\portable_data\addons\plugin.video.demo\demo.py", line 21, in <module>
                                                       functions.functions(url)
                                                     File "C:\Kodi\portable_data\addons\plugin.video.demo\resources\lib\modules\functions.py", line 1002, in router
                                                       running_dialog.update(0, 'Running "texturecache.py". Please wait.')
                                                   RuntimeError: Dialog not created.
                                                   -->End of Python script error report<--
Reply
#3
There is no create command for the progress dialog box.

Here's a sample of code I use to create and update a progress dialog box:

        msgdialogprogress = xbmcgui.DialogProgress()
        dialogmsg = translate(30402)
        dialoghead = translate(30401)
        msgdialogprogress.create(dialoghead, dialogmsg)
        servers = ssdp.discover("urn::\schemas-upnp-org::device:MediaServer:1", timeout=timeoutval)     
        srvcount = len(servers)
        addtlmsg = '  ' + str(srvcount) + '  uPNP servers discovered.'
        ddialogmsg = dialogmsg + addtlmsg
        msgdialogprogress.update(50, ddialogmsg)
        xbmc.sleep(1000)

This might help.

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
#4
Sorry for the delay in responding, that is great thanks!  I will tinker with this.

Cheers,
Ken
Reply

Logout Mark Read Team Forum Stats Members Help
How to make a progress indicator in my add-on0