""" find and loads the ui objects """ from PySide2.QtUiTools import QUiLoader from PySide2.QtCore import QFile from PySide2 import QtWidgets class RunTimeWidget: """ the parent class of all the run time loadable widgets """ loader: QUiLoader window: QtWidgets.QWidget def __init__(self, ui_name: str): self.ui_name = ui_name self.loader = QUiLoader() self.__load_ui() def __load_ui(self): """ loads the ui file of the GUI at run time :return: none """ ui_file = QFile(self.ui_name) ui_file.open(QFile.ReadOnly) self.window = self.loader.load(ui_file) # assert if the ui file can't be loaded error = self.loader.errorString() assert len(error) == 0, error ui_file.close() def show(self): """ shows the main container window :return: none """ self.window.show() def find_widget(self, child_type, child_name: str) -> QtWidgets.QWidget: """ finds a child in the loaded ui and returns the reference to it if found otherwise quits the application :param child_type: (var) type of the child :param child_name: (str) name of the child :return: (QtWidgets.QWidget) reference to the child """ child: QtWidgets.QWidget = self.window.findChild(child_type, child_name) assert child is not None, "child name '{}' with type '{}' can't be found.".format(child_name, child_type) return child def find_label(self, name: str) -> QtWidgets.QLabel: """ convenient method of find_child for QLabel :param name: (str) name of the QLabel Object :return: (QLabel) reference to the QLabel """ child = self.find_widget(QtWidgets.QLabel, name) return child def find_button(self, name: str) -> QtWidgets.QPushButton: """ convenient method of find_child for QPushButton :param name: (str) name of the QPushButton Object :return: (QPushButton) reference to the QPushButton """ child = self.find_widget(QtWidgets.QPushButton, name) return child def find_combobox(self, name: str) -> QtWidgets.QComboBox: """ convenient method of find_child for QComboBox :param name: (str) name of the QComboBox Object :return: (QComboBox) reference to the QComboBox """ child = self.find_widget(QtWidgets.QComboBox, name) return child def find_checkox(self, name: str) -> QtWidgets.QCheckBox: """ convenient method of find_child for QCheckBox :param name: (str) name of the QCheckBox Object :return: (QCheckBox) reference to the QComboBox """ child = self.find_widget(QtWidgets.QCheckBox, name) return child def find_spinbox(self, name: str) -> QtWidgets.QSpinBox: """ convenient method of find_child for QSpinBox :param name: (str) name of the QSpinBox Object :return: (QSpinBox) reference to the QSpinBox """ child = self.find_widget(QtWidgets.QSpinBox, name) return child def find_slider(self, name: str) -> QtWidgets.QSlider: """ convenient method of find_child for QSlider :param name: (str) name of the QSlider Object :return: (QSlider) reference to the QSlider """ child = self.find_widget(QtWidgets.QSlider, name) return child def find_table_widget(self, name: str) -> QtWidgets.QTableWidget: """ convenient method of find_child for QTableWidget :param name: (str) name of the QTableWidget Object :return: (QTableWidget) reference to the QTableWidget """ child: QtWidgets.QTableWidget = self.find_widget(QtWidgets.QTableWidget, name) return child