Skip to content

Commit

Permalink
Added menu option for shared output.
Browse files Browse the repository at this point in the history
  • Loading branch information
rogerhurwitz committed Oct 14, 2019
1 parent acaa027 commit 22a8653
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 26 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Expand Up @@ -7,3 +7,6 @@ spikely/__pycache__/
tests/__pycache__/
venv/
*.json
tmp_klusta/
tmp_mountainsort4
tmp_herdingspikes
44 changes: 28 additions & 16 deletions spikely/file_menu.py
Expand Up @@ -30,30 +30,42 @@ def create_file_menu(main_window: QtWidgets.QMainWindow,
_pipeline_model = pipeline_model

file_menu = QtWidgets.QMenu('&File', main_window)
_create_file_actions(file_menu, main_window)
return file_menu

file_menu.addAction(_action(
'Load Pipeline', 'Load pipeline from JSON file', _perform_load_action))
file_menu.addAction(_action(
'Save Pipeline', 'Save pipeline to JSON file', _perform_save_action))
file_menu.addSeparator()
file_menu.addAction(_action(
'Share Output', 'Use terminal for all pipeline output',
_toggle_share_state, checkable=True, checked=False))
file_menu.addSeparator()
file_menu.addAction(_action(
'Exit', 'Terminate the application.',
QtWidgets.QApplication.closeAllWindows))

return file_menu

def _create_file_actions(menu, win):
file_actions = [
('Load Pipeline', 'Ctrl+L', 'Load pipeline from JSON file',
_perform_load_action),
('Save Pipeline', 'Ctrl+S', 'Save pipeline to JSON file.',
_perform_save_action),
('Exit', 'Ctrl+Q', 'Terminate the application',
QtWidgets.QApplication.closeAllWindows)
]

for name, shortcut, statustip, signal in file_actions:
action = QtWidgets.QAction(name, win)
def _action(name, tip, slot, shortcut=None, checkable=False, checked=None):
action = QtWidgets.QAction(name, config.get_main_window(),
checkable=checkable)
action.setStatusTip(tip)
action.triggered.connect(slot)
if shortcut is not None:
action.setShortcut(shortcut)
action.setStatusTip(statustip)
action.triggered.connect(signal)
menu.addAction(action)
if checkable and checked is not None:
action.setChecked(checked)

return action


# Menu Action execution methods

def _toggle_share_state(checked):
_pipeline_model.share_output = checked


def _perform_load_action() -> None:
"""Loads current pipeline with elements from a previously saved JSON file
Expand Down
26 changes: 21 additions & 5 deletions spikely/pipeline_model.py
Expand Up @@ -16,6 +16,16 @@ def __init__(self, parameter_model):
self._element_list = []
self._element_policy = sp_ste.StdElementPolicy()
self._parameter_model = parameter_model
self._share_output = False

# TODO: Put back in when ready to support terminal output
@property
def share_output(self):
return self._share_output

@share_output.setter
def share_output(self, state):
self._share_output = state

def _elem_cls_count(self, target_cls):
elem_cls_list = [type(elem) for elem in self._element_list]
Expand Down Expand Up @@ -60,16 +70,22 @@ def run(self):
for element in self._element_list]

elem_list_str = json.dumps(elem_jdict_list)
pipeman_path = pkg_resources.resource_filename(
'spikely.pipeman', 'pipeman.py')

run_process = QtCore.QProcess()
# TODO: Add plumbing for shared output support
if self.share_output:
run_path = pkg_resources.resource_filename(
'spikely.pipeman', 'piperun.py')
else:
run_path = pkg_resources.resource_filename(
'spikely.pipeman', 'pipeman.py')

run_process = QtCore.QProcess(self)
success = run_process.startDetached(
'python', [f'{pipeman_path}', elem_list_str])
'python', [f'{run_path}', elem_list_str])
if not success:
QtWidgets.QMessageBox.warning(
config.get_main_window(), 'Failed to Start Python Process',
f'Command line: python {pipeman_path}, elem_list_str')
f'Command line: python {run_path}, elem_list_str')

def clear(self):
self.beginResetModel()
Expand Down
8 changes: 5 additions & 3 deletions spikely/pipeman/pipeman.py
Expand Up @@ -32,13 +32,15 @@ def __init__(self):

piperun_path = pkg_resources.resource_filename(
'spikely.pipeman', 'piperun.py')
self.process.start('python', [piperun_path, sys.argv[1]])
self.process.start('python', ['-u', piperun_path, sys.argv[1]])

if self.process.state() == QtCore.QProcess.Starting \
or self.process.state() == QtCore.QProcess.Running:
self.cancel_btn.setDisabled(False)
self.process.finished.connect(
lambda: self.cancel_btn.setDisabled(True))
self.process.finished.connect(self._process_finished)

def _process_finished(self, exit_status):
self.cancel_btn.setDisabled(True)

def _init_ui(self):
self.setWindowTitle("spikely pipeline manager")
Expand Down
5 changes: 4 additions & 1 deletion spikely/pipeman/piperun.py
@@ -1,4 +1,5 @@
import json
import os
import sys

from spikely import config as cfg
Expand All @@ -22,7 +23,9 @@ def run(elem_list_str):

def main():
run(sys.argv[1])
sys.exit()

# Turns out that this is a very important call
os._exit(1)


if __name__ == '__main__':
Expand Down
2 changes: 1 addition & 1 deletion spikely/version.py
@@ -1 +1 @@
__version__ = '0.6.2'
__version__ = '0.6.3'

0 comments on commit 22a8653

Please sign in to comment.