def multi_select(options, window_header=""): '''allows the user to choose from multiple options''' listitems = [] for option in options: if not option["condition"] or getCondVisibility(option["condition"]): listitem = xbmcgui.ListItem(label=option["label"], label2=option["description"]) listitem.setProperty("id", option["id"]) if getCondVisibility("Skin.HasSetting(%s)" % option["id"]) or (not xbmc.getInfoLabel( "Skin.String(defaultset_%s)" % option["id"]) and getCondVisibility(option["default"])): listitem.select(selected=True) listitems.append(listitem) # show select dialog dialog = DialogSelect("DialogSelect.xml", "", listing=listitems, windowtitle=window_header, multiselect=True) dialog.doModal() result = dialog.result if result: for item in result: if item.isSelected(): # option is enabled xbmc.executebuiltin("Skin.SetBool(%s)" % item.getProperty("id")) else: # option is disabled xbmc.executebuiltin("Skin.Reset(%s)" % item.getProperty("id")) # always set additional prop to define the defaults xbmc.executebuiltin("Skin.SetString(defaultset_%s,defaultset)" % item.getProperty("id")) del dialog
def daynightthemes(self, dayornight): '''allow user to set a specific theme during day/night time''' if dayornight not in ["day", "night"]: log_msg( "Invalid parameter for day/night theme - must be day or night") return # show listing with themes listitems = self.get_skin_colorthemes() listitems += self.get_user_colorthemes() header = self.addon.getLocalizedString(32031) curvalue = xbmc.getInfoLabel( "Skin.String(SkinHelper.ColorTheme.%s.theme)" % dayornight).decode("utf-8") dialog = DialogSelect("DialogSelect.xml", "", windowtitle=header, richlayout=True, listing=listitems, autofocus=curvalue) dialog.doModal() result = dialog.result del dialog if result: themefile = result.getfilename().decode("utf-8") themename = result.getLabel().decode("utf-8") self.set_day_night_theme(dayornight, themename, themefile)
def getcastmedia(self): '''helper to show a dialog with all media for a specific actor''' xbmc.executebuiltin("ActivateWindow(busydialog)") name = self.params.get("name", "") window_header = self.params.get("name", "") results = [] items = self.kodidb.castmedia(name) items = process_method_on_list(self.kodidb.prepare_listitem, items) for item in items: if item["file"].startswith("videodb://"): item["file"] = "ActivateWindow(Videos,%s,return)" % item["file"] else: item["file"] = 'PlayMedia("%s")' % item["file"] results.append(self.kodidb.create_listitem(item, False)) # finished lookup - display listing with results xbmc.executebuiltin("dialog.Close(busydialog)") dialog = DialogSelect("DialogSelect.xml", "", listing=results, windowtitle=window_header, richlayout=True) dialog.doModal() result = dialog.result del dialog if result: while xbmc.getCondVisibility("System.HasModalDialog"): xbmc.executebuiltin("Action(Back)") xbmc.sleep(300) xbmc.executebuiltin(result.getfilename()) del result
def selectview(self, content_type="other", current_view=None, display_none=False): '''reads skinfile with all views to present a dialog to choose from''' cur_view_select_id = None label = "" all_views = [] if display_none: listitem = xbmcgui.ListItem(label="None") listitem.setProperty("id", "None") all_views.append(listitem) # read the special skin views file if sys.version_info.major == 3: views_file = try_decode( xbmcvfs.translatePath('special://skin/extras/views.xml')) else: views_file = try_decode( xbmc.translatePath('special://skin/extras/views.xml')) if xbmcvfs.exists(views_file): doc = parse(views_file) listing = doc.documentElement.getElementsByTagName('view') itemcount = 0 for view in listing: label = xbmc.getLocalizedString( int(view.attributes['languageid'].nodeValue)) viewid = view.attributes['value'].nodeValue mediatypes = view.attributes['type'].nodeValue.lower().split( ",") if label.lower() == current_view.lower( ) or viewid == current_view: cur_view_select_id = itemcount if display_none: cur_view_select_id += 1 if (("all" in mediatypes or content_type.lower() in mediatypes) and (not "!" + content_type.lower() in mediatypes) and not getCondVisibility( "Skin.HasSetting(SkinHelper.view.Disabled.%s)" % viewid)): image = "special://skin/extras/viewthumbs/%s.jpg" % viewid listitem = xbmcgui.ListItem(label=label, iconImage=image) listitem.setProperty("viewid", viewid) listitem.setProperty("icon", image) all_views.append(listitem) itemcount += 1 dialog = DialogSelect("DialogSelect.xml", "", listing=all_views, windowtitle=self.addon.getLocalizedString(32012), richlayout=True) dialog.autofocus_id = cur_view_select_id dialog.doModal() result = dialog.result del dialog if result: viewid = result.getProperty("viewid") label = try_decode(result.getLabel()) return (viewid, label) else: return (None, None)
def multi_select(options, window_header=""): '''allows the user to choose from multiple options''' listitems = [] for option in options: if not option["condition"] or xbmc.getCondVisibility(option["condition"]): listitem = xbmcgui.ListItem(label=option["label"], label2=option["description"]) listitem.setProperty("id", option["id"]) if xbmc.getCondVisibility("Skin.HasSetting(%s)" % option["id"]) or (not xbmc.getInfoLabel( "Skin.String(defaultset_%s)" % option["id"]) and xbmc.getCondVisibility(option["default"])): listitem.select(selected=True) listitems.append(listitem) # show select dialog dialog = DialogSelect("DialogSelect.xml", "", listing=listitems, windowtitle=window_header, multiselect=True) dialog.doModal() result = dialog.result if result: for item in result: if item.isSelected(): # option is enabled xbmc.executebuiltin("Skin.SetBool(%s)" % item.getProperty("id")) else: # option is disabled xbmc.executebuiltin("Skin.Reset(%s)" % item.getProperty("id")) # always set additional prop to define the defaults xbmc.executebuiltin("Skin.SetString(defaultset_%s,defaultset)" % item.getProperty("id")) del dialog
def searchyoutube(self): '''helper to search youtube for the given title''' xbmc.executebuiltin("ActivateWindow(busydialog)") title = self.params.get("title", "") window_header = self.params.get("header", "") results = [] for media in self.get_youtube_listing(title): if not media["filetype"] == "directory": label = media["label"] label2 = media["plot"] image = "" if media.get('art'): if media['art'].get('thumb'): image = (media['art']['thumb']) listitem = xbmcgui.ListItem(label=label, label2=label2, iconImage=image) listitem.setProperty("path", media["file"]) results.append(listitem) # finished lookup - display listing with results xbmc.executebuiltin("dialog.Close(busydialog)") dialog = DialogSelect("DialogSelect.xml", "", listing=results, windowtitle=window_header, multiselect=False, richlayout=True) dialog.doModal() result = dialog.result del dialog if result: if getCondVisibility( "Window.IsActive(script-skin_helper_service-CustomInfo.xml) | " "Window.IsActive(movieinformation)"): xbmc.executebuiltin("Dialog.Close(movieinformation)") xbmc.executebuiltin("Dialog.Close(script-skin_helper_service-CustomInfo.xml)") xbmc.sleep(1000) xbmc.executebuiltin('PlayMedia("%s")' % result.getProperty("path")) del result
def enableviews(self): '''show select dialog to enable/disable views''' all_views = [] views_file = xbmc.translatePath('special://skin/extras/views.xml').decode("utf-8") if xbmcvfs.exists(views_file): doc = parse(views_file) listing = doc.documentElement.getElementsByTagName('view') for view in listing: view_id = view.attributes['value'].nodeValue label = xbmc.getLocalizedString(int(view.attributes['languageid'].nodeValue)) desc = label + " (" + str(view_id) + ")" listitem = xbmcgui.ListItem(label=label, label2=desc) listitem.setProperty("viewid", view_id) if not xbmc.getCondVisibility("Skin.HasSetting(SkinHelper.view.Disabled.%s)" % view_id): listitem.select(selected=True) all_views.append(listitem) dialog = DialogSelect( "DialogSelect.xml", "", listing=all_views, windowtitle=self.addon.getLocalizedString(32013), multiselect=True) dialog.doModal() result = dialog.result del dialog if result: for item in result: view_id = item.getProperty("viewid") if item.isSelected(): # view is enabled xbmc.executebuiltin("Skin.Reset(SkinHelper.view.Disabled.%s)" % view_id) else: # view is disabled xbmc.executebuiltin("Skin.SetBool(SkinHelper.view.Disabled.%s)" % view_id)
def searchyoutube(self): '''helper to search youtube for the given title''' xbmc.executebuiltin("ActivateWindow(busydialog)") title = self.params.get("title", "") window_header = self.params.get("header", "") results = [] for media in self.get_youtube_listing(title): if not media["filetype"] == "directory": label = media["label"] label2 = media["plot"] image = "" if media.get('art'): if media['art'].get('thumb'): image = (media['art']['thumb']) listitem = xbmcgui.ListItem(label=label, label2=label2, iconImage=image) listitem.setProperty("path", media["file"]) results.append(listitem) # finished lookup - display listing with results xbmc.executebuiltin("dialog.Close(busydialog)") dialog = DialogSelect("DialogSelect.xml", "", listing=results, windowtitle=window_header, multiselect=False, richlayout=True) dialog.doModal() result = dialog.result del dialog if result: if xbmc.getCondVisibility( "Window.IsActive(script-skin_helper_service-CustomInfo.xml) | " "Window.IsActive(movieinformation)"): xbmc.executebuiltin("Dialog.Close(movieinformation)") xbmc.executebuiltin("Dialog.Close(script-skin_helper_service-CustomInfo.xml)") xbmc.sleep(1000) xbmc.executebuiltin('PlayMedia("%s")' % result.getProperty("path")) del result
def getcastmedia(self): '''helper to show a dialog with all media for a specific actor''' xbmc.executebuiltin("ActivateWindow(busydialog)") name = self.params.get("name", "") window_header = self.params.get("name", "") results = [] items = self.mutils.kodidb.castmedia(name) items = self.mutils.process_method_on_list( self.mutils.kodidb.prepare_listitem, items) for item in items: if item["file"].startswith("videodb://"): item[ "file"] = "ActivateWindow(Videos,%s,return)" % item["file"] else: item["file"] = 'PlayMedia("%s")' % item["file"] results.append(self.mutils.kodidb.create_listitem(item, False)) # finished lookup - display listing with results xbmc.executebuiltin("dialog.Close(busydialog)") dialog = DialogSelect("DialogSelect.xml", "", listing=results, windowtitle=window_header, richlayout=True) dialog.doModal() result = dialog.result del dialog if result: while getCondVisibility( "System.HasModalDialog | System.HasVisibleModalDialog"): xbmc.executebuiltin("Action(Back)") xbmc.sleep(300) xbmc.executebuiltin(result.getfilename()) del result
def enableviews(self): '''show select dialog to enable/disable views''' all_views = [] if sys.version_info.major == 3: views_file = try_decode( xbmcvfs.translatePath('special://skin/extras/views.xml')) else: views_file = try_decode( xbmc.translatePath('special://skin/extras/views.xml')) richlayout = self.params.get("richlayout", "") == "true" if xbmcvfs.exists(views_file): doc = parse(views_file) listing = doc.documentElement.getElementsByTagName('view') for view in listing: view_id = view.attributes['value'].nodeValue label = xbmc.getLocalizedString( int(view.attributes['languageid'].nodeValue)) desc = label + " (" + str(view_id) + ")" image = "special://skin/extras/viewthumbs/%s.jpg" % view_id listitem = xbmcgui.ListItem(label=label, label2=desc, iconImage=image) listitem.setProperty("viewid", view_id) if not getCondVisibility( "Skin.HasSetting(SkinHelper.view.Disabled.%s)" % view_id): listitem.select(selected=True) excludefromdisable = False try: excludefromdisable = view.attributes[ 'excludefromdisable'].nodeValue == "true" except Exception: pass if not excludefromdisable: all_views.append(listitem) dialog = DialogSelect("DialogSelect.xml", "", listing=all_views, windowtitle=self.addon.getLocalizedString(32013), multiselect=True, richlayout=richlayout) dialog.doModal() result = dialog.result del dialog if result: for item in result: view_id = item.getProperty("viewid") if item.isSelected(): # view is enabled xbmc.executebuiltin( "Skin.Reset(SkinHelper.view.Disabled.%s)" % view_id) else: # view is disabled xbmc.executebuiltin( "Skin.SetBool(SkinHelper.view.Disabled.%s)" % view_id)
def downloadresourceaddons(addontype): '''show dialog with all available resource addons on the repo so the user can install one''' xbmc.executebuiltin("ActivateWindow(busydialog)") listitems = [] addon = xbmcaddon.Addon(ADDON_ID) for item in get_repo_resourceaddons(addontype): if not xbmc.getCondVisibility("System.HasAddon(%s)" % item["addonid"]): label2 = "%s: %s" % (xbmc.getLocalizedString(21863), item["author"]) listitem = xbmcgui.ListItem(label=item["name"], label2=label2, iconImage=item["thumbnail"]) listitem.setPath(item["path"]) listitem.setProperty("addonid", item["addonid"]) listitems.append(listitem) # if no addons available show OK dialog.. if not listitems: dialog = xbmcgui.Dialog() dialog.ok(addon.getLocalizedString(32021), addon.getLocalizedString(32022)) del dialog else: # show select dialog with choices dialog = DialogSelect("DialogSelect.xml", "", listing=listitems, windowtitle=addon.getLocalizedString(32021), richlayout=True) dialog.doModal() result = dialog.result del dialog del addon # process selection... if result: addon_id = result.getProperty("addonid") # trigger install... monitor = xbmc.Monitor() if KODI_VERSION > 16: xbmc.executebuiltin("InstallAddon(%s)" % addon_id) else: xbmc.executebuiltin("RunPlugin(plugin://%s)" % addon_id) count = 0 # wait (max 2 minutes) untill install is completed install_succes = False while not monitor.waitForAbort( 1) and not install_succes and count < 120: install_succes = xbmc.getCondVisibility("System.HasAddon(%s)" % addon_id) del monitor if install_succes: return True return False
def backuprestore(self): '''show dialog with all options for skin backups''' listitems = [] # create backup option label = self.addon.getLocalizedString(32013) listitem = xbmcgui.ListItem(label=label, iconImage="DefaultFolder.png") listitem.setPath("backup") listitems.append(listitem) # list existing backups backuppath = self.get_backuppath() if backuppath: for backupfile in xbmcvfs.listdir(backuppath)[1]: backupfile = backupfile.decode("utf-8") if "Skinbackup" in backupfile and backupfile.endswith(".zip"): label = "%s: %s" % (self.addon.getLocalizedString(32015), backupfile) listitem = xbmcgui.ListItem(label=label, iconImage="DefaultFile.png") listitem.setPath(backuppath + backupfile) listitems.append(listitem) # show dialog and list options header = self.addon.getLocalizedString(32016) extrabutton = self.addon.getLocalizedString(32012) dialog = DialogSelect("DialogSelect.xml", "", windowtitle=header, extrabutton=extrabutton, richlayout=True, listing=listitems) dialog.doModal() result = dialog.result del dialog if result: if isinstance(result, bool): # show settings xbmc.executebuiltin("Addon.OpenSettings(%s)" % ADDON_ID) else: if result.getfilename() == "backup": # create new backup self.backup(backup_file=self.get_backupfilename()) else: # restore backup self.restore(result.getfilename().decode("utf-8")) # always open the dialog again self.backuprestore()
def selectview(self, content_type="other", current_view=None, display_none=False): '''reads skinfile with all views to present a dialog to choose from''' cur_view_select_id = None label = "" all_views = [] if display_none: listitem = xbmcgui.ListItem(label="None") listitem.setProperty("id", "None") all_views.append(listitem) # read the special skin views file views_file = xbmc.translatePath('special://skin/extras/views.xml').decode("utf-8") if xbmcvfs.exists(views_file): doc = parse(views_file) listing = doc.documentElement.getElementsByTagName('view') itemcount = 0 for view in listing: label = xbmc.getLocalizedString(int(view.attributes['languageid'].nodeValue)) viewid = view.attributes['value'].nodeValue mediatypes = view.attributes['type'].nodeValue.lower().split(",") if label.lower() == current_view.lower() or viewid == current_view: cur_view_select_id = itemcount if display_none: cur_view_select_id += 1 if (("all" in mediatypes or content_type.lower() in mediatypes) and (not "!" + content_type.lower() in mediatypes) and not xbmc.getCondVisibility("Skin.HasSetting(SkinHelper.view.Disabled.%s)" % viewid)): image = "special://skin/extras/viewthumbs/%s.jpg" % viewid listitem = xbmcgui.ListItem(label=label, iconImage=image) listitem.setProperty("viewid", viewid) listitem.setProperty("icon", image) all_views.append(listitem) itemcount += 1 dialog = DialogSelect("DialogSelect.xml", "", listing=all_views, windowtitle=self.addon.getLocalizedString(32012), richlayout=True) dialog.autofocus_id = cur_view_select_id dialog.doModal() result = dialog.result del dialog if result: viewid = result.getProperty("viewid") label = result.getLabel().decode("utf-8") return (viewid, label) else: return (None, None)
def downloadresourceaddons(addontype): '''show dialog with all available resource addons on the repo so the user can install one''' xbmc.executebuiltin("ActivateWindow(busydialog)") listitems = [] addon = xbmcaddon.Addon(ADDON_ID) for item in get_repo_resourceaddons(addontype): if not xbmc.getCondVisibility("System.HasAddon(%s)" % item["addonid"]): label2 = "%s: %s" % (xbmc.getLocalizedString(21863), item["author"]) listitem = xbmcgui.ListItem(label=item["name"], label2=label2, iconImage=item["thumbnail"]) listitem.setPath(item["path"]) listitem.setProperty("addonid", item["addonid"]) listitems.append(listitem) # if no addons available show OK dialog.. if not listitems: dialog = xbmcgui.Dialog() dialog.ok(addon.getLocalizedString(32021), addon.getLocalizedString(32022)) del dialog else: # show select dialog with choices dialog = DialogSelect("DialogSelect.xml", "", listing=listitems, windowtitle=addon.getLocalizedString(32021), richlayout=True) dialog.doModal() result = dialog.result del dialog del addon # process selection... if result: addon_id = result.getProperty("addonid") # trigger install... monitor = xbmc.Monitor() if KODI_VERSION >= 17: xbmc.executebuiltin("InstallAddon(%s)" % addon_id) else: xbmc.executebuiltin("RunPlugin(plugin://%s)" % addon_id) count = 0 # wait (max 2 minutes) untill install is completed install_succes = False while not monitor.waitForAbort(1) and not install_succes and count < 120: install_succes = xbmc.getCondVisibility("System.HasAddon(%s)" % addon_id) del monitor if install_succes: return True return False
def open_item(self): """open selected item""" control_id = self.getFocusId() listitem = self.getControl(control_id).getSelectedItem() filename = listitem.getfilename() if "videodb:" in filename: # tvshow: open path xbmc.executebuiltin('Dialog.Close(all,true)') xbmc.executebuiltin('ReplaceWindow(Videos,%s/-2/)' % filename) self.close_dialog() elif "actor" in listitem.getProperty("DBTYPE"): # cast dialog busyDialog("activate") from dialogselect import DialogSelect results = [] name = listitem.getLabel().decode("utf-8") items = self.mutils.kodidb.castmedia(name) items = self.mutils.process_method_on_list( self.mutils.kodidb.prepare_listitem, items) for item in items: if item["file"].startswith("videodb://"): item["file"] = "ActivateWindow(Videos,%s,return)" % item[ "file"] else: item["file"] = 'PlayMedia("%s")' % item["file"] results.append(self.mutils.kodidb.create_listitem(item, False)) # finished lookup - display listing with results busyDialog("close") dialog = DialogSelect("DialogSelect.xml", "", listing=results, windowtitle=name, richlayout=True) dialog.doModal() result = dialog.result del dialog if result: xbmc.executebuiltin(result.getfilename()) self.close_dialog() else: # video file: start playback xbmc.executebuiltin('PlayMedia("%s")' % filename) self.close_dialog()
def enableviews(self): '''show select dialog to enable/disable views''' all_views = [] views_file = xbmc.translatePath( 'special://skin/extras/views.xml').decode("utf-8") if xbmcvfs.exists(views_file): doc = parse(views_file) listing = doc.documentElement.getElementsByTagName('view') for view in listing: view_id = view.attributes['value'].nodeValue label = xbmc.getLocalizedString( int(view.attributes['languageid'].nodeValue)) desc = label + " (" + str(view_id) + ")" listitem = xbmcgui.ListItem(label=label, label2=desc) listitem.setProperty("viewid", view_id) if not xbmc.getCondVisibility( "Skin.HasSetting(SkinHelper.view.Disabled.%s)" % view_id): listitem.select(selected=True) all_views.append(listitem) dialog = DialogSelect("DialogSelect.xml", "", listing=all_views, windowtitle=self.addon.getLocalizedString(32013), multiselect=True) dialog.doModal() result = dialog.result del dialog if result: for item in result: view_id = item.getProperty("viewid") if item.isSelected(): # view is enabled xbmc.executebuiltin( "Skin.Reset(SkinHelper.view.Disabled.%s)" % view_id) else: # view is disabled xbmc.executebuiltin( "Skin.SetBool(SkinHelper.view.Disabled.%s)" % view_id)
def open_item(self): '''open selected item''' control_id = self.getFocusId() listitem = self.getControl(control_id).getSelectedItem() if "videodb:" in listitem.getLabel(): # tvshow: open path xbmc.executebuiltin('ReplaceWindow(Videos,"%s")' % self.listitem.getLabel()) self.close_dialog() elif "actor" in listitem.getProperty("DBTYPE"): # cast dialog xbmc.executebuiltin("ActivateWindow(busydialog)") if sys.version_info.major == 3: from .dialogselect import DialogSelect else: from dialogselect import DialogSelect results = [] name = try_decode(listitem.getLabel()) items = self.mutils.kodidb.castmedia(name) items = self.mutils.process_method_on_list(self.mutils.kodidb.prepare_listitem, items) for item in items: if item["file"].startswith("videodb://"): item["file"] = "ActivateWindow(Videos,%s,return)" % item["file"] else: item["file"] = 'PlayMedia("%s")' % item["file"] results.append(self.mutils.kodidb.create_listitem(item, False)) # finished lookup - display listing with results xbmc.executebuiltin("dialog.Close(busydialog)") dialog = DialogSelect("DialogSelect.xml", "", listing=results, windowtitle=name, richlayout=True) dialog.doModal() result = dialog.result del dialog if result: xbmc.executebuiltin(result.getLabel()) self.close_dialog() else: # video file: start playback xbmc.executebuiltin('PlayMedia("%s")' % listitem.getLabel()) self.close_dialog()
def open_item(self): '''open selected item''' control_id = self.getFocusId() listitem = self.getControl(control_id).getSelectedItem() if "videodb:" in listitem.getfilename(): # tvshow: open path xbmc.executebuiltin('ReplaceWindow(Videos,"%s")' % self.listitem.getfilename()) self.close_dialog() elif "actor" in listitem.getProperty("DBTYPE"): # cast dialog xbmc.executebuiltin("ActivateWindow(busydialog)") from dialogselect import DialogSelect results = [] kodidb = KodiDb() name = listitem.getLabel().decode("utf-8") items = kodidb.castmedia(name) items = process_method_on_list(kodidb.prepare_listitem, items) for item in items: if item["file"].startswith("videodb://"): item["file"] = "ActivateWindow(Videos,%s,return)" % item["file"] else: item["file"] = 'PlayMedia("%s")' % item["file"] results.append(kodidb.create_listitem(item, False)) # finished lookup - display listing with results xbmc.executebuiltin("dialog.Close(busydialog)") dialog = DialogSelect("DialogSelect.xml", "", listing=results, windowtitle=name, richlayout=True) dialog.doModal() result = dialog.result del dialog if result: xbmc.executebuiltin(result.getfilename()) self.close_dialog() else: # video file: start playback xbmc.executebuiltin('PlayMedia("%s")' % listitem.getfilename()) self.close_dialog()
def select_image(self, skinstring, allow_multi=True, windowheader="", resource_addon="", skinhelper_backgrounds=False, current_value=""): '''helper which lets the user select an image or imagepath from resourceaddons or custom path''' xbmc.executebuiltin("ActivateWindow(busydialog)") images = [] if not windowheader: windowheader = self.addon.getLocalizedString(32020) if not current_value: current_value = xbmc.getInfoLabel("Skin.String(%s.label)" % skinstring).decode("utf-8") # none option images.append((self.addon.getLocalizedString(32001), "", "", "DefaultAddonNone.png")) # custom single images.append((self.addon.getLocalizedString(32004), "", "", "DefaultAddonPicture.png")) # custom multi if allow_multi: images.append((self.addon.getLocalizedString(32005), "", "", "DefaultFolder.png")) # backgrounds supplied in our special skinsettings.xml file skinimages = self.skinsettings if skinimages.get(skinstring): for item in skinimages[skinstring]: if not item["condition"] or getCondVisibility(item["condition"]): images.append((item["label"], item["value"], item["description"], item["icon"])) # backgrounds provided by skinhelper if skinhelper_backgrounds: from skinshortcuts import get_skinhelper_backgrounds for label, image in get_skinhelper_backgrounds(): images.append((label, image, "Skin Helper Backgrounds", xbmc.getInfoLabel(image))) # resource addon images if resource_addon: from resourceaddons import get_resourceimages images += get_resourceimages(resource_addon) # create listitems listitems = [] for label, imagepath, label2, icon in images: listitem = xbmcgui.ListItem(label=label, label2=label2, iconImage=icon) listitem.setPath(imagepath) listitems.append(listitem) # show select dialog with choices dialog = DialogSelect("DialogSelect.xml", "", listing=listitems, windowtitle=windowheader, richlayout=True, getmorebutton=resource_addon, autofocuslabel=current_value) xbmc.executebuiltin("Dialog.Close(busydialog)") dialog.doModal() result = dialog.result del dialog if isinstance(result, bool): if result: # refresh listing requested by getmore button return self.select_image(skinstring, allow_multi, windowheader, resource_addon, skinhelper_backgrounds, current_value) elif result: label = result.getLabel().decode("utf-8") if label == self.addon.getLocalizedString(32004): # browse for single image custom_image = SkinSettings().save_skin_image(skinstring, False, self.addon.getLocalizedString(32004)) if custom_image: result.setPath(custom_image) else: return self.selectimage() elif label == self.addon.getLocalizedString(32005): # browse for image path custom_image = SkinSettings().save_skin_image(skinstring, True, self.addon.getLocalizedString(32005)) if custom_image: result.setPath(custom_image) else: return self.selectimage() # return values return (result.getLabel().decode("utf-8"), result.getfilename().decode("utf-8")) # return empty values return ("", "")
def setresourceaddon(addontype, skinstring="", header=""): '''helper to let the user choose a resource addon and set that as skin string''' xbmc.executebuiltin("ActivateWindow(busydialog)") cur_value = xbmc.getInfoLabel("Skin.String(%s.name)" % skinstring).decode("utf-8") listing = [] addon = xbmcaddon.Addon(ADDON_ID) if not header: header = addon.getLocalizedString(32010) # none option listitem = xbmcgui.ListItem(label=addon.getLocalizedString(32001), iconImage="DefaultAddonNone.png") listitem.setProperty("addonid", "none") listing.append(listitem) # custom path listitem = xbmcgui.ListItem(label=addon.getLocalizedString(32009), iconImage="DefaultFolder.png") listitem.setProperty("addonid", "custom") listing.append(listitem) # available resource addons for item in get_resourceaddons(addontype): label2 = "%s: %s" % (xbmc.getLocalizedString(21863), item["author"]) listitem = xbmcgui.ListItem(label=item["name"], label2=label2, iconImage=item["thumbnail"]) listitem.setPath(item["path"]) listitem.setProperty("addonid", item["addonid"]) listing.append(listitem) # special skinhelper paths if addontype == "resource.images.moviegenrefanart": label = addon.getLocalizedString(32019) listitem = xbmcgui.ListItem( label=label, label2="Skin Helper Service", iconImage="special://home/addons/script.skin.helper.service/icon.png") listitem.setPath("plugin://script.skin.helper.service/?action=moviegenrebackground&genre=") listitem.setProperty("addonid", "skinhelper.forgenre") listing.append(listitem) # show select dialog with choices dialog = DialogSelect("DialogSelect.xml", "", listing=listing, windowtitle=header, richlayout=True, getmorebutton=addontype, autofocuslabel=cur_value) dialog.doModal() result = dialog.result del dialog # process selection... if isinstance(result, bool) and result: # refresh listing requested by getmore button del addon return setresourceaddon(addontype, skinstring) elif result: addon_id = result.getProperty("addonid") addon_name = result.getLabel().decode("utf-8") if addon_id == "none" and skinstring: # None xbmc.executebuiltin('Skin.Reset(%s)' % skinstring) xbmc.executebuiltin('Skin.Reset(%s.ext)' % skinstring) xbmc.executebuiltin('Skin.SetString(%s.name,%s)' % (skinstring, addon_name)) xbmc.executebuiltin('Skin.SetString(%s.label,%s)' % (skinstring, addon_name)) xbmc.executebuiltin('Skin.Reset(%s.path)' % skinstring) xbmc.executebuiltin('Skin.Reset(%s.multi)' % skinstring) else: if addon_id == "custom": # custom path dialog = xbmcgui.Dialog() custom_path = dialog.browse(0, addon.getLocalizedString(32005), 'files') del dialog result.setPath(custom_path) addonpath = result.getfilename().decode("utf-8") if addonpath: is_multi, extension = get_multi_extension(addonpath) xbmc.executebuiltin('Skin.SetString(%s,%s)' % (skinstring, addonpath)) xbmc.executebuiltin('Skin.SetString(%s.path,%s)' % (skinstring, addonpath)) xbmc.executebuiltin('Skin.SetString(%s.name,%s)' % (skinstring, addon_name)) xbmc.executebuiltin('Skin.SetString(%s.label,%s)' % (skinstring, addon_name)) xbmc.executebuiltin('Skin.SetString(%s.ext,%s)' % (skinstring, extension)) if is_multi: xbmc.executebuiltin('Skin.SetBool(%s.multi)' % skinstring) else: xbmc.executebuiltin('Skin.Reset(%s.multi)' % skinstring) del addon
def set_skin_setting(self, setting="", window_header="", sublevel="", cur_value_label="", skip_skin_string=False, original_id="", cur_value=""): '''allows the skinner to use a select dialog to set all kind of skin settings''' if not cur_value_label: cur_value_label = xbmc.getInfoLabel("Skin.String(%s.label)" % setting).decode("utf-8") if not cur_value: cur_value = xbmc.getInfoLabel("Skin.String(%s)" % setting).decode("utf-8") rich_layout = False listitems = [] if sublevel: listitem = xbmcgui.ListItem(label="..", iconImage="DefaultFolderBack.png") listitem.setProperty("icon", "DefaultFolderBack.png") listitem.setProperty("value", "||BACK||") listitems.append(listitem) all_values = self.skinsettings.get(sublevel, []) elif original_id: all_values = self.skinsettings.get(original_id, []) else: all_values = self.skinsettings.get(setting, []) for item in all_values: if not item["condition"] or xbmc.getCondVisibility(item["condition"]): value = item["value"] icon = item["icon"] if icon: rich_layout = True label = item["label"] if "%" in label: label = label % value if value == "||MULTISELECT||" or item["settingoptions"]: return self.multi_select(item["settingoptions"], window_header) listitem = xbmcgui.ListItem(label, iconImage=icon, label2=item["description"]) listitem.setProperty("value", value) listitem.setProperty("icon", icon) listitem.setProperty("description", item["description"]) listitem.setProperty("onselectactions", repr(item["onselectactions"])) listitems.append(listitem) # show select dialog dialog = DialogSelect("DialogSelect.xml", "", listing=listitems, windowtitle=window_header, richlayout=rich_layout, autofocuslabel=cur_value_label) dialog.doModal() selected_item = dialog.result del dialog # process the results if selected_item: value = selected_item.getProperty("value").decode("utf-8") label = selected_item.getLabel().decode("utf-8") if value.startswith("||SUBLEVEL||"): sublevel = value.replace("||SUBLEVEL||", "") self.set_skin_setting(setting, window_header, sublevel) elif value == "||BACK||": self.set_skin_setting(setting, window_header) else: if value == "||BROWSEIMAGE||": value = self.save_skin_image(setting, True, label) if value == "||BROWSESINGLEIMAGE||": value = self.save_skin_image(setting, False, label) if value == "||BROWSEMULTIIMAGE||": value = self.save_skin_image(setting, True, label) if value == "||PROMPTNUMERIC||": value = xbmcgui.Dialog().input(label, cur_value, 1).decode("utf-8") if value == "||PROMPTSTRING||": value = xbmcgui.Dialog().input(label, cur_value, 0).decode("utf-8") if value == "||PROMPTSTRINGASNUMERIC||": validinput = False while not validinput: try: value = xbmcgui.Dialog().input(label, cur_value, 0).decode("utf-8") valueint = int(value) validinput = True del valueint except Exception: value = xbmcgui.Dialog().notification("Invalid input", "Please enter a number...") # write skin strings if not skip_skin_string and value != "||SKIPSTRING||": xbmc.executebuiltin("Skin.SetString(%s,%s)" % (setting.encode("utf-8"), value.encode("utf-8"))) xbmc.executebuiltin("Skin.SetString(%s.label,%s)" % (setting.encode("utf-8"), label.encode("utf-8"))) # process additional actions onselectactions = selected_item.getProperty("onselectactions") if onselectactions: for action in eval(onselectactions): if not action["condition"] or xbmc.getCondVisibility(action["condition"]): xbmc.executebuiltin(action["command"]) return (value, label) else: return (None, None)
def select_image(self, skinstring, allow_multi=True, windowheader="", resource_addon="", skinhelper_backgrounds=False, current_value=""): '''helper which lets the user select an image or imagepath from resourceaddons or custom path''' xbmc.executebuiltin("ActivateWindow(busydialog)") images = [] if not windowheader: windowheader = self.addon.getLocalizedString(32020) if not current_value: current_value = xbmc.getInfoLabel("Skin.String(%s.label)" % skinstring).decode("utf-8") # none option images.append((self.addon.getLocalizedString(32001), "", "", "DefaultAddonNone.png")) # custom single images.append((self.addon.getLocalizedString(32004), "", "", "DefaultAddonPicture.png")) # custom multi if allow_multi: images.append((self.addon.getLocalizedString(32005), "", "", "DefaultFolder.png")) # backgrounds supplied in our special skinsettings.xml file skinimages = self.skinsettings if skinimages.get(skinstring): for item in skinimages[skinstring]: if not item["condition"] or xbmc.getCondVisibility(item["condition"]): images.append((item["label"], item["value"], item["description"], item["icon"])) # backgrounds provided by skinhelper if skinhelper_backgrounds: from skinshortcuts import get_skinhelper_backgrounds for label, image in get_skinhelper_backgrounds(): images.append((label, image, "Skin Helper Backgrounds", xbmc.getInfoLabel(image))) # resource addon images if resource_addon: from resourceaddons import get_resourceimages images += get_resourceimages(resource_addon) # create listitems listitems = [] for label, imagepath, label2, icon in images: listitem = xbmcgui.ListItem(label=label, label2=label2, iconImage=icon) listitem.setPath(imagepath) listitems.append(listitem) # show select dialog with choices dialog = DialogSelect("DialogSelect.xml", "", listing=listitems, windowtitle=windowheader, richlayout=True, getmorebutton=resource_addon, autofocuslabel=current_value) xbmc.executebuiltin("Dialog.Close(busydialog)") dialog.doModal() result = dialog.result del dialog if isinstance(result, bool): if result: # refresh listing requested by getmore button return self.select_image(skinstring, allow_multi, windowheader, resource_addon, skinhelper_backgrounds, current_value) elif result: label = result.getLabel().decode("utf-8") if label == self.addon.getLocalizedString(32004): # browse for single image custom_image = SkinSettings().save_skin_image(skinstring, False, self.addon.getLocalizedString(32004)) if custom_image: result.setPath(custom_image) else: return self.selectimage() elif label == self.addon.getLocalizedString(32005): # browse for image path custom_image = SkinSettings().save_skin_image(skinstring, True, self.addon.getLocalizedString(32005)) if custom_image: result.setPath(custom_image) else: return self.selectimage() # return values return (result.getLabel().decode("utf-8"), result.getfilename().decode("utf-8")) # return empty values return ("", "")
def colorthemes(self): '''show dialog with all available color themes''' listitems = [] # create item listitem = xbmcgui.ListItem(label=self.addon.getLocalizedString(32035), iconImage="DefaultAddonSkin.png") listitem.setLabel2(self.addon.getLocalizedString(32036)) listitem.setPath("add") listitems.append(listitem) # import item listitem = xbmcgui.ListItem(label=self.addon.getLocalizedString(32037), iconImage="DefaultAddonSkin.png") listitem.setLabel2(self.addon.getLocalizedString(32038)) listitem.setPath("import") listitems.append(listitem) # get all skin and user defined themes listitems += self.get_skin_colorthemes() listitems += self.get_user_colorthemes() # show dialog and list options header = self.addon.getLocalizedString(32020) dialog = DialogSelect("DialogSelect.xml", "", windowtitle=header, richlayout=True, listing=listitems) dialog.doModal() result = dialog.result del dialog if result: themefile = result.getfilename().decode("utf-8") themename = result.getLabel().decode("utf-8") has_icon = xbmcvfs.exists(themefile.replace(".theme", ".jpg")) if themefile == "add": # create new colortheme self.create_colortheme() self.colorthemes() elif themefile == "import": # import theme file self.restore_colortheme() self.colorthemes() elif self.skinthemes_path in themefile: # load skin provided theme self.load_colortheme(themefile) else: # show contextmenu for user custom theme menuoptions = [] menuoptions.append(self.addon.getLocalizedString(32021)) menuoptions.append(xbmc.getLocalizedString(117)) if not has_icon: menuoptions.append(xbmc.getLocalizedString(19285)) menuoptions.append(self.addon.getLocalizedString(32022)) ret = xbmcgui.Dialog().select(themename, menuoptions) if ret == 0: self.load_colortheme(themefile) elif ret == 1: self.remove_theme(themefile) elif ret == 2 and not has_icon: self.set_icon_for_theme(themefile) elif ret == 3 or (ret == 2 and has_icon): self.backup_theme(themename) if not ret == 0: # show selection dialog again self.colorthemes()
def set_skin_setting(self, setting="", window_header="", sublevel="", cur_value_label="", skip_skin_string=False, original_id="", cur_value=""): '''allows the skinner to use a select dialog to set all kind of skin settings''' if not cur_value_label: cur_value_label = xbmc.getInfoLabel("Skin.String(%s.label)" % setting).decode("utf-8") if not cur_value: cur_value = xbmc.getInfoLabel("Skin.String(%s)" % setting).decode("utf-8") rich_layout = False listitems = [] if sublevel: listitem = xbmcgui.ListItem(label="..", iconImage="DefaultFolderBack.png") listitem.setProperty("icon", "DefaultFolderBack.png") listitem.setProperty("value", "||BACK||") listitems.append(listitem) all_values = self.skinsettings.get(sublevel, []) elif original_id: all_values = self.skinsettings.get(original_id, []) else: all_values = self.skinsettings.get(setting, []) for item in all_values: if not item["condition"] or getCondVisibility(item["condition"]): value = item["value"] icon = item["icon"] if icon: rich_layout = True label = item["label"] if "%" in label: label = label % value if value == "||MULTISELECT||" or item["settingoptions"]: return self.multi_select(item["settingoptions"], window_header) listitem = xbmcgui.ListItem(label, iconImage=icon, label2=item["description"]) listitem.setProperty("value", value) listitem.setProperty("icon", icon) listitem.setProperty("description", item["description"]) listitem.setProperty("onselectactions", repr(item["onselectactions"])) listitems.append(listitem) # show select dialog dialog = DialogSelect("DialogSelect.xml", "", listing=listitems, windowtitle=window_header, richlayout=rich_layout, autofocuslabel=cur_value_label) dialog.doModal() selected_item = dialog.result del dialog # process the results if selected_item: value = selected_item.getProperty("value").decode("utf-8") label = selected_item.getLabel().decode("utf-8") if value.startswith("||SUBLEVEL||"): sublevel = value.replace("||SUBLEVEL||", "") self.set_skin_setting(setting, window_header, sublevel) elif value == "||BACK||": self.set_skin_setting(setting, window_header) else: if value == "||BROWSEIMAGE||": value = self.save_skin_image(setting, True, label) if value == "||BROWSESINGLEIMAGE||": value = self.save_skin_image(setting, False, label) if value == "||BROWSEMULTIIMAGE||": value = self.save_skin_image(setting, True, label) if value == "||PROMPTNUMERIC||": value = xbmcgui.Dialog().input(label, cur_value, 1).decode("utf-8") if value == "||PROMPTSTRING||": value = xbmcgui.Dialog().input(label, cur_value, 0).decode("utf-8") if value == "||PROMPTSTRINGASNUMERIC||": validinput = False while not validinput: try: value = xbmcgui.Dialog().input(label, cur_value, 0).decode("utf-8") valueint = int(value) validinput = True del valueint except Exception: value = xbmcgui.Dialog().notification("Invalid input", "Please enter a number...") # write skin strings if not skip_skin_string and value != "||SKIPSTRING||": xbmc.executebuiltin("Skin.SetString(%s,%s)" % (setting.encode("utf-8"), value.encode("utf-8"))) xbmc.executebuiltin("Skin.SetString(%s.label,%s)" % (setting.encode("utf-8"), label.encode("utf-8"))) # process additional actions onselectactions = selected_item.getProperty("onselectactions") if onselectactions: for action in eval(onselectactions): if not action["condition"] or getCondVisibility(action["condition"]): xbmc.executebuiltin(action["command"]) return (value, label) else: return (None, None)