def update_path(widget_id, target, path=None): widget_def = manage.get_widget_by_id(widget_id) if not widget_def: return stack = widget_def.get("stack", []) if target == "next" and path: utils.log("Next Page selected from {}".format(widget_id), "debug") path_def = manage.get_path_by_id(widget_def["path"], widget_def["group"]) if isinstance(path_def, dict): widget_def["label"] = path_def["label"] stack.append(path) widget_def["stack"] = stack elif target == "back" and widget_def.get("stack"): utils.log("Previous Page selected from {}".format(widget_id), "debug") widget_def["stack"] = widget_def["stack"][:-1] elif target == "reset": if len(stack) > 0: # simple compatibility with pre-3.3.0 widgets if isinstance(stack[0], dict): widget_def["path"] = stack[0].get("id", "") widget_def["stack"] = [] manage.save_path_details(widget_def) _update_strings(widget_def) utils.update_container(True) back_to_top(target)
def refresh(widget_id, widget_def=None, paths=None, force=False, single=False): if not widget_def: widget_def = manage.get_widget_by_id(widget_id) if widget_def["action"] in ["static", "merged"]: return paths current_time = time.time() updated_at = widget_def.get("updated", 0) default_refresh = settings.get_setting_float("service.refresh_duration") refresh_duration = float(widget_def.get("refresh", default_refresh)) if updated_at <= current_time - (3600 * refresh_duration) or force: group_id = widget_def["group"] action = widget_def.get("action") current = int(widget_def.get("current", 0)) widget_def["stack"] = [] if not paths: cycle_paths = widget_def.get("cycle_paths") if cycle_paths is None: cycle_paths = [ p.get("id") for p in manage.find_defined_paths(group_id) ] widget_def["cycle_paths"] = cycle_paths paths = [p for p in cycle_paths] if action: if len(paths) > 0: next = 0 if action == "next": next = (current + 1) % len(paths) elif action == "random": random.shuffle(paths) next = random.randrange(len(paths)) widget_def["current"] = next path_id = paths[next] paths.remove(paths[next]) widget_def["path"] = path_id if widget_def["path"]: path_label = manage.get_path_by_id(path_id, group_id).get( "label", "") widget_def["label"] = path_label widget_def["updated"] = 0 if force else current_time manage.save_path_details(widget_def) _update_strings(widget_def) if single: utils.update_container(True) return paths
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
def refresh(widget_id, widget_def=None, paths=None, force=False, single=False): if not widget_def: widget_def = manage.get_widget_by_id(widget_id) if widget_def["action"] in ["static", "merged"]: return paths current_time = time.time() updated_at = widget_def.get("updated", 0) default_refresh = utils.get_setting_float("service.refresh_duration") refresh_duration = float(widget_def.get("refresh", default_refresh)) if updated_at <= current_time - (3600 * refresh_duration) or force: group_id = widget_def["group"] action = widget_def.get("action") current = int(widget_def.get("current", -1)) widget_def["stack"] = [] widget_def["label"] = "" if not paths: paths = manage.find_defined_paths(group_id) if action: if len(paths) > 0: next = 0 if action == "next": next = (current + 1) % len(paths) elif action == "random": random.shuffle(paths) next = random.randrange(len(paths)) elif action == 'randomized': next = manage.get_inactive_path(paths) if next == []: next = current widget_def['current'] = next path_def = paths[next] paths.remove(paths[next]) widget_def["path"] = path_def if widget_def["path"]: widget_def["updated"] = 0 if force else current_time manage.save_path_details(widget_def) _update_strings(widget_def) if single: utils.update_container(True) return paths
def edit_widget_dialog(widget_id): updated = False if advanced and not warning_shown: _warn() widget_def = manage.get_widget_by_id(widget_id) if not widget_def: return updated = _show_widget_options(widget_def) if updated: manage.save_path_details(widget_def) utils.update_container(True) edit_widget_dialog(widget_id)
def refresh(widget_id, widget_def=None, paths=None, force=False, single=False): if not widget_def: widget_def = manage.get_widget_by_id(widget_id) if widget_def['action'] in ['static', 'merged']: return paths current_time = time.time() updated_at = widget_def.get('updated', 0) default_refresh = utils.get_setting_float('service.refresh_duration') refresh_duration = float(widget_def.get('refresh', default_refresh)) if updated_at <= current_time - (3600 * refresh_duration) or force: group_id = widget_def['group'] action = widget_def.get('action') current = int(widget_def.get('current', -1)) widget_def['stack'] = [] widget_def['label'] = '' if not paths: paths = manage.find_defined_paths(group_id) if action: if len(paths) > 0: next = 0 if action == 'next': next = (current + 1) % len(paths) elif action == 'random': random.shuffle(paths) next = random.randrange(len(paths)) widget_def['current'] = next path_def = paths[next] paths.remove(paths[next]) widget_def['path'] = path_def if widget_def['path']: widget_def['updated'] = 0 if force else current_time manage.save_path_details(widget_def) _update_strings(widget_def) if single: utils.update_container(True) return paths
def update_path(widget_id, target, path=None): widget_def = manage.get_widget_by_id(widget_id) if not widget_def: return stack = widget_def.get('stack', []) if target == 'next' and path: utils.log('Next Page selected from {}'.format(widget_id), 'debug') path_def = widget_def['path'] if isinstance(path_def, dict): widget_def['label'] = path_def['label'] stack.append(widget_def['path']) widget_def['stack'] = stack widget_def['path'] = path elif target == 'back' and widget_def.get('stack'): utils.log('Previous Page selected from {}'.format(widget_id), 'debug') widget_def['path'] = widget_def['stack'][-1] widget_def['stack'] = widget_def['stack'][:-1] if len(widget_def['stack']) == 0: widget_def['label'] = '' elif target == 'reset': if len(stack) > 0: widget_def['path'] = widget_def['stack'][0] widget_def['stack'] = [] widget_def['label'] = '' action = widget_def[ 'path'] if widget_def['action'] != 'merged' else 'merged' if isinstance(widget_def['path'], dict): action = widget_def['path']['file']['file'] manage.save_path_details(widget_def) _update_strings(widget_def) utils.update_container(True) back_to_top(target)
def update_path(widget_id, target, path=None): widget_def = manage.get_widget_by_id(widget_id) if not widget_def: return stack = widget_def.get("stack", []) if target == "next" and path: utils.log("Next Page selected from {}".format(widget_id), "debug") path_def = widget_def["path"] if isinstance(path_def, dict): widget_def["label"] = path_def["label"] stack.append(widget_def["path"]) widget_def["stack"] = stack widget_def["path"] = path elif target == "back" and widget_def.get("stack"): utils.log("Previous Page selected from {}".format(widget_id), "debug") widget_def["path"] = widget_def["stack"][-1] widget_def["stack"] = widget_def["stack"][:-1] if len(widget_def["stack"]) == 0: widget_def["label"] = "" elif target == "reset": if len(stack) > 0: widget_def["path"] = widget_def["stack"][0] widget_def["stack"] = [] widget_def["label"] = "" action = widget_def[ "path"] if widget_def["action"] != "merged" else "merged" if isinstance(widget_def["path"], dict): action = widget_def["path"]["file"]["file"] manage.save_path_details(widget_def) _update_strings(widget_def) utils.update_container(True) back_to_top(target)
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