-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
68 lines (57 loc) · 2.25 KB
/
Copy pathmain.py
File metadata and controls
68 lines (57 loc) · 2.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
from PyQt5 import QtQml, QtWidgets, QtGui, QtCore
from weather import Weather, Unit
import sys
#---------------------------------------------#
# weather setup + variables to use in classes #
#---------------------------------------------#
mainLocation = "warsaw"
#weather setup, units, location and the conditions
weather = Weather(unit = Unit.CELSIUS)
weatherLocation = weather.lookup_by_location(mainLocation)
weatherCondition = weatherLocation.condition
weatherForecast = weatherLocation.forecast
#----------------------------#
# main window class with QML #
#----------------------------#
class Window(QtWidgets.QMainWindow):
def __init__(self):
super().__init__()
#---------------------------------------------#
# main function that can be output trough QML #
#---------------------------------------------#
@QtCore.pyqtSlot(result = str)
def mainWeather(self):
#final output
weatherFullString = "Today it's " + self.mainWeatherDate() + ", we have " + self.mainWeatherTemp() + " and a " + self.mainWeatherStatus() + " day."
return weatherFullString
#-----------------------------------------#
# main date that can be output trough QML #
#-----------------------------------------#
@QtCore.pyqtSlot(result = str)
def mainWeatherDate(self):
weatherDate = weatherCondition.date
return weatherDate
#-----------------------------------------#
# main temp that can be output trough QML #
#-----------------------------------------#
@QtCore.pyqtSlot(result = str)
def mainWeatherTemp(self):
weatherTemp = weatherCondition.temp + "°"
return weatherTemp
#----------------------------------------------#
# main condition that can be output trough QML #
#----------------------------------------------#
@QtCore.pyqtSlot(result = str)
def mainWeatherStatus(self):
weatherStatus = weatherCondition.text
return weatherStatus
#-------------------#
# app setup for QML #
#-------------------#
app = QtWidgets.QApplication(sys.argv)
window = Window()
engine = QtQml.QQmlApplicationEngine()
engine.rootContext().setContextProperty("window", window)
engine.load("main.qml")
engine.quit.connect(app.quit)
sys.exit(app.exec_())