diff --git a/plugins/python/lastdocumentsdocker/__init__.py b/plugins/python/lastdocumentsdocker/__init__.py --- a/plugins/python/lastdocumentsdocker/__init__.py +++ b/plugins/python/lastdocumentsdocker/__init__.py @@ -1,2 +1,8 @@ -# let's make a module -from .lastdocumentsdocker import * +import krita +from .lastdocumentsdocker import LastDocumentsDocker + + +Application.addDockWidgetFactory( + krita.DockWidgetFactory("lastdocumentsdocker", + krita.DockWidgetFactoryBase.DockRight, + LastDocumentsDocker)) diff --git a/plugins/python/lastdocumentsdocker/lastdocumentsdocker.py b/plugins/python/lastdocumentsdocker/lastdocumentsdocker.py --- a/plugins/python/lastdocumentsdocker/lastdocumentsdocker.py +++ b/plugins/python/lastdocumentsdocker/lastdocumentsdocker.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 QWidget, QVBoxLayout, QListView, QPushButton import krita from . import lastdocumentslistmodel @@ -42,6 +45,3 @@ def refreshRecentDocuments(self): self.listModel.loadRecentDocuments() - - -Application.addDockWidgetFactory(krita.DockWidgetFactory("lastdocumentsdocker", krita.DockWidgetFactoryBase.DockRight, LastDocumentsDocker)) diff --git a/plugins/python/lastdocumentsdocker/lastdocumentslistmodel.py b/plugins/python/lastdocumentsdocker/lastdocumentslistmodel.py --- a/plugins/python/lastdocumentsdocker/lastdocumentslistmodel.py +++ b/plugins/python/lastdocumentsdocker/lastdocumentslistmodel.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.QtCore import QAbstractListModel, Qt from PyQt5.QtGui import QImage import krita diff --git a/plugins/python/quick_settings_docker/__init__.py b/plugins/python/quick_settings_docker/__init__.py --- a/plugins/python/quick_settings_docker/__init__.py +++ b/plugins/python/quick_settings_docker/__init__.py @@ -1,2 +1,8 @@ -# let's make a module -from .quick_settings_docker import * +from krita import DockWidgetFactory, DockWidgetFactoryBase +from .quick_settings_docker import QuickSettingsDocker + + +Application.addDockWidgetFactory( + DockWidgetFactory("quick_settings_docker", + DockWidgetFactoryBase.DockRight, + QuickSettingsDocker)) diff --git a/plugins/python/quick_settings_docker/quick_settings_docker.py b/plugins/python/quick_settings_docker/quick_settings_docker.py --- a/plugins/python/quick_settings_docker/quick_settings_docker.py +++ b/plugins/python/quick_settings_docker/quick_settings_docker.py @@ -1,27 +1,32 @@ -''' -Description: A Python based docker for quickly choosing the brushsize like similar dockers in other drawing programs. +# By Wolthera(originally) -By Wolthera(originally) +# 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 +'''A Python based docker for quickly choosing the brushsize like +similar dockers in other drawing programs. @package quick_settings_docker + ''' # Importing the relevant dependencies: -import sys from PyQt5.QtCore import pyqtSlot, Qt, QPointF -from PyQt5.QtGui import QStandardItem, QStandardItemModel, QPainter, QPalette, QPixmap, QImage, QBrush, QPen, QIcon +from PyQt5.QtGui import (QStandardItem, QStandardItemModel, QPainter, QPalette, + QPixmap, QImage, QBrush, QPen, QIcon) from PyQt5.QtWidgets import QWidget, QTabWidget, QListView, QVBoxLayout -from krita import * +from krita import DockWidget class QuickSettingsDocker(DockWidget): @@ -65,30 +70,43 @@ # amount of columns in each row for all the tables. - # We want a grid with possible options to select. - # To do this, we'll make a ListView widget and use a standarditemmodel for the entries. - # The entries are filled out based on the sizes and opacity lists. - - # Sizes and opacity lists. The former is half-way copied from ptsai, the latter is based on personal experience of useful opacities. - self.sizesList = [0.7, 1.0, 1.5, 2, 2.5, 3, 3.5, 4, 5, 6, 7, 8, 9, 10, 12, 14, 16, 20, 25, 30, 35, 40, 50, 60, 70, 80, 100, 120, 160, 200, 250, 300, 350, 400, 450, 500] - self.opacityList = [0.1, 0.5, 1, 5, 10, 15, 20, 30, 40, 50, 60, 70, 80, 90, 100] + # We want a grid with possible options to select. To do this, + # we'll make a ListView widget and use a standarditemmodel for + # the entries. The entries are filled out based on the sizes + # and opacity lists. + + # Sizes and opacity lists. The former is half-way copied from + # ptsai, the latter is based on personal experience of useful + # opacities. + self.sizesList = [ + 0.7, 1.0, 1.5, 2, 2.5, 3, 3.5, 4, 5, 6, 7, 8, 9, 10, 12, 14, 16, + 20, 25, 30, 35, 40, 50, 60, 70, 80, 100, 120, 160, 200, 250, 300, + 350, 400, 450, 500] + self.opacityList = [ + 0.1, 0.5, 1, 5, 10, 15, 20, 30, 40, 50, 60, 70, 80, 90, 100] self.brushSizeModel = QStandardItemModel() self.brushOpacityModel = QStandardItemModel() self.brushFlowModel = QStandardItemModel() self.fillSizesModel() self.fillOpacityModel() - # Now we're done filling out our tables, we connect the views to the functions that'll change the settings. + # Now we're done filling out our tables, we connect the views + # to the functions that'll change the settings. self.brushSizeTableView.clicked.connect(self.setBrushSize) self.brushOpacityTableView.clicked.connect(self.setBrushOpacity) self.brushFlowTableView.clicked.connect(self.setBrushFlow) def fillSizesModel(self): - # First we empty the old model. We might wanna use this function in the future to fill it with the brushmask of the selected brush, but there's currently no API for recognising changes in the current brush nor is there a way to get its brushmask. + # First we empty the old model. We might wanna use this + # function in the future to fill it with the brushmask of the + # selected brush, but there's currently no API for recognising + # changes in the current brush nor is there a way to get its + # brushmask. self.brushSizeModel.clear() for s in range(len(self.sizesList)): - # we're gonna iterate over our list, and make a new item for each entry. - # We need to disable a bunch of stuff to make sure people won't do funny things to our entries. + # we're gonna iterate over our list, and make a new item + # for each entry. We need to disable a bunch of stuff to + # make sure people won't do funny things to our entries. item = QStandardItem() item.setCheckable(False) item.setEditable(False) @@ -101,7 +119,8 @@ img.fill(Qt.transparent) circlePainter.begin(img) brush = QBrush(Qt.SolidPattern) - brush.setColor(self.brushSizeTableView.palette().color(QPalette.Text)) + brush.setColor( + self.brushSizeTableView.palette().color(QPalette.Text)) circlePainter.setBrush(brush) circlePainter.setPen(QPen(QBrush(Qt.transparent), 0)) brushSize = max(min(self.sizesList[s], 64), 1) @@ -118,7 +137,8 @@ self.brushOpacityModel.clear() self.brushFlowModel.clear() for s in range(len(self.opacityList)): - # we're gonna iterate over our list, and make a new item for each entry. + # we're gonna iterate over our list, and make a new item + # for each entry. item = QStandardItem() item.setCheckable(False) item.setEditable(False) @@ -130,15 +150,17 @@ img.fill(Qt.transparent) circlePainter.begin(img) brush = QBrush(Qt.SolidPattern) - brush.setColor(self.brushSizeTableView.palette().color(QPalette.Text)) + brush.setColor( + self.brushSizeTableView.palette().color(QPalette.Text)) circlePainter.setBrush(brush) circlePainter.setPen(QPen(QBrush(Qt.transparent), 0)) circlePainter.setOpacity(float(self.opacityList[s]) / 100.0) circlePainter.drawEllipse(QPointF(32, 32), 32, 32) circlePainter.end() brushImage = QPixmap.fromImage(img) item.setIcon(QIcon(brushImage)) - # the flow and opacity models will use virtually the same items, but Qt would like us to make sure we understand + # the flow and opacity models will use virtually the same + # items, but Qt would like us to make sure we understand # these are not really the same items, so hence the clone. itemFlow = item.clone() self.brushOpacityModel.appendRow(item) @@ -153,23 +175,22 @@ def setBrushSize(self, index): i = index.row() brushSize = self.sizesList[i] - if Application.activeWindow() and len(Application.activeWindow().views()) > 0: - Application.activeWindow().views()[0].setBrushSize(brushSize) + window = Application.activeWindow() + if window and window.views(): + window.views()[0].setBrushSize(brushSize) @pyqtSlot('QModelIndex') def setBrushOpacity(self, index): i = index.row() brushOpacity = float(self.opacityList[i]) / 100.0 - if Application.activeWindow() and len(Application.activeWindow().views()) > 0: - Application.activeWindow().views()[0].setPaintingOpacity(brushOpacity) + window = Application.activeWindow() + if window and window.views(): + window.views()[0].setPaintingOpacity(brushOpacity) @pyqtSlot('QModelIndex') def setBrushFlow(self, index): i = index.row() brushOpacity = float(self.opacityList[i]) / 100.0 - if Application.activeWindow() and len(Application.activeWindow().views()) > 0: - Application.activeWindow().views()[0].setPaintingFlow(brushOpacity) - - -# Add docker to the application :) -Application.addDockWidgetFactory(DockWidgetFactory("quick_settings_docker", DockWidgetFactoryBase.DockRight, QuickSettingsDocker)) + window = Application.activeWindow() + if window and window.views(): + window.views()[0].setPaintingFlow(brushOpacity) diff --git a/plugins/python/selectionsbagdocker/__init__.py b/plugins/python/selectionsbagdocker/__init__.py --- a/plugins/python/selectionsbagdocker/__init__.py +++ b/plugins/python/selectionsbagdocker/__init__.py @@ -1,4 +1,7 @@ -from krita import * -from .selectionsbagdocker import * +from krita import Krita, DockWidgetFactory +from .selectionsbagdocker import SelectionsBagDocker -Krita.instance().addDockWidgetFactory(DockWidgetFactory("SelectionsBagDocker", DockWidgetFactory.DockRight, SelectionsBagDocker)) +Krita.instance().addDockWidgetFactory( + DockWidgetFactory("SelectionsBagDocker", + DockWidgetFactory.DockRight, + SelectionsBagDocker)) diff --git a/plugins/python/selectionsbagdocker/selectionsbagdocker.py b/plugins/python/selectionsbagdocker/selectionsbagdocker.py --- a/plugins/python/selectionsbagdocker/selectionsbagdocker.py +++ b/plugins/python/selectionsbagdocker/selectionsbagdocker.py @@ -1,29 +1,33 @@ -''' -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 * -from PyQt5.QtGui import * -from PyQt5.QtWidgets import * +# https://creativecommons.org/publicdomain/zero/1.0/legalcode + +from PyQt5.QtWidgets import QWidget from PyQt5 import uic -from krita import * +from krita import DockWidget import os class SelectionsBagDocker(DockWidget): def __init__(self): super().__init__() widget = QWidget(self) - uic.loadUi(os.path.dirname(os.path.realpath(__file__)) + '/selectionsbagdocker.ui', widget) + ui_filename = os.path.join( + os.path.dirname(os.path.realpath(__file__)), + 'selectionsbagdocker.ui') + uic.loadUi(ui_filename, widget) self.setWidget(widget) self.setWindowTitle(i18n("Selections Bag")) diff --git a/plugins/python/tenbrushes/__init__.py b/plugins/python/tenbrushes/__init__.py --- a/plugins/python/tenbrushes/__init__.py +++ b/plugins/python/tenbrushes/__init__.py @@ -1,2 +1,3 @@ -# let's make a module -from .tenbrushes import * +from .tenbrushes import TenBrushesExtension + +Scripter.addExtension(TenBrushesExtension(Application)) diff --git a/plugins/python/tenbrushes/dropbutton.py b/plugins/python/tenbrushes/dropbutton.py --- a/plugins/python/tenbrushes/dropbutton.py +++ b/plugins/python/tenbrushes/dropbutton.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 QPushButton from PyQt5.QtGui import QPixmap, QIcon from PyQt5.QtCore import QSize @@ -27,4 +30,5 @@ def selectPreset(self): self.preset = self.presetChooser.currentPreset().name() - self.setIcon(QIcon(QPixmap.fromImage(self.presetChooser.currentPreset().image()))) + current_preset = self.presetChooser.currentPreset() + self.setIcon(QIcon(QPixmap.fromImage(current_preset.image()))) diff --git a/plugins/python/tenbrushes/tenbrushes.py b/plugins/python/tenbrushes/tenbrushes.py --- a/plugins/python/tenbrushes/tenbrushes.py +++ b/plugins/python/tenbrushes/tenbrushes.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 uitenbrushes @@ -40,8 +43,10 @@ self.uitenbrushes.initialize(self) def readSettings(self): - self.selectedPresets = Application.readSetting("", "tenbrushes", "").split(',') - setting = Application.readSetting("", "tenbrushesActivatePrev2ndPress", "True") + self.selectedPresets = Application.readSetting( + "", "tenbrushes", "").split(',') + setting = Application.readSetting( + "", "tenbrushesActivatePrev2ndPress", "True") # we should not get anything other than 'True' and 'False' self.activatePrev = setting == 'True' @@ -58,26 +63,31 @@ def loadActions(self, window): allPresets = Application.resources("preset") - for index, item in enumerate(['1', '2', '3', '4', '5', '6', '7', '8', '9', '0']): - action = window.createAction("activate_preset_" + item, str(i18n("Activate Brush Preset {num}")).format(num=item), "") + for index, item in enumerate(['1', '2', '3', '4', '5', + '6', '7', '8', '9', '0']): + action = window.createAction( + "activate_preset_" + item, + str(i18n("Activate Brush Preset {num}")).format(num=item), "") action.triggered.connect(self.activatePreset) - if index < len(self.selectedPresets) and self.selectedPresets[index] in allPresets: + if (index < len(self.selectedPresets) + and self.selectedPresets[index] in allPresets): action.preset = self.selectedPresets[index] else: action.preset = None self.actions.append(action) def activatePreset(self): allPresets = Application.resources("preset") - if Application.activeWindow() and len(Application.activeWindow().views()) > 0 and self.sender().preset in allPresets: - currentPreset = Application.activeWindow().views()[0].currentBrushPreset() - if self.activatePrev and self.sender().preset == currentPreset.name(): - Application.activeWindow().views()[0].activateResource(self.oldPreset) + window = Application.activeWindow() + if (window and len(window.views()) > 0 + and self.sender().preset in allPresets): + currentPreset = window.views()[0].currentBrushPreset() + if (self.activatePrev + and self.sender().preset == currentPreset.name()): + window.views()[0].activateResource(self.oldPreset) else: - self.oldPreset = Application.activeWindow().views()[0].currentBrushPreset() - Application.activeWindow().views()[0].activateResource(allPresets[self.sender().preset]) - - -Scripter.addExtension(TenBrushesExtension(Application)) + self.oldPreset = window.views()[0].currentBrushPreset() + window.views()[0].activateResource( + allPresets[self.sender().preset]) diff --git a/plugins/python/tenbrushes/tenbrushesdialog.py b/plugins/python/tenbrushes/tenbrushesdialog.py --- a/plugins/python/tenbrushes/tenbrushesdialog.py +++ b/plugins/python/tenbrushes/tenbrushesdialog.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/tenbrushes/uitenbrushes.py b/plugins/python/tenbrushes/uitenbrushes.py --- a/plugins/python/tenbrushes/uitenbrushes.py +++ b/plugins/python/tenbrushes/uitenbrushes.py @@ -1,37 +1,46 @@ -''' -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 Qt, QSize +# https://creativecommons.org/publicdomain/zero/1.0/legalcode + +from PyQt5.QtCore import Qt from PyQt5.QtGui import QPixmap, QIcon -from PyQt5.QtWidgets import (QDialogButtonBox, QLabel, QVBoxLayout, QHBoxLayout, QCheckBox) +from PyQt5.QtWidgets import (QDialogButtonBox, QLabel, QVBoxLayout, + QHBoxLayout, QCheckBox) from . import tenbrushesdialog, dropbutton import krita class UITenBrushes(object): def __init__(self): self.kritaInstance = krita.Krita.instance() - self.mainDialog = tenbrushesdialog.TenBrushesDialog(self, self.kritaInstance.activeWindow().qwindow()) + self.mainDialog = tenbrushesdialog.TenBrushesDialog( + self, self.kritaInstance.activeWindow().qwindow()) self.buttonBox = QDialogButtonBox(self.mainDialog) self.vbox = QVBoxLayout(self.mainDialog) self.hbox = QHBoxLayout(self.mainDialog) - self.checkBox = QCheckBox(i18n("&Activate previous brush when pressing the shortcut for the second time"), self.mainDialog) + self.checkBox = QCheckBox( + i18n("&Activate previous brush when pressing the shortcut for the " + "second time"), + self.mainDialog) self.buttonBox.accepted.connect(self.mainDialog.accept) self.buttonBox.rejected.connect(self.mainDialog.reject) self.buttonBox.setOrientation(Qt.Horizontal) - self.buttonBox.setStandardButtons(QDialogButtonBox.Ok | QDialogButtonBox.Cancel) + self.buttonBox.setStandardButtons( + QDialogButtonBox.Ok | QDialogButtonBox.Cancel) self.presetChooser = krita.PresetChooser(self.mainDialog) @@ -41,7 +50,9 @@ self.loadButtons() self.vbox.addLayout(self.hbox) - self.vbox.addWidget(QLabel(i18n("Select the brush preset, then click on the button you want to use to select the preset"))) + self.vbox.addWidget( + QLabel(i18n("Select the brush preset, then click on the button " + "you want to use to select the preset"))) self.vbox.addWidget(self.presetChooser) self.checkBox.setChecked(self.tenbrushes.activatePrev) @@ -62,21 +73,25 @@ allPresets = Application.resources("preset") - for index, item in enumerate(['1', '2', '3', '4', '5', '6', '7', '8', '9', '0']): + for index, item in enumerate(['1', '2', '3', '4', '5', + '6', '7', '8', '9', '0']): buttonLayout = QVBoxLayout() button = dropbutton.DropButton(self.mainDialog) button.setObjectName(item) button.clicked.connect(button.selectPreset) button.presetChooser = self.presetChooser - if self.tenbrushes.actions[index] and self.tenbrushes.actions[index].preset and self.tenbrushes.actions[index].preset in allPresets: - p = allPresets[self.tenbrushes.actions[index].preset] + action = self.tenbrushes.actions[index] + + if action and action.preset and action.preset in allPresets: + p = allPresets[action.preset] button.preset = p.name() button.setIcon(QIcon(QPixmap.fromImage(p.image()))) buttonLayout.addWidget(button) - label = QLabel(self.tenbrushes.actions[index].shortcut().toString()) + label = QLabel( + action.shortcut().toString()) label.setAlignment(Qt.AlignHCenter) buttonLayout.addWidget(label) diff --git a/plugins/python/tenscripts/__init__.py b/plugins/python/tenscripts/__init__.py --- a/plugins/python/tenscripts/__init__.py +++ b/plugins/python/tenscripts/__init__.py @@ -1,2 +1,3 @@ - # let's make a module -from .tenscripts import * +from .tenscripts import TenScriptsExtension + +Scripter.addExtension(TenScriptsExtension(Application)) diff --git a/plugins/python/tenscripts/tenscripts.py b/plugins/python/tenscripts/tenscripts.py --- a/plugins/python/tenscripts/tenscripts.py +++ b/plugins/python/tenscripts/tenscripts.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 sys from PyQt5.QtWidgets import QMessageBox @@ -43,19 +46,25 @@ self.uitenscripts.initialize(self) def readSettings(self): - self.scripts = Application.readSetting("tenscripts", "scripts", "").split(',') + self.scripts = Application.readSetting( + "tenscripts", "scripts", "").split(',') def writeSettings(self): saved_scripts = self.uitenscripts.saved_scripts() for index, script in enumerate(saved_scripts): self.actions[index].script = script - Application.writeSetting("tenscripts", "scripts", ','.join(map(str, saved_scripts))) + Application.writeSetting( + "tenscripts", "scripts", ','.join(map(str, saved_scripts))) def loadActions(self, window): - for index, item in enumerate(['1', '2', '3', '4', '5', '6', '7', '8', '9', '10']): - action = window.createAction("execute_script_" + item, str(i18n("Execute Script {num}")).format(num=item), "") + for index, item in enumerate(['1', '2', '3', '4', '5', + '6', '7', '8', '9', '10']): + action = window.createAction( + "execute_script_" + item, + str(i18n("Execute Script {num}")).format(num=item), + "") action.script = None action.triggered.connect(self._executeScript) @@ -69,25 +78,26 @@ if script: try: if sys.version_info[0] > 2: - spec = importlib.util.spec_from_file_location("users_script", script) + spec = importlib.util.spec_from_file_location( + "users_script", script) users_module = importlib.util.module_from_spec(spec) spec.loader.exec_module(users_module) else: users_module = imp.load_source("users_script", script) - if hasattr(users_module, 'main') and callable(users_module.main): + if (hasattr(users_module, 'main') + and callable(users_module.main)): users_module.main() - self.showMessage(str(i18n("Script {0} executed")).format(self.sender().script)) + self.showMessage( + str(i18n("Script {0} executed")).format(script)) except Exception as e: self.showMessage(str(e)) else: - self.showMessage(i18n("You did not assign a script to that action")) + self.showMessage( + i18n("You did not assign a script to that action")) def showMessage(self, message): - self.msgBox = QMessageBox(Application.activeWindow().qwindow()) + self.msgBox = QMessageBox(Application.activeWindow().qwindow()) self.msgBox.setText(message) self.msgBox.exec_() - - -Scripter.addExtension(TenScriptsExtension(Application)) diff --git a/plugins/python/tenscripts/tenscriptsdialog.py b/plugins/python/tenscripts/tenscriptsdialog.py --- a/plugins/python/tenscripts/tenscriptsdialog.py +++ b/plugins/python/tenscripts/tenscriptsdialog.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/tenscripts/uitenscripts.py b/plugins/python/tenscripts/uitenscripts.py --- a/plugins/python/tenscripts/uitenscripts.py +++ b/plugins/python/tenscripts/uitenscripts.py @@ -1,16 +1,19 @@ -''' -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.QtCore import Qt -from PyQt5.QtWidgets import (QWidget, QVBoxLayout, QHBoxLayout, QPushButton, +from PyQt5.QtWidgets import (QWidget, QVBoxLayout, QPushButton, QLineEdit, QScrollArea, QGridLayout, QFileDialog, QLabel, QDialogButtonBox) from . import tenscriptsdialog @@ -21,7 +24,8 @@ def __init__(self): self.kritaInstance = krita.Krita.instance() - self.mainDialog = tenscriptsdialog.TenScriptsDialog(self, self.kritaInstance.activeWindow().qwindow()) + self.mainDialog = tenscriptsdialog.TenScriptsDialog( + self, self.kritaInstance.activeWindow().qwindow()) self.buttonBox = QDialogButtonBox(self.mainDialog) self.layout = QVBoxLayout(self.mainDialog) @@ -34,7 +38,8 @@ self.buttonBox.rejected.connect(self.mainDialog.reject) self.buttonBox.setOrientation(Qt.Horizontal) - self.buttonBox.setStandardButtons(QDialogButtonBox.Ok | QDialogButtonBox.Cancel) + self.buttonBox.setStandardButtons( + QDialogButtonBox.Ok | QDialogButtonBox.Cancel) self.scrollArea.setWidgetResizable(True) def initialize(self, tenscripts): @@ -55,7 +60,6 @@ def addNewRow(self, key): rowPosition = self.scriptsLayout.rowCount() - rowLayout = QHBoxLayout() label = QLabel() directoryTextField = QLineEdit() directoryDialogButton = QPushButton(i18n("...")) @@ -66,9 +70,12 @@ directoryDialogButton.setToolTip(i18n("Select the script")) directoryDialogButton.clicked.connect(self._selectScript) - self.scriptsLayout.addWidget(label, rowPosition, 0, Qt.AlignLeft|Qt.AlignTop) - self.scriptsLayout.addWidget(directoryTextField, rowPosition, 1, Qt.AlignLeft|Qt.AlignTop) - self.scriptsLayout.addWidget(directoryDialogButton, rowPosition, 2, Qt.AlignLeft|Qt.AlignTop) + self.scriptsLayout.addWidget( + label, rowPosition, 0, Qt.AlignLeft | Qt.AlignTop) + self.scriptsLayout.addWidget( + directoryTextField, rowPosition, 1, Qt.AlignLeft | Qt.AlignTop) + self.scriptsLayout.addWidget( + directoryDialogButton, rowPosition, 2, Qt.AlignLeft | Qt.AlignTop) def saved_scripts(self): _saved_scripts = [] @@ -89,7 +96,8 @@ if dialog.exec_(): selectedFile = dialog.selectedFiles()[0] obj = self.mainDialog.sender() - textField = self.scriptsLayout.itemAt(self.scriptsLayout.indexOf(obj)-1).widget() + textField = self.scriptsLayout.itemAt( + self.scriptsLayout.indexOf(obj)-1).widget() textField.setText(selectedFile) def _loadGridLayout(self):