aboutsummaryrefslogtreecommitdiff
path: root/src/avp/gui/preview_win.py
diff options
context:
space:
mode:
authorAeliton G. Silva2026-01-12 22:39:55 -0300
committerAeliton G. Silva2026-01-13 04:22:25 -0300
commitf975144f25d34f97329b2d4e52891061573cea08 (patch)
tree226fe223b31af6f217b1dd413629ab2cf26964d4 /src/avp/gui/preview_win.py
parentb8703752ffc7768b0275897b3c2a869ff41504e5 (diff)
Use pyproject.toml + uv_build
This replaces setup.py by a modern pyproject.toml using uv_build backend. Dependencies are being also managed by uv, so to install dependencies and run the project one can execute: ``` uv sync uv run pytest # optional python -m avp ``` To build the both source and binary (wheel) distribution package run: ``` uv build ``` Uv can be installed with `pip install uv`. The directory structure has been changed to reflect best practices. - src/* -> src/avp/ - src/tests -> ../tests
Diffstat (limited to 'src/avp/gui/preview_win.py')
-rw-r--r--src/avp/gui/preview_win.py58
1 files changed, 58 insertions, 0 deletions
diff --git a/src/avp/gui/preview_win.py b/src/avp/gui/preview_win.py
new file mode 100644
index 0000000..f52f8a3
--- /dev/null
+++ b/src/avp/gui/preview_win.py
@@ -0,0 +1,58 @@
+from PyQt6 import QtCore, QtGui, QtWidgets
+import logging
+
+log = logging.getLogger("AVP.Gui.PreviewWindow")
+
+
+class PreviewWindow(QtWidgets.QLabel):
+ """
+ Paints the preview QLabel in MainWindow and maintains the aspect ratio
+ when the window is resized.
+ """
+
+ def __init__(self, parent, img):
+ super().__init__()
+ self.parent = parent
+ # FIXME
+ # self.setFrameStyle(QtWidgets.QFrame.StyledPanel)
+ self.pixmap = QtGui.QPixmap(img)
+
+ def paintEvent(self, event):
+ size = self.size()
+ painter = QtGui.QPainter(self)
+ point = QtCore.QPoint(0, 0)
+ scaledPix = self.pixmap.scaled(
+ size,
+ QtCore.Qt.AspectRatioMode.KeepAspectRatio,
+ transformMode=QtCore.Qt.TransformationMode.SmoothTransformation,
+ )
+
+ # start painting the label from left upper corner
+ point.setX(int((size.width() - scaledPix.width()) / 2))
+ point.setY(int((size.height() - scaledPix.height()) / 2))
+ painter.drawPixmap(point, scaledPix)
+
+ def changePixmap(self, img):
+ self.pixmap = QtGui.QPixmap(img)
+ self.repaint()
+
+ def mousePressEvent(self, event):
+ if self.parent.encoding:
+ return
+
+ i = self.parent.listWidget_componentList.currentRow()
+ if i >= 0:
+ component = self.parent.core.selectedComponents[i]
+ if not hasattr(component, "previewClickEvent"):
+ return
+ qpoint = event.position().toPoint()
+ pos = (qpoint.x(), qpoint.y())
+ size = (self.width(), self.height())
+ butt = event.button()
+ log.info("Click event for #%s: %s button %s" % (i, pos, butt))
+ component.previewClickEvent(pos, size, butt)
+
+ @QtCore.pyqtSlot(str)
+ def threadError(self, msg):
+ self.parent.showMessage(msg=msg, icon="Critical", parent=self)
+ log.info("%", repr(self.parent))