Moved sensors reading page to its own widget

This commit is contained in:
Daniele Verducci 2024-04-30 08:28:18 +02:00
parent 5273206c33
commit 6f7134d6fb
7 changed files with 93 additions and 45 deletions

View File

@ -5,6 +5,7 @@
<file preprocess="xml-stripblanks">widgets/time_priority_page.ui</file>
<file preprocess="xml-stripblanks">widgets/aperture_priority_page.ui</file>
<file preprocess="xml-stripblanks">widgets/manual_exposure_page.ui</file>
<file preprocess="xml-stripblanks">widgets/sensor_readings_page.ui</file>
<file preprocess="xml-stripblanks">gtk/help-overlay.ui</file>
<file compressed="true">style.css</file>
</gresource>

View File

@ -36,6 +36,7 @@ lumos_sources = [
'widgets/time_priority_page.py',
'widgets/aperture_priority_page.py',
'widgets/manual_exposure_page.py',
'widgets/sensor_readings_page.py',
]
install_data(lumos_sources, install_dir: moduledir)

View File

@ -0,0 +1,46 @@
# sensor_readings_page.py
#
# Copyright 2024 Daniele Verducci
#
# 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 3 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.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
# SPDX-License-Identifier: GPL-3.0-or-later
from gi.repository import Adw
from gi.repository import Gtk
from .ev_calculator import EVCalculator
@Gtk.Template(resource_path='/eu/ichibi/Lumos/widgets/sensor_readings_page.ui')
class SensorReadingsPage(Gtk.Box):
__gtype_name__ = 'SensorReadingsPage'
# Labels
lux_label = Gtk.Template.Child()
ev_label = Gtk.Template.Child()
def onValuesChanged(self, isoSpeed: int, sensorValue: float, sensorUnit: str):
# Called when the light value changed
if self.lux_label:
self.lux_label.set_label("{:.0f} {}".format(sensorValue, sensorUnit))
# Check the unit is absolute ("lux"), otherwise there's no way to convert to an absolute EV value
if sensorUnit != "lux":
return
# Convert lux to EV
ev = EVCalculator.luxToEV(sensorValue)
if self.ev_label:
self.ev_label.set_label("{:.1f} EV".format(ev))

View File

@ -0,0 +1,33 @@
<interface>
<requires lib="gtk" version="4.0"/>
<requires lib="adw" version="1.0"/>
<template class="SensorReadingsPage" parent="GtkBox">
<property name="orientation">1</property>
<property name="valign">3</property>
<property name="halign">3</property>
<child>
<object class="GtkImage" id="lux-icon">
<property name="icon-name">lightbulb-symbolic</property>
<property name="pixel-size">128</property>
<property name="margin-bottom">30</property>
</object>
</child>
<child>
<object class="GtkLabel" id="lux_label">
<property name="label" translatable="no">XXX Lux</property>
<style>
<class name="title-1"/>
</style>
</object>
</child>
<child>
<object class="GtkLabel" id="ev_label">
<property name="label" translatable="no">-- EV</property>
<style>
<class name="title-1"/>
</style>
</object>
</child>
</template>
</interface>

View File

@ -3,10 +3,12 @@ from gi.repository import GObject
from .time_priority_page import TimePriorityPage
from .aperture_priority_page import AperturePriorityPage
from .manual_exposure_page import ManualExposurePage
from .sensor_readings_page import SensorReadingsPage
# Register widgets to be used in templates UI
def registerWidgets() -> None:
GObject.type_ensure(TimePriorityPage)
GObject.type_ensure(AperturePriorityPage)
GObject.type_ensure(ManualExposurePage)
GObject.type_ensure(SensorReadingsPage)

View File

@ -19,17 +19,16 @@
from gi.repository import Adw, Gtk, GObject
from .sensors_polling_timer import SensorsPollingTimer
from .ev_calculator import EVCalculator
@Gtk.Template(resource_path='/eu/ichibi/Lumos/window.ui')
class LumosWindow(Adw.ApplicationWindow):
__gtype_name__ = 'LumosWindow'
# Labels
lux_label = Gtk.Template.Child()
ev_label = Gtk.Template.Child()
error_banner = Gtk.Template.Child()
sensor_unit_error_banner = Gtk.Template.Child()
# Pages
sensor_readings_page_widget = Gtk.Template.Child()
def __init__(self, **kwargs):
super().__init__(**kwargs)
@ -49,22 +48,16 @@ class LumosWindow(Adw.ApplicationWindow):
self.sensorsPollingTimer.cancel()
def onSensorRead(self, value: float, unit: str):
# Called when the light value changed
if self.lux_label:
self.lux_label.set_label("{:.0f} {}".format(value, unit))
# Called when the light value changed: notify all pages
if self.sensor_readings_page_widget:
self.sensor_readings_page_widget.onValuesChanged(100, 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
ev = EVCalculator.luxToEV(value)
if self.ev_label:
self.ev_label.set_label("{:.1f} EV".format(ev))
def onError(self, e: Exception):
print(e)
self.lastError = e
self.error_banner.set_revealed(True)

View File

@ -104,44 +104,16 @@
</object>
</child>
<!-- Light page -->
<!-- Sensor readings page -->
<child>
<object class="AdwViewStackPage" id="light-measure-page">
<property name="name">light-measure-page</property>
<object class="AdwViewStackPage" id="sensor_readings_page">
<property name="name">sensor_readings_page</property>
<property name="title" translatable="true">Light</property>
<property name="icon-name">lightbulb-symbolic</property>
<property name="use-underline">true</property>
<property name="child">
<object class="GtkBox">
<property name="orientation">1</property>
<property name="valign">3</property>
<property name="halign">3</property>
<child>
<object class="GtkImage" id="lux-icon">
<property name="icon-name">lightbulb-symbolic</property>
<property name="pixel-size">128</property>
<property name="margin-bottom">30</property>
<object class="SensorReadingsPage" id="sensor_readings_page_widget">
</object>
</child>
<child>
<object class="GtkLabel" id="lux_label">
<property name="label" translatable="no">XXX Lux</property>
<style>
<class name="title-1"/>
</style>
</object>
</child>
<child>
<object class="GtkLabel" id="ev_label">
<property name="label" translatable="no">-- EV</property>
<style>
<class name="title-1"/>
</style>
</object>"
</child>
</object>
</property>
</object>
</child>