-
Notifications
You must be signed in to change notification settings - Fork 1
/
simulation_controller_simple.py
155 lines (120 loc) · 5.34 KB
/
simulation_controller_simple.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
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
import sys
from PyQt4.QtCore import *
from PyQt4.QtGui import *
from PyQt4 import QtGui, QtCore
import nett_python as nett
from float_message_pb2 import *
import subprocess
nett.initialize('tcp://127.0.0.1:2003')
#hard-coded, might be changed later
update_interval_min = 0.1 * 100
update_interval_max = 10000
class SimulationController(QtGui.QWidget):
def __init__(self):
super(SimulationController, self).__init__()
self.init_ui()
self.init_actions()
self.quit_slot_out = nett.slot_out_float_message('quit')
self.pause_slot_out = nett.slot_out_float_message('pause')
self.reset_slot_out = nett.slot_out_float_message('reset')
self.update_interval_slot_out = nett.slot_out_float_message('update_interval')
self.save_slot_out = nett.slot_out_float_message('save')
#send valid update_interval
msg = float_message()
msg.value = update_interval_min
self.update_interval_slot_out.send(msg.SerializeToString())
def init_ui(self):
layout = QVBoxLayout()
self.l1 = QLabel("Update Interval")
self.l1.setAlignment(Qt.AlignCenter)
layout.addWidget(self.l1)
self.sl = QSlider(Qt.Horizontal)
self.sl.setMinimum(update_interval_min)
self.sl.setMaximum(update_interval_max)
self.sl.setValue(1000)
self.sl.setTickPosition(QSlider.TicksBelow)
self.sl.setTickInterval(1)
layout.addWidget(self.sl)
self.sl.valueChanged.connect(self.on_slidervalue_change)
self.setLayout(layout)
self.pause_button = QtGui.QPushButton('Pause', self)
self.pause_button.clicked.connect(self.send_pause)
layout.addWidget(self.pause_button)
self.quit_button = QtGui.QPushButton('Quit', self)
self.quit_button.clicked.connect(self.send_quit)
layout.addWidget(self.quit_button)
self.reset_button = QtGui.QPushButton('Reset', self)
self.reset_button.clicked.connect(self.send_reset)
layout.addWidget(self.reset_button)
self.start_frplot_button = QtGui.QPushButton('Firing rate Plot', self)
self.start_frplot_button.clicked.connect(self.start_frplot)
layout.addWidget(self.start_frplot_button)
self.start_connectionplot_button = QtGui.QPushButton('Connection Plot', self)
self.start_connectionplot_button.clicked.connect(self.start_connectionplot)
layout.addWidget(self.start_connectionplot_button)
self.start_region_button = QtGui.QPushButton('Region Selector', self)
self.start_region_button.clicked.connect(self.start_region)
layout.addWidget(self.start_region_button)
self.start_eta_button = QtGui.QPushButton('ETA change', self)
self.start_eta_button.clicked.connect(self.start_eta)
layout.addWidget(self.start_eta_button)
self.start_growth_button = QtGui.QPushButton('Growth change', self)
self.start_growth_button.clicked.connect(self.start_growth)
layout.addWidget(self.start_growth_button)
self.save_button = QtGui.QPushButton('Save status', self)
self.save_button.clicked.connect(self.send_save)
layout.addWidget(self.save_button)
self.setGeometry(300, 300, 350, 150)
self.setWindowTitle('SimControl')
self.show()
def init_actions(self):
self.exit_action = QtGui.QAction('Quit', self)
self.exit_action.setShortcut('Ctrl+Q')
self.exit_action.setStatusTip('Exit application')
self.connect(self.exit_action, QtCore.SIGNAL('triggered()'), self.close)
self.addAction(self.exit_action)
def on_slidervalue_change(self):
msg = float_message()
msg.value = self.sl.value()
self.update_interval_slot_out.send(msg.SerializeToString())
print msg
def send_reset(self):
msg = float_message()
msg.value = 1.
self.reset_slot_out.send(msg.SerializeToString())
print 'reset sent'
def send_quit(self):
msg = float_message()
msg.value = 1.
self.quit_slot_out.send(msg.SerializeToString())
print 'quit sent'
def send_pause(self):
msg = float_message()
msg.value = 1.
self.pause_slot_out.send(msg.SerializeToString())
print 'pause sent'
if str(self.pause_button.text()) == 'Continue':
self.pause_button.setText('Pause')
else:
self.pause_button.setText('Continue')
def send_save(self):
msg = float_message()
msg.value = 1.
self.save_slot_out.send(msg.SerializeToString())
print 'save sent'
def start_frplot(self):
subprocess.Popen( ['python', 'fr_plotter.py'], shell=False )
def start_connectionplot(self):
subprocess.Popen( ['python', 'connection_plotter_simple.py'], shell=False )
def start_region(self):
subprocess.Popen( ['python', 'region_selector.py'], shell=False )
def start_eta(self):
subprocess.Popen( ['python', 'eta_manipulator.py'], shell=False )
def start_growth(self):
subprocess.Popen( ['python', 'growth_rate_manipulator_simple.py'], shell=False )
def main():
app = QtGui.QApplication(sys.argv)
simulation_controller = SimulationController()
sys.exit(app.exec_())
if __name__ == '__main__':
main()