Untitled
unknown
plain_text
3 years ago
11 kB
1
Indexable
Never
from PyQt5 import QtCore, QtGui, QtWidgets import sys DATA_CALL_MAP = { "Test Data Call": { "data_call": "test-data-call", "required_params": ["resource"], "optional_params": ["endtime"], "output_params": [] }, "Test Data Call 2": { "data_call": "test-data-call-alt", "required_params": ["resource"], "optional_params": ["endtime"], "output_params": ["source"] } } _translate = QtCore.QCoreApplication.translate class Ui_TestCaseWindow(object): def setupUi(self, TestCaseWindow): TestCaseWindow.setObjectName("TestCaseWindow") TestCaseWindow.resize(800, 512) TestCaseWindow.setStyleSheet("background-color: rgb(235, 236, 244); color: rgb(66, 77, 112);") self.centralwidget = QtWidgets.QWidget(TestCaseWindow) self.centralwidget.setObjectName("centralwidget") self.label_test_input = QtWidgets.QLabel(self.centralwidget) self.label_test_input.setGeometry(QtCore.QRect(50, 60, 68, 16)) self.label_test_input.setStyleSheet("font-weight: bold;") self.label_test_input.setObjectName("label_test_input") self.label_test_input.setText(_translate("TestCaseWindow", "Test Input:")) self.label_expected_output = QtWidgets.QLabel(self.centralwidget) self.label_expected_output.setGeometry(QtCore.QRect(440, 60, 112, 16)) self.label_expected_output.setStyleSheet("font-weight: bold;") self.label_expected_output.setObjectName("label_expected_output") self.label_expected_output.setText(_translate("TestCaseWindow", "Expected Output:")) self.layoutWidget = QtWidgets.QWidget(self.centralwidget) self.layoutWidget.setGeometry(QtCore.QRect(530, 420, 216, 32)) self.layoutWidget.setObjectName("layoutWidget") self.horizontalLayout_2 = QtWidgets.QHBoxLayout(self.layoutWidget) self.horizontalLayout_2.setContentsMargins(0, 0, 0, 0) self.horizontalLayout_2.setObjectName("horizontalLayout_2") self.btn_cancel_new_test = QtWidgets.QPushButton(self.layoutWidget, clicked=lambda: TestCaseWindow.close()) self.btn_cancel_new_test.setStyleSheet("font-weight: bold;") self.btn_cancel_new_test.setObjectName("btn_cancel_new_test") self.btn_cancel_new_test.setText(_translate("TestCaseWindow", "Cancel")) self.horizontalLayout_2.addWidget(self.btn_cancel_new_test) self.btn_save_new_test = QtWidgets.QPushButton(self.layoutWidget, clicked=lambda: self.on_btn_save_new_test_click(TestCaseWindow)) self.btn_save_new_test.setStyleSheet("font-weight: bold;") self.btn_save_new_test.setObjectName("btn_save_new_test") self.btn_save_new_test.setText(_translate("TestCaseWindow", "Save")) self.horizontalLayout_2.addWidget(self.btn_save_new_test) self.layoutWidget1 = QtWidgets.QWidget(self.centralwidget) self.layoutWidget1.setGeometry(QtCore.QRect(50, 10, 249, 28)) self.layoutWidget1.setObjectName("layoutWidget1") self.formLayout_data_call = QtWidgets.QFormLayout(self.layoutWidget1) self.formLayout_data_call.setContentsMargins(0, 0, 0, 0) self.formLayout_data_call.setObjectName("formLayout_data_call") self.label_data_call = QtWidgets.QLabel(self.layoutWidget1) self.label_data_call.setStyleSheet("font-weight: bold;") self.label_data_call.setObjectName("label_data_call") self.label_data_call.setText(_translate("TestCaseWindow", "Data Call:")) self.combobox_data_call = QtWidgets.QComboBox(self.layoutWidget1) self.combobox_data_call.setObjectName("combobox_data_call") self.combobox_data_call.addItems(list(DATA_CALL_MAP.keys())) self.combobox_data_call.currentIndexChanged.connect( self.on_combobox_data_call_changed, self.combobox_data_call.currentIndex() ) self.formLayout_data_call.setWidget(0, QtWidgets.QFormLayout.LabelRole, self.label_data_call) self.formLayout_data_call.setWidget(0, QtWidgets.QFormLayout.FieldRole, self.combobox_data_call) self.input_scrollArea = QtWidgets.QScrollArea(self.centralwidget) self.input_scrollArea.setWidgetResizable(True) self.input_scrollArea.setVerticalScrollBarPolicy(QtCore.Qt.ScrollBarAsNeeded) self.input_scrollArea.setHorizontalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff) self.input_scrollArea.setGeometry(QtCore.QRect(50, 90, 311, 311)) self.input_scrollArea.setObjectName("input_scrollArea") self.input_scrollAreaWidgetContents = QtWidgets.QWidget() self.input_scrollAreaWidgetContents.setGeometry(QtCore.QRect(0, 0, 309, 309)) self.input_scrollAreaWidgetContents.setObjectName("input_scrollAreaWidgetContents") self.output_scrollArea = QtWidgets.QScrollArea(self.centralwidget) self.output_scrollArea.setWidgetResizable(True) self.output_scrollArea.setVerticalScrollBarPolicy(QtCore.Qt.ScrollBarAsNeeded) self.output_scrollArea.setHorizontalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff) self.output_scrollArea.setGeometry(QtCore.QRect(440, 90, 311, 311)) self.output_scrollArea.setObjectName("output_scrollArea") self.output_scrollAreaWidgetContents = QtWidgets.QWidget() self.output_scrollAreaWidgetContents.setGeometry(QtCore.QRect(0, 0, 309, 309)) self.output_scrollAreaWidgetContents.setObjectName("output_scrollAreaWidgetContents") self.input_vbox = QtWidgets.QVBoxLayout() self.output_vbox = QtWidgets.QVBoxLayout() self.spacer = QtWidgets.QSpacerItem(150, 10, QtWidgets.QSizePolicy.Minimum, QtWidgets.QSizePolicy.Expanding) self.label_status_code = QtWidgets.QLabel("Status Code:") self.label_status_code.setGeometry(QtCore.QRect(10, 10, 16, 21)) self.label_status_code.setObjectName("label_status_code") self.output_vbox.addWidget(self.label_status_code) self.status_code = QtWidgets.QLineEdit() self.status_code.setGeometry(QtCore.QRect(150, 10, 125, 21)) self.status_code.setObjectName("status_code") self.status_code.setPlaceholderText(_translate("TestCaseWindow", "200")) self.output_vbox.addWidget(self.status_code) self.output_vbox.addSpacerItem(self.spacer) self.items_in_previous_view = [] self.on_combobox_data_call_changed(0) self.input_scrollAreaWidgetContents.setLayout(self.input_vbox) self.output_scrollAreaWidgetContents.setLayout(self.output_vbox) self.input_scrollArea.setWidget(self.input_scrollAreaWidgetContents) self.output_scrollArea.setWidget(self.output_scrollAreaWidgetContents) TestCaseWindow.setCentralWidget(self.centralwidget) TestCaseWindow.setWindowTitle(_translate("TestCaseWindow", "MainWindow")) self.menubar = QtWidgets.QMenuBar(TestCaseWindow) self.menubar.setGeometry(QtCore.QRect(0, 0, 800, 24)) self.menubar.setObjectName("menubar") TestCaseWindow.setMenuBar(self.menubar) self.statusbar = QtWidgets.QStatusBar(TestCaseWindow) self.statusbar.setObjectName("statusbar") TestCaseWindow.setStatusBar(self.statusbar) QtCore.QMetaObject.connectSlotsByName(TestCaseWindow) def on_combobox_data_call_changed(self, combobox_index): data_call_name = list(DATA_CALL_MAP.keys())[combobox_index] while self.items_in_previous_view: item_to_del = self.items_in_previous_view.pop() item_to_del.deleteLater() if DATA_CALL_MAP[data_call_name]["optional_params"]: self.label_required_params = QtWidgets.QLabel("Required Parameters:") self.label_required_params.setStyleSheet("font-weight: bold;") self.label_required_params.setObjectName("label_required_params") self.input_vbox.addWidget(self.label_required_params) self.input_vbox.addSpacerItem(self.spacer) self.items_in_previous_view.append(self.label_required_params) for param in DATA_CALL_MAP[data_call_name]["required_params"]: exec(f"self.test_label_{param} = QtWidgets.QLabel(\"{param}:\")") exec(f"self.test_label_{param}.setObjectName(\"test_label_{param}\")") exec(f"self.input_vbox.addWidget(self.test_label_{param})") exec(f"self.items_in_previous_view.append(self.test_label_{param})") exec(f"self.test_input_{param} = QtWidgets.QLineEdit()") exec(f"self.test_input_{param}.setObjectName(\"test_input_{param}\")") exec(f"self.input_vbox.addWidget(self.test_input_{param})") self.input_vbox.addSpacerItem(self.spacer) exec(f"self.items_in_previous_view.append(self.test_input_{param})") if DATA_CALL_MAP[data_call_name]["optional_params"]: self.label_optional_params = QtWidgets.QLabel("Optional Parameters:") self.label_optional_params.setStyleSheet("font-weight: bold;") self.label_optional_params.setObjectName("label_optional_params") self.input_vbox.addWidget(self.label_optional_params) self.input_vbox.addSpacerItem(self.spacer) self.items_in_previous_view.append(self.label_optional_params) for param in DATA_CALL_MAP[data_call_name]["optional_params"]: exec(f"self.test_label_{param} = QtWidgets.QLabel(\"{param}:\")") exec(f"self.test_label_{param}.setObjectName(\"test_label_{param}\")") exec(f"self.input_vbox.addWidget(self.test_label_{param})") exec(f"self.items_in_previous_view.append(self.test_label_{param})") exec(f"self.test_input_{param} = QtWidgets.QLineEdit()") exec(f"self.test_input_{param}.setObjectName(\"test_input_{param}\")") exec(f"self.input_vbox.addWidget(self.test_input_{param})") self.input_vbox.addSpacerItem(self.spacer) exec(f"self.items_in_previous_view.append(self.test_input_{param})") for param in DATA_CALL_MAP[data_call_name]["output_params"]: exec(f"self.expected_label_{param} = QtWidgets.QLabel(\"{param}:\")") exec(f"self.expected_label_{param}.setObjectName(\"expected_label_{param}\")") exec(f"self.output_vbox.addWidget(self.expected_label_{param})") exec(f"self.items_in_previous_view.append(self.expected_label_{param})") exec(f"self.expected_input_{param} = QtWidgets.QLineEdit()") exec(f"self.expected_input_{param}.setObjectName(\"expected_input_{param}\")") exec(f"self.output_vbox.addWidget(self.expected_input_{param})") self.output_vbox.addSpacerItem(self.spacer) exec(f"self.items_in_previous_view.append(self.expected_input_{param})") def on_btn_save_new_test_click(self, test_case_window): print("saved") test_case_window.close() if __name__ == "__main__": app = QtWidgets.QApplication(sys.argv) app.setStyle("fusion") TestCaseWindow = QtWidgets.QMainWindow() ui = Ui_TestCaseWindow() ui.setupUi(TestCaseWindow) TestCaseWindow.show() sys.exit(app.exec_())