-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
77 lines (59 loc) · 2 KB
/
main.py
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
69
70
71
72
73
74
75
76
77
import sys
from pprint import pprint
from PySide6 import QtCore
from PySide6.QtCore import Signal
from PySide6.QtWidgets import QApplication, QMainWindow
import WeatherUnits
WeatherUnits.config.read('config-example-us.ini')
from ui.main_UI import Ui_MainWindow
SECOND_DISPLAY = True
class MainWindow(QMainWindow, Ui_MainWindow):
signal = Signal(str)
def __init__(self, *args, **kwargs):
super(MainWindow, self).__init__(*args, **kwargs)
self.devices = self.getDevices()
print(list(self.devices.keys()))
self.setupUi(self)
self.stationSelection.addItem(str(list(self.devices.keys())[0]))
self.connectionToggle.clicked.connect(self.toggle)
def getDevices(self):
import urllib.request
from json import loads
url = 'https://swd.weatherflow.com/swd/rest/stations/'
token = "f2f4cc66-7dec-4b09-bf64-f70c01da9690"
devices = {}
url = "{}?token={}".format(url, token)
with urllib.request.urlopen(url) as response:
the_page: bytes = response.read()
data = loads(the_page.decode('ascii'))
pprint(data)
for x in data['stations']:
for y in x['devices']:
if y['device_type'] != 'HB':
id = y.pop('device_id')
devices[id] = y
return devices
def toggle(self):
if self.tabs.currentWidget().objectName() == 'udp':
self.udpFrame.toggle()
elif self.tabs.currentWidget().objectName() == 'webSocket':
self.webFrame.toggle()
def eventFilter(self, obj, event):
if event.type() == QtCore.QEvent.KeyPress:
if event.key() == QtCore.Qt.Key_R:
self.loop.create_task(self.messenger.connectSocket())
return super(MainWindow, self).eventFilter(obj, event)
def exitHandler(self):
self.webFrame.messenger.terminate()
if __name__ == '__main__':
import logging
app = QApplication()
app.setQuitOnLastWindowClosed(True)
window = MainWindow()
app.aboutToQuit.connect(window.exitHandler)
if SECOND_DISPLAY:
display = app.screens()[1]
window.setScreen(display)
window.move(display.geometry().x() + 200, display.geometry().y() + 200)
window.show()
sys.exit(app.exec_())