Advertisement
Guest User

Untitled

a guest
Sep 1st, 2015
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.58 KB | None | 0 0
  1. # The example of a multi-select dialog in a Kodi addon created with PyXBMCt framework.
  2. # You will need a checkmark image file.
  3. import os
  4. import xbmcgui
  5. import xbmcaddon
  6. import pyxbmct.addonwindow as pyxbmct
  7.  
  8. _addon = xbmcaddon.Addon()
  9. _path = _addon.getAddonInfo("path")
  10. _check_icon = os.path.join(_path, "check.png") # Don't decode _path to utf-8!!!
  11.  
  12.  
  13. class MultiChoiceDialog(pyxbmct.AddonDialogWindow):
  14. def __init__(self, title="", items=[]):
  15. super(MultiChoiceDialog, self).__init__(title)
  16. self.setGeometry(450, 300, 4, 4)
  17. self.selected = []
  18. self.set_controls()
  19. self.connect_controls()
  20. self.listing.addItems(items)
  21. self.set_navigation()
  22.  
  23. def set_controls(self):
  24. self.listing = pyxbmct.List(_imageWidth=15)
  25. self.placeControl(self.listing, 0, 0, rowspan=3, columnspan=4)
  26. self.ok_button = pyxbmct.Button("OK")
  27. self.placeControl(self.ok_button, 3, 1)
  28. self.cancel_button = pyxbmct.Button("Cancel")
  29. self.placeControl(self.cancel_button, 3, 2)
  30.  
  31. def connect_controls(self):
  32. self.connect(self.listing, self.check_uncheck)
  33. self.connect(self.ok_button, self.ok)
  34. self.connect(self.cancel_button, self.close)
  35.  
  36. def set_navigation(self):
  37. self.listing.controlUp(self.ok_button)
  38. self.listing.controlDown(self.ok_button)
  39. self.ok_button.setNavigation(self.listing, self.listing, self.cancel_button, self.cancel_button)
  40. self.cancel_button.setNavigation(self.listing, self.listing, self.ok_button, self.ok_button)
  41. self.setFocus(self.listing)
  42.  
  43.  
  44. def check_uncheck(self):
  45. list_item = self.listing.getSelectedItem()
  46. if list_item.getLabel2() == "checked":
  47. list_item.setIconImage("")
  48. list_item.setLabel2("unchecked")
  49. else:
  50. list_item.setIconImage(_check_icon)
  51. list_item.setLabel2("checked")
  52.  
  53. def ok(self):
  54. for index in xrange(self.listing.size()):
  55. if self.listing.getListItem(index).getLabel2() == "checked":
  56. self.selected.append(index)
  57. super(MultiChoiceDialog, self).close()
  58.  
  59. def close(self):
  60. self.selected = []
  61. super(MultiChoiceDialog, self).close()
  62.  
  63. if __name__ == "__main__":
  64. items = ["Item {0}".format(i) for i in xrange(1, 11)]
  65. dialog = MultiChoiceDialog("Select items", items)
  66. dialog.doModal()
  67. xbmcgui.Dialog().notification("Finished", "Selected: {0}".format(dialog.selected))
  68. del dialog #You need to delete your instance when it is no longer needed
  69. #because underlying xbmcgui classes are not grabage-collected.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement