Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 6 additions & 11 deletions BlocksScreen/lib/panels/widgets/colorWheelWidget.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,12 +105,12 @@ def _pick(self, pos: QtCore.QPointF) -> None:
self.update()
self.hue_sat_changed.emit(self._hue, self._sat)

# def mousePressEvent(self, event: QtGui.QMouseEvent) -> None:
# self._pick(event.position())
def mouseMoveEvent(self, a0: QtGui.QMouseEvent | None) -> None:
if a0.buttons() & QtCore.Qt.MouseButton.LeftButton:
self._pick(a0.position())

def mouseMoveEvent(self, event: QtGui.QMouseEvent) -> None:
if event.buttons() & QtCore.Qt.MouseButton.LeftButton:
self._pick(event.position())
def mousePressEvent(self, a0: QtGui.QMouseEvent | None) -> None:
self._pick(a0.position())


class ColorWheelWidget(QtWidgets.QWidget):
Expand Down Expand Up @@ -208,7 +208,6 @@ def _lbl(
root.setContentsMargins(12, 8, 12, 8)
root.setSpacing(8)

# ── Header ──────────────────────────────────────────────────────
header = QtWidgets.QHBoxLayout()
header.setContentsMargins(0, 0, 0, 0)

Expand All @@ -230,22 +229,18 @@ def _lbl(
header.addWidget(back_btn)
root.addLayout(header)

# ── Body ─────────────────────────────────────────────────────────
body = QtWidgets.QHBoxLayout()
body.setSpacing(16)

# Left: colour wheel, vertically centred
self._wheel = _ColorWheel(self, diameter=260)
self._wheel.hue_sat_changed.connect(self._on_hue_sat)
body.addWidget(self._wheel, 0, QtCore.Qt.AlignmentFlag.AlignVCenter)

# Right: card containing all controls
card = BlocksCustomFrame(self)
card_lay = QtWidgets.QVBoxLayout(card)
card_lay.setContentsMargins(14, 14, 14, 14)
card_lay.setSpacing(10)

# Combined swatch + hex code — one element instead of two
self._swatch = BlocksLabel(card)
self._swatch.setFixedHeight(76)
self._swatch.rounded = True
Expand All @@ -256,7 +251,6 @@ def _lbl(
self._swatch.setFont(swatch_font)
card_lay.addWidget(self._swatch)

# Brightness row
card_lay.addWidget(
_lbl("Brightness", 22, QtGui.QColor(160, 160, 160), card, 30)
)
Expand All @@ -275,6 +269,7 @@ def _lbl(
f.setPointSize(16)
select_btn.setFont(f)
select_btn.setText("Select")
select_btn.setPixmap(QtGui.QPixmap(":/dialog/media/btn_icons/yes.svg"))
select_btn.clicked.connect(self._on_select)
card_lay.addWidget(select_btn, 0, QtCore.Qt.AlignmentFlag.AlignHCenter)

Expand Down
11 changes: 9 additions & 2 deletions BlocksScreen/lib/panels/widgets/keyboardPage.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ def __init__(self, parent: QtWidgets.QWidget) -> None:
self._key_buttons: list[QtWidgets.QPushButton] = []
self._pattern: str = ""
self._max_length: int = 0
self.firsttime: bool = True

self._setup_ui()
self.setCursor(QtCore.Qt.CursorShape.BlankCursor)
Expand Down Expand Up @@ -211,9 +212,10 @@ def _geometry_calc(self) -> None:

self.setGeometry(x, y, width, height)

def show(self) -> None:
def showEvent(self, a0: QtGui.QShowEvent | None) -> None:
self._geometry_calc()
return super().show()
self.firsttime = True
return super().showEvent(a0)

def handle_keyboard_layout(self) -> None:
"""Update key labels based on current shift/keychange state."""
Expand Down Expand Up @@ -244,6 +246,11 @@ def handle_keyboard_layout(self) -> None:

def value_inserted(self, value: str) -> None:
"""Handle key press: append char, delete, or submit on enter."""

if self.firsttime and value not in ("enter", "clear"):
self.current_value = ""
self.firsttime = False

if value == "&&":
value = "&"

Expand Down
24 changes: 22 additions & 2 deletions BlocksScreen/lib/panels/widgets/numpadPage.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ def __init__(
self.name: str = ""
self.min_value: int = 0
self.max_value: int = 100
self.enforce_range: bool = True
self.firsttime: bool = True

self.numpad_0.clicked.connect(lambda: self.value_inserted("0"))
Expand All @@ -41,6 +42,7 @@ def __init__(

def showEvent(self, a0: QtGui.QShowEvent | None) -> None:
self.firsttime = True
self.min_max_label.setVisible(True)
return super().showEvent(a0)

def value_inserted(self, value: str) -> None:
Expand All @@ -58,10 +60,12 @@ def value_inserted(self, value: str) -> None:
else:
self.current_value += str(value)

in_range = self.min_value <= int(self.current_value) <= self.max_value

if "enter" in value and self.current_value.isnumeric():
if len(self.current_value) == 0:
self.current_value = "0"
if self.min_value <= int(self.current_value) <= self.max_value:
if in_range or not self.enforce_range:
self.value_selected.emit(self.name, int(self.current_value))
self.request_back.emit()

Expand All @@ -70,8 +74,9 @@ def value_inserted(self, value: str) -> None:
self.current_value = self.current_value[:-1]
else:
self.current_value = "0"
in_range = self.min_value <= int(self.current_value) <= self.max_value

if not (self.min_value <= int(self.current_value) <= self.max_value):
if not in_range and self.enforce_range:
self.start_glow_animation.emit()
else:
self.inserted_value.glow_animation.stop()
Expand Down Expand Up @@ -104,8 +109,14 @@ def set_max_value(self, max_value: int) -> None:
self.max_value = max_value
self.update_min_max_label()

def set_enforce_range(self, enforce: bool = True) -> None:
"""Enable or disable min/max range enforcement. Enabled by default."""
self.enforce_range = enforce
self.min_max_label.setVisible(enforce)

def update_min_max_label(self) -> None:
"""Updates the text of the min/max label."""
self.enforce_range = True
self.min_max_label.setText(f"Range: {self.min_value} - {self.max_value}")

def _setupUI(self) -> None:
Expand Down Expand Up @@ -133,6 +144,15 @@ def _setupUI(self) -> None:

self.header_layout.setContentsMargins(0, 0, 0, 0)
self.header_layout.setObjectName("header_layout")

spacerItem1 = QtWidgets.QSpacerItem(
60,
60,
QtWidgets.QSizePolicy.Policy.Minimum,
QtWidgets.QSizePolicy.Policy.Minimum,
)
self.header_layout.addItem(spacerItem1)

self.numpad_title = BlocksLabel(self)
self.numpad_title.setMinimumSize(QtCore.QSize(500, 60))
self.numpad_title.setMaximumSize(QtCore.QSize(16777215, 60))
Expand Down
9 changes: 4 additions & 5 deletions BlocksScreen/lib/utils/blocks_linedit.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ def __init__(self, parent: typing.Optional[QtWidgets.QWidget] = None) -> None:

# Pre-allocated colors (avoid allocation in paint)
self._bg_color = QtGui.QColor(223, 223, 223)
self._disabled_bg_color = QtGui.QColor(169, 169, 169)
self._bg_pressed_color = QtGui.QColor(200, 200, 200)
self._text_color = QtGui.QColor(0, 0, 0)
self._placeholder_color = QtGui.QColor(130, 130, 130)
Expand Down Expand Up @@ -85,17 +86,15 @@ def mousePressEvent(self, event: QtGui.QMouseEvent) -> None:
self.clicked.emit()
super().mousePressEvent(event)

def mouseReleaseEvent(self, event: QtGui.QMouseEvent) -> None:
"""Handle mouse release"""
super().mouseReleaseEvent(event)

def paintEvent(self, event: typing.Optional[QtGui.QPaintEvent]) -> None:
"""Custom paint with embedded toggle button."""
painter = QtGui.QPainter(self)
painter.setRenderHint(QtGui.QPainter.RenderHint.Antialiasing, True)

# Background
painter.setBrush(self._bg_color)
painter.setBrush(
self._bg_color if self.isEnabled() else self._disabled_bg_color
)
painter.setPen(QtCore.Qt.PenStyle.NoPen)
painter.drawRoundedRect(self.rect(), self.CORNER_RADIUS, self.CORNER_RADIUS)

Expand Down
2 changes: 1 addition & 1 deletion tests/util/test_keyboard_page_unit.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ def test_set_value_prefills(self, keyboard):
def test_set_value_then_type(self, keyboard):
keyboard.set_value("abc")
keyboard.value_inserted("d")
assert keyboard.current_value == "abcd"
assert keyboard.current_value == "d"


class TestDotButton:
Expand Down
Loading