-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsettings.py
83 lines (63 loc) · 2.54 KB
/
settings.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
81
82
import CallUI
import json
from PyQt5 import QtCore
from PyQt5.QtWidgets import QTableWidgetItem
import helpfunctions
import sampleDB
def openSettingsdialog(self):
self.settingsdialog = CallUI.settingsUI()
with open('config.json', 'r') as f:
config = json.load(f)
legend = config['legend']
i = 0
self.settingsdialog.legendAttributes.setColumnWidth(0, 200) # Width for attribute column
for key in legend:
if config['legend'][key] == True:
chkBoxItem = QTableWidgetItem()
chkBoxItem.setFlags(QtCore.Qt.ItemIsUserCheckable | QtCore.Qt.ItemIsEnabled)
chkBoxItem.setCheckState(QtCore.Qt.Checked)
self.settingsdialog.legendAttributes.setItem(i, 1, chkBoxItem)
i = i + 1
theme = config['theme']
self.settingsdialog.theme.setCurrentText(theme)
context = config['context']
self.settingsdialog.context.setCurrentText(context)
xraywavelength = config['xraywavelength']
self.settingsdialog.xraywavelength.setText(str(xraywavelength))
neutronwavelength = config['neutronwavelength']
self.settingsdialog.neutronwavelength.setText(str(neutronwavelength))
source = config['source']
self.settingsdialog.source.setCurrentText(source)
self.settingsdialog.show()
self.settingsdialog.accepted.connect(lambda: loadSettings(self))
def loadSettings(self):
writeConfig(self)
try:
sampleDB.loadSampleDB(self)
except:
print("Can't load selected samples. You probably haven't opened the SampleDB yet")
def writeConfig(self):
with open('config.json', 'r') as f:
config = json.load(f)
legend = config['legend']
i = 0
for key in legend:
config['legend'][key] = False
if self.settingsdialog.legendAttributes.item(i, 1).checkState() == QtCore.Qt.Checked:
config['legend'][key] = True
i = i + 1
theme = str(self.settingsdialog.theme.currentText())
config['theme'] = theme
context = str(self.settingsdialog.context.currentText())
config['context'] = context
xraywavelength = str(self.settingsdialog.xraywavelength.text())
config['xraywavelength'] = float(xraywavelength)
neutronwavelength = str(self.settingsdialog.neutronwavelength.text())
config['neutronwavelength'] = float(neutronwavelength)
source = str(self.settingsdialog.source.currentText())
config['source'] = source
with open('config.json', 'w') as f:
json.dump(config, f)
def showAbout(self):
self.aboutWindow = CallUI.aboutWindow()
self.aboutWindow.show()