Пример #1
0
def run(receivers, args, find_receiver, find_device):
    assert receivers
    assert args.device

    device_name = args.device.lower()

    dev = None
    for dev in find_device(receivers, device_name):
        if dev.ping():
            break
        dev = None

    if not dev:
        raise Exception("no online device found matching '%s'" % device_name)

    if not args.setting:  # print all settings, so first set them all up
        if not dev.settings:
            raise Exception('no settings for %s' % dev.name)
        _configuration.attach_to(dev)
        _settings.apply_all_settings(dev)
        print(dev.name, '(%s) [%s:%s]' % (dev.codename, dev.wpid, dev.serial))
        for s in dev.settings:
            print('')
            _print_setting(s)
        return

    setting_name = args.setting.lower()
    setting = _settings_templates.check_feature_setting(dev, setting_name)
    if setting is None:
        raise Exception("no setting '%s' for %s" % (args.setting, dev.name))
    _configuration.attach_to(dev)

    if args.value_key is None:
        setting.apply()
        _print_setting(setting)
        return

    APP_ID = 'io.github.pwr.solaar'
    application = Gtk.Application.new(APP_ID, Gio.ApplicationFlags.HANDLES_COMMAND_LINE)
    application.register()

    # if the Solaar UI is running don't save configuration here
    result, message, value = set(dev, setting, args, not application.get_is_remote())
    if message is not None:
        print(message)
        if result is None:
            raise Exception("%s: failed to set value '%s' [%r]" % (setting.name, str(value), value))

    # if the Solaar UI is running tell it to also perform the set
    if application.get_is_remote():
        argl = ['config', dev.serial, setting.name]
        argl.extend([a for a in [args.value_key, args.extra_subkey, args.extra2] if a is not None])
        application.run(_yaml.safe_dump(argl))
Пример #2
0
def run(receivers, args, find_receiver, find_device):
    assert receivers
    assert args.device

    device_name = args.device.lower()

    dev = None
    for dev in find_device(receivers, device_name):
        if dev.ping():
            break
        dev = None

    if not dev:
        raise Exception("no online device found matching '%s'" % device_name)

    if not args.setting:  # print all settings, so first set them all up
        if not dev.settings:
            raise Exception('no settings for %s' % dev.name)
        _configuration.attach_to(dev)
        _settings.apply_all_settings(dev)
        print(dev.name, '(%s) [%s:%s]' % (dev.codename, dev.wpid, dev.serial))
        for s in dev.settings:
            print('')
            _print_setting(s)
        return

    setting_name = args.setting.lower()
    setting = _settings_templates.check_feature_setting(dev, setting_name)
    if setting is None:
        raise Exception("no setting '%s' for %s" % (args.setting, dev.name))
    _configuration.attach_to(dev)

    if args.value_key is None:
        setting.apply()
        _print_setting(setting)
        return

    message, result, value = set(dev, setting, args)
    print(message)
    if result is None:
        raise Exception("%s: failed to set value '%s' [%r]" %
                        (setting.name, str(value), value))
Пример #3
0
def run(receivers, args, find_receiver, find_device):
    assert receivers
    assert args.device

    device_name = args.device.lower()
    dev = find_device(receivers, device_name)

    if not dev.ping():
        raise Exception('%s is offline' % dev.name)

    if not dev.settings:
        raise Exception('no settings for %s' % dev.name)

    _configuration.attach_to(dev)

    if not args.setting:
        print(dev.name, '(%s) [%s:%s]' % (dev.codename, dev.wpid, dev.serial))
        for s in dev.settings:
            print('')
            _print_setting(s)
        return

    setting_name = args.setting.lower()
    setting = None
    for s in dev.settings:
        if setting_name == s.name.lower():
            setting = s
            break
    if setting is None:
        raise Exception("no setting '%s' for %s" % (args.setting, dev.name))

    if args.value is None:
        _print_setting(setting)
        return

    if setting.kind == _settings.KIND.toggle:
        value = args.value
        try:
            value = bool(int(value))
        except:
            if value.lower() in ('true', 'yes', 'on', 't', 'y'):
                value = True
            elif value.lower() in ('false', 'no', 'off', 'f', 'n'):
                value = False
            else:
                raise Exception("don't know how to interpret '%s' as boolean" %
                                value)

    elif setting.choices:
        value = args.value.lower()

        if value in ('higher', 'lower'):
            old_value = setting.read()
            if old_value is None:
                raise Exception("could not read current value of '%s'" %
                                setting.name)

            if value == 'lower':
                lower_values = setting.choices[:old_value]
                value = lower_values[
                    -1] if lower_values else setting.choices[:][0]
            elif value == 'higher':
                higher_values = setting.choices[old_value + 1:]
                value = higher_values[
                    0] if higher_values else setting.choices[:][-1]
        elif value in ('highest', 'max'):
            value = setting.choices[:][-1]
        elif value in ('lowest', 'min'):
            value = setting.choices[:][0]
        elif value not in setting.choices:
            raise Exception(
                "possible values for '%s' are: [%s]" %
                (setting.name, ', '.join(str(v) for v in setting.choices)))
            value = setting.choices[value]

    else:
        raise NotImplemented

    result = setting.write(value)
    if result is None:
        raise Exception("failed to set '%s' = '%s' [%r]" %
                        (setting.name, str(value), value))
    _print_setting(setting, False)
