diff --git a/BlocksScreen/lib/panels/widgets/babystepPage.py b/BlocksScreen/lib/panels/widgets/babystepPage.py index b0fdfdca..6505c0aa 100644 --- a/BlocksScreen/lib/panels/widgets/babystepPage.py +++ b/BlocksScreen/lib/panels/widgets/babystepPage.py @@ -3,7 +3,7 @@ from lib.utils.blocks_button import BlocksCustomButton from lib.utils.blocks_label import BlocksLabel from lib.utils.icon_button import IconButton -from lib.utils.group_button import GroupButton +from lib.utils.check_button import BlocksCustomCheckButton from PyQt6 import QtCore, QtGui, QtWidgets @@ -212,7 +212,7 @@ def setupUI(self): self.bbp_offset_steps_buttons.setObjectName("bbp_offset_steps_buttons") # 0.1mm button - self.bbp_nozzle_offset_1 = GroupButton( + self.bbp_nozzle_offset_1 = BlocksCustomCheckButton( parent=self.bbp_offset_steps_buttons_group_box ) self.bbp_nozzle_offset_1.setMinimumSize(QtCore.QSize(100, 70)) @@ -237,7 +237,7 @@ def setupUI(self): # Line separator for 0.1mm - set size policy to expanding horizontally # 0.01mm button - self.bbp_nozzle_offset_01 = GroupButton( + self.bbp_nozzle_offset_01 = BlocksCustomCheckButton( parent=self.bbp_offset_steps_buttons_group_box ) self.bbp_nozzle_offset_01.setMinimumSize(QtCore.QSize(100, 70)) @@ -261,7 +261,7 @@ def setupUI(self): ) # 0.05mm button - self.bbp_nozzle_offset_05 = GroupButton( + self.bbp_nozzle_offset_05 = BlocksCustomCheckButton( parent=self.bbp_offset_steps_buttons_group_box ) self.bbp_nozzle_offset_05.setMinimumSize(QtCore.QSize(100, 70)) @@ -285,7 +285,7 @@ def setupUI(self): ) # 0.025mm button - self.bbp_nozzle_offset_025 = GroupButton( + self.bbp_nozzle_offset_025 = BlocksCustomCheckButton( parent=self.bbp_offset_steps_buttons_group_box ) self.bbp_nozzle_offset_025.setMinimumSize(QtCore.QSize(100, 70)) diff --git a/BlocksScreen/lib/panels/widgets/probeHelperPage.py b/BlocksScreen/lib/panels/widgets/probeHelperPage.py index 5eeb3a3d..cc0f1be8 100644 --- a/BlocksScreen/lib/panels/widgets/probeHelperPage.py +++ b/BlocksScreen/lib/panels/widgets/probeHelperPage.py @@ -4,7 +4,7 @@ from PyQt6 import QtCore, QtGui, QtWidgets from lib.utils.blocks_label import BlocksLabel from lib.utils.icon_button import IconButton -from lib.utils.group_button import GroupButton +from lib.utils.check_button import BlocksCustomCheckButton from lib.utils.blocks_button import BlocksCustomButton from lib.panels.widgets.loadPage import LoadScreen @@ -709,7 +709,9 @@ def _setupUi(self) -> None: self.bbp_offset_steps_buttons.setObjectName("bbp_offset_steps_buttons") # 0.1mm button - self.move_option_1 = GroupButton(parent=self.bbp_offset_steps_buttons_group_box) + self.move_option_1 = BlocksCustomCheckButton( + parent=self.bbp_offset_steps_buttons_group_box + ) self.move_option_1.setMinimumSize(QtCore.QSize(100, 60)) self.move_option_1.setMaximumSize(QtCore.QSize(100, 60)) self.move_option_1.setText("0.01 mm") @@ -730,7 +732,9 @@ def _setupUi(self) -> None: ) # 0.01mm button - self.move_option_2 = GroupButton(parent=self.bbp_offset_steps_buttons_group_box) + self.move_option_2 = BlocksCustomCheckButton( + parent=self.bbp_offset_steps_buttons_group_box + ) self.move_option_2.setMinimumSize(QtCore.QSize(100, 60)) self.move_option_2.setMaximumSize( QtCore.QSize(100, 60) @@ -752,7 +756,9 @@ def _setupUi(self) -> None: ) # 0.05mm button - self.move_option_3 = GroupButton(parent=self.bbp_offset_steps_buttons_group_box) + self.move_option_3 = BlocksCustomCheckButton( + parent=self.bbp_offset_steps_buttons_group_box + ) self.move_option_3.setMinimumSize(QtCore.QSize(100, 60)) self.move_option_3.setMaximumSize( QtCore.QSize(100, 60) @@ -774,7 +780,9 @@ def _setupUi(self) -> None: ) # 0.025mm button - self.move_option_4 = GroupButton(parent=self.bbp_offset_steps_buttons_group_box) + self.move_option_4 = BlocksCustomCheckButton( + parent=self.bbp_offset_steps_buttons_group_box + ) self.move_option_4.setMinimumSize(QtCore.QSize(100, 60)) self.move_option_4.setMaximumSize( QtCore.QSize(100, 60) @@ -796,7 +804,9 @@ def _setupUi(self) -> None: ) # 0.01mm button - self.move_option_5 = GroupButton(parent=self.bbp_offset_steps_buttons_group_box) + self.move_option_5 = BlocksCustomCheckButton( + parent=self.bbp_offset_steps_buttons_group_box + ) self.move_option_5.setMinimumSize(QtCore.QSize(100, 60)) self.move_option_5.setMaximumSize( QtCore.QSize(100, 60) diff --git a/BlocksScreen/lib/ui/controlStackedWidget_ui.py b/BlocksScreen/lib/ui/controlStackedWidget_ui.py index 88817b36..d76bb627 100644 --- a/BlocksScreen/lib/ui/controlStackedWidget_ui.py +++ b/BlocksScreen/lib/ui/controlStackedWidget_ui.py @@ -453,7 +453,7 @@ def setupUi(self, controlStackedWidget): self.exp_length_content_layout.setContentsMargins(5, 5, 5, 5) self.exp_length_content_layout.setSpacing(5) self.exp_length_content_layout.setObjectName("exp_length_content_layout") - self.extrude_select_length_10_btn = GroupButton(parent=self.layoutWidget) + self.extrude_select_length_10_btn = BlocksCustomCheckButton(parent=self.layoutWidget) sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Policy.Minimum, QtWidgets.QSizePolicy.Policy.Expanding) sizePolicy.setHorizontalStretch(0) sizePolicy.setVerticalStretch(0) @@ -521,7 +521,7 @@ def setupUi(self, controlStackedWidget): self.extrude_select_length_group.setObjectName("extrude_select_length_group") self.extrude_select_length_group.addButton(self.extrude_select_length_10_btn) self.exp_length_content_layout.addWidget(self.extrude_select_length_10_btn) - self.extrude_select_length_50_btn = GroupButton(parent=self.layoutWidget) + self.extrude_select_length_50_btn = BlocksCustomCheckButton(parent=self.layoutWidget) sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Policy.Minimum, QtWidgets.QSizePolicy.Policy.Expanding) sizePolicy.setHorizontalStretch(0) sizePolicy.setVerticalStretch(0) @@ -586,7 +586,7 @@ def setupUi(self, controlStackedWidget): self.extrude_select_length_50_btn.setObjectName("extrude_select_length_50_btn") self.extrude_select_length_group.addButton(self.extrude_select_length_50_btn) self.exp_length_content_layout.addWidget(self.extrude_select_length_50_btn) - self.extrude_select_length_100_btn = GroupButton(parent=self.layoutWidget) + self.extrude_select_length_100_btn = BlocksCustomCheckButton(parent=self.layoutWidget) sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Policy.Minimum, QtWidgets.QSizePolicy.Policy.Expanding) sizePolicy.setHorizontalStretch(0) sizePolicy.setVerticalStretch(0) @@ -677,7 +677,7 @@ def setupUi(self, controlStackedWidget): self.exp_feedrate_content_layout.setContentsMargins(5, 5, 5, 5) self.exp_feedrate_content_layout.setSpacing(5) self.exp_feedrate_content_layout.setObjectName("exp_feedrate_content_layout") - self.extrude_select_feedrate_2_btn = GroupButton(parent=self.layoutWidget1) + self.extrude_select_feedrate_2_btn = BlocksCustomCheckButton(parent=self.layoutWidget1) sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Policy.Minimum, QtWidgets.QSizePolicy.Policy.Expanding) sizePolicy.setHorizontalStretch(0) sizePolicy.setVerticalStretch(0) @@ -745,7 +745,7 @@ def setupUi(self, controlStackedWidget): self.extrude_select_feedrate_group.setObjectName("extrude_select_feedrate_group") self.extrude_select_feedrate_group.addButton(self.extrude_select_feedrate_2_btn) self.exp_feedrate_content_layout.addWidget(self.extrude_select_feedrate_2_btn) - self.extrude_select_feedrate_5_btn = GroupButton(parent=self.layoutWidget1) + self.extrude_select_feedrate_5_btn = BlocksCustomCheckButton(parent=self.layoutWidget1) sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Policy.Minimum, QtWidgets.QSizePolicy.Policy.Expanding) sizePolicy.setHorizontalStretch(0) sizePolicy.setVerticalStretch(0) @@ -810,7 +810,7 @@ def setupUi(self, controlStackedWidget): self.extrude_select_feedrate_5_btn.setObjectName("extrude_select_feedrate_5_btn") self.extrude_select_feedrate_group.addButton(self.extrude_select_feedrate_5_btn) self.exp_feedrate_content_layout.addWidget(self.extrude_select_feedrate_5_btn) - self.extrude_select_feedrate_10_btn = GroupButton(parent=self.layoutWidget1) + self.extrude_select_feedrate_10_btn = BlocksCustomCheckButton(parent=self.layoutWidget1) sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Policy.Minimum, QtWidgets.QSizePolicy.Policy.Expanding) sizePolicy.setHorizontalStretch(0) sizePolicy.setVerticalStretch(0) @@ -1196,7 +1196,7 @@ def setupUi(self, controlStackedWidget): self.mva_home_all_btn.setProperty("icon_pixmap", QtGui.QPixmap(":/motion/media/btn_icons/home_all.svg")) self.mva_home_all_btn.setObjectName("mva_home_all_btn") self.mva_home_axis_layout.addWidget(self.mva_home_all_btn, 0, QtCore.Qt.AlignmentFlag.AlignHCenter) - self.mva_select_speed_25_btn = GroupButton(parent=self.move_axis_page) + self.mva_select_speed_25_btn = BlocksCustomCheckButton(parent=self.move_axis_page) self.mva_select_speed_25_btn.setGeometry(QtCore.QRect(96, 240, 100, 100)) self.mva_select_speed_25_btn.setMinimumSize(QtCore.QSize(60, 60)) self.mva_select_speed_25_btn.setMaximumSize(QtCore.QSize(100, 100)) @@ -1239,7 +1239,7 @@ def setupUi(self, controlStackedWidget): self.axis_select_speed_group = QtWidgets.QButtonGroup(controlStackedWidget) self.axis_select_speed_group.setObjectName("axis_select_speed_group") self.axis_select_speed_group.addButton(self.mva_select_speed_25_btn) - self.mva_select_speed_50_btn = GroupButton(parent=self.move_axis_page) + self.mva_select_speed_50_btn = BlocksCustomCheckButton(parent=self.move_axis_page) self.mva_select_speed_50_btn.setGeometry(QtCore.QRect(205, 240, 100, 100)) self.mva_select_speed_50_btn.setMinimumSize(QtCore.QSize(60, 60)) self.mva_select_speed_50_btn.setMaximumSize(QtCore.QSize(100, 100)) @@ -1279,7 +1279,7 @@ def setupUi(self, controlStackedWidget): self.mva_select_speed_50_btn.setFlat(False) self.mva_select_speed_50_btn.setObjectName("mva_select_speed_50_btn") self.axis_select_speed_group.addButton(self.mva_select_speed_50_btn) - self.mva_select_speed_100_btn = GroupButton(parent=self.move_axis_page) + self.mva_select_speed_100_btn = BlocksCustomCheckButton(parent=self.move_axis_page) self.mva_select_speed_100_btn.setGeometry(QtCore.QRect(315, 240, 100, 100)) self.mva_select_speed_100_btn.setMinimumSize(QtCore.QSize(60, 60)) self.mva_select_speed_100_btn.setMaximumSize(QtCore.QSize(100, 100)) @@ -1326,7 +1326,7 @@ def setupUi(self, controlStackedWidget): self.label.setFont(font) self.label.setStyleSheet("color:white") self.label.setObjectName("label") - self.mva_select_length_1_btn = GroupButton(parent=self.move_axis_page) + self.mva_select_length_1_btn = BlocksCustomCheckButton(parent=self.move_axis_page) self.mva_select_length_1_btn.setGeometry(QtCore.QRect(96, 110, 100, 100)) self.mva_select_length_1_btn.setMinimumSize(QtCore.QSize(60, 60)) self.mva_select_length_1_btn.setMaximumSize(QtCore.QSize(100, 100)) @@ -1369,7 +1369,7 @@ def setupUi(self, controlStackedWidget): self.axis_select_length_group = QtWidgets.QButtonGroup(controlStackedWidget) self.axis_select_length_group.setObjectName("axis_select_length_group") self.axis_select_length_group.addButton(self.mva_select_length_1_btn) - self.mva_select_length_10_btn = GroupButton(parent=self.move_axis_page) + self.mva_select_length_10_btn = BlocksCustomCheckButton(parent=self.move_axis_page) self.mva_select_length_10_btn.setGeometry(QtCore.QRect(204, 110, 100, 100)) self.mva_select_length_10_btn.setMinimumSize(QtCore.QSize(60, 60)) self.mva_select_length_10_btn.setMaximumSize(QtCore.QSize(100, 100)) @@ -1409,7 +1409,7 @@ def setupUi(self, controlStackedWidget): self.mva_select_length_10_btn.setFlat(False) self.mva_select_length_10_btn.setObjectName("mva_select_length_10_btn") self.axis_select_length_group.addButton(self.mva_select_length_10_btn) - self.mva_select_length_100_btn = GroupButton(parent=self.move_axis_page) + self.mva_select_length_100_btn = BlocksCustomCheckButton(parent=self.move_axis_page) self.mva_select_length_100_btn.setGeometry(QtCore.QRect(315, 110, 100, 100)) self.mva_select_length_100_btn.setMinimumSize(QtCore.QSize(60, 60)) self.mva_select_length_100_btn.setMaximumSize(QtCore.QSize(100, 100)) @@ -2190,5 +2190,5 @@ def retranslateUi(self, controlStackedWidget): from lib.utils.blocks_button import BlocksCustomButton from lib.utils.blocks_label import BlocksLabel from lib.utils.display_button import DisplayButton -from lib.utils.group_button import GroupButton +from lib.utils.check_button import BlocksCustomCheckButton from lib.utils.icon_button import IconButton diff --git a/BlocksScreen/lib/ui/utilitiesStackedWidget_ui.py b/BlocksScreen/lib/ui/utilitiesStackedWidget_ui.py index 987ed2f8..bb2ca93e 100644 --- a/BlocksScreen/lib/ui/utilitiesStackedWidget_ui.py +++ b/BlocksScreen/lib/ui/utilitiesStackedWidget_ui.py @@ -821,7 +821,7 @@ def setupUi(self, utilitiesStackedWidget): self.is_xy_layout.addWidget(self.is_X_startis_btn, 0, 0, 1, 2, QtCore.Qt.AlignmentFlag.AlignHCenter) self.gridLayout = QtWidgets.QGridLayout() self.gridLayout.setObjectName("gridLayout") - self.btn2 = GroupButton(parent=self.input_shaper_page) + self.btn2 = BlocksCustomCheckButton(parent=self.input_shaper_page) sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Policy.Minimum, QtWidgets.QSizePolicy.Policy.Expanding) sizePolicy.setHorizontalStretch(0) sizePolicy.setVerticalStretch(0) @@ -851,7 +851,7 @@ def setupUi(self, utilitiesStackedWidget): self.isc_btn_group.setObjectName("isc_btn_group") self.isc_btn_group.addButton(self.btn2) self.gridLayout.addWidget(self.btn2, 1, 1, 1, 1) - self.btn3 = GroupButton(parent=self.input_shaper_page) + self.btn3 = BlocksCustomCheckButton(parent=self.input_shaper_page) sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Policy.Minimum, QtWidgets.QSizePolicy.Policy.Expanding) sizePolicy.setHorizontalStretch(0) sizePolicy.setVerticalStretch(0) @@ -879,7 +879,7 @@ def setupUi(self, utilitiesStackedWidget): self.btn3.setObjectName("btn3") self.isc_btn_group.addButton(self.btn3) self.gridLayout.addWidget(self.btn3, 2, 0, 1, 1) - self.btn5 = GroupButton(parent=self.input_shaper_page) + self.btn5 = BlocksCustomCheckButton(parent=self.input_shaper_page) sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Policy.Minimum, QtWidgets.QSizePolicy.Policy.Expanding) sizePolicy.setHorizontalStretch(0) sizePolicy.setVerticalStretch(0) @@ -907,7 +907,7 @@ def setupUi(self, utilitiesStackedWidget): self.btn5.setObjectName("btn5") self.isc_btn_group.addButton(self.btn5) self.gridLayout.addWidget(self.btn5, 3, 0, 1, 2, QtCore.Qt.AlignmentFlag.AlignHCenter) - self.btn1 = GroupButton(parent=self.input_shaper_page) + self.btn1 = BlocksCustomCheckButton(parent=self.input_shaper_page) sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Policy.Minimum, QtWidgets.QSizePolicy.Policy.Expanding) sizePolicy.setHorizontalStretch(0) sizePolicy.setVerticalStretch(0) @@ -936,7 +936,7 @@ def setupUi(self, utilitiesStackedWidget): self.btn1.setObjectName("btn1") self.isc_btn_group.addButton(self.btn1) self.gridLayout.addWidget(self.btn1, 1, 0, 1, 1) - self.btn4 = GroupButton(parent=self.input_shaper_page) + self.btn4 = BlocksCustomCheckButton(parent=self.input_shaper_page) sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Policy.Minimum, QtWidgets.QSizePolicy.Policy.Expanding) sizePolicy.setHorizontalStretch(0) sizePolicy.setVerticalStretch(0) @@ -1000,7 +1000,7 @@ def setupUi(self, utilitiesStackedWidget): self.gridLayout_4 = QtWidgets.QGridLayout() self.gridLayout_4.setSpacing(0) self.gridLayout_4.setObjectName("gridLayout_4") - self.am_zv = GroupButton(parent=self.is_page) + self.am_zv = BlocksCustomCheckButton(parent=self.is_page) sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Policy.Minimum, QtWidgets.QSizePolicy.Policy.MinimumExpanding) sizePolicy.setHorizontalStretch(0) sizePolicy.setVerticalStretch(0) @@ -1027,7 +1027,7 @@ def setupUi(self, utilitiesStackedWidget): self.is_btn_group.setObjectName("is_btn_group") self.is_btn_group.addButton(self.am_zv) self.gridLayout_4.addWidget(self.am_zv, 0, 0, 1, 2, QtCore.Qt.AlignmentFlag.AlignHCenter) - self.am_ei = GroupButton(parent=self.is_page) + self.am_ei = BlocksCustomCheckButton(parent=self.is_page) sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Policy.Minimum, QtWidgets.QSizePolicy.Policy.MinimumExpanding) sizePolicy.setHorizontalStretch(0) sizePolicy.setVerticalStretch(0) @@ -1052,7 +1052,7 @@ def setupUi(self, utilitiesStackedWidget): self.am_ei.setObjectName("am_ei") self.is_btn_group.addButton(self.am_ei) self.gridLayout_4.addWidget(self.am_ei, 0, 2, 1, 2, QtCore.Qt.AlignmentFlag.AlignHCenter) - self.am_mzv = GroupButton(parent=self.is_page) + self.am_mzv = BlocksCustomCheckButton(parent=self.is_page) sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Policy.Minimum, QtWidgets.QSizePolicy.Policy.MinimumExpanding) sizePolicy.setHorizontalStretch(0) sizePolicy.setVerticalStretch(0) @@ -1077,7 +1077,7 @@ def setupUi(self, utilitiesStackedWidget): self.am_mzv.setObjectName("am_mzv") self.is_btn_group.addButton(self.am_mzv) self.gridLayout_4.addWidget(self.am_mzv, 1, 0, 1, 2, QtCore.Qt.AlignmentFlag.AlignHCenter) - self.am_3hump_ei = GroupButton(parent=self.is_page) + self.am_3hump_ei = BlocksCustomCheckButton(parent=self.is_page) sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Policy.Minimum, QtWidgets.QSizePolicy.Policy.MinimumExpanding) sizePolicy.setHorizontalStretch(0) sizePolicy.setVerticalStretch(0) @@ -1102,7 +1102,7 @@ def setupUi(self, utilitiesStackedWidget): self.am_3hump_ei.setObjectName("am_3hump_ei") self.is_btn_group.addButton(self.am_3hump_ei) self.gridLayout_4.addWidget(self.am_3hump_ei, 2, 0, 1, 2, QtCore.Qt.AlignmentFlag.AlignHCenter) - self.am_user_input = GroupButton(parent=self.is_page) + self.am_user_input = BlocksCustomCheckButton(parent=self.is_page) sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Policy.Minimum, QtWidgets.QSizePolicy.Policy.MinimumExpanding) sizePolicy.setHorizontalStretch(0) sizePolicy.setVerticalStretch(0) @@ -1128,7 +1128,7 @@ def setupUi(self, utilitiesStackedWidget): self.am_user_input.setObjectName("am_user_input") self.is_btn_group.addButton(self.am_user_input) self.gridLayout_4.addWidget(self.am_user_input, 2, 2, 1, 2, QtCore.Qt.AlignmentFlag.AlignHCenter) - self.am_2hump_ei = GroupButton(parent=self.is_page) + self.am_2hump_ei = BlocksCustomCheckButton(parent=self.is_page) sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Policy.Minimum, QtWidgets.QSizePolicy.Policy.MinimumExpanding) sizePolicy.setHorizontalStretch(0) sizePolicy.setVerticalStretch(0) @@ -1553,6 +1553,6 @@ def retranslateUi(self, utilitiesStackedWidget): from lib.utils.blocks_button import BlocksCustomButton from lib.utils.blocks_frame import BlocksCustomFrame from lib.utils.blocks_slider import BlocksSlider -from lib.utils.group_button import GroupButton +from lib.utils.check_button import BlocksCustomCheckButton from lib.utils.icon_button import IconButton from lib.utils.toggleAnimatedButton import ToggleAnimatedButton diff --git a/BlocksScreen/lib/utils/check_button.py b/BlocksScreen/lib/utils/check_button.py new file mode 100644 index 00000000..e5b184d5 --- /dev/null +++ b/BlocksScreen/lib/utils/check_button.py @@ -0,0 +1,87 @@ +import typing +from PyQt6 import QtCore, QtGui, QtWidgets + + +class BlocksCustomCheckButton(QtWidgets.QAbstractButton): + """Custom Blocks QPushButton + Rounded button with a hole on the left side where an icon can be inserted + + Args: + parent (QWidget): Parent of the button + """ + + def __init__( + self, + parent: QtWidgets.QWidget, + ) -> None: + super().__init__(parent) + self.button_ellipse = None + self._text: str = "" + self.setAttribute(QtCore.Qt.WidgetAttribute.WA_AcceptTouchEvents, True) + + def setFlat(self, flat) -> None: + """Disable setFlat behavior""" + return + + def setAutoDefault(self, _): + """Disable auto default behavior""" + return + + def text(self) -> str: + """returns Widget text""" + return self._text + + def setText(self, text: str | None) -> None: + """Set widget text""" + if text is None: + return + self._text = text + self.update() + return + + def paintEvent(self, e: typing.Optional[QtGui.QPaintEvent]): + """Re-implemented method, paint widget, optimized for performance.""" + + painter = QtGui.QPainter(self) + rect_f = self.rect().toRectF().normalized() + painter.setRenderHint(painter.RenderHint.Antialiasing, True) + height = rect_f.height() + + radius = height / 5.0 + self.button_ellipse = QtCore.QRectF( + rect_f.left() + height * 0.05, + rect_f.top() + height * 0.05, + (height * 0.40), + (height * 0.40), + ) + + if self.isChecked(): + bg_color = QtGui.QColor(223, 223, 223) + text_color = QtGui.QColor(0, 0, 0) + elif self.isDown(): + bg_color = QtGui.QColor(164, 164, 164, 90) + text_color = QtGui.QColor(255, 255, 255) + else: + bg_color = QtGui.QColor(0, 0, 0, 90) + text_color = QtGui.QColor(255, 255, 255) + + path = QtGui.QPainterPath() + path.addRoundedRect( + rect_f, + radius, + radius, + QtCore.Qt.SizeMode.AbsoluteSize, + ) + + painter.setPen(QtCore.Qt.PenStyle.NoPen) + painter.setBrush(bg_color) + painter.fillPath(path, bg_color) + + if self.text(): + painter.setPen(text_color) + painter.setFont(QtGui.QFont("Momcake", 14)) + painter.drawText( + rect_f, + QtCore.Qt.AlignmentFlag.AlignCenter, + str(self.text()), + ) diff --git a/BlocksScreen/lib/utils/group_button.py b/BlocksScreen/lib/utils/group_button.py deleted file mode 100644 index 79f4251e..00000000 --- a/BlocksScreen/lib/utils/group_button.py +++ /dev/null @@ -1,146 +0,0 @@ -import typing -from PyQt6 import QtCore, QtGui, QtWidgets - - -class GroupButton(QtWidgets.QPushButton): - """Custom Blocks QPushButton - Rounded button with a hole on the left side where an icon can be inserted - - Args: - parent (QWidget): Parent of the button - """ - - def __init__( - self, - parent: QtWidgets.QWidget, - ) -> None: - super(GroupButton, self).__init__(parent) - - self.icon_pixmap: QtGui.QPixmap = QtGui.QPixmap() - self._icon_rect: QtCore.QRectF = QtCore.QRectF() - self.button_background = None - self.button_ellipse = None - self._text: str = "" - self._name: str = "" - self.text_color: QtGui.QColor = QtGui.QColor(0, 0, 0) - self.setAttribute(QtCore.Qt.WidgetAttribute.WA_AcceptTouchEvents, True) - - @property - def name(self): - """Widget name""" - return self._name - - @name.setter - def name(self, new_name) -> None: - self._name = new_name - self.setObjectName(new_name) - - def text(self) -> str | None: - """Widget text""" - return self._text - - def setText(self, text: str) -> None: - """Set widget text""" - self._text = text - self.update() # Force button update - return - - def setPixmap(self, pixmap: QtGui.QPixmap) -> None: - """Set widget pixmap""" - self.icon_pixmap = pixmap - self.repaint() - - def paintEvent(self, e: typing.Optional[QtGui.QPaintEvent]): - """Re-implemented method, paint widget""" - opt = QtWidgets.QStyleOptionButton() - self.initStyleOption(opt) - - painter = QtGui.QPainter(self) - painter.setRenderHint(painter.RenderHint.Antialiasing, True) - painter.setRenderHint(painter.RenderHint.SmoothPixmapTransform, True) - painter.setRenderHint(painter.RenderHint.LosslessImageRendering, True) - - _rect = self.rect() - _style = self.style() - - if _style is None or _rect is None: - return - - bg_color = ( - QtGui.QColor(223, 223, 223) - if self.isChecked() - else QtGui.QColor(164, 164, 164, 90) - if self.isDown() - else QtGui.QColor(0, 0, 0, 90) - ) - - path = QtGui.QPainterPath() - xRadius = self.rect().toRectF().normalized().height() / 5.0 - yRadius = self.rect().toRectF().normalized().height() / 5.0 - painter.setBackgroundMode(QtCore.Qt.BGMode.TransparentMode) - path.addRoundedRect( - 0, - 0, - self.rect().toRectF().normalized().width(), - self.rect().toRectF().normalized().height(), - xRadius, - yRadius, - QtCore.Qt.SizeMode.AbsoluteSize, - ) - - self.button_ellipse = QtCore.QRectF( - self.rect().toRectF().normalized().left() - + self.rect().toRectF().normalized().height() * 0.05, - self.rect().toRectF().normalized().top() - + self.rect().toRectF().normalized().height() * 0.05, - (self.rect().toRectF().normalized().height() * 0.40), - (self.rect().toRectF().normalized().height() * 0.40), - ) - - painter.setPen(QtCore.Qt.PenStyle.NoPen) - painter.setBrush(bg_color) - painter.fillPath(path, bg_color) - - if self.text(): - if self.isChecked(): - painter.setPen(QtGui.QColor(0, 0, 0)) - else: - painter.setPen(QtGui.QColor(255, 255, 255)) - _start_text_position = int(self.button_ellipse.width() / 2) - _text_rect = _rect - _pen = painter.pen() - _pen.setStyle(QtCore.Qt.PenStyle.SolidLine) - _pen.setWidth(1) - painter.setPen(_pen) - painter.setFont(QtGui.QFont("Momcake-Thin", 14)) - - painter.drawText( - _text_rect, - QtCore.Qt.AlignmentFlag.AlignCenter, - str(self.text()), - ) - painter.setPen(QtCore.Qt.PenStyle.NoPen) - - def setProperty(self, name: str, value: typing.Any): - """Re-implemented method, set widget properties""" - if name == "name": - self._name = name - elif name == "text_color": - self.text_color = QtGui.QColor(value) - # return super().setProperty(name, value) - - def event(self, e: QtCore.QEvent) -> bool: - """Re-implemented method, filter events""" - if e.type() == QtCore.QEvent.Type.TouchBegin: - self.handleTouchBegin(e) - return False - elif e.type() == QtCore.QEvent.Type.TouchUpdate: - self.handleTouchUpdate(e) - return False - elif e.type() == QtCore.QEvent.Type.TouchEnd: - self.handleTouchEnd(e) - return False - elif e.type() == QtCore.QEvent.Type.TouchCancel: - self.handleTouchCancel(e) - return False - return super().event(e)