def _add_as(path_def): art = [folder_shortcut, folder_sync, folder_clone, folder_explode, folder_settings] path = path_def['file'] types = shortcut_types[:] if path_def['filetype'] == 'directory' and utils.get_active_window() != 'home': types = shortcut_types[:4] else: if (any(i in path for i in ['addons://user', 'plugin://', 'script://']) and not parse_qsl(path)) or ('widget', 'True') in parse_qsl(path): pass else: types = [shortcut_types[0]] options = [] for idx, type in enumerate(types): li = xbmcgui.ListItem(type) li.setArt(art[idx]) options.append(li) idx = dialog.select(utils.get_string(32084), options, useDetails=True) if idx < 0: return chosen = types[idx] if chosen == shortcut_types[0]: return 'shortcut' elif chosen == shortcut_types[1]: return 'widget' elif chosen == shortcut_types[2]: return 'clone' elif chosen == shortcut_types[3]: return 'explode' elif chosen == shortcut_types[4]: return 'settings'
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
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 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 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
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
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
def add_separator(title='', char='-'): _window = utils.get_active_window() sync = utils.get_art('sync.png') if _window != 'media': return if title: if isinstance(title, int): title = utils.get_string(title) split = (len(title) + 2) / 2 edge = char * int(40 - split) add_menu_item(title='{0} {1} {0}'.format(edge, string.capwords(title)), art=sync) else: add_menu_item(title=char * 80, art=sync)
def _add_as(path_def): art = [ folder_shortcut, folder_sync, folder_clone, folder_explode, folder_settings ] path = path_def["file"] types = shortcut_types[:] if path_def["filetype"] == "directory" and utils.get_active_window( ) != "home": types = shortcut_types[:4] else: if (any(i in path for i in ["addons://user", "plugin://", "script://"]) and not parse_qsl(path)) or ("widget", "True") in parse_qsl(path): pass else: types = [shortcut_types[0]] options = [] for idx, type in enumerate(types): li = xbmcgui.ListItem(type) li.setArt(art[idx]) options.append(li) dialog = xbmcgui.Dialog() idx = dialog.select(utils.get_string(30062), options, useDetails=True) del dialog if idx < 0: return chosen = types[idx] if chosen == shortcut_types[0]: return "shortcut" elif chosen == shortcut_types[1]: return "widget" elif chosen == shortcut_types[2]: return "clone" elif chosen == shortcut_types[3]: return "explode" elif chosen == shortcut_types[4]: return "settings"
def add_separator(title="", char="-", sort=""): _window = utils.get_active_window() sync = utils.get_art("sync") props = None if sort: props = {"specialsort": sort} if _window != "media": return if title: if isinstance(title, int): title = utils.get_string(title) split = (len(title) + 2) / 2 edge = char * int(40 - split) add_menu_item(title="{0} {1} {0}".format(edge, title), art=sync, props=props) else: add_menu_item(title=char * 80, art=sync, props=props)
def add_separator(title='', char='-', sort=''): _window = utils.get_active_window() sync = utils.get_art('sync') props = None if sort: props = {'specialsort': sort} if _window != 'media': return if title: if isinstance(title, int): title = utils.get_string(title) split = (len(title) + 2) / 2 edge = char * int(40 - split) add_menu_item(title='{0} {1} {0}'.format(edge, title), art=sync, props=props) else: add_menu_item(title=char * 80, art=sync, props=props)
def _update_widgets(self): self._refresh(True) while not self.abortRequested(): for _ in self.tick(15, 60 * 15): # TODO: somehow delay to all other plugins loaded? unrefreshed_widgets = set() for hash, widget_ids in utils.next_cache_queue(): effected_widgets = cache_and_update(widget_ids) utils.remove_cache_queue( hash ) # Just in queued path's widget defintion has changed and it didn't update this path unrefreshed_widgets = unrefreshed_widgets.union( effected_widgets).difference(set(widget_ids)) # # wait 5s or for the skin to reload the widget # # this should reduce churn at startup where widgets take too long too long show up # before_update = time.time() # TODO: have .access file so we can put above update # while _ in self.tick(1, 10, lambda: utils.last_read(hash) > before_update): # pass # utils.log("paused queue until read {:.2} for {}".format(utils.last_read(hash)-before_update, hash[:5]), 'info') if self.abortRequested(): break for widget_id in unrefreshed_widgets: widget_def = manage.get_widget_by_id(widget_id) if not widget_def: continue _update_strings(widget_def) if (os.path.exists(os.path.join(_addon_data, "refresh.time")) and utils.get_active_window() == "home"): utils.update_container(True) if self.abortRequested(): break if not self._refresh(): continue
def _update_widgets(self): self._refresh(True) while not self.abortRequested(): for _ in self.tick(step=1, max=60 * 15): # don't process cache queue during video playback if self.player.isPlayingVideo(): continue # TODO: somehow delay till all other plugins loaded? updated = False unrefreshed_widgets = set() queue = list(cache.next_cache_queue()) # class Progress(object): # dialog = None # service = self # done = set() # def __call__(self, groupname, path): # if self.dialog is None: # self.dialog = xbmcgui.DialogProgressBG() # self.dialog.create("AutoWidget", utils.get_string(30141)) # if not self.service.player.isPlayingVideo(): # percent = ( # len(self.done) # / float(len(queue) + len(self.done) + 1) # * 100 # ) # self.dialog.update( # int(percent), "AutoWidget", message=groupname # ) # self.done.add(path) # progress = Progress() while queue: path, cache_data, widget_id = queue.pop(0) hash = cache.path2hash(path) utils.log("Dequeued cache update: {}".format(hash[:5]), "notice") affected_widgets = set( cache.cache_and_update( path, widget_id, cache_data, # notify=progress ) ) if affected_widgets: updated = True unrefreshed_widgets = unrefreshed_widgets.union(affected_widgets) # # wait 5s or for the skin to reload the widget # # this should reduce churn at startup where widgets take too long too long show up # before_update = time.time() # TODO: have .access file so we can put above update # while _ in self.tick(1, 10, lambda: cache.last_read(hash) > before_update): # pass # utils.log("paused queue until read {:.2} for {}".format(cache.last_read(hash)-before_update, hash[:5]), 'info') if self.abortRequested(): break if self.player.isPlayingVideo(): # Video stop will cause another refresh anyway. break queue = list(cache.next_cache_queue()) for widget_id in unrefreshed_widgets: widget_def = manage.get_widget_by_id(widget_id) if not widget_def: continue _update_strings(widget_def) if ( os.path.exists(os.path.join(_addon_data, "refresh.time")) and utils.get_active_window() == "home" ): utils.update_container(True) # if progress.dialog is not None: # progress.dialog.update(100) # progress.dialog.close() if ( updated and self.refresh_enabled == 1 and not self.player.isPlayingVideo() ): dialog = xbmcgui.Dialog() dialog.notification( u"AutoWidget", utils.get_string(30142), sound=False ) if self.abortRequested(): break if not self._refresh(): continue
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