Commit f99cdfa0 authored by Eliakin Costa's avatar Eliakin Costa

Implement Document Tools Plugin

- Structure to dynamic add new document option to this plugin
- Pattern based in my implementation to scripter plugin
- Tabs are loaded dynamic with implemented classes in tools directory
- Canvas size plugin compose this plugin now
- Tool class must implement adjust method and will receive the mainDialog in your __init__
parent 181ea715
......@@ -76,7 +76,7 @@ install_pykrita_plugin(hello)
install_pykrita_plugin(assignprofiledialog)
install_pykrita_plugin(scripter)
install_pykrita_plugin(colorspace)
install_pykrita_plugin(canvassize)
install_pykrita_plugin(documenttools)
install_pykrita_plugin(filtermanager)
install_pykrita_plugin(exportlayers)
#install_pykrita_plugin(highpass)
......
import krita
from canvassize import uicanvassize
class CanvasSizeExtension(krita.Extension):
def __init__(self, parent):
super(CanvasSizeExtension, self).__init__(parent)
def setup(self):
action = krita.Krita.instance().createAction("canvas_size", "Canvas Size")
action.setToolTip("Plugin to change canvas size to selected documents")
action.triggered.connect(self.initialize)
def initialize(self):
self.uicanvassize = uicanvassize.UICanvasSize()
self.uicanvassize.initialize()
Scripter.addExtension(CanvasSizeExtension(krita.Krita.instance()))
[Desktop Entry]
Type=Service
ServiceTypes=Krita/PythonPlugin
X-KDE-Library=canvassize
X-Python-2-Compatible=false
Name=Canvas Size
Name[en_GB]=Canvas Size
Name[pt]=Tamanho da tela
Comment=Plugin to change canvas size to selected documents
Comment[en_GB]=Plugin to change canvas size to selected documents
Comment[pt]='Plugin' para alterar o tamanho da tela de documentos selecionados
import krita
from documenttools import uidocumenttools
class DocumentToolsExtension(krita.Extension):
def __init__(self, parent):
super(DocumentToolsExtension, self).__init__(parent)
def setup(self):
action = krita.Krita.instance().createAction("document_tools", "Document Tools")
action.setToolTip("Plugin to manipulate properties of selected documents")
action.triggered.connect(self.initialize)
def initialize(self):
self.uidocumenttools = uidocumenttools.UIDocumentTools()
self.uidocumenttools.initialize()
Scripter.addExtension(DocumentToolsExtension(krita.Krita.instance()))
from PyQt5.QtWidgets import QDialog
class CanvasSizeDialog(QDialog):
class DocumentToolsDialog(QDialog):
def __init__(self, parent=None):
super(CanvasSizeDialog, self).__init__(parent)
super(DocumentToolsDialog, self).__init__(parent)
def closeEvent(self, event):
event.accept()
[Desktop Entry]
Type=Service
ServiceTypes=Krita/PythonPlugin
X-KDE-Library=documenttools
X-Python-2-Compatible=false
Name=Document Tools
Name[en_GB]=Document Tools
Name[pt]=Ferramentas de Documento
Comment=Plugin to manipulate properties of selected documents
Comment[en_GB]=Plugin to manipulate properties of selected documents
Comment[pt]='Plugin' para manipular propriedades de documentos selecionados
ToolClasses = ['canvassizetool.canvassizetool.CanvasSizeTool',]
from PyQt5.QtWidgets import (QWidget, QSpinBox, QHBoxLayout,
QVBoxLayout, QFormLayout)
class CanvasSizeTool(QWidget):
def __init__(self, mainDialog, parent=None):
super(CanvasSizeTool, self).__init__(parent)
self.setObjectName("Canvas Size")
self.layout = QFormLayout()
self.offsetLayout = QVBoxLayout()
self.widthSpinBox = QSpinBox()
self.heightSpinBox = QSpinBox()
self.xOffsetSpinBox = QSpinBox()
self.yOffsetSpinBox = QSpinBox()
self.setLayout(self.layout)
self.initialize()
def initialize(self):
self.widthSpinBox.setRange(1, 10000)
self.heightSpinBox.setRange(1, 10000)
self.xOffsetSpinBox.setRange(-10000, 10000)
self.yOffsetSpinBox.setRange(-10000, 10000)
self.offsetLayout.addWidget(self.xOffsetSpinBox)
self.offsetLayout.addWidget(self.yOffsetSpinBox)
self.layout.addRow('Width', self.widthSpinBox)
self.layout.addRow('Height', self.heightSpinBox)
self.layout.addRow('Offset', self.offsetLayout)
def adjust(self, documents):
for document in documents:
document.resizeImage(self.xOffsetSpinBox.value(),
self.yOffsetSpinBox.value(),
self.widthSpinBox.value(),
self.heightSpinBox.value())
from canvassize import canvassizedialog
from documenttools import documenttoolsdialog
from PyQt5.QtCore import Qt
from PyQt5.QtWidgets import (QFormLayout, QListWidget,QAbstractItemView,
QDialogButtonBox, QVBoxLayout, QFrame,
QPushButton, QAbstractScrollArea, QSpinBox,
QHBoxLayout, QMessageBox)
from PyQt5.QtWidgets import (QFormLayout, QListWidget, QAbstractItemView,
QDialogButtonBox, QVBoxLayout, QFrame, QTabWidget,
QPushButton, QAbstractScrollArea, QMessageBox)
import krita
import importlib
class UICanvasSize(object):
class UIDocumentTools(object):
def __init__(self):
self.mainDialog = canvassizedialog.CanvasSizeDialog()
self.mainDialog = documenttoolsdialog.DocumentToolsDialog()
self.mainLayout = QVBoxLayout(self.mainDialog)
self.formLayout = QFormLayout()
self.documentLayout = QVBoxLayout()
self.offsetLayout = QHBoxLayout()
self.refreshButton = QPushButton("Refresh")
self.widgetDocuments = QListWidget()
self.widthSpinBox = QSpinBox()
self.heightSpinBox = QSpinBox()
self.xOffsetSpinBox = QSpinBox()
self.yOffsetSpinBox = QSpinBox()
self.tabTools = QTabWidget()
self.buttonBox = QDialogButtonBox(QDialogButtonBox.Ok | QDialogButtonBox.Cancel)
self.kritaInstance = krita.Krita.instance()
......@@ -36,22 +32,13 @@ class UICanvasSize(object):
def initialize(self):
self.loadDocuments()
self.widthSpinBox.setRange(1, 10000)
self.heightSpinBox.setRange(1, 10000)
self.xOffsetSpinBox.setRange(-10000, 10000)
self.yOffsetSpinBox.setRange(-10000, 10000)
self.loadTools()
self.documentLayout.addWidget(self.widgetDocuments)
self.documentLayout.addWidget(self.refreshButton)
self.offsetLayout.addWidget(self.xOffsetSpinBox)
self.offsetLayout.addWidget(self.yOffsetSpinBox)
self.formLayout.addRow('Documents', self.documentLayout)
self.formLayout.addRow('Width', self.widthSpinBox)
self.formLayout.addRow('Height', self.heightSpinBox)
self.formLayout.addRow('Offset', self.offsetLayout)
self.formLayout.addRow(self.tabTools)
self.line = QFrame()
self.line.setFrameShape(QFrame.HLine)
......@@ -62,11 +49,27 @@ class UICanvasSize(object):
self.mainLayout.addWidget(self.buttonBox)
self.mainDialog.resize(500, 300)
self.mainDialog.setWindowTitle("Canvas Size")
self.mainDialog.setWindowTitle("Document Tools")
self.mainDialog.setSizeGripEnabled(True)
self.mainDialog.show()
self.mainDialog.activateWindow()
def loadTools(self):
modulePath = 'documenttools.tools'
toolsModule = importlib.import_module(modulePath)
modules = []
for classPath in toolsModule.ToolClasses:
_module, _klass = classPath.rsplit('.', maxsplit=1)
modules.append(dict(module='{0}.{1}'.format(modulePath, _module),
klass=_klass))
for module in modules:
m = importlib.import_module(module['module'])
toolClass = getattr(m, module['klass'])
obj = toolClass(self.mainDialog)
self.tabTools.addTab(obj, obj.objectName())
def loadDocuments(self):
self.widgetDocuments.clear()
......@@ -84,15 +87,7 @@ class UICanvasSize(object):
self.msgBox = QMessageBox(self.mainDialog)
if selectedDocuments:
self._resizeAllDocuments(selectedDocuments)
self.msgBox.setText("The selected documents has been resized.")
self.msgBox.setText("The selected documents has been modified.")
else:
self.msgBox.setText("Select at least one document.")
self.msgBox.exec_()
def _resizeAllDocuments(self, documents):
for document in documents:
document.resizeImage(self.xOffsetSpinBox.value(),
self.yOffsetSpinBox.value(),
self.widthSpinBox.value(),
self.heightSpinBox.value())
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment