diff --git a/plugins/python/example_scripts/resize_to_all_layers.py b/plugins/python/example_scripts/resize_to_all_layers.py --- a/plugins/python/example_scripts/resize_to_all_layers.py +++ b/plugins/python/example_scripts/resize_to_all_layers.py @@ -1,20 +1,26 @@ -''' -This script is licensed CC 0 1.0, so that you can learn from it. +# This script is licensed CC 0 1.0, so that you can learn from it. ------- CC 0 1.0 --------------- +# ------ CC 0 1.0 --------------- -The person who associated a work with this deed has dedicated the work to the public domain by waiving all of his or her rights to the work worldwide under copyright law, including all related and neighboring rights, to the extent allowed by law. +# The person who associated a work with this deed has dedicated the +# work to the public domain by waiving all of his or her rights to the +# work worldwide under copyright law, including all related and +# neighboring rights, to the extent allowed by law. -You can copy, modify, distribute and perform the work, even for commercial purposes, all without asking permission. +# You can copy, modify, distribute and perform the work, even for +# commercial purposes, all without asking permission. + +# https://creativecommons.org/publicdomain/zero/1.0/legalcode + +""" +This script will iterate over all toplevel nodes, create +keeping track of the layer boundaries and then resize +the image to the unity of all boundaries. +""" + +from krita import Krita +from PyQt5.QtCore import QRect -https://creativecommons.org/publicdomain/zero/1.0/legalcode -''' -# -# This script will iterate over all toplevel nodes, create -# keeping track of the layer boundaries and then resize -# the image to the unity of all boundaries. -# -from krita import * d = Krita.instance().activeDocument() w = d.width() h = d.height() @@ -25,10 +31,10 @@ r = QRect(x, y, w, h) print(r) for n in d.topLevelNodes(): - print (n, n.bounds()) + print(n, n.bounds()) b = n.bounds() r = r.united(b) - -print (r) + +print(r) d.resizeImage(r.x(), r.y(), r.width(), r.height()) diff --git a/plugins/python/exportlayers/__init__.py b/plugins/python/exportlayers/__init__.py --- a/plugins/python/exportlayers/__init__.py +++ b/plugins/python/exportlayers/__init__.py @@ -1,2 +1,5 @@ -# let's make a module -from .exportlayers import * +import krita +from .exportlayers import ExportLayersExtension + + +Scripter.addExtension(ExportLayersExtension(krita.Krita.instance())) diff --git a/plugins/python/exportlayers/exportlayers.py b/plugins/python/exportlayers/exportlayers.py --- a/plugins/python/exportlayers/exportlayers.py +++ b/plugins/python/exportlayers/exportlayers.py @@ -1,14 +1,17 @@ -''' -This script is licensed CC 0 1.0, so that you can learn from it. +# This script is licensed CC 0 1.0, so that you can learn from it. ------- CC 0 1.0 --------------- +# ------ CC 0 1.0 --------------- -The person who associated a work with this deed has dedicated the work to the public domain by waiving all of his or her rights to the work worldwide under copyright law, including all related and neighboring rights, to the extent allowed by law. +# The person who associated a work with this deed has dedicated the +# work to the public domain by waiving all of his or her rights to the +# work worldwide under copyright law, including all related and +# neighboring rights, to the extent allowed by law. -You can copy, modify, distribute and perform the work, even for commercial purposes, all without asking permission. +# You can copy, modify, distribute and perform the work, even for +# commercial purposes, all without asking permission. + +# https://creativecommons.org/publicdomain/zero/1.0/legalcode -https://creativecommons.org/publicdomain/zero/1.0/legalcode -''' import krita from . import uiexportlayers @@ -29,6 +32,3 @@ def initialize(self): self.uiexportlayers = uiexportlayers.UIExportLayers() self.uiexportlayers.initialize() - - -Scripter.addExtension(ExportLayersExtension(krita.Krita.instance())) diff --git a/plugins/python/exportlayers/exportlayersdialog.py b/plugins/python/exportlayers/exportlayersdialog.py --- a/plugins/python/exportlayers/exportlayersdialog.py +++ b/plugins/python/exportlayers/exportlayersdialog.py @@ -1,14 +1,17 @@ -''' -This script is licensed CC 0 1.0, so that you can learn from it. +# This script is licensed CC 0 1.0, so that you can learn from it. ------- CC 0 1.0 --------------- +# ------ CC 0 1.0 --------------- -The person who associated a work with this deed has dedicated the work to the public domain by waiving all of his or her rights to the work worldwide under copyright law, including all related and neighboring rights, to the extent allowed by law. +# The person who associated a work with this deed has dedicated the +# work to the public domain by waiving all of his or her rights to the +# work worldwide under copyright law, including all related and +# neighboring rights, to the extent allowed by law. -You can copy, modify, distribute and perform the work, even for commercial purposes, all without asking permission. +# You can copy, modify, distribute and perform the work, even for +# commercial purposes, all without asking permission. + +# https://creativecommons.org/publicdomain/zero/1.0/legalcode -https://creativecommons.org/publicdomain/zero/1.0/legalcode -''' from PyQt5.QtWidgets import QDialog diff --git a/plugins/python/exportlayers/uiexportlayers.py b/plugins/python/exportlayers/uiexportlayers.py --- a/plugins/python/exportlayers/uiexportlayers.py +++ b/plugins/python/exportlayers/uiexportlayers.py @@ -1,23 +1,25 @@ -''' -This script is licensed CC 0 1.0, so that you can learn from it. +# This script is licensed CC 0 1.0, so that you can learn from it. ------- CC 0 1.0 --------------- +# ------ CC 0 1.0 --------------- -The person who associated a work with this deed has dedicated the work to the public domain by waiving all of his or her rights to the work worldwide under copyright law, including all related and neighboring rights, to the extent allowed by law. +# The person who associated a work with this deed has dedicated the +# work to the public domain by waiving all of his or her rights to the +# work worldwide under copyright law, including all related and +# neighboring rights, to the extent allowed by law. -You can copy, modify, distribute and perform the work, even for commercial purposes, all without asking permission. +# You can copy, modify, distribute and perform the work, even for +# commercial purposes, all without asking permission. + +# https://creativecommons.org/publicdomain/zero/1.0/legalcode -https://creativecommons.org/publicdomain/zero/1.0/legalcode -''' from . import exportlayersdialog from PyQt5.QtCore import Qt from PyQt5.QtWidgets import (QFormLayout, QListWidget, QHBoxLayout, QDialogButtonBox, QVBoxLayout, QFrame, QPushButton, QAbstractScrollArea, QLineEdit, QMessageBox, QFileDialog, QCheckBox, QSpinBox, QComboBox) import os -import errno import krita @@ -36,14 +38,17 @@ self.widgetDocuments = QListWidget() self.directoryTextField = QLineEdit() self.directoryDialogButton = QPushButton(i18n("...")) - self.exportFilterLayersCheckBox = QCheckBox(i18n("Export filter layers")) + self.exportFilterLayersCheckBox = QCheckBox( + i18n("Export filter layers")) self.batchmodeCheckBox = QCheckBox(i18n("Export in batchmode")) - self.ignoreInvisibleLayersCheckBox = QCheckBox(i18n("Ignore invisible layers")) + self.ignoreInvisibleLayersCheckBox = QCheckBox( + i18n("Ignore invisible layers")) self.xResSpinBox = QSpinBox() self.yResSpinBox = QSpinBox() self.formatsComboBox = QComboBox() - self.buttonBox = QDialogButtonBox(QDialogButtonBox.Ok | QDialogButtonBox.Cancel) + self.buttonBox = QDialogButtonBox( + QDialogButtonBox.Ok | QDialogButtonBox.Cancel) self.kritaInstance = krita.Krita.instance() self.documentsList = [] @@ -57,7 +62,8 @@ self.buttonBox.rejected.connect(self.mainDialog.close) self.mainDialog.setWindowModality(Qt.NonModal) - self.widgetDocuments.setSizeAdjustPolicy(QAbstractScrollArea.AdjustToContents) + self.widgetDocuments.setSizeAdjustPolicy( + QAbstractScrollArea.AdjustToContents) def initialize(self): self.loadDocuments() @@ -82,10 +88,12 @@ self.resolutionLayout.addWidget(self.yResSpinBox) self.formLayout.addRow(i18n("Documents:"), self.documentLayout) - self.formLayout.addRow(i18n("Initial directory:"), self.directorySelectorLayout) + self.formLayout.addRow( + i18n("Initial directory:"), self.directorySelectorLayout) self.formLayout.addRow(i18n("Export options:"), self.optionsLayout) self.formLayout.addRow(i18n("Resolution:"), self.resolutionLayout) - self.formLayout.addRow(i18n("Images extensions:"), self.formatsComboBox) + self.formLayout.addRow( + i18n("Images extensions:"), self.formatsComboBox) self.line = QFrame() self.line.setFrameShape(QFrame.HLine) @@ -104,17 +112,24 @@ def loadDocuments(self): self.widgetDocuments.clear() - self.documentsList = [document for document in self.kritaInstance.documents() if document.fileName()] + self.documentsList = [ + document for document in self.kritaInstance.documents() + if document.fileName() + ] for document in self.documentsList: self.widgetDocuments.addItem(document.fileName()) def refreshButtonClicked(self): self.loadDocuments() def confirmButton(self): - selectedPaths = [item.text() for item in self.widgetDocuments.selectedItems()] - selectedDocuments = [document for document in self.documentsList for path in selectedPaths if path == document.fileName()] + selectedPaths = [ + item.text() for item in self.widgetDocuments.selectedItems()] + selectedDocuments = [ + document for document in self.documentsList + for path in selectedPaths if path == document.fileName() + ] self.msgBox = QMessageBox(self.mainDialog) if not selectedDocuments: @@ -128,7 +143,8 @@ def mkdir(self, directory): target_directory = self.directoryTextField.text() + directory - if os.path.exists(target_directory) and os.path.isdir(target_directory): + if (os.path.exists(target_directory) + and os.path.isdir(target_directory)): return try: @@ -139,11 +155,14 @@ def export(self, document): Application.setBatchmode(self.batchmodeCheckBox.isChecked()) - documentName = document.fileName() if document.fileName() else 'Untitled' + documentName = document.fileName() if document.fileName() else 'Untitled' # noqa: E501 fileName, extension = os.path.splitext(os.path.basename(documentName)) self.mkdir('/' + fileName) - self._exportLayers(document.rootNode(), self.formatsComboBox.currentText(), '/' + fileName) + self._exportLayers( + document.rootNode(), + self.formatsComboBox.currentText(), + '/' + fileName) Application.setBatchmode(True) def _exportLayers(self, parentNode, fileFormat, parentDir): @@ -155,9 +174,11 @@ if node.type() == 'grouplayer': newDir = os.path.join(parentDir, node.name()) self.mkdir(newDir) - elif not self.exportFilterLayersCheckBox.isChecked() and 'filter' in node.type(): + elif (not self.exportFilterLayersCheckBox.isChecked() + and 'filter' in node.type()): continue - elif self.ignoreInvisibleLayersCheckBox.isChecked() and not node.visible(): + elif (self.ignoreInvisibleLayersCheckBox.isChecked() + and not node.visible()): continue else: nodeName = node.name() @@ -167,16 +188,21 @@ elif '[png]' in nodeName: _fileFormat = 'png' - layerFileName = '{0}{1}/{2}.{3}'.format(self.directoryTextField.text(), - parentDir, node.name(), _fileFormat) + layerFileName = '{0}{1}/{2}.{3}'.format( + self.directoryTextField.text(), + parentDir, node.name(), _fileFormat) node.save(layerFileName, self.xResSpinBox.value(), self.yResSpinBox.value(), krita.InfoObject()) if node.childNodes(): self._exportLayers(node, fileFormat, newDir) def _selectDir(self): - directory = QFileDialog.getExistingDirectory(self.mainDialog, i18n("Select a Folder"), os.path.expanduser("~"), QFileDialog.ShowDirsOnly) + directory = QFileDialog.getExistingDirectory( + self.mainDialog, + i18n("Select a Folder"), + os.path.expanduser("~"), + QFileDialog.ShowDirsOnly) self.directoryTextField.setText(directory) def _setResolution(self, index): diff --git a/plugins/python/filtermanager/__init__.py b/plugins/python/filtermanager/__init__.py --- a/plugins/python/filtermanager/__init__.py +++ b/plugins/python/filtermanager/__init__.py @@ -1,2 +1,5 @@ -# let's make a module -from .filtermanager import * +import krita +from .filtermanager import FilterManagerExtension + + +Scripter.addExtension(FilterManagerExtension(krita.Krita.instance())) diff --git a/plugins/python/filtermanager/components/filtercombobox.py b/plugins/python/filtermanager/components/filtercombobox.py --- a/plugins/python/filtermanager/components/filtercombobox.py +++ b/plugins/python/filtermanager/components/filtercombobox.py @@ -1,16 +1,18 @@ -''' -This script is licensed CC 0 1.0, so that you can learn from it. +# This script is licensed CC 0 1.0, so that you can learn from it. ------- CC 0 1.0 --------------- +# ------ CC 0 1.0 --------------- -The person who associated a work with this deed has dedicated the work to the public domain by waiving all of his or her rights to the work worldwide under copyright law, including all related and neighboring rights, to the extent allowed by law. +# The person who associated a work with this deed has dedicated the +# work to the public domain by waiving all of his or her rights to the +# work worldwide under copyright law, including all related and +# neighboring rights, to the extent allowed by law. -You can copy, modify, distribute and perform the work, even for commercial purposes, all without asking permission. +# You can copy, modify, distribute and perform the work, even for +# commercial purposes, all without asking permission. + +# https://creativecommons.org/publicdomain/zero/1.0/legalcode -https://creativecommons.org/publicdomain/zero/1.0/legalcode -''' from PyQt5.QtWidgets import QComboBox -import krita class FilterComboBox(QComboBox): diff --git a/plugins/python/filtermanager/components/filtermanagertreeitem.py b/plugins/python/filtermanager/components/filtermanagertreeitem.py --- a/plugins/python/filtermanager/components/filtermanagertreeitem.py +++ b/plugins/python/filtermanager/components/filtermanagertreeitem.py @@ -1,14 +1,18 @@ -''' -This script is licensed CC 0 1.0, so that you can learn from it. +# This script is licensed CC 0 1.0, so that you can learn from it. ------- CC 0 1.0 --------------- +# ------ CC 0 1.0 --------------- -The person who associated a work with this deed has dedicated the work to the public domain by waiving all of his or her rights to the work worldwide under copyright law, including all related and neighboring rights, to the extent allowed by law. +# The person who associated a work with this deed has dedicated the +# work to the public domain by waiving all of his or her rights to the +# work worldwide under copyright law, including all related and +# neighboring rights, to the extent allowed by law. + +# You can copy, modify, distribute and perform the work, even for +# commercial purposes, all without asking permission. + +# https://creativecommons.org/publicdomain/zero/1.0/legalcode -You can copy, modify, distribute and perform the work, even for commercial purposes, all without asking permission. -https://creativecommons.org/publicdomain/zero/1.0/legalcode -''' class FilterManagerTreeItem(object): def __init__(self, data, parent=None): diff --git a/plugins/python/filtermanager/components/filtermanagertreemodel.py b/plugins/python/filtermanager/components/filtermanagertreemodel.py --- a/plugins/python/filtermanager/components/filtermanagertreemodel.py +++ b/plugins/python/filtermanager/components/filtermanagertreemodel.py @@ -1,18 +1,20 @@ -''' -This script is licensed CC 0 1.0, so that you can learn from it. +# This script is licensed CC 0 1.0, so that you can learn from it. ------- CC 0 1.0 --------------- +# ------ CC 0 1.0 --------------- -The person who associated a work with this deed has dedicated the work to the public domain by waiving all of his or her rights to the work worldwide under copyright law, including all related and neighboring rights, to the extent allowed by law. +# The person who associated a work with this deed has dedicated the +# work to the public domain by waiving all of his or her rights to the +# work worldwide under copyright law, including all related and +# neighboring rights, to the extent allowed by law. -You can copy, modify, distribute and perform the work, even for commercial purposes, all without asking permission. +# You can copy, modify, distribute and perform the work, even for +# commercial purposes, all without asking permission. -https://creativecommons.org/publicdomain/zero/1.0/legalcode -''' -from PyQt5.QtCore import QAbstractItemModel, QFile, QIODevice, QModelIndex, Qt -from PyQt5.QtWidgets import QApplication, QTreeView -from . import filtermanagertreeitem +# https://creativecommons.org/publicdomain/zero/1.0/legalcode + +from PyQt5.QtCore import QAbstractItemModel, QModelIndex, Qt from PyQt5.QtGui import QPixmap +from . import filtermanagertreeitem class FilterManagerTreeModel(QAbstractItemModel): @@ -24,7 +26,8 @@ def __init__(self, uiFilterManager, parent=None): super(FilterManagerTreeModel, self).__init__(parent) - self.rootItem = filtermanagertreeitem.FilterManagerTreeItem(("Name", "Type", "Thumbnail")) + self.rootItem = filtermanagertreeitem.FilterManagerTreeItem( + ("Name", "Type", "Thumbnail")) self.uiFilterManager = uiFilterManager self._loadTreeModel(self.rootItem) @@ -111,7 +114,8 @@ "Document", QPixmap.fromImage(document.thumbnail(30, 30)), rootNode, index) - item = filtermanagertreeitem.FilterManagerTreeItem(columnData, parent) + item = filtermanagertreeitem.FilterManagerTreeItem( + columnData, parent) parent.appendChild(item) childNodes = rootNode.childNodes() @@ -126,7 +130,8 @@ "Untyped" if nodeType == '' else nodeType, QPixmap.fromImage(node.thumbnail(30, 30)), node, documentIndex) - item = filtermanagertreeitem.FilterManagerTreeItem(columnData, parent) + item = filtermanagertreeitem.FilterManagerTreeItem( + columnData, parent) parent.appendChild(item) childNodes = node.childNodes() diff --git a/plugins/python/filtermanager/filtermanager.py b/plugins/python/filtermanager/filtermanager.py --- a/plugins/python/filtermanager/filtermanager.py +++ b/plugins/python/filtermanager/filtermanager.py @@ -1,14 +1,17 @@ -''' -This script is licensed CC 0 1.0, so that you can learn from it. +# This script is licensed CC 0 1.0, so that you can learn from it. ------- CC 0 1.0 --------------- +# ------ CC 0 1.0 --------------- -The person who associated a work with this deed has dedicated the work to the public domain by waiving all of his or her rights to the work worldwide under copyright law, including all related and neighboring rights, to the extent allowed by law. +# The person who associated a work with this deed has dedicated the +# work to the public domain by waiving all of his or her rights to the +# work worldwide under copyright law, including all related and +# neighboring rights, to the extent allowed by law. -You can copy, modify, distribute and perform the work, even for commercial purposes, all without asking permission. +# You can copy, modify, distribute and perform the work, even for +# commercial purposes, all without asking permission. + +# https://creativecommons.org/publicdomain/zero/1.0/legalcode -https://creativecommons.org/publicdomain/zero/1.0/legalcode -''' import krita from . import uifiltermanager @@ -29,6 +32,3 @@ def initialize(self): self.uifiltermanager = uifiltermanager.UIFilterManager() self.uifiltermanager.initialize() - - -Scripter.addExtension(FilterManagerExtension(krita.Krita.instance())) diff --git a/plugins/python/filtermanager/filtermanagerdialog.py b/plugins/python/filtermanager/filtermanagerdialog.py --- a/plugins/python/filtermanager/filtermanagerdialog.py +++ b/plugins/python/filtermanager/filtermanagerdialog.py @@ -1,14 +1,17 @@ -''' -This script is licensed CC 0 1.0, so that you can learn from it. +# This script is licensed CC 0 1.0, so that you can learn from it. ------- CC 0 1.0 --------------- +# ------ CC 0 1.0 --------------- -The person who associated a work with this deed has dedicated the work to the public domain by waiving all of his or her rights to the work worldwide under copyright law, including all related and neighboring rights, to the extent allowed by law. +# The person who associated a work with this deed has dedicated the +# work to the public domain by waiving all of his or her rights to the +# work worldwide under copyright law, including all related and +# neighboring rights, to the extent allowed by law. -You can copy, modify, distribute and perform the work, even for commercial purposes, all without asking permission. +# You can copy, modify, distribute and perform the work, even for +# commercial purposes, all without asking permission. + +# https://creativecommons.org/publicdomain/zero/1.0/legalcode -https://creativecommons.org/publicdomain/zero/1.0/legalcode -''' from PyQt5.QtWidgets import QDialog diff --git a/plugins/python/filtermanager/uifiltermanager.py b/plugins/python/filtermanager/uifiltermanager.py --- a/plugins/python/filtermanager/uifiltermanager.py +++ b/plugins/python/filtermanager/uifiltermanager.py @@ -1,20 +1,22 @@ -''' -This script is licensed CC 0 1.0, so that you can learn from it. +# This script is licensed CC 0 1.0, so that you can learn from it. ------- CC 0 1.0 --------------- +# ------ CC 0 1.0 --------------- -The person who associated a work with this deed has dedicated the work to the public domain by waiving all of his or her rights to the work worldwide under copyright law, including all related and neighboring rights, to the extent allowed by law. +# The person who associated a work with this deed has dedicated the +# work to the public domain by waiving all of his or her rights to the +# work worldwide under copyright law, including all related and +# neighboring rights, to the extent allowed by law. -You can copy, modify, distribute and perform the work, even for commercial purposes, all without asking permission. +# You can copy, modify, distribute and perform the work, even for +# commercial purposes, all without asking permission. + +# https://creativecommons.org/publicdomain/zero/1.0/legalcode -https://creativecommons.org/publicdomain/zero/1.0/legalcode -''' from . import filtermanagerdialog from .components import (filtercombobox, filtermanagertreemodel) from PyQt5.QtCore import Qt from PyQt5.QtWidgets import (QFormLayout, QAbstractItemView, QDialogButtonBox, - QVBoxLayout, QFrame, QAbstractScrollArea, QWidget, - QTreeView) + QVBoxLayout, QFrame, QTreeView) import krita @@ -24,7 +26,8 @@ self.mainDialog = filtermanagerdialog.FilterManagerDialog() self.mainLayout = QVBoxLayout(self.mainDialog) self.formLayout = QFormLayout() - self.buttonBox = QDialogButtonBox(QDialogButtonBox.Ok | QDialogButtonBox.Cancel) + self.buttonBox = QDialogButtonBox( + QDialogButtonBox.Ok | QDialogButtonBox.Cancel) self.kritaInstance = krita.Krita.instance() self._filters = sorted(self.kritaInstance.filters()) @@ -37,7 +40,8 @@ self.buttonBox.accepted.connect(self.confirmButton) self.buttonBox.rejected.connect(self.mainDialog.close) - self.documentsTreeView.setSelectionMode(QAbstractItemView.SingleSelection) + self.documentsTreeView.setSelectionMode( + QAbstractItemView.SingleSelection) self.mainDialog.setWindowModality(Qt.NonModal) def initialize(self): @@ -92,8 +96,9 @@ _filter.apply(node, 0, 0, document.width(), document.height()) def applyFilterOverDocument(self, document): - """ This method applies the selected filter just to topLevelNodes, then - if topLevelNodes are GroupLayers, that filter will not be applied. """ + """This method applies the selected filter just to topLevelNodes, + then if topLevelNodes are GroupLayers, that filter will not be + applied.""" for node in document.topLevelNodes(): self.applyFilterOverNode(node, document) diff --git a/plugins/python/hello/__init__.py b/plugins/python/hello/__init__.py --- a/plugins/python/hello/__init__.py +++ b/plugins/python/hello/__init__.py @@ -1,2 +1,11 @@ -# let's make a module -from .hello import * +from krita import Krita, DockWidgetFactory, DockWidgetFactoryBase +from .hello import HelloExtension, HelloDocker + + +# Initialize and add the extension +Scripter.addExtension(HelloExtension(Krita.instance())) + + +# Register the docker so Krita can use it! +Application.addDockWidgetFactory( + DockWidgetFactory("hello", DockWidgetFactoryBase.DockRight, HelloDocker)) diff --git a/plugins/python/hello/hello.py b/plugins/python/hello/hello.py --- a/plugins/python/hello/hello.py +++ b/plugins/python/hello/hello.py @@ -1,34 +1,41 @@ -''' -This script is licensed CC 0 1.0, so that you can learn from it. +# This script is licensed CC 0 1.0, so that you can learn from it. ------- CC 0 1.0 --------------- +# ------ CC 0 1.0 --------------- -The person who associated a work with this deed has dedicated the work to the public domain by waiving all of his or her rights to the work worldwide under copyright law, including all related and neighboring rights, to the extent allowed by law. +# The person who associated a work with this deed has dedicated the +# work to the public domain by waiving all of his or her rights to the +# work worldwide under copyright law, including all related and +# neighboring rights, to the extent allowed by law. -You can copy, modify, distribute and perform the work, even for commercial purposes, all without asking permission. +# You can copy, modify, distribute and perform the work, even for +# commercial purposes, all without asking permission. + +# https://creativecommons.org/publicdomain/zero/1.0/legalcode + +""" +This is a simple example of a Python script for Krita. +It demonstrates how to set up a custom extension and a custom docker! +""" -https://creativecommons.org/publicdomain/zero/1.0/legalcode -''' -# -# This is a simple example of a Python script for Krita. -# It demonstrates how to set up a custom extension and a custom docker! -# from PyQt5.QtWidgets import QWidget, QLabel, QMessageBox -from krita import (Krita, Extension, DockWidget, - DockWidgetFactory, DockWidgetFactoryBase) +from krita import Extension, DockWidget def hello(): """ Show a test message box. """ - QMessageBox.information(QWidget(), i18n("Test"), i18n("Hello! This is Krita version %s") % Application.version()) + QMessageBox.information( + QWidget(), + i18n("Test"), + i18n("Hello! This is Krita version %s") % Application.version()) class HelloExtension(Extension): """ - HelloExtension is a small example extension demonstrating basic Python scripting support in Krita! + HelloExtension is a small example extension demonstrating basic + Python scripting support in Krita! """ def __init__(self, parent): @@ -52,10 +59,6 @@ action.triggered.connect(hello) -# Initialize and add the extension -Scripter.addExtension(HelloExtension(Krita.instance())) - - class HelloDocker(DockWidget): """ The HelloDocker is an example of a simple Python-based docker. @@ -82,7 +85,3 @@ Parameter `canvas` can be null if the last document is closed """ self._label.setText("HelloDocker: canvas changed") - - -# Register the docker so Krita can use it! -Application.addDockWidgetFactory(DockWidgetFactory("hello", DockWidgetFactoryBase.DockRight, HelloDocker))