From fe1876a0a0f59acdcc9f66219b5930891bdfb228 Mon Sep 17 00:00:00 2001 From: Oscar Gustafsson <oscar.gustafsson@gmail.com> Date: Thu, 20 Apr 2023 14:46:29 +0200 Subject: [PATCH] Return new schedule after editing --- b_asic/schedule.py | 16 +++++++++++++--- b_asic/scheduler_gui/main_window.py | 5 +++-- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/b_asic/schedule.py b/b_asic/schedule.py index 628117c4..e61ab864 100644 --- a/b_asic/schedule.py +++ b/b_asic/schedule.py @@ -314,11 +314,21 @@ class Schedule: """If the current schedule is cyclic.""" return self._cyclic - def edit(self) -> None: - """Edit schedule in GUI.""" + def edit(self, inplace=False) -> "Schedule": + """ + Edit schedule in GUI and return new schedule. + + Parameters + ---------- + inplace : bool, default: False + If True, replace the current schedule. + """ from b_asic.scheduler_gui.main_window import start_scheduler - start_scheduler(self) + new_schedule = start_scheduler(self) + if inplace: + self = new_schedule + return new_schedule def increase_time_resolution(self, factor: int) -> "Schedule": """ diff --git a/b_asic/scheduler_gui/main_window.py b/b_asic/scheduler_gui/main_window.py index 2e6e90c7..4b379c75 100644 --- a/b_asic/scheduler_gui/main_window.py +++ b/b_asic/scheduler_gui/main_window.py @@ -705,13 +705,14 @@ class ScheduleMainWindow(QMainWindow, Ui_MainWindow): self._update_recent_file_list() -def start_scheduler(schedule: Optional[Schedule] = None) -> None: +def start_scheduler(schedule: Optional[Schedule] = None) -> Schedule: app = QApplication(sys.argv) window = ScheduleMainWindow() if schedule: window.open(schedule) window.show() - sys.exit(app.exec_()) + app.exec_() + return window.schedule if __name__ == "__main__": -- GitLab