-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
80 lines (62 loc) · 2.16 KB
/
app.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
78
79
80
from cgi import print_environ_usage
from PyQt6.QtGui import *
from PyQt6.QtWidgets import *
from logic import connection_manager
import threading
import configparser
class SettingsWindow(QMainWindow):
def open(self):
settings.show()
def saveConfig(self):
config = configparser.ConfigParser()
config['OPTIONS'] = {
'HostIpAddress': self.ipTextField.text(),
'HostPort': self.portTextField.text(),
'VerboseOutput': self.verboseTextField.text()
}
with open('config.ini', 'w') as configfile:
config.write(configfile)
def __init__(self, connection, icon):
super(SettingsWindow, self).__init__()
self.setWindowTitle("Settings")
self.setMinimumWidth(300)
self.setWindowIcon(icon)
layout = QVBoxLayout()
ipLabel = QLabel('Host ip address')
portLabel = QLabel('Host port number')
verboseLabel = QLabel('Verbose logging')
self.ipTextField = QLineEdit(connection.HOST)
self.portTextField = QLineEdit(connection.PORT)
self.verboseTextField = QLineEdit(str(connection.VERBOSE))
saveButton = QPushButton('Save')
saveButton.clicked.connect(self.saveConfig)
layout.addWidget(ipLabel)
layout.addWidget(self.ipTextField)
layout.addWidget(portLabel)
layout.addWidget(self.portTextField)
layout.addWidget(verboseLabel)
layout.addWidget(self.verboseTextField)
layout.addWidget(saveButton)
widget = QWidget()
widget.setLayout(layout)
self.setCentralWidget(widget)
connection = connection_manager()
app = QApplication([])
menu = QMenu()
icon = QIcon("icon.png")
tray = QSystemTrayIcon()
settings = SettingsWindow(connection, icon)
app.setQuitOnLastWindowClosed(False)
tray.setIcon(icon)
tray.setVisible(True)
settingsItem = QAction("Settings")
settingsItem.triggered.connect(settings.open)
menu.addAction(settingsItem)
# Add a Quit option to the menu.
quit = QAction("Quit")
quit.triggered.connect(app.quit)
menu.addAction(quit)
tray.setContextMenu(menu)
t = threading.Thread(target=connection.main, daemon=True)
t.start()
app.exec()