This repository was archived by the owner on Apr 24, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathsettings.py
More file actions
291 lines (195 loc) · 8.71 KB
/
Copy pathsettings.py
File metadata and controls
291 lines (195 loc) · 8.71 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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
#!/usr/bin/python
# coding: utf-8
import sys
import os
from PyQt5 import QtGui, QtCore, QtWidgets
from log import MyLog
from wizard_add_journal import WizardAddJournal
from wizard_del_journal import WizardDelJournal
import hosts
import functions
class Settings(QtWidgets.QDialog):
"""Class for the program settings, modifiable by the user.
Creates a child window"""
def __init__(self, parent=None):
super(Settings, self).__init__(parent)
self.setModal(True)
self.setAttribute(QtCore.Qt.WA_DeleteOnClose)
self.parent = parent
self.resource_dir, self.DATA_PATH = functions.getRightDirs()
if parent is None:
self.l = MyLog("activity.log")
# Dummy file for saving if testing
self.options = QtCore.QSettings("debug/options.ini",
QtCore.QSettings.IniFormat)
self.test = True
else:
self.l = self.parent.l
self.options = self.parent.options
self.test = False
# Store the checkboxes of the window
self.check_journals = []
self.initUI()
self.connexion()
self.defineSlots()
def connexion(self):
"""Get the settings and restore them"""
journals_to_parse = self.options.value("journals_to_parse", [])
# Check the boxes
if not journals_to_parse:
return
else:
for box in self.check_journals:
if box.text() in journals_to_parse:
box.setCheckState(2)
else:
box.setCheckState(0)
def defineSlots(self):
"""Establish the slots"""
# To close the window and save the settings
self.ok_button.clicked.connect(self.saveSettings)
# Button "clean database" (erase the unintersting journals from the db)
# connected to the method of the main window class
# TO COMMENT to run the module standalone
if not self.test:
self.button_clean_db.clicked.connect(self.parent.cleanDb)
self.button_reset_db.clicked.connect(self.parent.resetDb)
self.button_erase_db.clicked.connect(self.parent.eraseDb)
def dialogManageJournals(self):
"""Opens a dialog, let the user choose between deleting and adding
journals"""
dial = QtWidgets.QDialog(self)
label_choice = QtWidgets.QLabel("Would you like to:")
button_add = QtWidgets.QPushButton("Add a journal")
button_del = QtWidgets.QPushButton("Delete a journal")
button_add.clicked.connect(dial.accept)
button_add.clicked.connect(lambda: WizardAddJournal(self))
button_del.clicked.connect(dial.accept)
button_del.clicked.connect(lambda: WizardDelJournal(self))
hbox_dial = QtWidgets.QHBoxLayout()
hbox_dial.addWidget(button_add)
hbox_dial.addWidget(button_del)
vbox_dial = QtWidgets.QVBoxLayout()
vbox_dial.addWidget(label_choice, alignment=QtCore.Qt.AlignHCenter)
vbox_dial.addLayout(hbox_dial)
dial.setLayout(vbox_dial)
dial.show()
def selectUnselectAll(self, state):
"""Select or unselect all the journals"""
for box in self.check_journals:
box.setCheckState(state)
def clearLayout(self, layout):
"""Method to erase the widgets from a layout"""
if layout is not None:
while layout.count():
item = layout.takeAt(0)
widget = item.widget()
if widget is not None:
widget.deleteLater()
QtWidgets.qApp.processEvents()
else:
self.clearLayout(item.layout())
def displayJournals(self):
"""Display the checkboxes of the journals"""
self.clearLayout(self.vbox_check_journals)
self.check_journals = []
self.button_manage_journals = QtWidgets.QPushButton("Manage journals")
self.vbox_check_journals.addWidget(self.button_manage_journals)
self.button_manage_journals.clicked.connect(self.dialogManageJournals)
labels_checkboxes = []
# Get labels of the future check boxes of the journals to be parsed
for company in hosts.getCompanies():
labels_checkboxes += hosts.getJournals(company)[1]
labels_checkboxes.sort()
self.box_select_all = QtWidgets.QCheckBox("(Un)Select all")
self.box_select_all.setCheckState(0)
self.vbox_check_journals.addWidget(self.box_select_all)
# Checkbox to select/unselect all the journals
self.box_select_all.stateChanged.connect(self.selectUnselectAll)
# Build the checkboxes, and put them in a layout
for label in labels_checkboxes:
check_box = QtWidgets.QCheckBox(label)
check_box.setCheckState(2)
self.check_journals.append(check_box)
self.vbox_check_journals.addWidget(check_box)
# Restore check boxes states
journals_to_parse = self.options.value("journals_to_parse", [])
if not journals_to_parse:
return
else:
for box in self.check_journals:
if box.text() in journals_to_parse:
box.setCheckState(2)
else:
box.setCheckState(0)
def initUI(self):
"""Handles the display"""
self.setWindowTitle('Settings')
self.ok_button = QtWidgets.QPushButton("OK", self)
self.tabs = QtWidgets.QTabWidget()
# ------------------------ JOURNALS TAB ---------------------------------------
# Scroll area for the journals to check
self.scroll_check_journals = QtWidgets.QScrollArea()
self.scrolling_check_journals = QtWidgets.QWidget()
self.vbox_check_journals = QtWidgets.QVBoxLayout()
self.scrolling_check_journals.setLayout(self.vbox_check_journals)
# Add the check boxes for all the journals
self.displayJournals()
self.scroll_check_journals.setWidget(self.scrolling_check_journals)
self.tabs.addTab(self.scroll_check_journals, "Journals")
# ------------------------ DATABASE TAB ---------------------------------------
self.widget_database = QtWidgets.QWidget()
self.vbox_database = QtWidgets.QVBoxLayout()
mes = """
Click on the buttons to display help.
Confirmation will be asked before anything
is done to your data: no worries.
"""
mes = mes.replace(" ", "")
self.label_explain = QtWidgets.QLabel(mes)
self.button_clean_db = QtWidgets.QPushButton("Clean database")
self.button_reset_db = QtWidgets.QPushButton("Reset database")
self.button_erase_db = QtWidgets.QPushButton("Erase database")
# Create an empty widget to act as a spacer
empty_widget = QtWidgets.QWidget()
empty_widget.setSizePolicy(QtWidgets.QSizePolicy.Preferred,
QtWidgets.QSizePolicy.Expanding)
# Add the spacer between each button
self.vbox_database.addWidget(self.label_explain,
alignment=QtCore.Qt.AlignTop)
self.vbox_database.addWidget(empty_widget)
self.vbox_database.addWidget(self.button_clean_db)
self.vbox_database.addWidget(empty_widget)
self.vbox_database.addWidget(self.button_reset_db)
self.vbox_database.addWidget(empty_widget)
self.vbox_database.addWidget(self.button_erase_db)
self.vbox_database.addWidget(empty_widget)
self.widget_database.setLayout(self.vbox_database)
self.tabs.addTab(self.widget_database, "Database")
# ------------------------ ASSEMBLING ------------------------------------------------
self.vbox_global = QtWidgets.QVBoxLayout()
self.vbox_global.addWidget(self.tabs)
self.vbox_global.addWidget(self.ok_button)
self.setLayout(self.vbox_global)
self.show()
def saveSettings(self):
"""Slot to save the settings"""
journals_to_parse = []
for box in self.check_journals:
if box.checkState() == 2:
journals_to_parse.append(box.text())
if journals_to_parse:
self.options.remove("journals_to_parse")
self.options.setValue("journals_to_parse", journals_to_parse)
else:
self.options.remove("journals_to_parse")
if not self.test:
self.parent.model.submitAll()
self.parent.displayTags()
self.parent.resetView()
# Close the settings window and free the memory
self.close()
if __name__ == '__main__':
app = QtWidgets.QApplication(sys.argv)
obj = Settings()
sys.exit(app.exec_())