diff --git a/deathclock/main.py b/deathclock/main.py index 42d9b0b..d413bed 100644 --- a/deathclock/main.py +++ b/deathclock/main.py @@ -56,12 +56,17 @@ def main(): engine.load( 'main.qml') # create instance of weather class weather_obj = weather.Weather() - weather_obj.download_sacramento_weather_map(engine) + weather_obj.weatherUpdated.connect(lambda weather_map_path: engine.rootContext().setContextProperty("weatherMapPath", weather_map_path)) # set timer for weather map weatherTimer = QTimer() - weatherTimer.setInterval(600000) # 10 minutes + weatherTimer.setInterval(300000) # 10 minutes weatherTimer.timeout.connect(weather_obj.download_sacramento_weather_map(engine)) + weather_obj.download_sacramento_weather_map(engine) + + + + weatherTimer.start() diff --git a/deathclock/weather.py b/deathclock/weather.py index 8d01d6a..ba42366 100644 --- a/deathclock/weather.py +++ b/deathclock/weather.py @@ -8,14 +8,14 @@ from PySide6.QtQml import QQmlApplicationEngine class Weather(QObject): - + weatherUpdated = Signal(str) def __init__(self): super().__init__() - def download_sacramento_weather_map(self, engine): + def download_sacramento_weather_map(self,engine): url = "https://www.google.com/search?q=weather&hl=en-GB" service = Service(executable_path='/home/death916/code/python/deathclock/deathclock/chromedriver') options = webdriver.ChromeOptions() @@ -27,12 +27,14 @@ class Weather(QObject): screenshot_path = 'sacramento_weather_map.png' map_element.screenshot(screenshot_path) print("screen shot taken") + weather_context = engine.rootContext() image = screenshot_path weather_context = engine.rootContext() weather_context.setContextProperty("weatherImage", image) driver.quit() + self.weatherUpdated.emit(image) return screenshot_path def cur_weather(): diff --git a/main.qml b/main.qml index ec05243..6693aea 100644 --- a/main.qml +++ b/main.qml @@ -83,7 +83,7 @@ ApplicationWindow { Image { anchors.fill: parent - source: weatherImage + source: weatherMapPath //fillMode: Image.fill // Fill the entire area // Uncomment this line to fill the entire area }