Пример #4
0
def run(receivers, args, find_receiver, find_device):
    assert receivers
    assert args.device

    device_name = args.device.lower()

    dev = None
    for dev in find_device(receivers, device_name):
        if dev.ping():
            break
        dev = None

    if not dev:
        raise Exception("no online device found matching '%s'" % device_name)

    if not args.setting:  # print all settings, so first set them all up
        if not dev.settings:
            raise Exception('no settings for %s' % dev.name)
        _configuration.attach_to(dev)
        for s in dev.settings:
            s.apply()
        print(dev.name, '(%s) [%s:%s]' % (dev.codename, dev.wpid, dev.serial))
        for s in dev.settings:
            print('')
            _print_setting(s)
        return

    setting_name = args.setting.lower()
    setting = _settings_templates.check_feature_setting(dev, setting_name)
    if setting is None:
        raise Exception("no setting '%s' for %s" % (args.setting, dev.name))
    _configuration.attach_to(dev)

    if args.value_key is None:
        setting.apply()
        _print_setting(setting)
        return

    if setting.kind == _settings.KIND.toggle:
        value = select_toggle(args.value_key, setting)
        print('Setting %s of %s to %s' % (setting.name, dev.name, value))
        result = setting.write(value)

    elif setting.kind == _settings.KIND.range:
        value = select_range(args.value_key, setting)
        print('Setting %s of %s to %s' % (setting.name, dev.name, value))
        result = setting.write(value)

    elif setting.kind == _settings.KIND.choice:
        value = select_choice(args.value_key, setting.choices, setting, None)
        print('Setting %s of %s to %s' % (setting.name, dev.name, value))
        result = setting.write(value)

    elif setting.kind == _settings.KIND.map_choice:
        key = args.value_key
        ikey = to_int(key)
        k = next((k for k in setting.choices.keys() if key == k), None)
        if k is None and ikey is not None:
            k = next((k for k in setting.choices.keys() if ikey == k), None)
        if k is not None:
            value = select_choice(args.extra_subkey, setting.choices[k], setting, key)
        else:
            raise Exception("%s: key '%s' not in setting" % (setting.name, key))
        print('Setting %s of %s key %r to %r' % (setting.name, dev.name, k, value))
        result = setting.write_key_value(int(k), value)

    elif setting.kind == _settings.KIND.multiple_toggle:
        key = args.value_key
        ikey = to_int(key)
        k = next((k for k in setting._labels if key == k), None)
        if k is None and ikey is not None:
            k = next((k for k in setting._labels if ikey == k), None)
        if k is not None:
            value = select_toggle(args.extra_subkey, setting)
        else:
            raise Exception("%s: key '%s' not in setting" % (setting.name, key))
        print('Setting %s key %r to %r' % (setting.name, k, value))
        result = setting.write_key_value(int(k), value)

    elif setting.kind == _settings.KIND.multiple_range:
        key = args.value_key
        ikey = to_int(key)
        if args.extra_subkey is None:
            raise Exception('%s: setting needs a subkey' % (setting.name))
        if args.extra2 is None or to_int(args.extra2) is None:
            raise Exception('%s: setting needs an integer value, not %s' % (setting.name, args.extra2))
        if not setting._value:  # ensure that there are values to look through
            setting.read()
        k = next((k for k in setting._value if key == k), None)
        if k is None and ikey is not None:
            k = next((k for k in setting._value if ikey == k), None)
        item = setting._value[k]
        if args.extra_subkey in item.keys():
            item[args.extra_subkey] = to_int(args.extra2)
        else:
            raise Exception("%s: key '%s' not in setting" % (setting.name, key))
        print('Setting %s key %s parameter %s to %r' % (setting.name, k, args.extra_subkey, item[args.extra_subkey]))
        result = setting.write_item_value(int(k), item)


# KIND = _NamedInts(, multiple_toggle=0x10, multiple_range=0x40)
# BitField; MultipleRange
# disable_keyboard_keys, gesture2; gesture2_params
# k400+ / craft, k400+; k400+

    else:
        raise Exception('NotImplemented')

    if result is None:
        raise Exception("%s: failed to set value '%s' [%r]" % (setting.name, str(value), value))
