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 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 getCondVisibility("System.HasAddon(%s)" % item["addonid"]):
            label2 = "%s: %s" % (xbmc.getLocalizedString(21863),
                                 item["author"])
            listitem = xbmcgui.ListItem(label=item["name"], label2=label2)
            listitem.setArt({"icon": 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 = 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)
        listitem.setArt({'icon': "defaultfolder.png"})
        listitem.setPath("backup")
        listitems.append(listitem)

        # list existing backups
        backuppath = self.get_backuppath()
        if backuppath:
            for backupfile in sorted(xbmcvfs.listdir(backuppath)[1],
                                     reverse=True):
                backupfile = backupfile
                if "Skinbackup" in backupfile and backupfile.endswith(".zip"):
                    label = "%s: %s" % (self.addon.getLocalizedString(32015),
                                        backupfile)
                    listitem = xbmcgui.ListItem(label=label)
                    listitem.setArt({'icon': "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.getPath() == "backup":
                    # create new backup
                    self.backup(backup_file=self.get_backupfilename())
                else:
                    # restore backup
                    self.restore(result.getPath())
                # always open the dialog again
                self.backuprestore()
예제 #5
0
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 = try_decode(xbmc.getInfoLabel("Skin.String(%s.name)" % skinstring))
    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 = try_decode(result.getLabel())
        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 = try_decode(result.getfilename())
            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 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 = try_decode(
                xbmc.getInfoLabel("Skin.String(%s.label)" % skinstring))

        # 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:
            if sys.version_info.major == 3:
                from .skinshortcuts import get_skinhelper_backgrounds
            else:
                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:
            if sys.version_info.major == 3:
                from .resourceaddons import get_resourceimages
            else:
                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)
            listitem.setArt({'icon': icon, 'thumb': icon, 'fanart': 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 = try_decode(result.getLabel())
            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 (try_decode(result.getLabel()),
                    try_decode(result.getPath()))
        # return empty values
        return ("", "")
    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)
        if not cur_value:
            cur_value = xbmc.getInfoLabel("Skin.String(%s)" % setting)
        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, label2=item["description"])
                listitem.setArt({'icon': icon})
                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")
            label = selected_item.getLabel()
            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)
                if value == "||PROMPTSTRING||":
                    value = xbmcgui.Dialog().input(label, cur_value, 0)
                if value == "||PROMPTSTRINGASNUMERIC||":
                    validinput = False
                    while not validinput:
                        try:
                            value = xbmcgui.Dialog().input(label, cur_value, 0)
                            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, value))
                    xbmc.executebuiltin("Skin.SetString(%s.label,%s)" %
                                        (setting, label))
                # 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)
    def colorthemes(self):
        '''show dialog with all available color themes'''
        listitems = []
        # create item
        listitem = xbmcgui.ListItem(label=self.addon.getLocalizedString(32035))
        listitem.setArt({"icon": "DefaultAddonSkin.png"})
        listitem.setLabel2(self.addon.getLocalizedString(32036))
        listitem.setPath("add")
        listitems.append(listitem)
        # import item
        listitem = xbmcgui.ListItem(label=self.addon.getLocalizedString(32037))
        listitem.setArt({"icon": "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()