Пример #1
0
def _update_receiver_panel(receiver, panel, buttons, full=False):
    assert receiver

    devices_count = len(receiver)

    paired_text = _('No device paired.') if devices_count == 0 else ngettext(
        '%(count)s paired device.', '%(count)s paired devices.',
        devices_count) % {
            'count': devices_count
        }

    if (receiver.max_devices > 0):
        paired_text += '\n\n<small>%s</small>' % ngettext(
            'Up to %(max_count)s device can be paired to this receiver.',
            'Up to %(max_count)s devices can be paired to this receiver.',
            receiver.max_devices) % {
                'max_count': receiver.max_devices
            }
    elif devices_count > 0:
        paired_text += '\n\n<small>%s</small>' % _(
            'Only one device can be paired to this receiver.')
    pairings = receiver.remaining_pairings(False)
    if (pairings is not None and pairings >= 0):
        paired_text += '\n<small>%s</small>' % (ngettext(
            'This receiver has %d pairing remaining.',
            'This receiver has %d pairings remaining.', pairings) % pairings)

    panel._count.set_markup(paired_text)

    is_pairing = receiver.status.lock_open
    if is_pairing:
        panel._scanning.set_visible(True)
        if not panel._spinner.get_visible():
            panel._spinner.start()
        panel._spinner.set_visible(True)
    else:
        panel._scanning.set_visible(False)
        if panel._spinner.get_visible():
            panel._spinner.stop()
        panel._spinner.set_visible(False)

    panel.set_visible(True)

    # b._insecure.set_visible(False)
    buttons._unpair.set_visible(False)

    if (receiver.may_unpair or receiver.re_pairs) and not is_pairing and \
       (receiver.remaining_pairings() is None or receiver.remaining_pairings() != 0):
        if not receiver.re_pairs and devices_count >= receiver.max_devices:
            paired_devices = tuple(n
                                   for n in range(1, receiver.max_devices + 1)
                                   if n in receiver)
            buttons._pair.set_sensitive(
                len(paired_devices) < receiver.max_devices)
        else:
            buttons._pair.set_sensitive(True)
    else:
        buttons._pair.set_sensitive(False)

    buttons._pair.set_visible(True)
Пример #2
0
def _update_receiver_panel(receiver, panel, buttons, full=False):
    assert receiver

    devices_count = len(receiver)

    paired_text = _('No device paired.') if devices_count == 0 else ngettext(
        '%(count)s paired device.', '%(count)s paired devices.',
        devices_count) % {
            'count': devices_count
        }

    if (receiver.max_devices > 0):
        paired_text += '\n\n<small>%s</small>' % ngettext(
            'Up to %(max_count)s device can be paired to this receiver.',
            'Up to %(max_count)s devices can be paired to this receiver.',
            receiver.max_devices) % {
                'max_count': receiver.max_devices
            }
    elif (devices_count > 0):
        paired_text += '\n\n<small>%s</small>' % _(
            'Only one device can be paired to this receiver.')

    panel._count.set_markup(paired_text)

    is_pairing = receiver.status.lock_open
    if is_pairing:
        panel._scanning.set_visible(True)
        if not panel._spinner.get_visible():
            panel._spinner.start()
        panel._spinner.set_visible(True)
    else:
        panel._scanning.set_visible(False)
        if panel._spinner.get_visible():
            panel._spinner.stop()
        panel._spinner.set_visible(False)

    panel.set_visible(True)

    # b._insecure.set_visible(False)
    buttons._unpair.set_visible(False)

    may_pair = receiver.may_unpair and not is_pairing
    if may_pair and devices_count >= receiver.max_devices:
        paired_devices = tuple(n for n in range(1, receiver.max_devices + 1)
                               if n in receiver)
        may_pair &= len(paired_devices) < receiver.max_devices
    buttons._pair.set_sensitive(may_pair)
    buttons._pair.set_visible(True)
Пример #3
0
def create(receiver):
    assert receiver is not None
    assert receiver.kind is None

    assistant = Gtk.Assistant()
    assistant.set_title(_('%(receiver_name)s: pair new device') % {'receiver_name': receiver.name})
    assistant.set_icon_name('list-add')

    assistant.set_size_request(400, 240)
    assistant.set_resizable(False)
    assistant.set_role('pair-device')

    page_text = _('If the device is already turned on, turn if off and on again.')
    if receiver.remaining_pairings() and receiver.remaining_pairings() >= 0:
        page_text += ngettext(
            '\n\nThis receiver has %d pairing remaining.', '\n\nThis receiver has %d pairings remaining.',
            receiver.remaining_pairings()
        ) % receiver.remaining_pairings()
        page_text += _('\nCancelling at this point will not use up a pairing.')

    page_intro = _create_page(
        assistant, Gtk.AssistantPageType.PROGRESS, _('Turn on the device you want to pair.'),
        'preferences-desktop-peripherals', page_text
    )
    spinner = Gtk.Spinner()
    spinner.set_visible(True)
    page_intro.pack_end(spinner, True, True, 24)

    assistant.connect('prepare', _prepare, receiver)
    assistant.connect('cancel', _finish, receiver)
    assistant.connect('close', _finish, receiver)

    return assistant