Пример #5
0
def run(receivers, args, find_receiver, find_device):
	assert receivers
	assert args.device

	device_name = args.device.lower()
	dev = find_device(receivers, device_name)

	if not dev.ping():
		raise Exception('%s is offline' % dev.name)

	if not dev.settings:
		raise Exception('no settings for %s' % dev.name)

	_configuration.attach_to(dev)

	if not args.setting:
		print (dev.name, '(%s) [%s:%s]' % (dev.codename, dev.wpid, dev.serial))
		for s in dev.settings:
			print ('')
			_print_setting(s)
		return

	setting_name = args.setting.lower()
	setting = None
	for s in dev.settings:
		if setting_name == s.name.lower():
			setting = s
			break
	if setting is None:
		raise Exception("no setting '%s' for %s" % (args.setting, dev.name))

	if args.value is None:
		_print_setting(setting)
		return

	if setting.kind == _settings.KIND.toggle:
		value = args.value
		try:
			value = bool(int(value))
		except:
			if value.lower() in ('true', 'yes', 'on', 't', 'y'):
				value = True
			elif value.lower() in ('false', 'no', 'off', 'f', 'n'):
				value = False
			else:
				raise Exception("don't know how to interpret '%s' as boolean" % value)

	elif setting.choices:
		value = args.value.lower()

		if value in ('higher', 'lower'):
			old_value = setting.read()
			if old_value is None:
				raise Exception("could not read current value of '%s'" % setting.name)

			if value == 'lower':
				lower_values = setting.choices[:old_value]
				value = lower_values[-1] if lower_values else setting.choices[:][0]
			elif value == 'higher':
				higher_values = setting.choices[old_value + 1:]
				value = higher_values[0] if higher_values else setting.choices[:][-1]
		elif value in ('highest', 'max'):
			value = setting.choices[:][-1]
		elif value in ('lowest', 'min'):
			value = setting.choices[:][0]
		elif value not in setting.choices:
			raise Exception("possible values for '%s' are: [%s]" % (setting.name, ', '.join(str(v) for v in setting.choices)))
			value = setting.choices[value]

	else:
		raise NotImplemented

	result = setting.write(value)
	if result is None:
		raise Exception("failed to set '%s' = '%s' [%r]" % (setting.name, value, value))
	_print_setting(setting, False)
Пример #6
0
def run(receivers, args, find_receiver, find_device):
    assert receivers
    assert args.device

    device_name = args.device.lower()
    dev = find_device(receivers, device_name)

    if not dev.ping():
        raise Exception('%s is offline' % dev.name)

    if not args.setting:  # print all settings, so first set them all up
        if not dev.settings:
            raise Exception('no settings for %s' % dev.name)
        _configuration.attach_to(dev)
        for s in dev.settings:
            s.apply()
        print(dev.name, '(%s) [%s:%s]' % (dev.codename, dev.wpid, dev.serial))
        for s in dev.settings:
            print('')
            _print_setting(s)
        return

    setting_name = args.setting.lower()
    setting = _settings_templates.check_feature_setting(dev, setting_name)
    if setting is None:
        raise Exception("no setting '%s' for %s" % (args.setting, dev.name))
    _configuration.attach_to(dev)

    if args.value is None:
        setting.apply()
        _print_setting(setting)
        return

    if setting.kind == _settings.KIND.toggle:
        value = args.value
        try:
            value = bool(int(value))
        except Exception:
            if value.lower() in ('true', 'yes', 'on', 't', 'y'):
                value = True
            elif value.lower() in ('false', 'no', 'off', 'f', 'n'):
                value = False
            else:
                raise Exception(
                    "%s: don't know how to interpret '%s' as boolean" %
                    (setting.name, value))
        print('Setting %s to %s' % (setting.name, value))

    elif setting.kind == _settings.KIND.range:
        try:
            value = int(args.value)
        except ValueError:
            raise Exception("%s: can't interpret '%s' as integer" %
                            (setting.name, args.value))
        min, max = setting.range
        if value < min or value > max:
            raise Exception("%s: value '%s' out of bounds" %
                            (setting.name, args.value))
        print('Setting %s to %s' % (setting.name, value))

    elif setting.kind == _settings.KIND.choice:
        value = args.value
        lvalue = value.lower()
        try:
            ivalue = int(value)
        except ValueError:
            ivalue = None
        if value in setting.choices:
            value = setting.choices[value]
        elif ivalue is not None and ivalue >= 0 and ivalue < len(
                setting.choices):
            value = setting.choices[ivalue]
        elif lvalue in ('higher', 'lower'):
            old_value = setting.read()
            if old_value is None:
                raise Exception("%s: could not read current value'" %
                                setting.name)
            if lvalue == 'lower':
                lower_values = setting.choices[:old_value]
                value = lower_values[
                    -1] if lower_values else setting.choices[:][0]
            elif lvalue == 'higher':
                higher_values = setting.choices[old_value + 1:]
                value = higher_values[
                    0] if higher_values else setting.choices[:][-1]
        elif lvalue in ('highest', 'max', 'first'):
            value = setting.choices[:][-1]
        elif lvalue in ('lowest', 'min', 'last'):
            value = setting.choices[:][0]
        else:
            raise Exception(
                '%s: possible values are [%s]' %
                (setting.name, ', '.join(str(v) for v in setting.choices)))
        print('Setting %s to %r' % (setting.name, value))

    else:
        raise Exception('NotImplemented')

    result = setting.write(value)
    if result is None:
        raise Exception("%s: failed to set value '%s' [%r]" %
                        (setting.name, str(value), value))