def next_path(group_id):
    _window = utils.get_active_window()

    if _window not in ['home', 'media'] and not label_warning_shown:
        _warn()

    group = manage.get_group_by_id(group_id)
    if not group:
        utils.log(
            '\"{}\" is missing, please repoint the widget to fix it.'.format(
                group_id),
            level=xbmc.LOGERROR)
        return False, 'AutoWidget'

    group_name = group.get('label', '')
    paths = manage.find_defined_paths(group_id)

    if len(paths) > 0:
        if _window == 'media':
            call_path(group_id, paths[0]['id'])
            return False, group_name
        else:
            directory.add_menu_item(title=32013,
                                    params={'mode': 'force'},
                                    art=unpack,
                                    info={'plot': utils.get_string(32014)},
                                    isFolder=False)
            return True, group_name
    else:
        directory.add_menu_item(title=32032, art=alert, isFolder=False)
        return False, group_name
示例#2
0
def _copy_path(path_def):
    group_id = add_group(path_def["target"], path_def["label"])
    if not group_id:
        return

    progress = xbmcgui.DialogProgressBG()
    progress.create("AutoWidget", utils.get_string(30143))
    progress.update(1, "AutoWidget", utils.get_string(30144))

    group_def = manage.get_group_by_id(group_id)
    files, hash = refresh.get_files_list(path_def["file"]["file"], background=False)
    if not files:
        progress.close()
        return
    done = 0
    for file in files:
        done += 1
        if file["type"] in ["movie", "episode", "musicvideo", "song"]:
            continue
        progress.update(
            int(done / float(len(files)) * 100),
            heading=utils.get_string(30143),
            message=file.get("label"),
        )

        labels = build_labels("json", file, path_def["target"])
        _add_path(group_def, labels, over=True)
    progress.close()
    del progress
    dialog = xbmcgui.Dialog()
    dialog.notification(
        "AutoWidget", utils.get_string(30105).format(len(files), group_def["label"])
    )
    del dialog
示例#3
0
def copy_group(group_id, type):
    old_group_def = manage.get_group_by_id(group_id)

    new_group_id = add_group(type, old_group_def.get("label"))
    if not new_group_id:
        return
    new_group_def = manage.get_group_by_id(new_group_id)
    new_group_def["art"] = old_group_def.get("art", {})
    new_group_def["content"] = old_group_def.get(
        "content", new_group_def.get("content", "files"))

    paths = old_group_def.get("paths", [])
    new_group_def["paths"] = manage.choose_paths(utils.get_string(30121),
                                                 paths,
                                                 indices=False)
    manage.write_path(new_group_def)

    utils.update_container()
示例#4
0
def group_menu(group_id):
    _window = utils.get_active_window()
    _id = uuid.uuid4()

    group_def = manage.get_group_by_id(group_id)
    if not group_def:
        utils.log(
            '"{}" is missing, please repoint the widget to fix it.'.format(
                group_id),
            "error",
        )
        return False, "AutoWidget", None

    group_name = group_def["label"]
    group_type = group_def["type"]
    paths = group_def["paths"]
    content = group_def.get("content")

    if len(paths) > 0:
        utils.log(
            u"Showing {} group: {}".format(group_type,
                                           six.text_type(group_name)),
            "debug",
        )
        cm = []
        art = folder_shortcut if group_type == "shortcut" else folder_sync

        for idx, path_def in enumerate(paths):
            if _window == "media":
                cm = _create_path_context_items(group_id, path_def["id"], idx,
                                                len(paths), group_type)

            directory.add_menu_item(
                title=path_def["label"],
                params={
                    "mode": "path",
                    "group": group_id,
                    "path_id": path_def["id"]
                },
                info=path_def["file"],
                art=path_def["file"].get("art", art),
                cm=cm,
                isFolder=False,
            )

        if _window != "home":
            _create_action_items(group_def, _id)
    else:
        directory.add_menu_item(
            title=30019,
            art=utils.get_art("alert"),
            isFolder=False,
            props={"specialsort": "bottom"},
        )

    return True, group_name, content
