Revize 3b3b9e9b
Přidáno uživatelem Martin Forejt před téměř 4 roky(ů)
aswi2021vochomurka/view/settings.py | ||
---|---|---|
1 | 1 |
from PyQt5 import QtCore |
2 | 2 |
from PyQt5.QtCore import QSettings, QSize |
3 |
from PyQt5.QtGui import QStandardItemModel, QStandardItem |
|
4 | 3 |
from PyQt5.QtWidgets import QDialog, QVBoxLayout, QDialogButtonBox, QGroupBox, QFormLayout, QLabel, QLineEdit, QSpinBox, \ |
5 |
QCheckBox, QListView, QWidget, QPushButton, QHBoxLayout, QListWidget, QListWidgetItem, QTableWidget
|
|
4 |
QCheckBox, QPushButton, QListWidget, QListWidgetItem
|
|
6 | 5 |
|
6 |
DEFAULT_HOST = "localhost" |
|
7 |
DEFAULT_PORT = 1883 |
|
8 |
DEFAULT_KEEPALIVE = 60 |
|
9 |
DEFAULT_ANONYMOUS = True |
|
10 |
DEFAULT_USERNAME = "" |
|
11 |
DEFAULT_PASSWORD = "" |
|
12 |
DEFAULT_TOPICS = ["/home/1", "/home/2"] |
|
13 |
DEFAULT_TIMEOUT = 60 |
|
7 | 14 |
|
8 | 15 |
class SettingsDialog(QDialog): |
9 |
topics = ['/home/1', '/home/2']
|
|
16 |
topics = DEFAULT_TOPICS
|
|
10 | 17 |
|
11 | 18 |
def __init__(self): |
12 | 19 |
super(SettingsDialog, self).__init__() |
... | ... | |
16 | 23 |
|
17 | 24 |
connectionGroupBox = QGroupBox("Connection") |
18 | 25 |
connectionLayout = QFormLayout() |
19 |
self.hostInput = QLineEdit(self.settings.value("connection_host", "localhost", str))
|
|
26 |
self.hostInput = QLineEdit(self.settings.value("connection_host", DEFAULT_HOST, str))
|
|
20 | 27 |
connectionLayout.addRow(QLabel("Host:"), self.hostInput) |
21 | 28 |
self.portInput = QSpinBox() |
22 | 29 |
self.portInput.setMaximum(65535) |
23 |
self.portInput.setValue(self.settings.value("connection_port", 1883, int))
|
|
30 |
self.portInput.setValue(self.settings.value("connection_port", DEFAULT_PORT, int))
|
|
24 | 31 |
connectionLayout.addRow(QLabel("Port:"), self.portInput) |
25 | 32 |
self.keepaliveInput = QSpinBox() |
26 | 33 |
self.keepaliveInput.setMaximum(1000) |
27 |
self.keepaliveInput.setValue(self.settings.value("connection_keepalive", 60, int))
|
|
34 |
self.keepaliveInput.setValue(self.settings.value("connection_keepalive", DEFAULT_KEEPALIVE, int))
|
|
28 | 35 |
connectionLayout.addRow(QLabel("Keepalive(s):"), self.keepaliveInput) |
29 | 36 |
self.anonymousInput = QCheckBox() |
30 |
self.anonymousInput.setChecked(self.settings.value("connection_anonymous", True, bool))
|
|
37 |
self.anonymousInput.setChecked(self.settings.value("connection_anonymous", DEFAULT_ANONYMOUS, bool))
|
|
31 | 38 |
self.anonymousInput.stateChanged.connect(self.anonymousChanged) |
32 | 39 |
connectionLayout.addRow(QLabel("Anonymous:"), self.anonymousInput) |
33 |
self.usernameInput = QLineEdit(self.settings.value("connection_username", "", str))
|
|
40 |
self.usernameInput = QLineEdit(self.settings.value("connection_username", DEFAULT_USERNAME, str))
|
|
34 | 41 |
connectionLayout.addRow(QLabel("Username:"), self.usernameInput) |
35 |
self.passwordInput = QLineEdit(self.settings.value("connection_password", "", str))
|
|
42 |
self.passwordInput = QLineEdit(self.settings.value("connection_password", DEFAULT_PASSWORD, str))
|
|
36 | 43 |
connectionLayout.addRow(QLabel("Password:"), self.passwordInput) |
37 | 44 |
self.anonymousChanged() |
38 | 45 |
connectionGroupBox.setLayout(connectionLayout) |
... | ... | |
40 | 47 |
topicsGroupBox = QGroupBox("Topics") |
41 | 48 |
topicsLayout = QFormLayout() |
42 | 49 |
|
50 |
self.topics = self.settings.value("topics_items", DEFAULT_TOPICS, list) |
|
43 | 51 |
self.topicsListWidget = QListWidget() |
44 | 52 |
for topic in self.topics: |
45 | 53 |
item = QListWidgetItem() |
... | ... | |
63 | 71 |
timeoutLabel = QLabel("Topic timeout(s):") |
64 | 72 |
timeoutLabel.setToolTip("Unsubscribe topic and close file when there is not new message after this " |
65 | 73 |
"timeout (in seconds) expires") |
66 |
self.timeoutInput.setValue(self.settings.value("topic_timeout", 60, int))
|
|
74 |
self.timeoutInput.setValue(self.settings.value("topics_timeout", DEFAULT_TIMEOUT, int))
|
|
67 | 75 |
topicsLayout.addRow(timeoutLabel, self.timeoutInput) |
68 | 76 |
|
69 | 77 |
topicsGroupBox.setLayout(topicsLayout) |
... | ... | |
96 | 104 |
|
97 | 105 |
def accept(self) -> None: |
98 | 106 |
super().accept() |
99 |
self.topics = self.topicsListWidget.item(0).text() |
|
100 |
print(self.topics) |
|
107 |
self.topics = [] |
|
108 |
for index in range(self.topicsListWidget.count()): |
|
109 |
self.topics.append(self.topicsListWidget.item(index).text()) |
|
110 |
|
|
111 |
self.settings.setValue("topics_items", self.topics) |
|
112 |
self.settings.setValue("topics_timeout", self.timeoutInput.value()) |
|
101 | 113 |
self.settings.setValue("connection_host", self.hostInput.text()) |
102 | 114 |
self.settings.setValue("connection_port", self.portInput.value()) |
103 | 115 |
self.settings.setValue("connection_keepalive", self.keepaliveInput.value()) |
Také k dispozici: Unified diff
Re: #8921 - use configuration from QSettings