From 18a5d1d927f781efc7e81b9f5980fc2c418049ab Mon Sep 17 00:00:00 2001 From: JeanBilheux Date: Fri, 18 Aug 2023 12:34:34 -0400 Subject: [PATCH] working on looking at config file. this refs #76 --- .../event_handler.py | 19 ++++++++++++++++--- src/hyperctui/commands_launcher.py | 0 src/hyperctui/hyperctui.py | 3 ++- src/hyperctui/utilities/config_handler.py | 9 +++++++++ src/hyperctui/utilities/folder_path.py | 18 +++++++++++++++--- 5 files changed, 42 insertions(+), 7 deletions(-) create mode 100644 src/hyperctui/commands_launcher.py diff --git a/src/hyperctui/autonomous_reconstruction/event_handler.py b/src/hyperctui/autonomous_reconstruction/event_handler.py index 6cbe9e9..cd27f23 100644 --- a/src/hyperctui/autonomous_reconstruction/event_handler.py +++ b/src/hyperctui/autonomous_reconstruction/event_handler.py @@ -9,11 +9,12 @@ from hyperctui import interact_me_style, normal_style, error_style, label_in_focus_style from hyperctui.session import SessionKeys -from hyperctui.utilities.get import Get +from hyperctui.utilities.get import Get from hyperctui.utilities.status_message_config import StatusMessageStatus, show_status_message from hyperctui.utilities.table import TableHandler from hyperctui.utilities.array import formatting_list_for_print +from hyperctui.utilities.config_handler import ConfigHandler from hyperctui.preview_file.preview_file_launcher import PreviewFileLauncher, PreviewMetadataFileLauncher, \ PreviewImageLauncher @@ -374,10 +375,22 @@ def checking_state_of_projections_table(self): qcolor=background_color) row_index += 1 - def refrech_reconstruction_table_clicked(self): + def refresh_reconstruction_table_clicked(self): """this is where we will check the json file in {{location TBD}} and look for tag that list the reconstruction done!""" - pass + logging.info("User is refreshing the autonomous reconstruction table.") + + folder_path = self.parent.folder_path + reconstruction_config = folder_path.reconstruction_config + if not os.path.exists(reconstruction_config): + logging.info(f"- config file {reconstruction_config} not found!") + return + + logging.info(f"- config file {reconstruction_config} has been located!") + o_config = ConfigHandler(parent=self.parent) + o_config.load_reconstruction_config() + + diff --git a/src/hyperctui/commands_launcher.py b/src/hyperctui/commands_launcher.py new file mode 100644 index 0000000..e69de29 diff --git a/src/hyperctui/hyperctui.py b/src/hyperctui/hyperctui.py index d6fe98c..9702188 100644 --- a/src/hyperctui/hyperctui.py +++ b/src/hyperctui/hyperctui.py @@ -40,6 +40,7 @@ class HyperCTui(QMainWindow): log_id = None # UI id of the logger config = None # config dictionary + reconstruction_config = None # config of the log_buffer_size = 500 # 500 lines @@ -478,7 +479,7 @@ def autonomous_refresh_table_clicked(self): def autonomous_checking_reconstruction_clicked(self): o_event = AutonomousReconstructionHandler(parent=self) - o_event.refrech_reconstruction_table_clicked() + o_event.refresh_reconstruction_table_clicked() # leaving ui def closeEvent(self, c): diff --git a/src/hyperctui/utilities/config_handler.py b/src/hyperctui/utilities/config_handler.py index e88dcad..cb19092 100644 --- a/src/hyperctui/utilities/config_handler.py +++ b/src/hyperctui/utilities/config_handler.py @@ -29,3 +29,12 @@ def load(self): level=logging.INFO) logging.info("*** Starting a new session ***") logging.info(f" Version: {versioneer.get_version()}") + + def load_reconstruction_config(self, file_name=None): + if not os.path.exists(file_name): + return + + with open(file_name) as f: + config = json.load(f) + + self.parent.reconstruction_config = config diff --git a/src/hyperctui/utilities/folder_path.py b/src/hyperctui/utilities/folder_path.py index 30f1e89..764b895 100644 --- a/src/hyperctui/utilities/folder_path.py +++ b/src/hyperctui/utilities/folder_path.py @@ -3,6 +3,8 @@ from hyperctui.parent import Parent from hyperctui.session import SessionKeys +RECONSTRUCTION_CONFIG = "reconstruction_config.json" + class FolderPath(Parent): """ @@ -19,6 +21,7 @@ class FolderPath(Parent): nexus = None mcp_raw = None recon = None + reconstruction_config = None # json file created/updated by Shimin's code def update(self): @@ -42,12 +45,18 @@ def update(self): self.mcp() self.recon(title=title) self.create_mcp_raw() + self.svmbir_config(title=title) def __repr__(self): return f"folder_path:\n" + \ - f"- shared: \t\t{self.shared}\n- autoreduce: \t{self.autoreduce}" + \ - f"\n- mcp: \t\t\t{self.mcp}\n- reduction_log: {self.reduction_log}\n- nexus: \t\t{self.nexus}" + \ - f"\n- mcp_raw: \t\t{self.mcp_raw}\n- recon: \t\t{self.recon}" + f"- shared: \t\t{self.shared}\n" \ + f"- autoreduce: \t{self.autoreduce}\n" + \ + f"- mcp: \t\t{self.mcp}\n" \ + f"- reduction_log:{self.reduction_log}\n" \ + f"- nexus: \t\t{self.nexus}\n" + \ + f"- mcp_raw: \t{self.mcp_raw}\n" \ + f"- recon: \t\t{self.recon}\n" \ + f"- reconstruction_config: {self.reconstruction_config}\n" def shared(self): self.shared = os.sep.join([self.ipts_full_path, "shared"]) @@ -74,3 +83,6 @@ def create_mcp_raw(self): self.mcp_raw = os.sep.join([self.ipts_full_path, 'images', 'mcp']) + + def svmbir_config(self, title=None): + self.reconstruction_config = os.sep.join([self.shared, "insitu_recon", title, RECONSTRUCTION_CONFIG])