Browse Source

gui parameters are saved and loaded

master
Holger Frey 6 years ago
parent
commit
cf9e43f00a
  1. 2
      mia-gui.spec
  2. 51
      mtor/gui.py

2
mia-gui.spec

@ -4,7 +4,7 @@ block_cipher = None
a = Analysis(['mia-gui.py'], a = Analysis(['mia-gui.py'],
pathex=['C:\\Users\\Holgi\\Developer\\mtor-image-analysis'], pathex=['C:\\Users\\Holgi\\Developer\\python-libraries\\mtor-image-analysis'],
binaries=[], binaries=[],
datas=[], datas=[],
hiddenimports=[], hiddenimports=[],

51
mtor/gui.py

@ -1,5 +1,7 @@
import sys import json
import os import os
import sys
from pathlib import Path from pathlib import Path
from subprocess import Popen from subprocess import Popen
@ -23,6 +25,7 @@ from .workflows import (
postprocessing_workflow, postprocessing_workflow,
) )
PARAMETERS_FILE = "mia-gui-parameters.json"
class MtorImageAnalysis(QWidget): class MtorImageAnalysis(QWidget):
def __init__(self): def __init__(self):
@ -85,6 +88,17 @@ class MtorImageAnalysis(QWidget):
self.btn_exit = QPushButton("Exit", self) self.btn_exit = QPushButton("Exit", self)
self.btn_exit.clicked.connect(QApplication.instance().quit) self.btn_exit.clicked.connect(QApplication.instance().quit)
self.fields_map = {
'folder': (self.dir_selected, str),
'top': (self.roi_top_input, int),
'right': (self.roi_right_input, int),
'bottom': (self.roi_bottom_input, int),
'left': (self.roi_left_input, int),
'cut_pad_x': (self.pad_x_input, int),
'cut_pad_y': (self.pad_y_input, int),
'boost': (self.cc_boost_input, int),
}
# Layout # Layout
grid = QGridLayout() grid = QGridLayout()
grid.setSpacing(10) grid.setSpacing(10)
@ -155,6 +169,16 @@ class MtorImageAnalysis(QWidget):
self.check_button_state() self.check_button_state()
else: else:
self.dir_selected.setText(filenames[0]) self.dir_selected.setText(filenames[0])
parameter_path = folder / PARAMETERS_FILE
if parameter_path.is_file():
try:
with parameter_path.open("r") as fh:
parameters = json.load(fh)
for key, value in parameters.items():
field = self.fields_map[key][0]
field.setText(str(value))
except Exception:
pass
self.check_button_state() self.check_button_state()
def check_button_state(self): def check_button_state(self):
@ -162,19 +186,9 @@ class MtorImageAnalysis(QWidget):
self.btn_run.setEnabled(all(parameters.values())) self.btn_run.setEnabled(all(parameters.values()))
def get_parameters(self): def get_parameters(self):
fields = { parameters = {key: None for key in self.fields_map}
'folder': (self.dir_selected, str), for key, field_and_func in self.fields_map.items():
'top': (self.roi_top_input, int), field, func = field_and_func
'right': (self.roi_right_input, int),
'bottom': (self.roi_bottom_input, int),
'left': (self.roi_left_input, int),
'cut_pad_x': (self.pad_x_input, int),
'cut_pad_y': (self.pad_y_input, int),
'boost': (self.cc_boost_input, int),
}
parameters = {key: None for key in fields}
for key, name_and_func in fields.items():
field, func = name_and_func
raw_data = field.text().strip() raw_data = field.text().strip()
if raw_data: if raw_data:
if func is int: if func is int:
@ -186,6 +200,15 @@ class MtorImageAnalysis(QWidget):
def run_analysis(self): def run_analysis(self):
parameters = self.get_parameters() parameters = self.get_parameters()
if all(parameters.values()): if all(parameters.values()):
parameter_path = Path(parameters["folder"]) / PARAMETERS_FILE
try:
with parameter_path.open("w") as fh:
tmp = {k: v for k, v in parameters.items() if k != "folder"}
print(tmp)
json.dump(tmp, fh)
except Exception:
pass
self.analysis_parameters = parameters self.analysis_parameters = parameters
self.hide() self.hide()
QApplication.instance().quit() QApplication.instance().quit()

Loading…
Cancel
Save