From 5e67424aad1767f26e5d8dbbe8e6c2d501fbef67 Mon Sep 17 00:00:00 2001 From: Rustam SecondFry Gubaydullin Date: Wed, 20 Dec 2023 20:51:03 +0300 Subject: [PATCH] Make groupboxes checkable themselves to preserve vertical space --- resources/ui/gui_main.ui | 56 +++------------------------ src/shortcircuit/app.py | 39 +++++++++++-------- src/shortcircuit/view/gui_main.py | 64 ++++++------------------------- 3 files changed, 42 insertions(+), 117 deletions(-) diff --git a/resources/ui/gui_main.ui b/resources/ui/gui_main.ui index 8f94879..2aa1e4b 100644 --- a/resources/ui/gui_main.ui +++ b/resources/ui/gui_main.ui @@ -447,6 +447,9 @@ Security prioritization + + true + true @@ -613,13 +616,6 @@ - - - - Enabled - - - @@ -628,6 +624,9 @@ Avoidance list + + true + true @@ -647,42 +646,6 @@ 5 - - - - - - - 0 - 0 - - - - Enabled - - - - - - - - 0 - 0 - - - - Qt::LeftToRight - - - Addition status - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - - - @@ -741,13 +704,6 @@ - - - - Qt::Horizontal - - - diff --git a/src/shortcircuit/app.py b/src/shortcircuit/app.py index ef15a2f..8c5d20d 100644 --- a/src/shortcircuit/app.py +++ b/src/shortcircuit/app.py @@ -324,7 +324,7 @@ def read_settings(self): self.tableWidget_path.setColumnWidth(col_idx, int(column_width)) # Avoidance list - self.checkBox_avoid_enabled.setChecked( + self.groupBox_avoidance.setChecked( self.settings.value("avoidance_enabled", "false") == "true" ) for sys_name in self.settings.value("avoidance_list", "").split(','): @@ -349,7 +349,7 @@ def read_settings(self): ) # Security prioritization - self.checkBox_security_enabled.setChecked( + self.groupBox_security.setChecked( self.settings.value("security_enabled", "false") == "true" ) self.spinBox_prio_hs.setValue(int(self.settings.value("prio_hs", "1"))) @@ -388,7 +388,7 @@ def write_settings(self): # Avoidance list self.settings.setValue( - "avoidance_enabled", self.checkBox_avoid_enabled.isChecked() + "avoidance_enabled", self.groupBox_avoidance.isChecked() ) avoidance_list_string = ",".join(self.avoidance_list()) self.settings.setValue("avoidance_list", avoidance_list_string) @@ -410,7 +410,7 @@ def write_settings(self): # Security prioritization self.settings.setValue( - "security_enabled", self.checkBox_security_enabled.isChecked() + "security_enabled", self.groupBox_security.isChecked() ) self.settings.setValue("prio_hs", self.spinBox_prio_hs.value()) self.settings.setValue("prio_ls", self.spinBox_prio_ls.value()) @@ -437,7 +437,7 @@ def _label_message(label, message, message_type): label.setText(message) def _avoid_message(self, message, message_type): - MainWindow._label_message(self.label_avoid_status, message, message_type) + self.statusBar().showMessage(message, 5000) def _path_message(self, message, message_type): MainWindow._label_message(self.label_status, message, message_type) @@ -452,7 +452,7 @@ def _status_tripwire(self, message, message_type=MessageType.INFO): MainWindow._label_message(self.status_tripwire, message, message_type) def avoidance_enabled(self) -> bool: - return self.checkBox_avoid_enabled.isChecked() + return self.groupBox_avoidance.isChecked() def avoidance_list(self) -> List[str]: items: List[QtWidgets.QListWidgetItem] = [] @@ -461,14 +461,23 @@ def avoidance_list(self) -> List[str]: return [i.text() for i in items] def _avoid_system_name(self, sys_name): - if sys_name: - if sys_name not in self.avoidance_list(): - QtWidgets.QListWidgetItem(sys_name, self.listWidget_avoid) - self._avoid_message("Added", MessageType.OK) - else: - self._avoid_message("Already in list!", MessageType.ERROR) - else: - self._avoid_message("Invalid system name :(", MessageType.ERROR) + if not sys_name: + self._avoid_message( + "Avoidance list: invalid system name :(", MessageType.ERROR + ) + return + + if sys_name in self.avoidance_list(): + self._avoid_message( + "Avoidance list: {} is already in the list!".format(sys_name), + MessageType.ERROR + ) + return + + QtWidgets.QListWidgetItem(sys_name, self.listWidget_avoid) + self._avoid_message( + "Avoidance list: {} added".format(sys_name), MessageType.OK + ) def avoid_system(self): sys_name = self.nav.eve_db.normalize_name(self.lineEdit_avoid_name.text()) @@ -549,7 +558,7 @@ def get_restrictions_security(self) -> Dict[SpaceType, int]: SpaceType.WH: 1, } - if self.checkBox_security_enabled.isChecked(): + if self.groupBox_security.isChecked(): security_prio[SpaceType.HS] = self.spinBox_prio_hs.value() security_prio[SpaceType.LS] = self.spinBox_prio_ls.value() security_prio[SpaceType.NS] = self.spinBox_prio_ns.value() diff --git a/src/shortcircuit/view/gui_main.py b/src/shortcircuit/view/gui_main.py index 0009142..ad647e2 100644 --- a/src/shortcircuit/view/gui_main.py +++ b/src/shortcircuit/view/gui_main.py @@ -271,6 +271,7 @@ def setupUi(self, MainWindow): self.groupBox_security = QGroupBox(self.groupBox__options) self.groupBox_security.setObjectName(u"groupBox_security") + self.groupBox_security.setCheckable(True) self.groupBox_security.setFlat(True) self.groupBox_security.setAlignment(Qt.AlignHCenter) self.gridLayout_2 = QGridLayout(self.groupBox_security) @@ -356,67 +357,36 @@ def setupUi(self, MainWindow): self.gridLayout_2.addWidget(self.spinBox_prio_ls, 1, 3, 1, 1) - self.checkBox_security_enabled = QCheckBox(self.groupBox_security) - self.checkBox_security_enabled.setObjectName(u"checkBox_security_enabled") - - self.gridLayout_2.addWidget(self.checkBox_security_enabled, 0, 0, 1, 5) - self.verticalLayout_3.addWidget(self.groupBox_security) self.groupBox_avoidance = QGroupBox(self.groupBox__options) self.groupBox_avoidance.setObjectName(u"groupBox_avoidance") + self.groupBox_avoidance.setCheckable(True) self.groupBox_avoidance.setFlat(True) self.groupBox_avoidance.setAlignment(Qt.AlignHCenter) self.verticalLayout_4 = QVBoxLayout(self.groupBox_avoidance) self.verticalLayout_4.setObjectName(u"verticalLayout_4") self.verticalLayout_4.setContentsMargins(0, 5, 0, 5) - self.horizontalLayout_5 = QHBoxLayout() - self.horizontalLayout_5.setObjectName(u"horizontalLayout_5") - self.checkBox_avoid_enabled = QCheckBox(self.groupBox_avoidance) - self.checkBox_avoid_enabled.setObjectName(u"checkBox_avoid_enabled") - sizePolicy4 = QSizePolicy(QSizePolicy.Maximum, QSizePolicy.Fixed) - sizePolicy4.setHorizontalStretch(0) - sizePolicy4.setVerticalStretch(0) - sizePolicy4.setHeightForWidth(self.checkBox_avoid_enabled.sizePolicy().hasHeightForWidth()) - self.checkBox_avoid_enabled.setSizePolicy(sizePolicy4) - - self.horizontalLayout_5.addWidget(self.checkBox_avoid_enabled) - - self.label_avoid_status = QLabel(self.groupBox_avoidance) - self.label_avoid_status.setObjectName(u"label_avoid_status") - sizePolicy5 = QSizePolicy(QSizePolicy.Minimum, QSizePolicy.Preferred) - sizePolicy5.setHorizontalStretch(0) - sizePolicy5.setVerticalStretch(0) - sizePolicy5.setHeightForWidth(self.label_avoid_status.sizePolicy().hasHeightForWidth()) - self.label_avoid_status.setSizePolicy(sizePolicy5) - self.label_avoid_status.setLayoutDirection(Qt.LeftToRight) - self.label_avoid_status.setAlignment(Qt.AlignRight|Qt.AlignTrailing|Qt.AlignVCenter) - - self.horizontalLayout_5.addWidget(self.label_avoid_status) - - - self.verticalLayout_4.addLayout(self.horizontalLayout_5) - self.horizontalLayout_2 = QHBoxLayout() self.horizontalLayout_2.setObjectName(u"horizontalLayout_2") self.label_3 = QLabel(self.groupBox_avoidance) self.label_3.setObjectName(u"label_3") - sizePolicy6 = QSizePolicy(QSizePolicy.Minimum, QSizePolicy.Minimum) - sizePolicy6.setHorizontalStretch(0) - sizePolicy6.setVerticalStretch(0) - sizePolicy6.setHeightForWidth(self.label_3.sizePolicy().hasHeightForWidth()) - self.label_3.setSizePolicy(sizePolicy6) + sizePolicy4 = QSizePolicy(QSizePolicy.Minimum, QSizePolicy.Minimum) + sizePolicy4.setHorizontalStretch(0) + sizePolicy4.setVerticalStretch(0) + sizePolicy4.setHeightForWidth(self.label_3.sizePolicy().hasHeightForWidth()) + self.label_3.setSizePolicy(sizePolicy4) self.horizontalLayout_2.addWidget(self.label_3) self.lineEdit_avoid_name = QLineEdit(self.groupBox_avoidance) self.lineEdit_avoid_name.setObjectName(u"lineEdit_avoid_name") - sizePolicy7 = QSizePolicy(QSizePolicy.Expanding, QSizePolicy.Minimum) - sizePolicy7.setHorizontalStretch(0) - sizePolicy7.setVerticalStretch(0) - sizePolicy7.setHeightForWidth(self.lineEdit_avoid_name.sizePolicy().hasHeightForWidth()) - self.lineEdit_avoid_name.setSizePolicy(sizePolicy7) + sizePolicy5 = QSizePolicy(QSizePolicy.Expanding, QSizePolicy.Minimum) + sizePolicy5.setHorizontalStretch(0) + sizePolicy5.setVerticalStretch(0) + sizePolicy5.setHeightForWidth(self.lineEdit_avoid_name.sizePolicy().hasHeightForWidth()) + self.lineEdit_avoid_name.setSizePolicy(sizePolicy5) self.lineEdit_avoid_name.setMaxLength(32) self.horizontalLayout_2.addWidget(self.lineEdit_avoid_name) @@ -434,13 +404,6 @@ def setupUi(self, MainWindow): self.verticalLayout_4.addLayout(self.horizontalLayout_2) - self.line_2 = QFrame(self.groupBox_avoidance) - self.line_2.setObjectName(u"line_2") - self.line_2.setFrameShape(QFrame.HLine) - self.line_2.setFrameShadow(QFrame.Sunken) - - self.verticalLayout_4.addWidget(self.line_2) - self.listWidget_avoid = QListWidget(self.groupBox_avoidance) self.listWidget_avoid.setObjectName(u"listWidget_avoid") self.listWidget_avoid.setSelectionMode(QAbstractItemView.ExtendedSelection) @@ -525,10 +488,7 @@ def retranslateUi(self, MainWindow): self.label_7.setText(QCoreApplication.translate("MainWindow", u"HS:", None)) self.label_8.setText(QCoreApplication.translate("MainWindow", u"LS:", None)) self.label_9.setText(QCoreApplication.translate("MainWindow", u"WH:", None)) - self.checkBox_security_enabled.setText(QCoreApplication.translate("MainWindow", u"Enabled", None)) self.groupBox_avoidance.setTitle(QCoreApplication.translate("MainWindow", u"Avoidance list", None)) - self.checkBox_avoid_enabled.setText(QCoreApplication.translate("MainWindow", u"Enabled", None)) - self.label_avoid_status.setText(QCoreApplication.translate("MainWindow", u"Addition status", None)) self.label_3.setText(QCoreApplication.translate("MainWindow", u"System:", None)) self.pushButton_avoid_add.setText(QCoreApplication.translate("MainWindow", u"+", None)) self.pushButton_avoid_delete.setText(QCoreApplication.translate("MainWindow", u"Delete selected", None))