def _remove_group(group_id, over=False):
    group_def = manage.get_group_by_id(group_id)
    group_name = group_def['label']
    if not over:
        choice = dialog.yesno('AutoWidget', utils.get_string(32039))

    if over or choice:
        file = os.path.join(utils._addon_path, '{}.group'.format(group_id))
        utils.remove_file(file)
        dialog.notification('AutoWidget',
                            utils.get_string(32045).format(group_name))
示例#6
0
def _remove_group(group_id, over=False):
    group_def = manage.get_group_by_id(group_id)
    group_name = group_def["label"]
    if not over:
        choice = dialog.yesno("AutoWidget", utils.get_string(32039))

    if over or choice:
        file = os.path.join(utils._addon_path, "{}.group".format(group_id))
        utils.remove_file(file)
        dialog.notification(
            "AutoWidget",
            utils.get_string(32045).format(six.text_type(group_name)))
示例#7
0
def merged_path(group_id, widget_id):
    _window = utils.get_active_window()

    group_def = manage.get_group_by_id(group_id)
    group_name = group_def.get("label", "")
    paths = group_def.get("paths", [])
    if len(paths) == 0:
        directory.add_menu_item(title=30019,
                                art=utils.get_art("alert"),
                                isFolder=False)
        return True, group_name, None

    widget_def = manage.get_widget_by_id(widget_id, group_id)
    if widget_def and _window != "dialog":
        paths = widget_def["path"]
    elif not widget_def:
        idxs = manage.choose_paths(utils.get_string(30089), paths, 5)

        if idxs is not None:
            if len(idxs) > 0:
                widget_def = manage.initialize(group_def,
                                               "merged",
                                               widget_id,
                                               keep=idxs)
                paths = widget_def["path"]

    if widget_def:
        titles = []
        for idx, path in enumerate(paths):
            # simple compatibility with pre-3.3.0 widgets
            if isinstance(path, dict):
                path = path.get("id", "")
                paths[idx] = path
                widget_def["path"] = paths
                manage.save_path_details(widget_def)

            path_def = manage.get_path_by_id(path, group_id)
            titles, cat, type = show_path(
                group_id,
                path_def["label"],
                widget_id,
                path_def,
                idx=idx,
                titles=titles,
                num=len(paths),
                merged=True,
            )

        return titles, cat, type
    else:
        directory.add_menu_item(title=30045, art=info, isFolder=True)
        return True, group_name, None
示例#8
0
def merged_path(group_id, widget_id):
    _window = utils.get_active_window()

    group_def = manage.get_group_by_id(group_id)
    group_name = group_def.get("label", "")
    paths = group_def.get("paths", [])
    if len(paths) == 0:
        directory.add_menu_item(title=32032,
                                art=utils.get_art("alert"),
                                isFolder=False)
        return True, group_name

    widget_def = manage.get_widget_by_id(widget_id, group_id)
    if widget_def and _window != "dialog":
        paths = widget_def["path"]
    elif not widget_def:
        dialog = xbmcgui.Dialog()
        idxs = dialog.multiselect(
            utils.get_string(32115),
            [i["label"] for i in paths],
            preselect=list(range(len(paths))) if len(paths) <= 5 else [],
        )

        if idxs is not None:
            if len(idxs) > 0:
                widget_def = manage.initialize(group_def,
                                               "merged",
                                               widget_id,
                                               keep=idxs)
                paths = widget_def["path"]

    if widget_def:
        titles = []
        for idx, path_def in enumerate(paths):
            titles, cat = show_path(
                group_id,
                path_def["label"],
                widget_id,
                path_def["file"]["file"],
                idx=idx,
                titles=titles,
                num=len(paths),
                merged=True,
            )

        return titles, cat
    else:
        directory.add_menu_item(title=32067,
                                art=utils.get_art("information_outline"),
                                isFolder=True)
        return True, group_name