Пример #4
0
def create(receiver):
    assert receiver is not None
    assert receiver.kind is None

    global address, kind, authentication, name, passcode
    address = name = kind = authentication = passcode = None

    assistant = Gtk.Assistant()
    assistant.set_title(
        _('%(receiver_name)s: pair new device') %
        {'receiver_name': receiver.name})
    assistant.set_icon_name('list-add')

    assistant.set_size_request(400, 240)
    assistant.set_resizable(False)
    assistant.set_role('pair-device')

    if receiver.receiver_kind == 'bolt':
        page_text = _(
            'Press a pairing button or key until the pairing light flashes quickly.'
        )
        page_text += '\n'
        page_text += _(
            'You may have to first turn the device off and on again.')
    else:
        page_text = _('Turn on the device you want to pair.')
        page_text += '\n'
        page_text += _(
            'If the device is already turned on, turn it off and on again.')
    if receiver.remaining_pairings() and receiver.remaining_pairings() >= 0:
        page_text += ngettext(
            '\n\nThis receiver has %d pairing remaining.',
            '\n\nThis receiver has %d pairings remaining.',
            receiver.remaining_pairings()) % receiver.remaining_pairings()
        page_text += _('\nCancelling at this point will not use up a pairing.')

    intro_text = _('%(receiver_name)s: pair new device') % {
        'receiver_name': receiver.name
    }

    page_intro = _create_page(assistant, Gtk.AssistantPageType.PROGRESS,
                              intro_text, 'preferences-desktop-peripherals',
                              page_text)
    spinner = Gtk.Spinner()
    spinner.set_visible(True)
    page_intro.pack_end(spinner, True, True, 24)

    assistant.connect('prepare', _prepare, receiver)
    assistant.connect('cancel', _finish, receiver)
    assistant.connect('close', _finish, receiver)

    return assistant
Пример #5
0
 def set_value(self, value):
     b = ''
     n = len(self._items)
     for h in self._items:
         item = h._setting_item
         v = value.get(int(item), None)
         if v is not None:
             h.control.set_value(v)
         else:
             v = self.sbox.setting._value[int(item)]
         b += str(item) + ': (' + str(v) + ') '
     lbl_text = ngettext('%d value', '%d values', n) % n
     self._button.set_label(lbl_text)
     self._button.set_tooltip_text(b)
Пример #6
0
 def set_value(self, value):
     b = ''
     n = 0
     for ch in self._items:
         item = ch._setting_item
         v = value.get(str(int(item)), None)
         if v is not None:
             b += str(item) + ': ('
             to_join = []
             for c in ch._sub_items:
                 sub_item = c._setting_sub_item
                 c._control.set_value(v[str(sub_item)])
                 n += 1
                 to_join.append(str(sub_item) + f'={v[str(sub_item)]}')
             b += ', '.join(to_join) + ') '
         lbl_text = ngettext('%d value', '%d values', n) % n
     self._button.set_label(lbl_text)
     self._button.set_tooltip_text(b)
Пример #7
0
def _update_setting_item(sbox, value, is_online=True, sensitive=True):
    failed, spinner, control = _get_failed_spinner_control(sbox)
    spinner.set_visible(False)
    spinner.stop()

    if value is None:
        control.set_sensitive(False)
        _change_icon(False, sbox._change_icon)
        failed.set_visible(is_online)
        return

    control.set_sensitive(False)
    failed.set_visible(False)
    if isinstance(control, Gtk.Switch):
        control.set_active(value)
    elif isinstance(control, Gtk.ComboBoxText):
        control.set_active_id(str(int(value)))
    elif isinstance(control, Gtk.Scale):
        control.set_value(int(value))
    elif isinstance(control, Gtk.HBox):
        kbox, vbox = control.get_children()  # depends on box layout
        if value.get(kbox.get_active_id()) is not None:
            vbox.set_active_id(str(value.get(kbox.get_active_id())))
    elif isinstance(control, Gtk.ListBox):
        if control.kind == _SETTING_KIND.multiple_toggle:
            total = len(control._label_control_pairs)
            active = 0
            to_join = []
            for lbl, elem in control._label_control_pairs:
                v = value.get(elem._setting_key, None)
                if v is not None:
                    elem.set_active(v)
                if elem.get_active():
                    active += 1
                to_join.append(lbl.get_text() + ': ' + str(elem.get_active()))
            b = ', '.join(to_join)
            sbox._button.set_label(f'{active} / {total}')
            sbox._button.set_tooltip_text(b)
        elif control.kind == _SETTING_KIND.multiple_range:
            b = ''
            n = 0
            for ch in control._items:
                # item
                item = ch._setting_item
                v = value.get(str(int(item)), None)
                if v is not None:
                    b += str(item) + ': ('
                    to_join = []
                    for c in ch._sub_items:
                        # sub-item
                        sub_item = c._setting_sub_item
                        c._control.set_value(v[str(sub_item)])
                        n += 1
                        to_join.append(str(sub_item) + f'={v[str(sub_item)]}')
                    b += ', '.join(to_join) + ') '
                lbl_text = ngettext('%d value', '%d values', n) % n
                sbox._button.set_label(lbl_text)
                sbox._button.set_tooltip_text(b)
        else:
            raise NotImplementedError
    else:
        raise Exception('NotImplemented')

    control.set_sensitive(sensitive is True)
    _change_icon(sensitive, sbox._change_icon)