Skip to content

Commit

Permalink
src/main: UI refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex Robinson committed Mar 19, 2021
1 parent 970155f commit f9db14a
Show file tree
Hide file tree
Showing 2 changed files with 98 additions and 74 deletions.
25 changes: 11 additions & 14 deletions src/window.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,11 @@
@Gtk.Template(resource_path='/org/gnome/siglo/window.ui')
class SigloWindow(Gtk.ApplicationWindow):
__gtype_name__ = 'SigloWindow'
info_scan_fail = Gtk.Template.Child()
info_scan_pass = Gtk.Template.Child()
bbox_scan_fail = Gtk.Template.Child()
bbox_scan_pass = Gtk.Template.Child()
scan_fail_box = Gtk.Template.Child()
scan_pass_box = Gtk.Template.Child()
main_info = Gtk.Template.Child()
bt_spinner = Gtk.Template.Child()
sync_time_button = Gtk.Template.Child()

def __init__(self, **kwargs):
self.manager = None
Expand All @@ -21,20 +20,20 @@ def done_scanning(self, manager):
scan_result = manager.get_scan_result()
self.bt_spinner.set_visible(False)
if (scan_result):
self.main_info.set_text("Done Scanning...Success")
self.info_scan_pass.set_text("InfiniTime Found!\nMac Address: " + manager.get_mac_address())
self.info_scan_pass.set_visible(True)
self.bbox_scan_pass.set_visible(True)
self.scan_pass_box.set_visible(True)
else:
self.info_scan_fail.set_visible(True)
self.bbox_scan_fail.set_visible(True)
self.main_info.set_text("Done Scanning...Failed")
self.scan_fail_box.set_visible(True)

@Gtk.Template.Callback()
def rescan_button_clicked(self, widget):
if self.manager is not None:
print("Rescan button clicked...")
self.main_info.set_text("Rescanning...")
self.bt_spinner.set_visible(True)
self.info_scan_fail.set_visible(False)
self.bbox_scan_fail.set_visible(False)
self.scan_fail_box.set_visible(False)
self.manager.scan_for_infinitime()
self.done_scanning(self.manager)

Expand All @@ -44,8 +43,6 @@ def sync_time_button_clicked(self, widget):
print("Sync Time button clicked...")
device = InfiniTimeDevice(manager=self.manager, mac_address=self.manager.get_mac_address())
device.connect()
self.info_scan_pass.set_text("InfiniTime Syncing... Success!")
self.bbox_scan_pass.set_visible(False)
self.sync_time_button.set_visible(False)

self.main_info.set_text("InfiniTime Sync... Success!")
self.scan_pass_box.set_visible(False)

147 changes: 87 additions & 60 deletions src/window.ui
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,19 @@
<property name="default-height">300</property>
<signal name="set-focus" handler="on_window_focus" swapped="no"/>
<child>
<object class="GtkBox">
<object class="GtkBox" id="main_box">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="orientation">vertical</property>
<child>
<object class="GtkSpinner" id="bt_spinner">
<object class="GtkLabel" id="main_info">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="halign">center</property>
<property name="valign">center</property>
<property name="vexpand">True</property>
<property name="active">True</property>
<property name="margin-top">20</property>
<property name="label" translatable="yes">Scanning...</property>
<attributes>
<attribute name="weight" value="heavy"/>
</attributes>
</object>
<packing>
<property name="expand">False</property>
Expand All @@ -28,11 +29,13 @@
</packing>
</child>
<child>
<object class="GtkLabel" id="info_scan_pass">
<object class="GtkSpinner" id="bt_spinner">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="halign">center</property>
<property name="valign">center</property>
<property name="vexpand">True</property>
<property name="label" translatable="yes">default scan pass text</property>
<property name="justify">center</property>
<property name="active">True</property>
</object>
<packing>
<property name="expand">False</property>
Expand All @@ -41,86 +44,110 @@
</packing>
</child>
<child>
<object class="GtkLabel" id="info_scan_fail">
<property name="can-focus">False</property>
<property name="vexpand">True</property>
<property name="label" translatable="yes">Make sure InfiniTime is ON but NOT connected

To check, go to Settings-&gt;Bluetooth-&gt;Devices

Might take a few scans.</property>
<property name="justify">center</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">2</property>
</packing>
</child>
<child>
<object class="GtkButtonBox" id="bbox_scan_fail">
<object class="GtkBox" id="scan_pass_box">
<property name="can-focus">False</property>
<property name="halign">center</property>
<property name="vexpand">True</property>
<property name="layout-style">start</property>
<property name="orientation">vertical</property>
<child>
<object class="GtkButton" id="rescan_button">
<property name="label" translatable="yes">Rescan</property>
<object class="GtkLabel" id="info_scan_pass">
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="receives-default">True</property>
<signal name="clicked" handler="rescan_button_clicked" swapped="no"/>
<property name="can-focus">False</property>
<property name="vexpand">True</property>
<property name="label" translatable="yes">default scan pass text</property>
<property name="justify">center</property>
</object>
<packing>
<property name="expand">True</property>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkButtonBox" id="bbox_scan_pass">
<property name="width-request">-1</property>
<property name="height-request">-1</property>
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="halign">center</property>
<property name="orientation">vertical</property>
<property name="layout-style">start</property>
<child>
<object class="GtkButton" id="sync_time_button">
<property name="label" translatable="yes">Time Sync</property>
<property name="width-request">-1</property>
<property name="height-request">-1</property>
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="receives-default">True</property>
<property name="valign">start</property>
<property name="vexpand">True</property>
<signal name="clicked" handler="sync_time_button_clicked" swapped="no"/>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">3</property>
<property name="position">2</property>
</packing>
</child>
<child>
<object class="GtkButtonBox" id="bbox_scan_pass">
<property name="width-request">-1</property>
<property name="height-request">-1</property>
<object class="GtkBox" id="scan_fail_box">
<property name="can-focus">False</property>
<property name="halign">center</property>
<property name="vexpand">True</property>
<property name="orientation">vertical</property>
<property name="layout-style">start</property>
<child>
<object class="GtkButton" id="ota_update_button">
<property name="label" translatable="yes">OTA Update</property>
<object class="GtkLabel" id="info_scan_fail">
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="receives-default">True</property>
<property name="valign">start</property>
<property name="margin-bottom">10</property>
<property name="can-focus">False</property>
<property name="vexpand">True</property>
<property name="label" translatable="yes">Make sure InfiniTime is ON but NOT connected

To check, go to Settings-&gt;Bluetooth-&gt;Devices

Might take a few scans.</property>
<property name="justify">center</property>
</object>
<packing>
<property name="expand">True</property>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkButton" id="sync_time_button">
<property name="label" translatable="yes">Time Sync</property>
<property name="width-request">-1</property>
<property name="height-request">-1</property>
<object class="GtkButtonBox" id="bbox_scan_fail">
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="receives-default">True</property>
<property name="valign">start</property>
<signal name="clicked" handler="sync_time_button_clicked" swapped="no"/>
<property name="can-focus">False</property>
<property name="halign">center</property>
<property name="vexpand">True</property>
<property name="layout-style">start</property>
<child>
<object class="GtkButton" id="rescan_button">
<property name="label" translatable="yes">Rescan</property>
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="receives-default">True</property>
<signal name="clicked" handler="rescan_button_clicked" swapped="no"/>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
</object>
<packing>
<property name="expand">True</property>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
Expand All @@ -129,7 +156,7 @@ Might take a few scans.</property>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">4</property>
<property name="position">3</property>
</packing>
</child>
</object>
Expand Down

0 comments on commit f9db14a

Please sign in to comment.