示例#9
0
def _remove_group(group_id, over=False):
    dialog = xbmcgui.Dialog()
    group_def = manage.get_group_by_id(group_id)
    group_name = group_def["label"]
    if not over:
        choice = dialog.yesno("AutoWidget", utils.get_string(30025))

    if over or choice:
        file = os.path.join(_addon_data, "{}.group".format(group_id))
        utils.remove_file(file)
        dialog.notification(
            "AutoWidget",
            utils.get_string(30030).format(six.text_type(group_name)))
    del dialog
def _remove_path(path_id, group_id, over=False):
    if not over:
        choice = dialog.yesno('AutoWidget', utils.get_string(32035))

    if over or choice:
        group_def = manage.get_group_by_id(group_id)
        paths = group_def['paths']
        for path_def in paths:
            if path_def['id'] == path_id:
                path_name = path_def['label']
                group_def['paths'].remove(path_def)
                dialog.notification('AutoWidget',
                                    utils.get_string(32045).format(path_name))
        manage.write_path(group_def)
示例#11
0
def _remove_path(path_id, group_id, over=False):
    if not over:
        choice = dialog.yesno("AutoWidget", utils.get_string(32035))

    if over or choice:
        group_def = manage.get_group_by_id(group_id)
        paths = group_def["paths"]
        for path_def in paths:
            if path_def["id"] == path_id:
                path_name = path_def["label"]
                group_def["paths"].remove(path_def)
                dialog.notification(
                    "AutoWidget",
                    utils.get_string(32045).format(six.text_type(path_name)),
                )
        manage.write_path(group_def)
def edit_dialog(group_id, path_id=None, base_key=None):
    updated = False
    if advanced and not warning_shown:
        _warn()

    group_def = manage.get_group_by_id(group_id)
    path_def = manage.get_path_by_id(path_id, group_id)
    if not group_def or path_id and not path_def:
        return

    updated = _show_options(group_def, path_def)
    if updated:
        manage.write_path(group_def, path_def=path_def, update=path_id)
        utils.update_container(group_def['type'] == 'shortcut')

        edit_dialog(group_id, path_id)
示例#13
0
def group_menu(group_id):
    _window = utils.get_active_window()
    _id = uuid.uuid4()

    group_def = manage.get_group_by_id(group_id)
    if not group_def:
        utils.log(
            '\"{}\" is missing, please repoint the widget to fix it.'.format(
                group_id), 'error')
        return False, 'AutoWidget'

    group_name = group_def['label']
    group_type = group_def['type']
    paths = group_def['paths']

    if len(paths) > 0:
        utils.log(
            u'Showing {} group: {}'.format(group_type,
                                           six.text_type(group_name)), 'debug')
        cm = []
        art = folder_shortcut if group_type == 'shortcut' else folder_sync

        for idx, path_def in enumerate(paths):
            if _window == 'media':
                cm = _create_context_items(group_id, path_def['id'], idx,
                                           len(paths), group_type)

            directory.add_menu_item(title=path_def['label'],
                                    params={
                                        'mode': 'path',
                                        'group': group_id,
                                        'path_id': path_def['id']
                                    },
                                    info=path_def['file'],
                                    art=path_def['file']['art'] or art,
                                    cm=cm,
                                    isFolder=False)

        if _window != 'home':
            _create_action_items(group_def, _id)
    else:
        directory.add_menu_item(title=32032,
                                art=utils.get_art('alert'),
                                isFolder=False,
                                props={'specialsort': 'bottom'})

    return True, group_name
