From 718b3f2623af9b6c81688230f9d4f2372e64b605 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ignacio=20Mu=C3=B1oz=20Fernandez?= Date: Wed, 25 Nov 2020 11:50:12 +0100 Subject: [PATCH] wip: fixed qt cosmetic issue, added forecast text generation, initial for weather window --- qt_ui/widgets/QConditionsWidget.py | 85 +++++++++++++++++---- qt_ui/windows/weather/QWeatherInfoWindow.py | 16 ++++ 2 files changed, 86 insertions(+), 15 deletions(-) create mode 100644 qt_ui/windows/weather/QWeatherInfoWindow.py diff --git a/qt_ui/widgets/QConditionsWidget.py b/qt_ui/widgets/QConditionsWidget.py index d4712a1c..89713ad9 100644 --- a/qt_ui/widgets/QConditionsWidget.py +++ b/qt_ui/widgets/QConditionsWidget.py @@ -1,10 +1,17 @@ import datetime -from PySide2.QtWidgets import QLabel, QHBoxLayout, QGroupBox, QVBoxLayout, QFrame, QSizePolicy, QStyle, QPushButton +from PySide2.QtCore import Qt +from PySide2.QtWidgets import QLabel, QHBoxLayout, QGroupBox, QVBoxLayout, QFrame, QSizePolicy, QStyle, QPushButton, QGridLayout +from PySide2.QtGui import QFont -from game.weather import Conditions, TimeOfDay +from game.weather import Conditions, TimeOfDay, Weather +from dcs.weather import Weather as PydcsWeather + +from qt_ui.windows.weather.QWeatherInfoWindow import QWeatherInfoWindow import qt_ui.uiconstants as CONST + + class QTimeTurnWidget(QGroupBox): """ UI Component to display current turn and time info @@ -54,10 +61,14 @@ class QWeatherWidget(QGroupBox): """ UI Component to display current weather forecast """ + turn = None + conditions = None def __init__(self): super(QWeatherWidget, self).__init__("") self.setProperty('style', 'QWeatherWidget') + self.conditions = None + self.icons = { TimeOfDay.Dawn: CONST.ICONS["Dawn"], @@ -68,14 +79,22 @@ class QWeatherWidget(QGroupBox): self.layout = QHBoxLayout() self.setLayout(self.layout) - self.weather_icon = QLabel() self.weather_icon.setPixmap(self.icons[TimeOfDay.Dawn]) self.layout.addWidget(self.weather_icon) - self.forecast = QLabel('') - self.layout.addWidget(self.forecast) + self.textLayout = QVBoxLayout() + self.layout.addLayout(self.textLayout) + + self.forecastClouds = QLabel('') + self.textLayout.addWidget(self.forecastClouds) + + self.forecastRain = QLabel('') + self.textLayout.addWidget(self.forecastRain) + + self.forecastFog = QLabel('') + self.textLayout.addWidget(self.forecastFog) self.details = QPushButton("Weather") self.details.setProperty("style", "btn-primary") @@ -84,15 +103,22 @@ class QWeatherWidget(QGroupBox): self.layout.addWidget(self.details) def openDetailWindow(self): - pass + self.subwindow = QWeatherInfoWindow(self.turn, self.conditions) + self.subwindow.show() - def setCurrentConditions(self, conditions: Conditions) -> None: + def setCurrentTurn(self, turn: int, conditions: Conditions) -> None: """Sets the turn information display. :arg conditions Current time and weather conditions. """ + self.turn self.conditions = conditions + if conditions and turn > 0: + self.details.setDisabled(True) + else: + self.details.setDisabled(False) + self.updateIcon() self.updateText() @@ -110,31 +136,60 @@ class QWeatherWidget(QGroupBox): """ Updates the Forecast Text based on turn conditions """ + cloudDensity = self.conditions.weather.clouds.density + precipitation = self.conditions.weather.clouds.precipitation + + if cloudDensity <= 0: + self.forecastClouds.setText('Sunny') + + if cloudDensity > 0 and cloudDensity < 3: + self.forecastClouds.setText('Partly Cloudy') + + if cloudDensity > 3 and cloudDensity < 6: + self.forecastClouds.setText('Mostly Cloudy') + + if cloudDensity > 6: + self.forecastClouds.setText('Totally Cloudy') + + + if precipitation == PydcsWeather.Preceptions.Rain: + self.forecastRain.setText('Rain') + elif precipitation == PydcsWeather.Preceptions.Thunderstorm: + self.forecastRain.setText('Thunderstorm') + else: + self.forecastRain.setText('No Rain') + + if not self.conditions.weather.fog: + self.textLayout.removeWidget(self.forecastFog) - pass def updateDetailsBtn(self): if not self.conditions: self.details.setEnable(False) else: self.details.setEnable(True) - + class QConditionsWidget(QFrame): def __init__(self): super(QConditionsWidget, self).__init__() - self.layout = QHBoxLayout() - self.layout.setContentsMargins(0, 0, 0, 0) - self.setLayout(self.layout) self.setProperty('style', 'QConditionsWidget') + self.layout = QGridLayout() + self.layout.setContentsMargins(0, 0, 0, 0) + self.layout.setHorizontalSpacing(0) + self.layout.setVerticalSpacing(0) + self.setLayout(self.layout) + self.time_turn_widget = QTimeTurnWidget() - self.layout.addWidget(self.time_turn_widget) + self.time_turn_widget.setStyleSheet('QGroupBox { margin-right: 0px; border-right: 0px; }') + self.layout.addWidget(self.time_turn_widget, 0, 0) self.weather_widget = QWeatherWidget() - self.layout.addWidget(self.weather_widget) + self.weather_widget.setStyleSheet('QGroupBox { margin-top: 5px; margin-left: 0px; }') + self.layout.addWidget(self.weather_widget, 0, 1) def setCurrentTurn(self, turn: int, conditions: Conditions) -> None: self.time_turn_widget.setCurrentTurn(turn, conditions) - self.weather_widget.setCurrentConditions(conditions) + self.weather_widget.setCurrentTurn(turn, conditions) diff --git a/qt_ui/windows/weather/QWeatherInfoWindow.py b/qt_ui/windows/weather/QWeatherInfoWindow.py new file mode 100644 index 00000000..4a3ed446 --- /dev/null +++ b/qt_ui/windows/weather/QWeatherInfoWindow.py @@ -0,0 +1,16 @@ +from PySide2.QtWidgets import QDialog, QGridLayout, QLabel, QFrame, QSizePolicy + +from game.game import Game +from game.weather import Conditions, TimeOfDay, Weather + +import qt_ui.uiconstants as CONST + +class QWeatherInfoWindow(QDialog): + + def __init__(self, turn: int, conditions: Conditions): + super(QWeatherInfoWindow, self).__init__() + + self.setModal(True) + self.setWindowTitle("Weather Forecast Report") + self.setWindowIcon(CONST.ICONS["Money"]) + self.setMinimumSize(450, 200) \ No newline at end of file