Managed light sensor unit error

This commit is contained in:
Daniele Verducci 2024-04-26 09:43:55 +02:00
parent 1b3760a508
commit 5e557cc29f
2 changed files with 14 additions and 1 deletions

View File

@ -29,6 +29,7 @@ class LumosWindow(Adw.ApplicationWindow):
lux_label = Gtk.Template.Child() lux_label = Gtk.Template.Child()
ev_label = Gtk.Template.Child() ev_label = Gtk.Template.Child()
error_banner = Gtk.Template.Child() error_banner = Gtk.Template.Child()
sensor_unit_error_banner = Gtk.Template.Child()
def __init__(self, **kwargs): def __init__(self, **kwargs):
super().__init__(**kwargs) super().__init__(**kwargs)
@ -49,9 +50,15 @@ class LumosWindow(Adw.ApplicationWindow):
def onSensorRead(self, value: float, unit: str): def onSensorRead(self, value: float, unit: str):
# Called when the light value changed # Called when the light value changed
if self.lux_label: if self.lux_label:
self.lux_label.set_label("{:.0f} {}".format(value, unit)) self.lux_label.set_label("{:.0f} {}".format(value, unit))
# Check the unit is absolute ("lux"), otherwise there's no way to convert to an absolute EV value
if unit != "lux":
self.sensor_unit_error_banner.set_revealed(True)
return
# Convert lux to EV # Convert lux to EV
ev = EVCalculator.luxToEV(value) ev = EVCalculator.luxToEV(value)
if self.ev_label: if self.ev_label:

View File

@ -51,6 +51,12 @@
<signal name="button-clicked" handler="showErrorDetails"/>" <signal name="button-clicked" handler="showErrorDetails"/>"
</object> </object>
</child> </child>
<child>
<object class="AdwBanner" id="sensor_unit_error_banner">
<property name="title" translatable="true">Light sensor does not support absolute light measurement: unable to compute exposition</property>
</object>
</child>
"
<!-- Pages Stack --> <!-- Pages Stack -->
<child> <child>
@ -127,7 +133,7 @@
</child> </child>
<child> <child>
<object class="GtkLabel" id="ev_label"> <object class="GtkLabel" id="ev_label">
<property name="label" translatable="no">XXX EV</property> <property name="label" translatable="no">-- EV</property>
<style> <style>
<class name="title-1"/> <class name="title-1"/>
</style> </style>