示例#14
0
def merged_path(group_id, widget_id):
    _window = utils.get_active_window()

    group_def = manage.get_group_by_id(group_id)
    group_name = group_def.get('label', '')
    paths = group_def.get('paths', [])
    if len(paths) == 0:
        directory.add_menu_item(title=32032,
                                art=utils.get_art('alert'),
                                isFolder=False)
        return True, group_name

    widget_def = manage.get_widget_by_id(widget_id, group_id)
    if widget_def and _window != 'dialog':
        paths = widget_def['path']
    elif not widget_def:
        dialog = xbmcgui.Dialog()
        idxs = dialog.multiselect(
            utils.get_string(32115), [i['label'] for i in paths],
            preselect=list(range(len(paths))) if len(paths) <= 5 else [])

        if idxs is not None:
            if len(idxs) > 0:
                widget_def = manage.initialize(group_def,
                                               'merged',
                                               widget_id,
                                               keep=idxs)
                paths = widget_def['path']

    if widget_def:
        titles = []
        for idx, path_def in enumerate(paths):
            titles, cat = show_path(group_id,
                                    path_def['label'],
                                    widget_id,
                                    path_def['file']['file'],
                                    idx=idx,
                                    num=len(paths),
                                    merged=True)

        return titles, cat
    else:
        directory.add_menu_item(title=32067,
                                art=utils.get_art('information_outline'),
                                isFolder=True)
        return True, group_name
示例#15
0
def edit_dialog(group_id, path_id=''):
    dialog = xbmcgui.Dialog()
    updated = False
    if advanced and not warning_shown:
        _warn()

    group_def = manage.get_group_by_id(group_id)
    if not group_def:
        return
    if path_id:
        path_def = manage.get_path_by_id(path_id, group_id)
        if not path_def:
            return

    edit_def = path_def if path_id else group_def
    options = _get_options(edit_def)

    remove_label = utils.get_string(32025) if path_id else utils.get_string(
        32023)
    options.append('[COLOR firebrick]{}[/COLOR]'.format(remove_label))

    idx = dialog.select(utils.get_string(32048), options)
    if idx < 0:
        return
    elif idx == len(options) - 1:
        if path_id:
            _remove_path(path_id, group_id)
            utils.update_container(group_def['type'])
        else:
            _remove_group(group_id)
            utils.update_container(group_def['type'])
        return
    else:
        key = _clean_key(options[idx])

    updated = _get_value(edit_def, key)
    utils.log(updated, xbmc.LOGNOTICE)

    if updated:
        if path_id:
            manage.write_path(group_def, path_def=path_def, update=path_id)
        else:
            manage.write_path(group_def)

        utils.update_container(group_def['type'])
    edit_dialog(group_id, path_id)
def _copy_path(path_def):
    group_id = add_group(path_def['target'], path_def['label'])
    if not group_id:
        return
        
    group_def = manage.get_group_by_id(group_id)
    files = refresh.get_files_list(path_def['file']['file'])
    if not files:
        return
    
    for file in files:
        if file.get('type') in ['movie', 'episode', 'musicvideo', 'song']:
            continue
            
        labels = build_labels('json', file, path_def['target'])
        _add_path(group_def, labels, over=True)
    dialog.notification('AutoWidget', utils.get_string(32131)
                                      .format(len(files), group_def['label']))
示例#17
0
def _copy_path(path_def):
    group_id = add_group(path_def["target"], path_def["label"])
    if not group_id:
        return

    group_def = manage.get_group_by_id(group_id)
    files = refresh.get_files_list(path_def["file"]["file"])
    if not files:
        return

    for file in files:
        if file.get("type") in ["movie", "episode", "musicvideo", "song"]:
            continue

        labels = build_labels("json", file, path_def["target"])
        _add_path(group_def, labels, over=True)
    dialog.notification(
        "AutoWidget",
        utils.get_string(32131).format(len(files), group_def["label"]))
示例#18
0
def shift_path(group_id, path_id, target):
    group_def = manage.get_group_by_id(group_id)

    paths = group_def['paths']
    for idx, path_def in enumerate(paths):
        if path_def['id'] == path_id:
            if target == 'up' and idx > 0:
                temp = paths[idx - 1]
                paths[idx - 1] = path_def
                paths[idx] = temp
            elif target == 'down' and idx < len(paths) - 1:
                temp = paths[idx + 1]
                paths[idx + 1] = path_def
                paths[idx] = temp
            break

    group_def['paths'] = paths
    manage.write_path(group_def)
    utils.update_container(group_def['type'])
