# Path: pytripgui/executor_vc/executor_view.py
# class ExecutorQtView:
#     def __init__(self, parent=None):
#         self._ui = UiExecuteDialog(parent)
#         self._setup_internal_callbacks()
# 
#     def show(self):
#         self._ui.show()
#         self._ui.exec_()
# 
#     def _exit(self):
#         self._ui.close()
# 
#     def _set_ok_callback(self, fun):
#         self._ui.accept_ButtonBox.accepted.connect(fun)
# 
#     def _setup_internal_callbacks(self):
#         self._set_ok_callback(self._exit)
# 
#     def append_log(self, text):
#         self._ui.stdout_textBrowser.append(text)
# 
#     def enable_ok_button(self):
#         self._ui.accept_ButtonBox.setEnabled(True)
# 
# Path: pytripgui/plan_executor/threaded_executor.py
# class ThreadedExecutor(Thread):
#     def __init__(self, plan, patient, trip_config):
#         super().__init__()
# 
#         self.logger = HtmlExecutorLogger()
#         self.item_queue = Queue()
# 
#         self.patient = patient
#         self.plan = plan
#         self.trip_config = trip_config
# 
#     def run(self):
#         self.on_execute_selected_plan_threaded()
# 
#     def on_execute_selected_plan_threaded(self):
#         sim_results = self._execute_plan(self.plan, self.patient)
#         if sim_results:
#             self.item_queue.put(sim_results)
# 
#     def _execute_plan(self, plan, patient):
#         plan_executor = PlanExecutor(self.trip_config, self.logger)
#         item = plan_executor.execute(patient.data, plan.data)
#         return item
# 
# Path: pytripgui/tree_vc/tree_items.py
# class SimulationResultItem(TreeItem):
#     def __repr__(self):
#         if self.data:
#             return self.data.__str__()
#         return "Empty simulation"
# 
# Path: pytripgui/messages.py



from pytripgui.executor_vc.executor_view import ExecutorQtView
from pytripgui.plan_executor.threaded_executor import ThreadedExecutor
from pytripgui.tree_vc.tree_items import SimulationResultItem
from pytripgui.messages import InfoMessages
from PyQt5.QtCore import QTimer

    def show(self):
        self._ui.show()

    def update_gui(self):
        if self._thread.is_alive():
            # if thread is still alive, execute this function in GUI_UPDATE_RATE_MS
            self._gui_update_timer.singleShot(GuiExecutor.GUI_UPDATE_RATE_MS, self.update_gui)
        else:
            self._call_result_callback()
            self._ui.enable_ok_button()
            self.done = True

        while not self._thread.logger.empty():
            text = self._thread.logger.get()
            self._ui.append_log(text)

    def start(self):
        self._thread.start()
        # update gui in GUI_UPDATE_RATE_MS
        self._gui_update_timer.singleShot(GuiExecutor.GUI_UPDATE_RATE_MS, self.update_gui)

    def _call_result_callback(self):
        if self._thread.item_queue.empty():
            return

        item = SimulationResultItem()
        item.data = self._thread.item_queue.get(False)

        for dose in item.data.get_doses():

# Path: pytripgui/executor_vc/executor_view.py
# class ExecutorQtView:
#     def __init__(self, parent=None):
#         self._ui = UiExecuteDialog(parent)
#         self._setup_internal_callbacks()
# 
#     def show(self):
#         self._ui.show()
#         self._ui.exec_()
# 
#     def _exit(self):
#         self._ui.close()
# 
#     def _set_ok_callback(self, fun):
#         self._ui.accept_ButtonBox.accepted.connect(fun)
# 
#     def _setup_internal_callbacks(self):
#         self._set_ok_callback(self._exit)
# 
#     def append_log(self, text):
#         self._ui.stdout_textBrowser.append(text)
# 
#     def enable_ok_button(self):
#         self._ui.accept_ButtonBox.setEnabled(True)
# 
# Path: pytripgui/plan_executor/threaded_executor.py
# class ThreadedExecutor(Thread):
#     def __init__(self, plan, patient, trip_config):
#         super().__init__()
# 
#         self.logger = HtmlExecutorLogger()
#         self.item_queue = Queue()
# 
#         self.patient = patient
#         self.plan = plan
#         self.trip_config = trip_config
# 
#     def run(self):
#         self.on_execute_selected_plan_threaded()
# 
#     def on_execute_selected_plan_threaded(self):
#         sim_results = self._execute_plan(self.plan, self.patient)
#         if sim_results:
#             self.item_queue.put(sim_results)
# 
#     def _execute_plan(self, plan, patient):
#         plan_executor = PlanExecutor(self.trip_config, self.logger)
#         item = plan_executor.execute(patient.data, plan.data)
#         return item
# 
# Path: pytripgui/tree_vc/tree_items.py
# class SimulationResultItem(TreeItem):
#     def __repr__(self):
#         if self.data:
#             return self.data.__str__()
#         return "Empty simulation"
# 
# Path: pytripgui/messages.py



# Path: pytripgui/app_logic/gui_executor.py
from pytripgui.executor_vc.executor_view import ExecutorQtView
from pytripgui.plan_executor.threaded_executor import ThreadedExecutor
from pytripgui.tree_vc.tree_items import SimulationResultItem
from pytripgui.messages import InfoMessages
from PyQt5.QtCore import QTimer


    def show(self):
        self._ui.show()

    def update_gui(self):
        if self._thread.is_alive():
            # if thread is still alive, execute this function in GUI_UPDATE_RATE_MS
            self._gui_update_timer.singleShot(GuiExecutor.GUI_UPDATE_RATE_MS, self.update_gui)
        else:
            self._call_result_callback()
            self._ui.enable_ok_button()
            self.done = True

        while not self._thread.logger.empty():
            text = self._thread.logger.get()
            self._ui.append_log(text)

    def start(self):
        self._thread.start()
        # update gui in GUI_UPDATE_RATE_MS
        self._gui_update_timer.singleShot(GuiExecutor.GUI_UPDATE_RATE_MS, self.update_gui)

    def _call_result_callback(self):
        if self._thread.item_queue.empty():
            return

        item = SimulationResultItem()
        item.data = self._thread.item_queue.get(False)

        for dose in item.data.get_doses():

            dose_item = SimulationResultItem()