aboutsummaryrefslogtreecommitdiff
path: root/src/components/image.py
diff options
context:
space:
mode:
Diffstat (limited to 'src/components/image.py')
-rw-r--r--src/components/image.py71
1 files changed, 37 insertions, 34 deletions
diff --git a/src/components/image.py b/src/components/image.py
index 42f9564..2393611 100644
--- a/src/components/image.py
+++ b/src/components/image.py
@@ -1,5 +1,5 @@
from PIL import Image, ImageDraw, ImageEnhance
-from PyQt5 import QtGui, QtCore, QtWidgets
+from PyQt6 import QtGui, QtCore, QtWidgets
import os
from ..component import Component
@@ -7,37 +7,39 @@ from ..toolkit.frame import BlankFrame
class Component(Component):
- name = 'Image'
- version = '1.0.1'
+ name = "Image"
+ version = "1.0.1"
def widget(self, *args):
super().widget(*args)
self.page.pushButton_image.clicked.connect(self.pickImage)
- self.trackWidgets({
- 'imagePath': self.page.lineEdit_image,
- 'scale': self.page.spinBox_scale,
- 'stretchScale': self.page.spinBox_scale_stretch,
- 'rotate': self.page.spinBox_rotate,
- 'color': self.page.spinBox_color,
- 'xPosition': self.page.spinBox_x,
- 'yPosition': self.page.spinBox_y,
- 'stretched': self.page.checkBox_stretch,
- 'mirror': self.page.checkBox_mirror,
- }, presetNames={
- 'imagePath': 'image',
- 'xPosition': 'x',
- 'yPosition': 'y',
- }, relativeWidgets=[
- 'xPosition', 'yPosition', 'scale'
- ])
+ self.trackWidgets(
+ {
+ "imagePath": self.page.lineEdit_image,
+ "scale": self.page.spinBox_scale,
+ "stretchScale": self.page.spinBox_scale_stretch,
+ "rotate": self.page.spinBox_rotate,
+ "color": self.page.spinBox_color,
+ "xPosition": self.page.spinBox_x,
+ "yPosition": self.page.spinBox_y,
+ "stretched": self.page.checkBox_stretch,
+ "mirror": self.page.checkBox_mirror,
+ },
+ presetNames={
+ "imagePath": "image",
+ "xPosition": "x",
+ "yPosition": "y",
+ },
+ relativeWidgets=["xPosition", "yPosition", "scale"],
+ )
def previewRender(self):
return self.drawFrame(self.width, self.height)
def properties(self):
- props = ['static']
+ props = ["static"]
if not os.path.exists(self.imagePath):
- props.append('error')
+ props.append("error")
return props
def error(self):
@@ -57,17 +59,15 @@ class Component(Component):
# Modify image's appearance
if self.color != 100:
- image = ImageEnhance.Color(image).enhance(
- float(self.color / 100)
- )
+ image = ImageEnhance.Color(image).enhance(float(self.color / 100))
if self.mirror:
- image = image.transpose(Image.FLIP_LEFT_RIGHT)
+ image = image.transpose(Image.Transpose.FLIP_LEFT_RIGHT)
if self.stretched and image.size != (width, height):
- image = image.resize((width, height), Image.ANTIALIAS)
+ image = image.resize((width, height), Image.Resampling.LANCZOS)
if scale != 100:
newHeight = int((image.height / 100) * scale)
newWidth = int((image.width / 100) * scale)
- image = image.resize((newWidth, newHeight), Image.ANTIALIAS)
+ image = image.resize((newWidth, newHeight), Image.Resampling.LANCZOS)
# Paste image at correct position
frame.paste(image, box=(self.xPosition, self.yPosition))
@@ -79,8 +79,11 @@ class Component(Component):
def pickImage(self):
imgDir = self.settings.value("componentDir", os.path.expanduser("~"))
filename, _ = QtWidgets.QFileDialog.getOpenFileName(
- self.page, "Choose Image", imgDir,
- "Image Files (%s)" % " ".join(self.core.imageFormats))
+ self.page,
+ "Choose Image",
+ imgDir,
+ "Image Files (%s)" % " ".join(self.core.imageFormats),
+ )
if filename:
self.settings.setValue("componentDir", os.path.dirname(filename))
self.mergeUndo = False
@@ -88,9 +91,9 @@ class Component(Component):
self.mergeUndo = True
def command(self, arg):
- if '=' in arg:
- key, arg = arg.split('=', 1)
- if key == 'path' and os.path.exists(arg):
+ if "=" in arg:
+ key, arg = arg.split("=", 1)
+ if key == "path" and os.path.exists(arg):
try:
Image.open(arg)
self.page.lineEdit_image.setText(arg)
@@ -102,7 +105,7 @@ class Component(Component):
super().command(arg)
def commandHelp(self):
- print('Load an image:\n path=/filepath/to/image.png')
+ print("Load an image:\n path=/filepath/to/image.png")
def savePreset(self):
# Maintain the illusion that the scale spinbox is one widget