19from krita
import Krita, DockWidget, FileDialog
20from builtins
import Application, i18n, i18nc
25 from PyQt6.QtCore import Qt, QDirIterator, QMimeData, QUrl, QStandardPaths
26 from PyQt6.QtWidgets import QWidget, QSizePolicy, QApplication, QMessageBox
30 from PyQt5.QtCore import Qt, QDirIterator, QMimeData, QUrl, QStandardPaths
31 from PyQt5.QtWidgets import QWidget, QSizePolicy, QApplication, QMessageBox
33from .photobash_images_modulo
import (
74 for value
in favouriteImagesValues:
75 if value !=
"[" and value !=
", " and value !=
"]" and value !=
"" and value !=
"[]":
78 self.
bg_alpha = str(
"background-color: rgba(0, 0, 0, 50); ")
79 self.
bg_hover = str(
"background-color: rgba(0, 0, 0, 100); ")
83 self.setWindowTitle(i18nc(
"@title:window",
"Photobash Images"))
95 self.
layout.imagesButtons0,
96 self.
layout.imagesButtons1,
97 self.
layout.imagesButtons2,
98 self.
layout.imagesButtons3,
99 self.
layout.imagesButtons4,
100 self.
layout.imagesButtons5,
101 self.
layout.imagesButtons6,
102 self.
layout.imagesButtons7,
103 self.
layout.imagesButtons8,
107 self.
layout.imageWidget.setSizePolicy(QSizePolicy.Policy.Expanding, QSizePolicy.Policy.Ignored)
108 self.
layout.middleWidget.setSizePolicy(QSizePolicy.Policy.Expanding, QSizePolicy.Policy.Expanding)
117 self.
layout.paginationSlider.setMinimum(0)
132 imageButton.setNumber(i)
151 self.
layout.changePathButton.setText(i18n(
"Change References Folder"))
157 self.
layout.scaleSliderLabel.setText(i18n(
"Image Scale: {0}%").format(100))
164 favouriteFoundImages = []
168 favouriteFoundImages.append(image)
173 stringsInText = self.
layout.filterTextEdit.text().lower().split(
" ")
174 if self.
layout.filterTextEdit.text().lower() ==
"":
181 for word
in stringsInText:
184 if word
in path.replace(self.
directoryPath,
"").lower()
and not path
in newImages
and word !=
"" and word !=
" ":
185 newImages.append(path)
201 it = QDirIterator(self.
directoryPath, QDirIterator.IteratorFlag.Subdirectories)
205 if (
".webp" in it.filePath()
or ".png" in it.filePath()
or ".jpg" in it.filePath()
or ".jpeg" in it.filePath())
and \
206 (
not ".webp~" in it.filePath()
and not ".png~" in it.filePath()
and not ".jpg~" in it.filePath()
and not ".jpeg~" in it.filePath()):
207 newImages.append(it.filePath())
217 if (self.
currPage == 0
and increment == -1)
or \
240 self.
currPage = max(0, min(value, maxNumPage - 1))
244 if state == Qt.CheckState.Checked:
261 if SIGNAL_HOVER ==
"D":
268 if SIGNAL_HOVER == str(i):
282 self.
cachedImages[path] = QImage(path).scaled(200, 200, Qt.AspectRatioMode.KeepAspectRatio, Qt.TransformationMode.FastTransformation)
323 currPage =
" " + str(currPage)
325 currPage =
" " + str(currPage)
326 elif currPage < 1000:
327 currPage =
" " + str(currPage)
331 self.
layout.paginationLabel.setText(i18n(
"Page: {0}/{1}").format(currPage, maxNumPage))
333 self.
layout.paginationSlider.setRange(0, maxNumPage - 1)
350 if self.canvas()
is None or self.canvas().view()
is None:
357 image = QImage(photoPath).scaled(int(doc.width() * scale), int(doc.height() * scale), Qt.AspectRatioMode.KeepAspectRatio, Qt.TransformationMode.SmoothTransformation)
359 image = QImage(photoPath)
361 image = image.scaled(int(image.width() * scale), int(image.height() * scale), Qt.AspectRatioMode.KeepAspectRatio, Qt.TransformationMode.SmoothTransformation)
364 mimedata = QMimeData()
365 url = QUrl().fromLocalFile(photoPath)
366 mimedata.setUrls([url])
367 mimedata.setImageData(image)
370 QApplication.clipboard().setImage(image)
377 if not os.path.isfile(path):
385 dlg = QMessageBox(self)
386 dlg.setWindowTitle(
"Missing Image!")
387 dlg.setText(
"This image you tried to open was not found. Removing from the list.")
400 Application.activeWindow().addView(document)
408 mimedata = QMimeData()
409 url = QUrl().fromLocalFile(path)
410 mimedata.setUrls([url])
412 mimedata.setImageData(image)
414 QApplication.clipboard().setImage(image)
419 self.
layout.imageWidget.setSizePolicy(QSizePolicy.Policy.Expanding, QSizePolicy.Policy.Expanding)
420 self.
layout.middleWidget.setSizePolicy(QSizePolicy.Policy.Expanding, QSizePolicy.Policy.Ignored)
423 self.
layout.imageWidget.setSizePolicy(QSizePolicy.Policy.Expanding, QSizePolicy.Policy.Ignored)
424 self.
layout.middleWidget.setSizePolicy(QSizePolicy.Policy.Expanding, QSizePolicy.Policy.Expanding)
446 orderedImages.append(image)
453 self.
layout.filterTextEdit.clearFocus()
459 if position < len(self.foundImages) - len(self.imagesButtons) * self.currPage:
460 self.addImageLayer(self.foundImages[position + len(self.imagesButtons) * self.currPage])
464 dialogDirectory = QStandardPaths.writableLocation(QStandardPaths.StandardLocation.PicturesLocation)
477 self.
layout.changePathButton.setText(i18n(
"Set References Folder"))
479 self.
layout.changePathButton.setText(i18n(
"Change References Folder"))
static QString getExistingDirectory(QWidget *parent=nullptr, const QString &caption=QString(), const QString &directory=QString(), const QString &dialogName=QString())
Create and show a file dialog and return the name of an existing directory selected by the user.
static Krita * instance()
instance retrieve the singleton instance of the Application object.
updateCurrentPage(self, increment)
getImagesFromDirectory(self)
unpinFromFavourites(self, path)
cursorHover(self, SIGNAL_HOVER)
addImageLayer(self, photoPath)
buttonClick(self, position)
pinToFavourites(self, path)
changedFitCanvas(self, state)
openNewDocument(self, path)
canvasChanged(self, canvas)
placeReference(self, path)