Skip to content

Commit 15072d7

Browse files
committed
config: Add a PyQt4 app to fill in the config.
1 parent 15dd1e6 commit 15072d7

File tree

2 files changed

+245
-0
lines changed

2 files changed

+245
-0
lines changed

config.py

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
#!/usr/bin/env python
2+
3+
4+
from __future__ import print_function
5+
6+
from collections import OrderedDict
7+
import json
8+
import sys
9+
10+
from PyQt4 import QtCore, QtGui, uic
11+
12+
13+
# Python 3 compatibility
14+
try:
15+
xrange
16+
except NameError:
17+
xrange = range
18+
19+
20+
class Config(QtGui.QDialog):
21+
"""
22+
Parses the configuration the user applies
23+
"""
24+
25+
def __init__(self):
26+
super(Config, self).__init__()
27+
28+
self.config = OrderedDict()
29+
30+
self.ui = uic.loadUi("config.ui")
31+
self.ui.show()
32+
33+
btn = self.ui.buttonBox.button(
34+
QtGui.QDialogButtonBox.Ok
35+
)
36+
btn.clicked.connect(self.accept)
37+
38+
def accept(self):
39+
table = self.ui.tableWidget
40+
for i in xrange(table.rowCount()):
41+
header_i = str(table.verticalHeaderItem(i).text())
42+
self.config[header_i] = ""
43+
item_i = table.item(0, i)
44+
if item_i:
45+
self.config[header_i] = str(item_i.text())
46+
47+
filename = QtGui.QFileDialog.getSaveFileName(
48+
self,
49+
"Save file",
50+
"",
51+
"*.json"
52+
)
53+
with open(filename, "w") as f:
54+
json.dump(self.config, f, indent=True)
55+
56+
def main(*argv):
57+
app = QtGui.QApplication(sys.argv)
58+
window = Config()
59+
return app.exec_()
60+
61+
if __name__ == "__main__":
62+
sys.exit(main(*sys.argv))

config.ui

Lines changed: 183 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,183 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<ui version="4.0">
3+
<class>Dialog</class>
4+
<widget class="QDialog" name="Dialog">
5+
<property name="geometry">
6+
<rect>
7+
<x>0</x>
8+
<y>0</y>
9+
<width>598</width>
10+
<height>648</height>
11+
</rect>
12+
</property>
13+
<property name="sizePolicy">
14+
<sizepolicy hsizetype="Maximum" vsizetype="Maximum">
15+
<horstretch>0</horstretch>
16+
<verstretch>0</verstretch>
17+
</sizepolicy>
18+
</property>
19+
<property name="windowTitle">
20+
<string>Dialog</string>
21+
</property>
22+
<property name="autoFillBackground">
23+
<bool>false</bool>
24+
</property>
25+
<layout class="QGridLayout" name="gridLayout">
26+
<item row="1" column="0">
27+
<layout class="QVBoxLayout" name="verticalLayout">
28+
<item>
29+
<widget class="QTableWidget" name="tableWidget">
30+
<attribute name="horizontalHeaderStretchLastSection">
31+
<bool>true</bool>
32+
</attribute>
33+
<attribute name="verticalHeaderCascadingSectionResizes">
34+
<bool>false</bool>
35+
</attribute>
36+
<attribute name="verticalHeaderStretchLastSection">
37+
<bool>false</bool>
38+
</attribute>
39+
<row>
40+
<property name="text">
41+
<string>Rig_Name</string>
42+
</property>
43+
</row>
44+
<row>
45+
<property name="text">
46+
<string>User</string>
47+
</property>
48+
</row>
49+
<row>
50+
<property name="text">
51+
<string>Proj_Code</string>
52+
</property>
53+
</row>
54+
<row>
55+
<property name="text">
56+
<string>Rec_Sys</string>
57+
</property>
58+
</row>
59+
<row>
60+
<property name="text">
61+
<string>Behav_Code_Ver</string>
62+
</property>
63+
</row>
64+
<row>
65+
<property name="text">
66+
<string>NS_Path</string>
67+
</property>
68+
</row>
69+
<row>
70+
<property name="text">
71+
<string>Behav_Path</string>
72+
</property>
73+
</row>
74+
<row>
75+
<property name="text">
76+
<string>Jpos_X_Ch</string>
77+
</property>
78+
</row>
79+
<row>
80+
<property name="text">
81+
<string>Jpos_Y_Ch</string>
82+
</property>
83+
</row>
84+
<row>
85+
<property name="text">
86+
<string>Mpos_X_Ch</string>
87+
</property>
88+
</row>
89+
<row>
90+
<property name="text">
91+
<string>Mpos_Y_Ch</string>
92+
</property>
93+
</row>
94+
<row>
95+
<property name="text">
96+
<string>Lick_Ch</string>
97+
</property>
98+
</row>
99+
<row>
100+
<property name="text">
101+
<string>Rew_Ch</string>
102+
</property>
103+
</row>
104+
<row>
105+
<property name="text">
106+
<string>Trial_Start_Ch</string>
107+
</property>
108+
</row>
109+
<row>
110+
<property name="text">
111+
<string>Trial_Event_Ch</string>
112+
</property>
113+
</row>
114+
<column>
115+
<property name="text">
116+
<string>Input</string>
117+
</property>
118+
</column>
119+
</widget>
120+
</item>
121+
<item>
122+
<widget class="QDialogButtonBox" name="buttonBox">
123+
<property name="orientation">
124+
<enum>Qt::Horizontal</enum>
125+
</property>
126+
<property name="standardButtons">
127+
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
128+
</property>
129+
</widget>
130+
</item>
131+
</layout>
132+
</item>
133+
<item row="0" column="0" alignment="Qt::AlignHCenter">
134+
<widget class="QLabel" name="label">
135+
<property name="text">
136+
<string>&lt;b&gt;Lab Data Configuration Generator&lt;/b&gt;</string>
137+
</property>
138+
<property name="textFormat">
139+
<enum>Qt::AutoText</enum>
140+
</property>
141+
<property name="wordWrap">
142+
<bool>false</bool>
143+
</property>
144+
</widget>
145+
</item>
146+
</layout>
147+
</widget>
148+
<resources/>
149+
<connections>
150+
<connection>
151+
<sender>buttonBox</sender>
152+
<signal>accepted()</signal>
153+
<receiver>Dialog</receiver>
154+
<slot>accept()</slot>
155+
<hints>
156+
<hint type="sourcelabel">
157+
<x>248</x>
158+
<y>254</y>
159+
</hint>
160+
<hint type="destinationlabel">
161+
<x>157</x>
162+
<y>274</y>
163+
</hint>
164+
</hints>
165+
</connection>
166+
<connection>
167+
<sender>buttonBox</sender>
168+
<signal>rejected()</signal>
169+
<receiver>Dialog</receiver>
170+
<slot>reject()</slot>
171+
<hints>
172+
<hint type="sourcelabel">
173+
<x>316</x>
174+
<y>260</y>
175+
</hint>
176+
<hint type="destinationlabel">
177+
<x>286</x>
178+
<y>274</y>
179+
</hint>
180+
</hints>
181+
</connection>
182+
</connections>
183+
</ui>

0 commit comments

Comments
 (0)