1. def addingItemsTest():
  2. import sys,xbmc,xbmcplugin,xbmcgui,time
  3. xbmc.executebuiltin("XBMC.Dialog.Close(busydialog,true)")
  4. dialogWait = xbmcgui.DialogProgress()
  5. dialogWait.create('Adding Items')
  6. totalItems = 1000
  7. addedItems = 0
  8. startTime = time.time()
  9. endTime = startTime
  10. for n in range(totalItems):
  11. time.sleep(5/float(totalItems)) #5 seconds in total
  12. infoLabels={ "Title": str(n), "Plot": "x" * 500, "Duration": str(n), "Year": "2017" ,"Genre": "HORROR!" }
  13. item = xbmcgui.ListItem(str(n) )
  14. item.setInfo( type="Video", infoLabels=infoLabels )
  15. xbmcplugin.addDirectoryItem(handle=int(sys.argv[1]),url="",listitem=item)
  16. addedItems += 1
  17. percent = (addedItems * 100)/totalItems
  18. remaining_display = 'Added Items: [B]'+str(addedItems)+' / '+str(totalItems)+'[/B].'
  19. endTime = time.time()
  20. elapsedTime = "Elapsed time: [B]" + str("%0.03f" % (round(endTime - startTime,3))) + "s[/B]"
  21. dialogWait.update(percent,remaining_display,elapsedTime)
  22. if dialogWait.iscanceled(): break
  23. xbmcplugin.endOfDirectory(int(sys.argv[1]))
  24. dialogWait.close()
  25. del dialogWait
  26. endTime = time.time()
  27. results = 'Added %s items in %ss' % (addedItems,str("%0.03f" % (round(endTime - startTime,3))));
  28. xbmc.log(results,xbmc.LOGNOTICE)
  29. dialog = xbmcgui.Dialog()
  30. dialog.ok('Results:',results,'')
Comments powered by Disqus