Moved sensors reading page to its own widget
This commit is contained in:
46
src/widgets/sensor_readings_page.py
Normal file
46
src/widgets/sensor_readings_page.py
Normal 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))
|
||||
|
33
src/widgets/sensor_readings_page.ui
Normal file
33
src/widgets/sensor_readings_page.ui
Normal 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>
|
||||
|
@@ -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)
|
||||
|
||||
|
Reference in New Issue
Block a user