Skip to content

Commit 5abb791

Browse files
committed
Added a CONFIGURE command to set the the interpreter's frame rate.
1 parent be2f636 commit 5abb791

File tree

4 files changed

+43
-28
lines changed

4 files changed

+43
-28
lines changed

floppy/floppySettings.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ def __init__(self, *args, settings=None, globals=None):
1717
('Pin Size', PinSizeEdit(settings, globals, self)),
1818
('Temporary File Settings', None),
1919
('Work File Directory', WorkFileDirEdit(settings, globals, self)),
20+
('Remote Interpreter Settings', None),
21+
('Frame Rate', RGIFrameRateEdit(settings, globals, self)),
2022
]
2123
super(SettingsDialog, self).__init__(*args)
2224
self.setStyleSheet('''SettingsDialog {
@@ -266,3 +268,17 @@ def __init__(self, settings, globals, parent):
266268
def commit(self):
267269
self.settings.setValue('LocalPort', self.value())
268270
self.globals['LOCALPORT'] = self.value()
271+
272+
273+
class RGIFrameRateEdit(QLineEdit):
274+
def __init__(self, settings, globals, parent):
275+
self.parent = parent
276+
self.globals = globals
277+
self.settings = settings
278+
super(RGIFrameRateEdit, self).__init__()
279+
v = settings.value('FrameRate', type=float)
280+
v = v if v else .1
281+
self.setText(str(v))
282+
283+
def commit(self):
284+
self.settings.setValue('FrameRate', float(self.text()))

floppy/graph.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -670,6 +670,9 @@ def deleteNode(self, node):
670670
self.removeConnection(out.ID)
671671
del self.nodes[node.ID]
672672

673+
def configureInterpreter(self, options):
674+
self.rgiConnection.send('CONFIGURE{}'.format(json.dumps(options)), print)
675+
673676

674677
class NodeThread(Thread):
675678

floppy/painter.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -872,6 +872,11 @@ def initActions(self):
872872
self.createSubgraphAction.setIconVisibleInMenu(False)
873873
self.addAction(self.createSubgraphAction)
874874

875+
self.configureAction = QAction(QIcon(os.path.join(self.iconRoot, 'configure.png')), 'configure', self)
876+
self.configureAction.setShortcut('Ctrl+Y')
877+
self.configureAction.triggered.connect(self.configureInterpreter)
878+
self.configureAction.setIconVisibleInMenu(False)
879+
self.addAction(self.configureAction)
875880

876881
def initMenus(self):
877882
fileMenu = self.menuBar.addMenu('&File')
@@ -928,6 +933,9 @@ def selectSubgraph(self):
928933
self.drawer.setSelectedSubgraph(self.macroSelector.currentText())
929934
self.drawer.update()
930935

936+
def configureInterpreter(self):
937+
self.drawer.graph.configureInterpreter({'framerate': 0.01, 'foo': 'bar'})
938+
931939
def getSubgraphList(self):
932940
new = self.drawer.getAllSubgraphs()
933941
self.macroSelector.addItems(new.difference(self.knownSubgraphs))

floppy/runner.py

Lines changed: 16 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,14 @@ def kill(self):
109109
self.cmdQueue.put(ExecutionThread.kill)
110110
xLock.release()
111111

112+
def configure(self, options):
113+
try:
114+
framerate = options['framerate']
115+
except KeyError:
116+
pass
117+
else:
118+
self.executionThread.setFrameRate(framerate)
119+
112120
def unpause(self):
113121
xLock.acquire()
114122
if not self.cmdQueue.empty():
@@ -151,7 +159,7 @@ def getReport(self, nodeID):
151159
class ExecutionThread(Thread):
152160
def __init__(self, cmdQueue, master):
153161
self.graph = None
154-
162+
self.framerate = 0.1
155163
self.master = master
156164
self.paused = True
157165
self.alive = True
@@ -161,6 +169,9 @@ def __init__(self, cmdQueue, master):
161169
# self.updateGraph()
162170
self.start()
163171

172+
def setFrameRate(self, framerate):
173+
self.framerate = framerate
174+
164175
def run(self):
165176
while self.alive:
166177
xLock.acquire()
@@ -183,7 +194,7 @@ def run(self):
183194
self.executeGraphStepPar()
184195
self.master.updateRunningNodes(self.graph.runningNodes)
185196
else:
186-
time.sleep(.5)
197+
time.sleep(self.framerate)
187198
print('That\'s it. I\'m dead.')
188199

189200
def pause(self):
@@ -269,32 +280,6 @@ def executeGraphStepPar(self):
269280
print('Nothing to do here @ {}'.format(time.time()))
270281
time.sleep(.1)
271282

272-
def execute(self):
273-
"""
274-
Execute the Graph instance.
275-
276-
First, the execution loop will set itself up to terminate after the first iteration.
277-
Next, every node is given the chance to run if all prerequisites are met.
278-
If a node is executed, the loop termination criterion will be reset to allow an additional iteration over all
279-
nodes.
280-
If no node is execute during one iteration, the termination criterion will not be reset and the execution loop
281-
terminates.
282-
:return:
283-
"""
284-
return self.testRun()
285-
running = True
286-
i = 0
287-
while running:
288-
i += 1
289-
print('\nExecuting iteration {}.'.format(i))
290-
running = False
291-
for node in self.nodes.values():
292-
checked = node.check()
293-
running = checked if not running else True
294-
if checked:
295-
node.run()
296-
# raise RuntimeError('Uncaught exception while executing node {}.'.format(node))
297-
node.notify()
298283

299284

300285
class Listener(Thread):
@@ -374,6 +359,9 @@ def run(self):
374359
nextID = int(message[4:])
375360
self.send('Runner jumping to node {}.'.format(nextID))
376361
self.master.goto(nextID)
362+
elif message.startswith('CONFIGURE'):
363+
msg = message[9:]
364+
self.master.configure(json.loads(msg))
377365
elif message == 'STEP':
378366
self.send('Runner is performing one step.')
379367
self.master.step()

0 commit comments

Comments
 (0)