feat(GUI): implement preprocessing

This commit is contained in:
Daniel S. 2019-09-28 21:22:17 +02:00
parent 3ee952e548
commit f34d37a9d6
1 changed files with 39 additions and 0 deletions

View File

@ -104,6 +104,33 @@ class Job(QObject):
self.last_val = res
class PreprocessJob(Job):
def __init__(self, app, main_window, *args, **kwargs):
super().__init__(app, main_window, Preprocessor, *args, **kwargs)
self.progress_dialog = ProgressDialog("", "Cancel", 0, 0, self.main_window)
self.progress_dialog.setAutoClose(False)
self.progress_dialog.canceled.connect(self.cancel)
self.progress_dialog.show()
self.start()
def handle_progess(self, state):
if not self:
self.progress_dialog.close()
return
msg = "Processed: {}/{}".format(
sizeof_fmt(state["status"]["done"]), sizeof_fmt(state["status"]["total"])
)
state["status"]["prc_done"] = (
state["status"]["done"] / state["status"]["total"]
) * 100
title = "[{prc_done:.2f}%] Processing {file}".format(**state["status"])
self.progress_dialog.setMinimum(0)
self.progress_dialog.setMaximum(100 * 100)
self.progress_dialog.setWindowTitle(title)
self.progress_dialog.setLabelText(msg)
self.progress_dialog.setValue(int(state["status"]["prc_done"] * 100))
class RouterJob(Job):
def __init__(self, app, main_window, *args, **kwargs):
super().__init__(app, main_window, Router, *args, **kwargs)
@ -260,6 +287,17 @@ class ED_LRR(Ui_ED_LRR):
return callback(fileName)
return fileName
def preprocess(self):
if self.current_job:
# ERROR
return
bodies_json = self.inp_bodies_pp.currentText()
systems_json = self.inp_systems_pp.currentText()
output_file = self.inp_out_pp.currentText()
self.current_job = PreprocessJob(
self.app, self.main_window, systems_json, bodies_json, output_file
)
def set_sys_lst(self, path):
if path not in cfg["history.stars_csv_path"]:
cfg["history.stars_csv_path"].append(path)
@ -547,6 +585,7 @@ class ED_LRR(Ui_ED_LRR):
self.btn_go.clicked.connect(self.compute_route)
self.btn_add.clicked.connect(self.add_system)
self.btn_rm.clicked.connect(self.remove_system)
self.btn_preprocess.clicked.connect(self.preprocess)
self.chk_permute.stateChanged.connect(self.update_permute_chk)
self.btn_out_browse_pp.clicked.connect(
lambda: self.get_save_file("CSV File (*.csv)", self.set_sys_lst)