Exemple #1
0
 def backup_theme(self, themename):
     """backup a colortheme to a zipfile"""
     import zipfile
     backup_path = xbmcgui.Dialog().browse(
         3, self.addon.getLocalizedString(32029), "files").decode("utf-8")
     if backup_path:
         busyDialog("activate")
         backup_name = u"%s ColorTheme - %s" % (
             get_skin_name().capitalize(), themename)
         backupfile = os.path.join(backup_path, backup_name + u".zip")
         zip_temp = u'special://temp/%s.zip' % backup_name
         xbmcvfs.delete(zip_temp)
         xbmcvfs.delete(backupfile)
         zip_temp = xbmc.translatePath(zip_temp).decode("utf-8")
         zip_file = zipfile.ZipFile(zip_temp, "w", zipfile.ZIP_DEFLATED)
         abs_src = os.path.abspath(
             xbmc.translatePath(self.userthemes_path).decode("utf-8"))
         for filename in xbmcvfs.listdir(self.userthemes_path)[1]:
             if (filename.startswith("%s_" % themename) or filename.replace(
                     ".theme", "").replace(".jpg", "") == themename):
                 filename = filename.decode("utf-8")
                 filepath = xbmc.translatePath(self.userthemes_path +
                                               filename).decode("utf-8")
                 absname = os.path.abspath(filepath)
                 arcname = absname[len(abs_src) + 1:]
                 zip_file.write(absname, arcname)
         zip_file.close()
         xbmcvfs.copy(zip_temp, backupfile)
         busyDialog("close")
def downloadresourceaddons(addontype):
    """show dialog with all available resource addons on the repo so the user can install one"""
    busyDialog("activate")
    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,
                                        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 = 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()
Exemple #4
0
"""
    script.skin.helper.service
    Contextmenu for Pvr art
"""

import xbmc
import xbmcgui
from metadatautils import MetadataUtils
from utils import busyDialog

# pylint: disable-msg=invalid-constant-name

