-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathSaveState.py
More file actions
executable file
·127 lines (102 loc) · 4.5 KB
/
Copy pathSaveState.py
File metadata and controls
executable file
·127 lines (102 loc) · 4.5 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
#===================================================================
# Module with functions to save & restore qt widget values
# Written by: Alan Lilly
# Website: http://panofish.net
#===================================================================
from PyQt4.QtGui import *
import inspect
from datetime import datetime
def strtobool(astr):
return astr == True
def guisave(self):
# Save geometry
settings = self.settings
for name, obj in inspect.getmembers(self.ui):
if isinstance(obj, QComboBox):
name = obj.objectName() # get combobox name
index = obj.currentIndex() # get current index from combobox
text = obj.itemText(index) # get the text for current index
settings.setValue(name, text) # save combobox selection to registry
if isinstance(obj, QLineEdit):
name = obj.objectName()
value = obj.text()
settings.setValue(name, value) # save ui values, so they can be restored next time
if isinstance(obj, QCheckBox):
name = obj.objectName()
state = obj.isChecked()
settings.setValue(name, state)
if isinstance(obj, QRadioButton):
name = obj.objectName()
value = obj.isChecked() # get stored value from registry
settings.setValue(name, value)
if isinstance(obj, QSpinBox):
name = obj.objectName()
state = obj.value()
settings.setValue(name, state)
def guidebug(self):
# debug UI
settingsDebug = []
settings = self.settings
for name, obj in inspect.getmembers(self.ui):
if isinstance(obj, QComboBox):
name = obj.objectName() # get combobox name
index = obj.currentIndex() # get current index from combobox
text = obj.itemText(index) # get the text for current index\
settingsDebug.append((name, text))
if isinstance(obj, QLineEdit):
name = obj.objectName()
value = obj.text()
settingsDebug.append((name, value))
if isinstance(obj, QCheckBox):
name = obj.objectName()
state = obj.isChecked()
settingsDebug.append((name, state))
if isinstance(obj, QRadioButton):
name = obj.objectName()
value = obj.isChecked() # get stored value from registry
settingsDebug.append((name, value))
if isinstance(obj, QSpinBox):
name = obj.objectName()
state = obj.value()
settingsDebug.append((name, state))
with open("settingsLog_" + str(self.deviceName.text()) + ".txt", "a") as f:
f.write(str(datetime.now()) + "\n")
for key, value in settingsDebug:
f.write("[" + str(key) + "] " + str(value) + "\n")
f.write("\n")
def guirestore(self):
settings = self.settings
for name, obj in inspect.getmembers(self.ui):
if isinstance(obj, QComboBox):
index = obj.currentIndex() # get current region from combobox
# text = obj.itemText(index) # get the text for new selected index
name = obj.objectName()
value = (settings.value(name))
if value == "":
continue
index = obj.findText(value) # get the corresponding index for specified string in combobox
if index == -1: # add to list if not found
obj.insertItems(0, [value])
index = obj.findText(value)
obj.setCurrentIndex(index)
else:
obj.setCurrentIndex(index) # preselect a combobox value by index
if isinstance(obj, QLineEdit):
name = obj.objectName()
value = (settings.value(name)) # get stored value from registry
obj.setText(value.toString()) # restore lineEditFile
if isinstance(obj, QCheckBox):
name = obj.objectName()
value = settings.value(name) # get stored value from registry
if value != None:
obj.setChecked(strtobool(value)) # restore checkbox
if isinstance(obj, QRadioButton):
name = obj.objectName()
value = settings.value(name) # get stored value from registry
if value != None:
obj.setChecked(strtobool(value))
if isinstance(obj, QSpinBox):
name = obj.objectName()
value = settings.value(name)
if value != None:
obj.setValue(value.toInt()[0]) # toInt returns tuple??