def shift_path(group_id, path_id, target):
    group_def = manage.get_group_by_id(group_id)
    paths = group_def['paths']
    for idx, path_def in enumerate(paths):
        if path_def['id'] == path_id:
            if target == 'up' and idx >= 0:
                if idx > 0:
                    temp = paths[idx - 1]
                    paths[idx - 1] = path_def
                    paths[idx] = temp
                else:
                    paths.append(paths.pop(idx))
            elif target == 'down' and idx <= len(paths) - 1:
                if idx < len(paths) - 1:
                    temp = paths[idx + 1]
                    paths[idx + 1] = path_def
                    paths[idx] = temp
                else:
                    paths.insert(0, paths.pop())
            break
    group_def['paths'] = paths
    manage.write_path(group_def)
    utils.update_container(group_def['type'] == 'shortcut')
示例#20
0
def _copy_path(path_def):
    params = {
        'jsonrpc': '2.0',
        'method': 'Files.GetDirectory',
        'params': {
            'directory': path_def['path'],
            'properties': utils.info_types
        },
        'id': 1
    }
    group_id = add_group(path_def['target'])
    if not group_id:
        return

    group_def = manage.get_group_by_id(group_id)
    files = xbmc.executeJSONRPC(json.dumps(params))
    if 'error' not in files:
        files = json.loads(files)['result']['files']
        for file in files:
            if file['type'] in ['movie', 'episode', 'musicvideo', 'song']:
                continue

            labels = build_labels('json', file, path_def['target'])
            _add_path(group_def, labels, over=True)
def group_menu(group_id, target, _id):
    _window = utils.get_active_window()

    group = manage.get_group_by_id(group_id)
    if not group:
        utils.log(
            '\"{}\" is missing, please repoint the widget to fix it.'.format(
                group_id),
            level=xbmc.LOGERROR)
        return False, 'AutoWidget'

    group_name = group['label']

    paths = manage.find_defined_paths(group_id)
    if len(paths) > 0:
        cm = []
        art = folder_shortcut if target == 'shortcut' else folder_sync

        for idx, path in enumerate(paths):
            if _window == 'media':
                cm = _create_context_items(group_id, path['id'], idx,
                                           len(paths))

            directory.add_menu_item(title=path['label'],
                                    params={
                                        'mode': 'path',
                                        'action': 'call',
                                        'group': group_id,
                                        'path': path['id']
                                    },
                                    info=path.get('info'),
                                    art=path.get('art') or art,
                                    cm=cm,
                                    isFolder=False)
        if target == 'widget' and _window != 'home':
            directory.add_separator(title=32010, char='/')

            directory.add_menu_item(title=utils.get_string(32028).format(
                group_name, _id),
                                    params={
                                        'mode': 'path',
                                        'action': 'random',
                                        'group': group_id,
                                        'id': six.text_type(_id)
                                    },
                                    art=folder_sync,
                                    isFolder=True)
            directory.add_menu_item(title=utils.get_string(32076).format(
                group_name, _id),
                                    params={
                                        'mode': 'path',
                                        'action': 'next',
                                        'group': group_id,
                                        'id': six.text_type(_id)
                                    },
                                    art=folder_next,
                                    isFolder=True)
    else:
        directory.add_menu_item(title=32032, art=alert, isFolder=False)

    return True, group_name
示例#22
0
def path_menu(group_id, action, widget_id):
    group_def = manage.get_group_by_id(group_id)
    if not group_def:
        directory.add_menu_item(title=32073,
                                info={'plot': utils.get_string(32075)},
                                art=utils.get_art('alert'),
                                isFolder=True)
        return True, 'AutoWidget'

    group_name = group_def.get('label', '')
    paths = group_def.get('paths', [])
    if len(paths) == 0:
        directory.add_menu_item(title=32032,
                                art=utils.get_art('alert'),
                                isFolder=True)
        return True, group_name

    widget_def = manage.get_widget_by_id(widget_id, group_id)
    if not widget_def:
        dialog = xbmcgui.Dialog()
        if action == 'static':
            idx = dialog.select(utils.get_string(32114),
                                [i['label'] for i in paths])
            if idx == -1:
                return True, 'AutoWidget'

            widget_def = manage.initialize(group_def,
                                           action,
                                           widget_id,
                                           keep=idx)
        elif action == 'cycling':
            idx = dialog.select(
                utils.get_string(32081),
                [utils.get_string(32079),
                 utils.get_string(32080)])
            if idx == -1:
                return True, 'AutoWidget'

            _action = 'random' if idx == 0 else 'next'
            widget_def = manage.initialize(group_def, _action, widget_id)

    if widget_def:
        widget_path = widget_def.get('path', {})

        if isinstance(widget_path, dict):
            _label = widget_path['label']
            widget_path = widget_path['file']['file']
        else:
            stack = widget_def.get('stack', [])
            if stack:
                _label = stack[0]['label']
            else:
                _label = widget_def.get('label', '')
        utils.log('Showing widget {}'.format(widget_id), 'debug')
        titles, cat = show_path(group_id, _label, widget_id, widget_path)
        return titles, cat
    else:
        directory.add_menu_item(title=32067,
                                art=utils.get_art('information_outline'),
                                isFolder=True)
        return True, group_name
示例#23
0
def active_widgets_menu():
    manage.clean()
    widgets = sorted(manage.find_defined_widgets(),
                     key=lambda x: x.get('updated'),
                     reverse=True)

    if len(widgets) > 0:
        for widget_def in widgets:
            widget_id = widget_def.get('id', '')
            action = widget_def.get('action', '')
            group = widget_def.get('group', '')
            path_def = widget_def.get('path', {})

            group_def = manage.get_group_by_id(group)

            title = ''
            if path_def and group_def:
                try:
                    if action != 'merged':
                        if isinstance(path_def, dict):
                            label = path_def['label'].encode('utf-8')
                        else:
                            label = widget_def['stack'][0]['label'].encode(
                                'utf-8')
                        group_def['label'] = group_def['label'].encode('utf-8')
                    else:
                        label = utils.get_string(32128).format(len(path_def))
                except:
                    pass

                title = '{} - {}'.format(label, group_def['label'])
            elif group_def:
                title = group_def.get('label')

            art = {}
            params = {}
            cm = []
            if not action:
                art = folder_shortcut
                title = utils.get_string(32030).format(title)
            else:
                if action in ['random', 'next']:
                    art = shuffle
                    cm.append((utils.get_string(32069),
                               ('RunPlugin('
                                'plugin://plugin.program.autowidget/'
                                '?mode=refresh'
                                '&id={})').format(widget_id)))
                elif action == 'merged':
                    art = merge
                elif action == 'static':
                    art = utils.get_art('folder')

            cm.append((utils.get_string(32070),
                       ('RunPlugin('
                        'plugin://plugin.program.autowidget/'
                        '?mode=manage'
                        '&action=edit_widget'
                        '&id={})').format(widget_id)))

            if not group_def:
                title = '{} - [COLOR firebrick]{}[/COLOR]'.format(
                    widget_id, utils.get_string(32071))

            directory.add_menu_item(title=title,
                                    art=art,
                                    params={
                                        'mode': 'group',
                                        'group': group
                                    },
                                    cm=cm[1:] if not action else cm,
                                    isFolder=True)
    else:
        directory.add_menu_item(title=32072,
                                art=utils.get_art('alert'),
                                isFolder=False,
                                props={'specialsort': 'bottom'})

    return True, utils.get_string(32074)
示例#24
0
def path_menu(group_id, action, widget_id):
    group_def = manage.get_group_by_id(group_id)
    if not group_def:
        directory.add_menu_item(
            title=30051,
            info={"plot": utils.get_string(30053)},
            art=utils.get_art("alert"),
            isFolder=True,
        )
        return True, "AutoWidget", None

    group_name = group_def.get("label", "")
    paths = group_def.get("paths", [])
    if len(paths) == 0:
        directory.add_menu_item(title=30019,
                                art=utils.get_art("alert"),
                                isFolder=True)
        return True, group_name, None

    widget_def = manage.get_widget_by_id(widget_id, group_id)
    if not widget_def:
        dialog = xbmcgui.Dialog()
        if action == "static":
            idx = manage.choose_paths(utils.get_string(30088),
                                      paths,
                                      indices=True,
                                      single=True)
            if idx == -1:
                return True, "AutoWidget", None

            widget_def = manage.initialize(group_def,
                                           action,
                                           widget_id,
                                           keep=idx)
        elif action == "cycling":
            idx = dialog.select(
                utils.get_string(30059),
                [utils.get_string(30057),
                 utils.get_string(30058)],
            )
            if idx == -1:
                del dialog
                return True, "AutoWidget", None

            _action = "random" if idx == 0 else "next"

            cycle_paths = manage.choose_paths(utils.get_string(30123),
                                              paths,
                                              threshold=-1,
                                              indices=True)

            widget_def = manage.initialize(group_def,
                                           _action,
                                           widget_id,
                                           keep=cycle_paths)
        del dialog

    if widget_def:
        widget_path = widget_def.get("path", "")

        # simple compatibility with pre-3.3.0 widgets
        if isinstance(widget_path, dict):
            widget_path = widget_def.get("path", {}).get("id", "")
            widget_def["path"] = widget_path
            manage.save_path_details(widget_def)

        widget_path = manage.get_path_by_id(widget_path, group_id)

        _label = ""
        if isinstance(widget_path, dict):
            _label = widget_path.get("label", "")

        utils.log("Showing widget {}".format(widget_id), "debug")
        titles, cat, type = show_path(group_id, _label, widget_id, widget_path)
        return titles, cat, type
    else:
        directory.add_menu_item(title=30045, art=info, isFolder=True)
        return True, group_name, None
示例#25
0
def active_widgets_menu():
    widgets = sorted(manage.clean(all=True),
                     key=lambda x: x.get("updated", 0),
                     reverse=True)

    if len(widgets) > 0:
        for widget_def in widgets:
            widget_id = widget_def.get("id", "")
            action = widget_def.get("action", "")
            group = widget_def.get("group", "")
            path_def = widget_def.get("path", {})

            group_def = manage.get_group_by_id(group)

            title = ""
            if path_def and group_def:
                try:
                    if action != "merged":
                        if isinstance(path_def, dict):
                            label = path_def["label"].encode("utf-8")
                        else:
                            label = widget_def["stack"][0]["label"].encode(
                                "utf-8")
                        group_def["label"] = group_def["label"].encode("utf-8")
                    else:
                        label = utils.get_string(32128).format(len(path_def))
                except:
                    pass

                title = "{} - {}".format(six.ensure_text(label),
                                         six.ensure_text(group_def["label"]))
            elif group_def:
                title = group_def.get("label")

            art = {}
            params = {}
            cm = []
            if not action:
                art = folder_shortcut
                title = utils.get_string(32030).format(title)
            else:
                if action in ['random', 'next', 'randomized']:
                    art = shuffle
                    cm.append((
                        utils.get_string(32069),
                        ("RunPlugin("
                         "plugin://plugin.program.autowidget/"
                         "?mode=refresh"
                         "&id={})").format(widget_id),
                    ))
                elif action == "merged":
                    art = merge
                elif action == "static":
                    art = utils.get_art("folder")

            cm.append((
                utils.get_string(32070),
                ("RunPlugin("
                 "plugin://plugin.program.autowidget/"
                 "?mode=manage"
                 "&action=edit_widget"
                 "&id={})").format(widget_id),
            ))

            if not group_def:
                title = "{} - [COLOR firebrick]{}[/COLOR]".format(
                    widget_id, utils.get_string(32071))

            directory.add_menu_item(
                title=title,
                art=art,
                params={
                    "mode": "group",
                    "group": group
                },
                cm=cm[1:] if not action else cm,
                isFolder=True,
            )
    else:
        directory.add_menu_item(
            title=32072,
            art=utils.get_art("alert"),
            isFolder=False,
            props={"specialsort": "bottom"},
        )

    return True, utils.get_string(32074)
