From 4f183b2826a07607b4f636bbecb3c16837b41f82 Mon Sep 17 00:00:00 2001 From: Daniel Pavel Date: Mon, 22 Oct 2012 20:59:21 +0300 Subject: [PATCH] added info box for the unifying receiver --- app/pairing.py | 4 +- app/receiver.py | 17 ++++++++ app/ui/main_window.py | 59 +++++++++++++++++++++------ app/ui/pair_window.py | 6 ++- lib/logitech/unifying_receiver/api.py | 4 +- 5 files changed, 74 insertions(+), 16 deletions(-) diff --git a/app/pairing.py b/app/pairing.py index 1a0b45f5..60a6a170 100644 --- a/app/pairing.py +++ b/app/pairing.py @@ -29,6 +29,9 @@ class State(object): self._countdown -= 1 return True + if self._countdown < 0: + return False + self._countdown -= 1 if self._countdown > 0 and self.success is None: return True @@ -46,7 +49,6 @@ class State(object): def stop_scan(self): if self._countdown >= 0: self._countdown = -1 - reply = self._watcher.receiver.request(0xFF, b'\x80\xB2', b'\x02') _l.debug("stop scan reply %s", repr(reply)) self._watcher.receiver.events_filter = None diff --git a/app/receiver.py b/app/receiver.py index 49545874..6bd2b6de 100644 --- a/app/receiver.py +++ b/app/receiver.py @@ -154,6 +154,9 @@ class Receiver(_listener.EventsListener): self.LOG = _Logger("Receiver-%s" % path) self.LOG.info("initializing") + self._serial = None + self._firmware = None + self.devices = {} self.events_filter = None self.events_handler = None @@ -212,6 +215,20 @@ class Receiver(_listener.EventsListener): def count_devices(self): return self.call_api(_api.count_devices) + @property + def serial(self): + if self._serial is None: + if self: + self._serial, firmware, bootloader = self.call_api(_api.get_receiver_info) + self._firmware = (firmware, bootloader) + return self._serial or '?' + + @property + def firmware(self): + s = self.serial + return self._firmware or ('?', '?') + + def _device_changed(self, dev, urgent=False): self.status_changed.reason = dev self.status_changed.urgent = urgent diff --git a/app/ui/main_window.py b/app/ui/main_window.py index b3761283..797e2428 100644 --- a/app/ui/main_window.py +++ b/app/ui/main_window.py @@ -15,10 +15,19 @@ _PLACEHOLDER = '~' def _update_receiver_box(box, receiver): - label, buttons = ui.find_children(box, 'label', 'buttons') + button, label, frame, info = ui.find_children(box, + 'info-button', 'status-label', 'info-frame', 'info-label') label.set_text(receiver.status_text or '') - # buttons.set_visible(receiver.status >= STATUS.CONNECTED) - + if receiver.status < STATUS.CONNECTED: + button.set_sensitive(False) + button.set_active(False) + frame.set_visible(False) + info.set_text('') + else: + button.set_sensitive(True) + if not info.get_text(): + info.set_text('Serial:\t\t%s\nFirmware: \t%s\nBootloader: \t%s\nMax devices:\t%s' % + (receiver.serial, receiver.firmware[0], receiver.firmware[1], receiver.max_devices)) def _update_device_box(frame, dev): if dev is None: @@ -100,25 +109,51 @@ def update(window, receiver): # def _receiver_box(name): - box = _device_box(False, False) + info_button = Gtk.ToggleButton() + info_button.set_name('info-button') + info_button.set_alignment(0.5, 0) + info_button.set_image(Gtk.Image.new_from_icon_name(name, _SMALL_DEVICE_ICON_SIZE)) + info_button.set_relief(Gtk.ReliefStyle.NONE) + info_button.set_tooltip_text(name) + info_button.set_sensitive(False) - icon, status_box = ui.find_children(box, 'icon', 'status') - icon.set_from_icon_name(name, _SMALL_DEVICE_ICON_SIZE) - icon.set_tooltip_text(name) + label = Gtk.Label('Initializing...') + label.set_name('status-label') + label.set_alignment(0, 0.5) toolbar = Gtk.Toolbar() toolbar.set_name('buttons') toolbar.set_style(Gtk.ToolbarStyle.ICONS) toolbar.set_icon_size(Gtk.IconSize.MENU) toolbar.set_show_arrow(False) - toolbar.insert(ui.action.pair.create_tool_item(), 0) - toolbar.show_all() - # toolbar.set_visible(False) - status_box.pack_end(toolbar, False, False, 0) + info_label = Gtk.Label('') + info_label.set_name('info-label') + info_label.set_alignment(0, 0.5) + info_label.set_padding(24, 4) + info_label.set_selectable(True) - return box + info_frame = Gtk.Frame() + info_frame.set_name('info-frame') + info_frame.set_label(name) + info_frame.add(info_label) + + info_button.connect('toggled', lambda b: info_frame.set_visible(b.get_active())) + + hbox = Gtk.HBox(homogeneous=False, spacing=8) + hbox.pack_start(info_button, False, False, 0) + hbox.pack_start(label, True, True, 0) + hbox.pack_end(toolbar, False, False, 0) + + vbox = Gtk.VBox(homogeneous=False, spacing=4) + vbox.set_border_width(4) + vbox.pack_start(hbox, True, True, 0) + vbox.pack_start(info_frame, True, True, 0) + vbox.show_all() + + info_frame.set_visible(False) + return vbox def _device_box(has_status_icons=True, has_frame=True): diff --git a/app/ui/pair_window.py b/app/ui/pair_window.py index 06bcc442..61e6a2e1 100644 --- a/app/ui/pair_window.py +++ b/app/ui/pair_window.py @@ -54,7 +54,8 @@ def _prepare(assistant, page, state): assistant.remove_page(0) state.stop_scan() -def _scan_complete(assistant, device): + +def _scan_complete_ui(assistant, device): if device is None: page = _create_page(assistant, 'No new device detected.\n' @@ -93,6 +94,9 @@ def _scan_complete(assistant, device): assistant.next_page() +def _scan_complete(assistant, device): + GObject.idle_add(_scan_complete_ui, assistant, device) + def create(action, state): assistant = Gtk.Assistant() diff --git a/lib/logitech/unifying_receiver/api.py b/lib/logitech/unifying_receiver/api.py index 06fb9530..777aba28 100644 --- a/lib/logitech/unifying_receiver/api.py +++ b/lib/logitech/unifying_receiver/api.py @@ -40,7 +40,7 @@ def get_receiver_info(handle): serial = None reply = _base.request(handle, 0xFF, b'\x83\xB5', b'\x03') if reply and reply[0:1] == b'\x03': - serial = _hexlify(reply[1:5]) + serial = _hexlify(reply[1:5]).upper() firmware = '??.??' reply = _base.request(handle, 0xFF, b'\x81\xF1', b'\x01') @@ -50,7 +50,7 @@ def get_receiver_info(handle): reply = _base.request(handle, 0xFF, b'\x81\xF1', b'\x02') if reply and reply[0:1] == b'\x02': - firmware += '.B' + _hexlify(reply[1:3]) + firmware += '.' + _hexlify(reply[1:3]) bootloader = None reply = _base.request(handle, 0xFF, b'\x81\xF1', b'\x04')