2019-07-10 01:51:41 +02:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
#
|
|
|
|
# This program is free software; you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation; either version 2 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
|
|
|
|
from gi.repository import GObject, Gtk
|
|
|
|
|
|
|
|
import gi
|
|
|
|
gi.require_version("Gtk", "3.0")
|
|
|
|
|
|
|
|
|
|
|
|
@Gtk.Template(resource_path="/org/freedesktop/TuhiGui/ui/SetupPerspective.ui")
|
2019-07-15 07:05:30 +02:00
|
|
|
class SetupDialog(Gtk.Dialog):
|
|
|
|
__gtype_name__ = "SetupDialog"
|
2019-07-10 01:51:41 +02:00
|
|
|
__gsignals__ = {
|
|
|
|
'new-device':
|
|
|
|
(GObject.SignalFlags.RUN_FIRST, None, (GObject.TYPE_PYOBJECT,)),
|
|
|
|
}
|
|
|
|
|
2019-07-15 07:05:30 +02:00
|
|
|
stack = Gtk.Template.Child()
|
2019-07-10 01:51:41 +02:00
|
|
|
device_name_p3 = Gtk.Template.Child()
|
|
|
|
label_size = Gtk.Template.Child()
|
|
|
|
label_btaddr = Gtk.Template.Child()
|
|
|
|
label_battery = Gtk.Template.Child()
|
2019-07-15 07:05:30 +02:00
|
|
|
btn_quit = Gtk.Template.Child()
|
2019-07-10 01:51:41 +02:00
|
|
|
|
|
|
|
def __init__(self, tuhi, *args, **kwargs):
|
|
|
|
super().__init__(*args, **kwargs)
|
|
|
|
self._tuhi = tuhi
|
|
|
|
self._sig = tuhi.connect('unregistered-device', self._on_unregistered_device)
|
|
|
|
tuhi.start_search()
|
2019-07-15 07:05:30 +02:00
|
|
|
self.device = None
|
2019-07-10 01:51:41 +02:00
|
|
|
|
|
|
|
def _on_unregistered_device(self, tuhi, device):
|
|
|
|
tuhi.disconnect(self._sig)
|
|
|
|
|
2019-07-15 07:05:30 +02:00
|
|
|
self.stack.set_visible_child_name('page1')
|
2019-07-10 01:51:41 +02:00
|
|
|
self._sig = device.connect('button-press-required', self._on_button_press_required)
|
|
|
|
device.register()
|
|
|
|
|
|
|
|
def _on_button_press_required(self, tuhi, device):
|
|
|
|
tuhi.disconnect(self._sig)
|
|
|
|
|
2019-07-15 07:05:30 +02:00
|
|
|
self.stack.set_visible_child_name('page2')
|
2019-07-10 01:51:41 +02:00
|
|
|
self._sig = device.connect('registered', self._on_registered)
|
|
|
|
|
|
|
|
def _on_registered(self, tuhi, device):
|
|
|
|
tuhi.disconnect(self._sig)
|
|
|
|
|
|
|
|
self.device_name_p3.set_text(device.name)
|
2019-07-15 07:05:30 +02:00
|
|
|
self.stack.set_visible_child_name('page3')
|
|
|
|
w, h = device.dimensions # in 100th of mm
|
|
|
|
self.label_size.set_text(f'{w/100}x{h/100}mm')
|
2019-07-10 01:51:41 +02:00
|
|
|
self.label_btaddr.set_text(device.address)
|
|
|
|
self.label_battery.set_text(f'{device.battery_percent}%')
|
|
|
|
self.device = device
|
|
|
|
|
2019-07-15 07:05:30 +02:00
|
|
|
self.btn_quit.set_label("Let's go")
|
|
|
|
|
2019-07-10 01:51:41 +02:00
|
|
|
@GObject.Property
|
|
|
|
def name(self):
|
2019-07-15 07:05:30 +02:00
|
|
|
return "setup_dialog"
|