# Kodi contextmenu item to configure pvr artwork
if __name__ == '__main__':

    ##### PVR Artwork ########
    win = xbmcgui.Window(10000)
    win.setProperty("SkinHelper.Artwork.ManualLookup", "busy")
    busyDialog("activate")
    title = xbmc.getInfoLabel("ListItem.Title").decode('utf-8')
    if not title:
        title = xbmc.getInfoLabel("ListItem.Label").decode('utf-8')
    channel = xbmc.getInfoLabel("ListItem.ChannelName").decode('utf-8')
    genre = xbmc.getInfoLabel("ListItem.Genre").decode('utf-8')
    metadatautils = MetadataUtils()
    metadatautils.pvr_artwork_options(title, channel, genre)
    busyDialog("close")
    win.clearProperty("SkinHelper.Artwork.ManualLookup")
    metadatautils.close()
    del win
    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"""
        busyDialog("activate")
        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)
        busyDialog("close")
        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 "", ""
Exemple #6
0
    def create_colortheme(self):
        """create a colortheme from current skin color settings"""
        try:
            current_skinfont = None
            json_response = kodi_json("Settings.GetSettingValue",
                                      {"setting": "lookandfeel.font"})
            if json_response:
                current_skinfont = json_response
            current_skincolors = None
            json_response = kodi_json("Settings.GetSettingValue",
                                      {"setting": "lookandfeel.skincolors"})
            if json_response:
                current_skincolors = json_response

            # user has to enter name for the theme
            themename = xbmcgui.Dialog().input(
                self.addon.getLocalizedString(32023),
                type=xbmcgui.INPUT_ALPHANUM).decode("utf-8")
            if not themename:
                return

            busyDialog("activate")
            xbmc.executebuiltin(
                "Skin.SetString(SkinHelper.LastColorTheme,%s)" %
                themename.encode("utf-8"))

            # add screenshot
            custom_thumbnail = xbmcgui.Dialog().browse(
                2, self.addon.getLocalizedString(32024), 'files')

            if custom_thumbnail:
                xbmcvfs.copy(custom_thumbnail,
                             self.userthemes_path + themename + ".jpg")

            # read the guisettings file to get all skin settings
            from backuprestore import BackupRestore
            skinsettingslist = BackupRestore().get_skinsettings([
                "color", "opacity", "texture", "panel", "colour", "background",
                "image"
            ])
            newlist = []
            if skinsettingslist:
                newlist.append(("THEMENAME", themename))
                newlist.append(
                    ("DESCRIPTION", self.addon.getLocalizedString(32025)))
                newlist.append(
                    ("SKINTHEME", xbmc.getInfoLabel("Skin.CurrentTheme")))
                newlist.append(("SKINFONT", current_skinfont))
                newlist.append(("SKINCOLORS", current_skincolors))

                # look for any images in the skin settings and translate them so they can
                # be included in the theme backup
                for skinsetting in skinsettingslist:
                    setting_type = skinsetting[0]
                    setting_name = skinsetting[1]
                    setting_value = skinsetting[2]
                    if setting_type == "string" and setting_value:
                        if (setting_value
                                and (setting_value.endswith(".png")
                                     or setting_value.endswith(".gif")
                                     or setting_value.endswith(".jpg"))
                                and "resource://" not in setting_value):
                            image = get_clean_image(setting_value)
                            extension = image.split(".")[-1]
                            newimage = "%s_%s.%s" % (
                                themename, normalize_string(setting_name),
                                extension)
                            newimage_path = self.userthemes_path + newimage
                            if xbmcvfs.exists(image):
                                xbmcvfs.copy(image, newimage_path)
                                skinsetting = (setting_type, setting_name,
                                               newimage_path)
                    newlist.append(skinsetting)

                # save guisettings
                text_file_path = self.userthemes_path + themename + ".theme"
                text_file = xbmcvfs.File(text_file_path, "w")
                text_file.write(repr(newlist))
                text_file.close()
                busyDialog("close")
                xbmcgui.Dialog().ok(self.addon.getLocalizedString(32026),
                                    self.addon.getLocalizedString(32027))
        except Exception as exc:
            busyDialog("close")
            log_exception(__name__, exc)
            xbmcgui.Dialog().ok(self.addon.getLocalizedString(32028),
                                self.addon.getLocalizedString(32030), str(exc))
Exemple #7
0
    def load_colortheme(filename):
        """load colortheme from themefile"""
        busyDialog("activate")
        xbmcfile = xbmcvfs.File(filename)
        data = xbmcfile.read()
        xbmcfile.close()
        importstring = eval(data)
        skintheme = None
        skincolor = None
        skinfont = None
        current_skintheme = xbmc.getInfoLabel("Skin.CurrentTheme").decode(
            "utf-8")

        current_skinfont = None
        json_response = kodi_json("Settings.GetSettingValue",
                                  {"setting": "lookandfeel.font"})
        if json_response:
            current_skinfont = json_response
        current_skincolors = None
        json_response = kodi_json("Settings.GetSettingValue",
                                  {"setting": "lookandfeel.skincolors"})
        if json_response:
            current_skincolors = json_response

        settingslist = set()
        for skinsetting in importstring:
            if skinsetting[0] == "SKINTHEME":
                skintheme = skinsetting[1].decode('utf-8')
            elif skinsetting[0] == "SKINCOLORS":
                skincolor = skinsetting[1]
            elif skinsetting[0] == "SKINFONT":
                skinfont = skinsetting[1]
            elif skinsetting[0] == "THEMENAME":
                xbmc.executebuiltin(
                    "Skin.SetString(SkinHelper.LastColorTheme,%s)" %
                    skinsetting[1])
            elif skinsetting[0] == "DESCRIPTION":
                xbmc.executebuiltin(
                    "Skin.SetString(SkinHelper.LastColorTheme.Description,%s)"
                    % skinsetting[1])
            elif skinsetting[1].startswith("SkinHelper.ColorTheme"):
                continue
            else:
                setting = skinsetting[1]
                if isinstance(setting, unicode):
                    setting = setting.encode("utf-8")
                if setting not in settingslist:
                    settingslist.add(setting)
                    if skinsetting[0] == "string":
                        if skinsetting[2] is not "":
                            xbmc.executebuiltin("Skin.SetString(%s,%s)" %
                                                (setting, skinsetting[2]))
                        else:
                            xbmc.executebuiltin("Skin.Reset(%s)" % setting)
                    elif skinsetting[0] == "bool":
                        if skinsetting[2] == "true":
                            xbmc.executebuiltin("Skin.SetBool(%s)" % setting)
                        else:
                            xbmc.executebuiltin("Skin.Reset(%s)" % setting)
                    xbmc.sleep(30)

        # change the skintheme, color and font if needed
        if skintheme and current_skintheme != skintheme:
            kodi_json("Settings.SetSettingValue", {
                "setting": "lookandfeel.skintheme",
                "value": skintheme
            })
        if skincolor and current_skincolors != skincolor:
            kodi_json("Settings.SetSettingValue", {
                "setting": "lookandfeel.skincolors",
                "value": skincolor
            })
        if skinfont and current_skinfont != skinfont and current_skinfont.lower(
        ) != "arial":
            kodi_json("Settings.SetSettingValue", {
                "setting": "lookandfeel.font",
                "value": skinfont
            })

        busyDialog("close")
def setresourceaddon(addontype, skinstring="", header=""):
    """helper to let the user choose a resource addon and set that as skin string"""
    busyDialog("activate")
    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