# Path: pytripgui/view/qt_gui.py
# class UiExecuteConfigDialog(QtWidgets.QDialog):
#     def __init__(self, parent=None):
#         super(UiExecuteConfigDialog, self).__init__(parent)
#         ui_path = os.path.join(current_directory, 'execute_config.ui')
#         uic.loadUi(ui_path, self)
# 
# Path: pytripgui/view/qt_view_adapter.py
# class ComboBox:
#     def __init__(self, combo_box):
#         self._ui = combo_box
#         self.last_index = 0
# 
#         self._on_item_change_user_callback = None
#         self._ui.currentIndexChanged.connect(self._on_item_change_callback)
# 
#     def fill(self, combo_list, lambda_names):
#         self.last_index = 0
#         self._ui.clear()
#         for item in combo_list:
#             self._ui.addItem(lambda_names(item), item)
# 
#     def append_element(self, data, name):
#         self._ui.addItem(name, data)
#         self.current_index = self.count - 1
# 
#     def emit_on_item_change(self, callback):
#         self._on_item_change_user_callback = callback
# 
#     def _on_item_change_callback(self):
#         if self._on_item_change_user_callback:
#             self._on_item_change_user_callback()
#         self.last_index = self.current_index
# 
#     def set_current_item_text(self, text):
#         self._ui.setItemText(self.current_index, text)
# 
#     def remove_current_item(self):
#         self.last_index = -1
#         self._ui.removeItem(self.current_index)
# 
#     @property
#     def current_index(self):
#         return self._ui.currentIndex()
# 
#     @property
#     def current_text(self):
#         return self._ui.currentText()
# 
#     @property
#     def count(self):
#         return self._ui.count()
# 
#     @current_index.setter
#     def current_index(self, index):
#         self._ui.setCurrentIndex(index)
# 
#     @property
#     def data(self):
#         data = []
#         for i in range(self.count):
#             data.append(self._ui.itemData(i))
#         return data
# 
#     @property
#     def current_data(self):
#         return self._ui.currentData()
# 
#     @property
#     def last_data(self):
#         return self._ui.itemData(self.last_index)


from pytripgui.view.qt_gui import UiExecuteConfigDialog
from pytripgui.view.qt_view_adapter import ComboBox


class ExecuteConfigView:
    def __init__(self, model, ui):
        self._ui = UiExecuteConfigDialog(ui)
        self.config = None

        self._configs = ComboBox(self._ui.configs_comboBox)
        self._configs.fill(model, lambda config: config.name)
        self._setup_ok_and_cancel_buttons_callbacks()

    def _setup_ok_and_cancel_buttons_callbacks(self):
        self.set_ok_callback(self._execute)
        self.set_cancel_callback(self._exit)

    def set_ok_callback(self, fun):
        self._ui.accept_buttonBox.accepted.connect(fun)

    def set_cancel_callback(self, fun):
        self._ui.accept_buttonBox.rejected.connect(fun)

    def _execute(self):

# Path: pytripgui/view/qt_gui.py
# class UiExecuteConfigDialog(QtWidgets.QDialog):
#     def __init__(self, parent=None):
#         super(UiExecuteConfigDialog, self).__init__(parent)
#         ui_path = os.path.join(current_directory, 'execute_config.ui')
#         uic.loadUi(ui_path, self)
# 
# Path: pytripgui/view/qt_view_adapter.py
# class ComboBox:
#     def __init__(self, combo_box):
#         self._ui = combo_box
#         self.last_index = 0
# 
#         self._on_item_change_user_callback = None
#         self._ui.currentIndexChanged.connect(self._on_item_change_callback)
# 
#     def fill(self, combo_list, lambda_names):
#         self.last_index = 0
#         self._ui.clear()
#         for item in combo_list:
#             self._ui.addItem(lambda_names(item), item)
# 
#     def append_element(self, data, name):
#         self._ui.addItem(name, data)
#         self.current_index = self.count - 1
# 
#     def emit_on_item_change(self, callback):
#         self._on_item_change_user_callback = callback
# 
#     def _on_item_change_callback(self):
#         if self._on_item_change_user_callback:
#             self._on_item_change_user_callback()
#         self.last_index = self.current_index
# 
#     def set_current_item_text(self, text):
#         self._ui.setItemText(self.current_index, text)
# 
#     def remove_current_item(self):
#         self.last_index = -1
#         self._ui.removeItem(self.current_index)
# 
#     @property
#     def current_index(self):
#         return self._ui.currentIndex()
# 
#     @property
#     def current_text(self):
#         return self._ui.currentText()
# 
#     @property
#     def count(self):
#         return self._ui.count()
# 
#     @current_index.setter
#     def current_index(self, index):
#         self._ui.setCurrentIndex(index)
# 
#     @property
#     def data(self):
#         data = []
#         for i in range(self.count):
#             data.append(self._ui.itemData(i))
#         return data
# 
#     @property
#     def current_data(self):
#         return self._ui.currentData()
# 
#     @property
#     def last_data(self):
#         return self._ui.itemData(self.last_index)


# Path: pytripgui/view/execute_config_view.py
from pytripgui.view.qt_gui import UiExecuteConfigDialog
from pytripgui.view.qt_view_adapter import ComboBox



class ExecuteConfigView:
    def __init__(self, model, ui):
        self._ui = UiExecuteConfigDialog(ui)
        self.config = None

        self._configs = ComboBox(self._ui.configs_comboBox)
        self._configs.fill(model, lambda config: config.name)
        self._setup_ok_and_cancel_buttons_callbacks()

    def _setup_ok_and_cancel_buttons_callbacks(self):
        self.set_ok_callback(self._execute)
        self.set_cancel_callback(self._exit)

    def set_ok_callback(self, fun):
        self._ui.accept_buttonBox.accepted.connect(fun)

    def set_cancel_callback(self, fun):
        self._ui.accept_buttonBox.rejected.connect(fun)

    def _execute(self):

        self.config = self._configs.current_data