From 624dd9632aae8c6728a426bf2145894a2a056657 Mon Sep 17 00:00:00 2001 From: Oscar Gustafsson <oscar.gustafsson@gmail.com> Date: Fri, 3 Feb 2023 14:43:44 +0100 Subject: [PATCH] Load schedule without asking if there is a single schedule in the file --- b_asic/scheduler_gui/main_window.py | 40 ++++++++++++++++------------- 1 file changed, 22 insertions(+), 18 deletions(-) diff --git a/b_asic/scheduler_gui/main_window.py b/b_asic/scheduler_gui/main_window.py index 9bbe5d5d..41b59263 100644 --- a/b_asic/scheduler_gui/main_window.py +++ b/b_asic/scheduler_gui/main_window.py @@ -255,35 +255,39 @@ class MainWindow(QMainWindow, Ui_MainWindow): self, self.tr("File not found"), self.tr( - "Could not find any Schedule object in file '{}'." + "Cannot find any Schedule object in file '{}'." ).format(os.path.basename(abs_path_filename)), ) log.info( - "Could not find any Schedule object in file '{}'.".format( + "Cannot find any Schedule object in file '{}'.".format( os.path.basename(abs_path_filename) ) ) del module return - ret_tuple = QInputDialog.getItem( - self, - self.tr("Load object"), - self.tr( - "Found the following Schedule object(s) in file.\n\n" - "Select an object to proceed:" - ), - schedule_obj_list.keys(), - 0, - False, - ) + if len(schedule_obj_list) == 1: + schedule = [val for val in schedule_obj_list.values()][0] + else: + ret_tuple = QInputDialog.getItem( + self, + self.tr("Load object"), + self.tr( + "Found the following Schedule objects in file.\n\n" + "Select an object to proceed:" + ), + schedule_obj_list.keys(), + 0, + False, + ) - if not ret_tuple[1]: # User canceled the operation - log.debug("Load schedule operation: user canceled") - del module - return + if not ret_tuple[1]: # User canceled the operation + log.debug("Load schedule operation: user canceled") + del module + return + schedule = schedule_obj_list[ret_tuple[0]] - self.open(schedule_obj_list[ret_tuple[0]]) + self.open(schedule) del module settings.setValue("mainwindow/last_opened_file", abs_path_filename) -- GitLab