示例#26
0
def path_menu(group_id, action, widget_id):
    group_def = manage.get_group_by_id(group_id)
    if not group_def:
        directory.add_menu_item(
            title=32073,
            info={"plot": utils.get_string(32075)},
            art=utils.get_art("alert"),
            isFolder=True,
        )
        return True, "AutoWidget"

    group_name = group_def.get("label", "")
    paths = group_def.get("paths", [])
    if len(paths) == 0:
        directory.add_menu_item(title=32032,
                                art=utils.get_art("alert"),
                                isFolder=True)
        return True, group_name

    widget_def = manage.get_widget_by_id(widget_id, group_id)
    if not widget_def:
        dialog = xbmcgui.Dialog()
        if action == "static":
            idx = dialog.select(utils.get_string(32114),
                                [i["label"] for i in paths])
            if idx == -1:
                return True, "AutoWidget"

            widget_def = manage.initialize(group_def,
                                           action,
                                           widget_id,
                                           keep=idx)
        elif action == 'cycling':
            idx = dialog.select(utils.get_string(32081), [
                utils.get_string(32079),
                utils.get_string(32080),
                utils.get_string(32242)
            ])
            if idx == -1:
                return True, 'AutoWidget'
            elif idx == 0:
                _action = 'random'
            elif idx == 1:
                _action = 'next'
            else:
                _action = 'randomized'

            widget_def = manage.initialize(group_def, _action, widget_id)

    if widget_def:
        widget_path = widget_def.get("path", {})

        if isinstance(widget_path, dict):
            _label = widget_path["label"]
            widget_path = widget_path["file"]["file"]
        else:
            stack = widget_def.get("stack", [])
            if stack:
                _label = stack[0]["label"]
            else:
                _label = widget_def.get("label", "")
        utils.log("Showing widget {}".format(widget_id), "debug")
        titles, cat = show_path(group_id, _label, widget_id, widget_path)
        return titles, cat
    else:
        directory.add_menu_item(title=32067,
                                art=utils.get_art("information_outline"),
                                isFolder=True)
        return True, group_name
def active_widgets_menu():
    widgets = manage.find_defined_widgets()

    if len(widgets) > 0:
        for widget_def in widgets:
            _id = widget_def.get('id', '')
            action = widget_def.get('action', '')
            group = widget_def.get('group', '')
            path = widget_def.get('path', '')
            updated = widget_def.get('updated', '')

            path_def = manage.get_path_by_id(path, group)
            group_def = manage.get_group_by_id(group)

            title = ''
            if path_def and group_def:
                try:
                    path_def['label'] = path_def['label'].encode('utf-8')
                    group_def['label'] = group_def['label'].encode('utf-8')
                except:
                    pass

                title = '{} - {}'.format(path_def['label'], group_def['label'])
            elif group_def:
                title = group_def.get('label')

            art = {}
            params = {}
            if not action:
                art = folder_shortcut
                params = {
                    'mode': 'group',
                    'group': group,
                    'target': 'shortcut',
                    'id': six.text_type(_id)
                }
                title = utils.get_string(32030).format(title)
            elif action in ['random', 'next']:
                art = folder_sync if action == 'random' else folder_next
                params = {
                    'mode': 'group',
                    'group': group,
                    'target': 'widget',
                    'id': six.text_type(_id)
                }

            cm = [(utils.get_string(32069),
                   ('RunPlugin('
                    'plugin://plugin.program.autowidget/'
                    '?mode=refresh'
                    '&target={})').format(_id)),
                  (utils.get_string(32070),
                   ('RunPlugin('
                    'plugin://plugin.program.autowidget/'
                    '?mode=manage'
                    '&action=edit_widget'
                    '&target={})').format(_id))]

            if not group_def:
                title = '{} - [COLOR firebrick]{}[/COLOR]'.format(
                    _id, utils.get_string(32071))

            directory.add_menu_item(title=title,
                                    art=art,
                                    params=params,
                                    cm=cm[1:] if not action else cm,
                                    isFolder=True)
    else:
        directory.add_menu_item(title=32072, art=alert, isFolder=False)

    return True, utils.get_string(32074)