From 95164ddb4177c53feb4eff46eb83602ffe50ea45 Mon Sep 17 00:00:00 2001 From: Daniele Verducci Date: Fri, 3 May 2024 08:57:25 +0200 Subject: [PATCH] ISO value change callback --- src/widgets/aperture_priority_page.py | 14 ++++++++++++-- src/widgets/manual_exposure_page.py | 2 ++ src/widgets/sensor_readings_page.py | 2 ++ src/widgets/time_priority_page.py | 11 ++++++++++- src/window.py | 12 ++++++++++++ src/window.ui | 3 ++- 6 files changed, 40 insertions(+), 4 deletions(-) diff --git a/src/widgets/aperture_priority_page.py b/src/widgets/aperture_priority_page.py index 7ad3e2a..b3d7699 100644 --- a/src/widgets/aperture_priority_page.py +++ b/src/widgets/aperture_priority_page.py @@ -43,13 +43,23 @@ class AperturePriorityPage(Gtk.Box): aperture_priority_aperture_dropdown = Gtk.Template.Child() aperture_priority_time_label = Gtk.Template.Child() - def onValuesChanged(self, isoSpeed: int, sensorValue: float, sensorUnit: str): + lastSensorValue = None + + def onValuesChanged(self, isoSpeed: int, sensorValue: float, sensorUnit: str): # Check the unit is absolute ("lux") if sensorUnit != "lux": return + self.lastSensorValue = sensorValue + self.updateView(isoSpeed, sensorValue) + + + def onIsoSpeedChanged(self, isoSpeed: int): + if self.lastSensorValue: + self.updateView(isoSpeed, self.lastSensorValue) + + def updateView(self, isoSpeed: int, sensorValue: float): apertureValue = self.aperture_priority_speed_dropdown_values[self.aperture_priority_aperture_dropdown.get_selected()] shutterSpeed = EVCalculator.calcShutterSpeed(isoSpeed, sensorValue, apertureValue) # TODO: Round shutter speed value to nearest existing value and set label color to red if outside 1 stop range self.aperture_priority_time_label.set_label("f/ {:.2f}".format(shutterSpeed)) - diff --git a/src/widgets/manual_exposure_page.py b/src/widgets/manual_exposure_page.py index c3cbdcd..ab7152c 100644 --- a/src/widgets/manual_exposure_page.py +++ b/src/widgets/manual_exposure_page.py @@ -30,3 +30,5 @@ class ManualExposurePage(Gtk.Box): if sensorUnit != "lux": return + def onIsoSpeedChanged(self, isoSpeed: int): + print("ME: onIsoSpeedChanged {}".format(isoSpeed)) diff --git a/src/widgets/sensor_readings_page.py b/src/widgets/sensor_readings_page.py index 4b8dd47..33b1aff 100644 --- a/src/widgets/sensor_readings_page.py +++ b/src/widgets/sensor_readings_page.py @@ -44,3 +44,5 @@ class SensorReadingsPage(Gtk.Box): if self.ev_label: self.ev_label.set_label("{:.1f} EV".format(ev)) + def onIsoSpeedChanged(self, isoSpeed: int): + print("SR: onIsoSpeedChanged {}".format(isoSpeed)) diff --git a/src/widgets/time_priority_page.py b/src/widgets/time_priority_page.py index e32144a..b651c36 100644 --- a/src/widgets/time_priority_page.py +++ b/src/widgets/time_priority_page.py @@ -51,13 +51,22 @@ class TimePriorityPage(Gtk.Box): time_priority_speed_dropdown = Gtk.Template.Child() time_priority_aperture_label = Gtk.Template.Child() + lastSensorValue = None + def onValuesChanged(self, isoSpeed: int, sensorValue: float, sensorUnit: str): # Check the unit is absolute ("lux") if sensorUnit != "lux": return + self.lastSensorValue = sensorValue + self.updateView(isoSpeed, sensorValue) + + def onIsoSpeedChanged(self, isoSpeed: int): + if self.lastSensorValue: + self.updateView(isoSpeed, self.lastSensorValue) + + def updateView(self, isoSpeed: int, sensorValue: float): shutterSpeed = self.time_priority_speed_dropdown_values[self.time_priority_speed_dropdown.get_selected()] apertureValue = EVCalculator.calcAperture(isoSpeed, sensorValue, shutterSpeed) # TODO: Round aperture value to nearest existing value and set label color to red if outside 1 stop range self.time_priority_aperture_label.set_label("f/ {:.2f}".format(apertureValue)) - diff --git a/src/window.py b/src/window.py index c147af1..acb3ca6 100644 --- a/src/window.py +++ b/src/window.py @@ -89,4 +89,16 @@ class LumosWindow(Adw.ApplicationWindow): dialog.add_response("close", "Close") dialog.choose(self, None, None) + @Gtk.Template.Callback() + def onIsoSpeedChanged(self, dropDown: Gtk.DropDown, _: any) -> None: + # Changed ISO value, notify all pages + isoSpeed = int(dropDown.get_selected_item().get_string()[4:]) + if self.aperture_priority_page_widget: + self.aperture_priority_page_widget.onIsoSpeedChanged(isoSpeed) + if self.time_priority_page_widget: + self.time_priority_page_widget.onIsoSpeedChanged(isoSpeed) + if self.manual_page_widget: + self.manual_page_widget.onIsoSpeedChanged(isoSpeed) + if self.sensor_readings_page_widget: + self.sensor_readings_page_widget.onIsoSpeedChanged(isoSpeed) diff --git a/src/window.ui b/src/window.ui index 6c7fca5..571b696 100644 --- a/src/window.ui +++ b/src/window.ui @@ -27,6 +27,7 @@ 1 + @@ -48,7 +49,7 @@ Unable to access light sensor Details - " +