финал
This commit is contained in:
@@ -1,44 +0,0 @@
|
|||||||
# -*- mode: python ; coding: utf-8 -*-
|
|
||||||
|
|
||||||
|
|
||||||
a = Analysis(
|
|
||||||
['main.py'],
|
|
||||||
pathex=[],
|
|
||||||
binaries=[],
|
|
||||||
datas=[],
|
|
||||||
hiddenimports=[],
|
|
||||||
hookspath=[],
|
|
||||||
hooksconfig={},
|
|
||||||
runtime_hooks=[],
|
|
||||||
excludes=[],
|
|
||||||
noarchive=False,
|
|
||||||
optimize=0,
|
|
||||||
)
|
|
||||||
pyz = PYZ(a.pure)
|
|
||||||
|
|
||||||
exe = EXE(
|
|
||||||
pyz,
|
|
||||||
a.scripts,
|
|
||||||
a.binaries,
|
|
||||||
a.datas,
|
|
||||||
[],
|
|
||||||
name='main',
|
|
||||||
debug=False,
|
|
||||||
bootloader_ignore_signals=False,
|
|
||||||
strip=False,
|
|
||||||
upx=True,
|
|
||||||
upx_exclude=[],
|
|
||||||
runtime_tmpdir=None,
|
|
||||||
console=False,
|
|
||||||
disable_windowed_traceback=False,
|
|
||||||
argv_emulation=False,
|
|
||||||
target_arch=None,
|
|
||||||
codesign_identity=None,
|
|
||||||
entitlements_file=None,
|
|
||||||
)
|
|
||||||
app = BUNDLE(
|
|
||||||
exe,
|
|
||||||
name='main.app',
|
|
||||||
icon=None,
|
|
||||||
bundle_identifier=None,
|
|
||||||
)
|
|
||||||
3
visuapPart1/firstLabVisualProg/razdel2.txt
Normal file
3
visuapPart1/firstLabVisualProg/razdel2.txt
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
"917:1872",
|
||||||
|
"region":
|
||||||
|
Проверка
|
||||||
@@ -6,7 +6,7 @@ from PyQt5.QtWidgets import (
|
|||||||
)
|
)
|
||||||
from PyQt5.QtCore import Qt, QPoint
|
from PyQt5.QtCore import Qt, QPoint
|
||||||
from PyQt5.QtGui import (
|
from PyQt5.QtGui import (
|
||||||
QImage, QPainter, QPen, QColor, QPixmap, QIcon
|
QImage, QPainter, QPen, QColor, QPixmap, QIcon, QPainterPath
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@@ -34,6 +34,9 @@ class Canvas(QWidget):
|
|||||||
self.redo_stack = []
|
self.redo_stack = []
|
||||||
self.save_state() # Сохраняем начальное состояние
|
self.save_state() # Сохраняем начальное состояние
|
||||||
|
|
||||||
|
# Путь для текущего штриха (для корректной работы пунктирных стилей)
|
||||||
|
self.current_path = None
|
||||||
|
|
||||||
def save_state(self):
|
def save_state(self):
|
||||||
"""Сохранить текущее состояние для undo"""
|
"""Сохранить текущее состояние для undo"""
|
||||||
self.undo_stack.append(self.image.copy())
|
self.undo_stack.append(self.image.copy())
|
||||||
@@ -123,28 +126,41 @@ class Canvas(QWidget):
|
|||||||
self.drawing = True
|
self.drawing = True
|
||||||
self.last_point = event.pos()
|
self.last_point = event.pos()
|
||||||
self.save_state() # Сохраняем состояние перед началом рисования
|
self.save_state() # Сохраняем состояние перед началом рисования
|
||||||
|
# Создаём новый путь для штриха
|
||||||
|
self.current_path = QPainterPath()
|
||||||
|
self.current_path.moveTo(event.pos())
|
||||||
|
|
||||||
def mouseMoveEvent(self, event):
|
def mouseMoveEvent(self, event):
|
||||||
"""Обработка движения мыши"""
|
"""Обработка движения мыши"""
|
||||||
if self.drawing:
|
if self.drawing:
|
||||||
painter = QPainter(self.image)
|
|
||||||
|
|
||||||
if event.buttons() & Qt.RightButton:
|
if event.buttons() & Qt.RightButton:
|
||||||
# Правая кнопка - ластик (стираем белым цветом)
|
# Правая кнопка - ластик (стираем белым цветом)
|
||||||
|
# Ластик рисуем линиями напрямую
|
||||||
|
painter = QPainter(self.image)
|
||||||
pen = QPen(Qt.white, self.eraser_width, Qt.SolidLine, Qt.RoundCap, Qt.RoundJoin)
|
pen = QPen(Qt.white, self.eraser_width, Qt.SolidLine, Qt.RoundCap, Qt.RoundJoin)
|
||||||
|
painter.setPen(pen)
|
||||||
|
painter.drawLine(self.last_point, event.pos())
|
||||||
|
self.last_point = event.pos()
|
||||||
else:
|
else:
|
||||||
# Левая кнопка - рисуем
|
# Левая кнопка - рисуем с использованием пути
|
||||||
pen = QPen(self.pen_color, self.pen_width, self.pen_style, Qt.RoundCap, Qt.RoundJoin)
|
self.current_path.lineTo(event.pos())
|
||||||
|
|
||||||
|
# Восстанавливаем сохранённое состояние и перерисовываем весь путь
|
||||||
|
if len(self.undo_stack) > 0:
|
||||||
|
self.image = self.undo_stack[-1].copy()
|
||||||
|
|
||||||
|
painter = QPainter(self.image)
|
||||||
|
pen = QPen(self.pen_color, self.pen_width, self.pen_style, Qt.RoundCap, Qt.RoundJoin)
|
||||||
|
painter.setPen(pen)
|
||||||
|
painter.drawPath(self.current_path)
|
||||||
|
|
||||||
painter.setPen(pen)
|
|
||||||
painter.drawLine(self.last_point, event.pos())
|
|
||||||
self.last_point = event.pos()
|
|
||||||
self.update()
|
self.update()
|
||||||
|
|
||||||
def mouseReleaseEvent(self, event):
|
def mouseReleaseEvent(self, event):
|
||||||
"""Обработка отпускания кнопки мыши"""
|
"""Обработка отпускания кнопки мыши"""
|
||||||
if event.button() == Qt.LeftButton or event.button() == Qt.RightButton:
|
if event.button() == Qt.LeftButton or event.button() == Qt.RightButton:
|
||||||
self.drawing = False
|
self.drawing = False
|
||||||
|
self.current_path = None
|
||||||
|
|
||||||
|
|
||||||
class MainWindow(QMainWindow):
|
class MainWindow(QMainWindow):
|
||||||
BIN
visuapPart1/secondLabVisualProg/test.png
Normal file
BIN
visuapPart1/secondLabVisualProg/test.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 24 KiB |
Binary file not shown.
Reference in New Issue
Block a user