Fix possible None-exceptions in weather selector

This commit is contained in:
Raffson 2024-07-01 18:56:10 +02:00
parent e9a14f066a
commit 1df042fcc6
No known key found for this signature in database
GPG Key ID: B0402B2C9B764D99
3 changed files with 15 additions and 8 deletions

View File

@ -2,22 +2,27 @@ from typing import Optional
from PySide6.QtCore import Qt from PySide6.QtCore import Qt
from PySide6.QtWidgets import QHBoxLayout, QLabel, QSlider, QSpinBox, QComboBox from PySide6.QtWidgets import QHBoxLayout, QLabel, QSlider, QSpinBox, QComboBox
from dcs.weather import CloudPreset
from game.weather.clouds import Clouds
class DcsCloudBaseSelector(QHBoxLayout): class DcsCloudBaseSelector(QHBoxLayout):
M2FT_FACTOR = 3.2808399 M2FT_FACTOR = 3.2808399
def __init__(self, preset: Optional[CloudPreset]) -> None: def __init__(self, clouds: Optional[Clouds]) -> None:
super().__init__() super().__init__()
self.preset = preset self.preset = clouds.preset if clouds else None
self.unit_changing = False self.unit_changing = False
self.label = QLabel("Cloud Base: ") self.label = QLabel("Cloud Base: ")
self.addWidget(self.label) self.addWidget(self.label)
self.base = QSlider(Qt.Orientation.Horizontal) self.base = QSlider(Qt.Orientation.Horizontal)
self.base.setValue(round(self.max_base - (self.max_base - self.min_base) / 2)) self.base.setValue(
clouds.base
if clouds
else round(self.max_base - (self.max_base - self.min_base) / 2)
)
self.base.valueChanged.connect(self.on_slider_change) self.base.valueChanged.connect(self.on_slider_change)
self.addWidget(self.base, 1) self.addWidget(self.base, 1)

View File

@ -8,7 +8,7 @@ from game.weather.clouds import Clouds
class DcsCloudDensitySelector(QHBoxLayout): class DcsCloudDensitySelector(QHBoxLayout):
def __init__(self, clouds: Clouds) -> None: def __init__(self, clouds: Optional[Clouds]) -> None:
super().__init__() super().__init__()
self.unit_changing = False self.unit_changing = False
@ -17,7 +17,8 @@ class DcsCloudDensitySelector(QHBoxLayout):
self.density = QSlider(Qt.Orientation.Horizontal) self.density = QSlider(Qt.Orientation.Horizontal)
self.density.setRange(0, 10) self.density.setRange(0, 10)
self.density.setValue(clouds.density) if clouds:
self.density.setValue(clouds.density)
self.density.valueChanged.connect(self.on_slider_change) self.density.valueChanged.connect(self.on_slider_change)
self.addWidget(self.density, 1) self.addWidget(self.density, 1)

View File

@ -10,7 +10,7 @@ from game.weather.clouds import Clouds
class DcsCloudThicknessSelector(QHBoxLayout): class DcsCloudThicknessSelector(QHBoxLayout):
M2FT_FACTOR = 3.2808399 M2FT_FACTOR = 3.2808399
def __init__(self, clouds: Clouds) -> None: def __init__(self, clouds: Optional[Clouds]) -> None:
super().__init__() super().__init__()
self.unit_changing = False self.unit_changing = False
@ -19,7 +19,8 @@ class DcsCloudThicknessSelector(QHBoxLayout):
self.thickness = QSlider(Qt.Orientation.Horizontal) self.thickness = QSlider(Qt.Orientation.Horizontal)
self.thickness.setRange(200, 2000) self.thickness.setRange(200, 2000)
self.thickness.setValue(clouds.thickness) if clouds:
self.thickness.setValue(clouds.thickness)
self.thickness.valueChanged.connect(self.on_slider_change) self.thickness.valueChanged.connect(self.on_slider_change)
self.addWidget(self.thickness, 1) self.addWidget(self.thickness, 1)