-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwhiteboard.py
More file actions
41 lines (35 loc) · 1.56 KB
/
whiteboard.py
File metadata and controls
41 lines (35 loc) · 1.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
from PySide6.QtWidgets import QWidget, QGraphicsView, QGraphicsScene
from PySide6.QtGui import QImage, QPixmap, QPainter, QPen, QColor
from PySide6.QtCore import Qt, QPoint
class Whiteboard(QWidget):
def __init__(self, parent=None):
super().__init__(parent)
self.scene = QGraphicsScene(self)
self.view = QGraphicsView(self.scene, self)
self.view.setGeometry(0, 0, 800, 600)
self.last_pos = None # Track the last drawn position
self.pen = QPen(QColor("black"), 3, Qt.SolidLine, Qt.RoundCap, Qt.RoundJoin)
def update_camera_feed(self, frame):
"""Update camera feed onto the whiteboard."""
if frame is not None:
height, width, channels = frame.shape
img = QImage(frame.data, width, height, channels * width, QImage.Format_BGR888)
pixmap = QPixmap.fromImage(img)
self.scene.clear()
self.scene.addPixmap(pixmap)
def mousePressEvent(self, event):
"""Start drawing."""
if event.button() == Qt.LeftButton:
self.last_pos = event.pos()
def mouseMoveEvent(self, event):
"""Continue drawing."""
if event.buttons() == Qt.LeftButton and self.last_pos is not None:
painter = QPainter(self.view.viewport())
painter.setPen(self.pen)
painter.drawLine(self.last_pos, event.pos())
self.last_pos = event.pos()
painter.end()
def mouseReleaseEvent(self, event):
"""Stop drawing."""
if event.button() == Qt.LeftButton:
self.last_pos = None