예제 #1
0
def _write_async(setting, value, sbox, sensitive=True, key=None):
    def _do_write(s, v, sb, key):
        try:
            if key is None:
                v = setting.write(v)
            else:
                v = setting.write_key_value(key, v)
                v = {key: v}
        except Exception:
            traceback.print_exc()
            v = None
        if sb:
            GLib.idle_add(_update_setting_item,
                          sb,
                          v,
                          True,
                          sensitive,
                          priority=99)

    if sbox:
        sbox._control.set_sensitive(False)
        sbox._failed.set_visible(False)
        sbox._spinner.set_visible(True)
        sbox._spinner.start()
    _ui_async(_do_write, setting, value, sbox, key)
예제 #2
0
def _read_async(setting, force_read, sbox, device_is_online, sensitive):
    def _do_read(s, force, sb, online, sensitive):
        v = s.read(not force)
        GLib.idle_add(_update_setting_item,
                      sb,
                      v,
                      online,
                      sensitive,
                      priority=99)

    _ui_async(_do_read, setting, force_read, sbox, device_is_online, sensitive)
예제 #3
0
def _write_async_item_value(setting, item, value, sbox):
    failed, spinner, control = _get_failed_spinner_control(sbox)
    control.set_sensitive(False)
    failed.set_visible(False)
    spinner.set_visible(True)
    spinner.start()

    def _do_write_item_value(s, k, v, sb):
        v = setting.write_item_value(k, v)
        GLib.idle_add(_update_setting_item, sb, {k: v}, True, priority=99)

    _ui_async(_do_write_item_value, setting, item, value, sbox)
예제 #4
0
def _write_async_key_value(setting, key, value, sbox):
    _ignore, failed, spinner, control = sbox.get_children()
    control.set_sensitive(False)
    failed.set_visible(False)
    spinner.set_visible(True)
    spinner.start()

    def _do_write_key_value(s, k, v, sb):
        v = setting.write_key_value(k, v)
        GLib.idle_add(_update_setting_item, sb, {k: v}, True, priority=99)

    _ui_async(_do_write_key_value, setting, key, value, sbox)
예제 #5
0
def _write_async(setting, value, sbox):
	_ignore, failed, spinner, control = sbox.get_children()
	control.set_sensitive(False)
	failed.set_visible(False)
	spinner.set_visible(True)
	spinner.start()

	def _do_write(s, v, sb):
		v = setting.write(v)
		GLib.idle_add(_update_setting_item, sb, v, True, priority=99)

	_ui_async(_do_write, setting, value, sbox)
예제 #6
0
def _update_details(button):
    assert button
    visible = button.get_active()

    if visible:
        # _details._text.set_markup('<small>reading...</small>')

        def _details_items(device, read_all=False):
            # If read_all is False, only return stuff that is ~100% already
            # cached, and involves no HID++ calls.

            if device.kind is None:
                yield (_("Path"), device.path)
                # 046d is the Logitech vendor id
                yield (_("USB id"), '046d:' + device.product_id)

                if read_all:
                    yield (_("Serial"), device.serial)
                else:
                    yield (_("Serial"), '...')

            else:
                # yield ('Codename', device.codename)
                yield (_("Index"), device.number)
                yield (_("Wireless PID"), device.wpid)
                hid_version = device.protocol
                yield (_("Protocol"), 'HID++ %1.1f' %
                       hid_version if hid_version else _('Unknown'))
                if read_all and device.polling_rate:
                    yield (_("Polling rate"),
                           _('%(rate)d ms (%(rate_hz)dHz)') % {
                               'rate': device.polling_rate,
                               'rate_hz': 1000 // device.polling_rate
                           })

                if read_all or not device.online:
                    yield (_("Serial"), device.serial)
                else:
                    yield (_("Serial"), '...')

            if read_all:
                for fw in list(device.firmware):
                    yield ('  ' + _(str(fw.kind)),
                           (fw.name + ' ' + fw.version).strip())
            elif device.kind is None or device.online:
                yield ('  %s' % _("Firmware"), '...')

            flag_bits = device.status.get(_K.NOTIFICATION_FLAGS)
            if flag_bits is not None:
                flag_names = (
                    '(%s)' % _("none"),
                ) if flag_bits == 0 else _hidpp10.NOTIFICATION_FLAG.flag_names(
                    flag_bits)
                yield (_("Notifications"), ('\n%15s' % ' ').join(flag_names))

        def _set_details(text):
            _details._text.set_markup(text)

        def _make_text(items):
            text = '\n'.join('%-13s: %s' % i for i in items)
            return '<small><tt>' + text + '</tt></small>'

        def _read_slow(device):
            items = _details_items(selected_device, True)
            text = _make_text(items)
            if device == _details._current_device:
                GLib.idle_add(_set_details, text)

        selected_device = _find_selected_device()
        assert selected_device
        _details._current_device = selected_device

        read_all = not (selected_device.kind is None or selected_device.online)
        items = _details_items(selected_device, read_all)
        _set_details(_make_text(items))

        if read_all:
            _details._current_device = None
        else:
            _ui_async(_read_slow, selected_device)

    _details.set_visible(visible)
