Beispiel #1
0
def initialize(group_def, action, widget_id, save=True, keep=None):
    duration = utils.get_setting_float("service.refresh_duration")
    paths = group_def.get("paths", [])
    path_def = []

    if action != "merged":
        if action == "static" and keep is not None:
            path_idx = keep
        elif action in ["random", "next"]:
            path_idx = random.randrange(len(paths)) if action == "random" else 0
        path_def = paths[path_idx]
    elif action == "merged" and keep:
        for idx in keep:
            path_def.append(paths[idx])

    params = {
        "action": action,
        "id": widget_id,
        "group": group_def["id"],
        "refresh": duration,
        "path": path_def,
        "version": utils._addon_version,
    }
    if save:
        save_path_details(params)

    return params
Beispiel #2
0
    def _reload_settings(self):
        self.refresh_enabled = utils.get_setting_int('service.refresh_enabled')
        self.refresh_duration = utils.get_setting_float('service.refresh_duration')
        self.refresh_notification = utils.get_setting_int('service.refresh_notification')
        self.refresh_sound = utils.get_setting_bool('service.refresh_sound')

        utils.update_container(True)
def initialize(group_def, action, widget_id, save=True, keep=None):
    duration = utils.get_setting_float('service.refresh_duration')
    paths = group_def.get('paths', [])
    path_def = []

    if action != 'merged':
        if action == 'static' and keep is not None:
            path_idx = keep
        elif action in ['random', 'next']:
            path_idx = random.randrange(
                len(paths)) if action == 'random' else 0
        path_def = paths[path_idx]
    elif action == 'merged' and keep:
        for idx in keep:
            path_def.append(paths[idx])

    params = {
        'action': action,
        'id': widget_id,
        'group': group_def['id'],
        'refresh': duration,
        'path': path_def,
        'version': utils._addon_version
    }
    if save:
        save_path_details(params)

    return params
Beispiel #4
0
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 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 refresh(widget_id, widget_def=None, paths=None, force=False):
    if not widget_def:
        widget_def = manage.get_widget_by_id(widget_id)

    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:
        path_def = {}

        _id = widget_def['id']
        group_id = widget_def['group']
        action = widget_def.get('action')
        setting = widget_def.get('path_setting')
        label_setting = widget_def.get('label_setting')
        current = int(widget_def.get('current', -1))

        if not paths:
            paths = manage.find_defined_paths(group_id)
            random.shuffle(paths)

        if action:
            if len(paths) > 0:
                next = 0
                if action == 'next':
                    next = (current + 1) % len(paths)
                elif action == 'random':
                    next = random.randrange(len(paths))

                widget_def['current'] = next
                path_def = paths[next]
                paths.remove(paths[next])

                widget_def['path'] = path_def.get('id')
                if widget_def['path']:
                    widget_def['updated'] = 0 if force else current_time

                    convert.save_path_details(widget_def, _id)
                    _update_strings(_id, path_def, setting, label_setting)

                    utils.update_container()

    return paths
def save_path_details(params, _id=''):
    for param in params:
        if str(params[param]).endswith(',return)'):
            return

    if not _id:
        _id = params.get('id')
        if not _id:
            return

    path_to_saved = os.path.join(_addon_path, '{}.widget'.format(_id))
    params['version'] = _addon_version

    if 'refresh' not in params:
        params['refresh'] = utils.get_setting_float('service.refresh_duration')

    utils.write_json(path_to_saved, params)

    return params
 def _reload_settings(self):
     self.refresh_enabled = utils.get_setting_int('service.refresh_enabled')
     self.refresh_duration = utils.get_setting_float(
         'service.refresh_duration')
     self.refresh_notification = utils.get_setting_int(
         'service.refresh_notification')