Skip to content

Commit

Permalink
Make groupboxes checkable themselves to preserve vertical space
Browse files Browse the repository at this point in the history
  • Loading branch information
secondfry committed Dec 20, 2023
1 parent 690ea66 commit 5e67424
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 117 deletions.
56 changes: 6 additions & 50 deletions resources/ui/gui_main.ui
Original file line number Diff line number Diff line change
Expand Up @@ -447,6 +447,9 @@
<property name="title">
<string>Security prioritization</string>
</property>
<property name="checkable">
<bool>true</bool>
</property>
<property name="flat">
<bool>true</bool>
</property>
Expand Down Expand Up @@ -613,13 +616,6 @@
</property>
</widget>
</item>
<item row="0" column="0" colspan="5">
<widget class="QCheckBox" name="checkBox_security_enabled">
<property name="text">
<string>Enabled</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
Expand All @@ -628,6 +624,9 @@
<property name="title">
<string>Avoidance list</string>
</property>
<property name="checkable">
<bool>true</bool>
</property>
<property name="flat">
<bool>true</bool>
</property>
Expand All @@ -647,42 +646,6 @@
<property name="bottomMargin">
<number>5</number>
</property>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_5">
<item>
<widget class="QCheckBox" name="checkBox_avoid_enabled">
<property name="sizePolicy">
<sizepolicy hsizetype="Maximum" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Enabled</string>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label_avoid_status">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="layoutDirection">
<enum>Qt::LeftToRight</enum>
</property>
<property name="text">
<string>Addition status</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
Expand Down Expand Up @@ -741,13 +704,6 @@
</item>
</layout>
</item>
<item>
<widget class="Line" name="line_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item>
<widget class="QListWidget" name="listWidget_avoid">
<property name="selectionMode">
Expand Down
39 changes: 24 additions & 15 deletions src/shortcircuit/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(','):
Expand All @@ -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")))
Expand Down Expand Up @@ -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)
Expand All @@ -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())
Expand All @@ -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)
Expand All @@ -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] = []
Expand All @@ -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())
Expand Down Expand Up @@ -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()
Expand Down
64 changes: 12 additions & 52 deletions src/shortcircuit/view/gui_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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))
Expand Down

0 comments on commit 5e67424

Please sign in to comment.