예제 #7
0
def _read_async(setting, force_read, sbox, device_is_online):
	def _do_read(s, force, sb, online):
		v = s.read(not force)
		GLib.idle_add(_update_setting_item, sb, v, online, priority=99)

	_ui_async(_do_read, setting, force_read, sbox, device_is_online)
예제 #8
0
파일: window.py 프로젝트: Lekensteyn/Solaar
def _update_details(button):
	assert button
	visible = button.get_active()

	if visible:
		# _details._text.set_markup('<small>reading...</small>')

		def _details_items(device, read_all=False):
			# If read_all is False, only return stuff that is ~100% already
			# cached, and involves no HID++ calls.

			if device.kind is None:
				yield (_("Path"), device.path)
				# 046d is the Logitech vendor id
				yield (_("USB id"), '046d:' + device.product_id)

				if read_all:
					yield (_("Serial"), device.serial)
				else:
					yield (_("Serial"), '...')

			else:
				# yield ('Codename', device.codename)
				yield (_("Index"), device.number)
				yield (_("Wireless PID"), device.wpid)
				hid_version = device.protocol
				yield (_("Protocol"), 'HID++ %1.1f' % hid_version if hid_version else _('Unknown'))
				if read_all and device.polling_rate:
					yield (_("Polling rate"), _('%(rate)d ms (%(rate_hz)dHz)') % { 'rate': device.polling_rate, 'rate_hz': 1000 // device.polling_rate })

				if read_all or not device.online:
					yield (_("Serial"), device.serial)
				else:
					yield (_("Serial"), '...')

			if read_all:
				for fw in list(device.firmware):
					yield ('  ' + _(str(fw.kind)), (fw.name + ' ' + fw.version).strip())
			elif device.kind is None or device.online:
				yield ('  %s' % _("Firmware"), '...')

			flag_bits = device.status.get(_K.NOTIFICATION_FLAGS)
			if flag_bits is not None:
				flag_names = ('(%s)' % _("none"),) if flag_bits == 0 else _hidpp10.NOTIFICATION_FLAG.flag_names(flag_bits)
				yield (_("Notifications"), ('\n%15s' % ' ').join(flag_names))

		def _set_details(text):
			_details._text.set_markup(text)

		def _make_text(items):
			text = '\n'.join('%-13s: %s' % i for i in items)
			return '<small><tt>' + text + '</tt></small>'

		def _read_slow(device):
			items = _details_items(selected_device, True)
			text = _make_text(items)
			if device == _details._current_device:
				GLib.idle_add(_set_details, text)

		selected_device = _find_selected_device()
		assert selected_device
		_details._current_device = selected_device

		read_all = not (selected_device.kind is None or selected_device.online)
		items = _details_items(selected_device, read_all)
		_set_details(_make_text(items))

		if read_all:
			_details._current_device = None
		else:
			_ui_async(_read_slow, selected_device)

	_details.set_visible(visible)