forked from Support/sp-hydra-veil-gui
68 lines
2 KiB
Python
68 lines
2 KiB
Python
from gui.v2.ui.styles.css.editor_css import PRE_SYNC_LAYOUT
|
|
|
|
from PyQt6.QtCore import Qt, QSize, QPointF
|
|
from PyQt6.QtGui import QPixmap, QPainter, QPen, QColor, QIcon, QPolygonF
|
|
|
|
|
|
def apply_arrow_images(button, button_path: str, direction: str = "left"):
|
|
"""Place an arrow image on the button"""
|
|
# 1. Set the image
|
|
button_path = f"{button_path}/{direction}.png"
|
|
button.setIcon(QIcon(button_path))
|
|
|
|
# 2. general sizing
|
|
button.setIconSize(QSize(64, 64))
|
|
|
|
# 3. Set button size to fit the image
|
|
button.setFixedSize(64, 64)
|
|
|
|
|
|
def apply_green_glow(button, direction: str = "left", set_size: bool = True):
|
|
"""Create a green triangle effect on the button"""
|
|
if set_size:
|
|
button.setFixedSize(60, 60)
|
|
|
|
# Get current dimensions of the button
|
|
w = button.width()
|
|
h = button.height()
|
|
|
|
# If the button hasn't been rendered yet, width/height might be 0.
|
|
# We provide a fallback size to prevent the code from crashing.
|
|
if w <= 0 or h <= 0:
|
|
w, h = 60, 60
|
|
|
|
# Create the transparent canvas
|
|
outline_pix = QPixmap(w, h)
|
|
outline_pix.fill(Qt.GlobalColor.transparent)
|
|
|
|
painter = QPainter(outline_pix)
|
|
painter.setRenderHint(QPainter.RenderHint.Antialiasing)
|
|
|
|
# Set up the green pen
|
|
pen = QPen(QColor(0, 255, 0))
|
|
pen.setWidth(3)
|
|
painter.setPen(pen)
|
|
painter.setBrush(Qt.BrushStyle.NoBrush)
|
|
|
|
# Define points based on direction
|
|
if direction == "left":
|
|
points = [
|
|
QPointF(w * 0.65, h * 0.15),
|
|
QPointF(w * 0.25, h * 0.50),
|
|
QPointF(w * 0.65, h * 0.85)
|
|
]
|
|
else: # Right arrow
|
|
points = [
|
|
QPointF(w * 0.35, h * 0.15),
|
|
QPointF(w * 0.75, h * 0.50),
|
|
QPointF(w * 0.35, h * 0.85)
|
|
]
|
|
|
|
painter.drawPolygon(QPolygonF(points))
|
|
painter.end()
|
|
|
|
# Apply the drawing to the button
|
|
button.setIcon(QIcon(outline_pix))
|
|
button.setIconSize(button.size())
|
|
button.setStyleSheet(PRE_SYNC_LAYOUT)
|
|
|