Skip to content

armgit / krita

Public Imported from GitHub
0

Krita is a free and open source cross-platform application that offers an end-to-end solution for creating digital art files from scratch built on the KDE and Qt frameworks.

C++

Add workflow buttons docker

Timothée Giet27dd17d3f42f
diff --git a/krita/data/kritarc b/krita/data/kritarc
index c58a6e5392..c3841e991f 100644
--- a/krita/data/kritarc
+++ b/krita/data/kritarc
@@ -366,6 +366,7 @@ enable_scripter=true
enable_tenbrushes=true
enable_tenscripts=true
enable_plugin_importer=true
+enable_workflow_buttons=true
[SPenSettings]
actionButtonClick=spen_show_popup_palette
diff --git a/plugins/python/CMakeLists.txt b/plugins/python/CMakeLists.txt
index 99e886acf4..aadde38807 100644
--- a/plugins/python/CMakeLists.txt
+++ b/plugins/python/CMakeLists.txt
@@ -78,6 +78,7 @@ install_pykrita_plugin(plugin_importer)
install_pykrita_plugin(mixer_slider_docker)
install_pykrita_plugin(channels2layers)
install_pykrita_plugin(photobash_images)
+install_pykrita_plugin(workflow_buttons)
# if(PYTHON_VERSION_MAJOR VERSION_EQUAL 3)
# install_pykrita_plugin(cmake_utils)
diff --git a/plugins/python/workflow_buttons/Manual.html b/plugins/python/workflow_buttons/Manual.html
new file mode 100644
index 0000000000..d24a10e74a
--- /dev/null
+++ b/plugins/python/workflow_buttons/Manual.html
@@ -0,0 +1,35 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!DOCTYPE html>
+
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head><title>Workflow buttons</title>
+</head>
+<body>
+<h1>Workflow buttons</h1>
+<p>A docker to create multi-action buttons to improve your workflow.</p>
+<h2>Usage</h2>
+<p>Each workflow buttons can do any of the following actions at the same time:</p>
+<ul>
+ <li>select a tool</li>
+ <li>select a brush preset</li>
+ <li>select a foreground color</li>
+ <li>select a background color</li>
+ <li>launch an extra script</li>
+</ul>
+<p>The first time you open the docker, it contains only one button to open its settings dialog.</p>
+<p>In the settings dialog, start by clicking the "+" button to add an empty button. It is selected by default. After creating several buttons, click on one to select it. You can move it to the left or to the right of the list with the arrow buttons. You can also delete selected button with the trash can button.</p>
+<p>You can see which button is selected in the list as it is "checked" (its background color is darker). If you add an icon which covers all of the button's background, you can still see which button is selected from the "Selected button" label which indicates the number of the selected button in the list.</p>
+<p>After creating and selecting a button, you can now:</p>
+<ul>
+ <li>Select an icon for the button (svg or png files). Click on the button on the left to open a file selection dialog.</li>
+ <li>Enter a tooltip text to describe your button.</li>
+ <li>Select a tool in the list. If you don't want to select any tool, select the emtpy line at the beginning of the list.</li>
+ <li>Select a brush preset. Click on the button on the left to open a prest selection dialog. To deselect the brush preset, erase the content of the corresponding text field.</li>
+ <li>Select a foreground color. You can load the currently selected foreground color with the corresponding button: the text below will then show the info used to save that color. You can save any kind of color supported by Krita. To delete selected color, click on "Clear foreground color".</li>
+ <li>Select a background color. Same as for the foreground color...</li>
+ <li>Select a script file. Click on the button on the left to open a file selection dialog. To deselect the script, erase the content of the corresponding text field.</li>
+</ul>
+<p>There is also an option to select the buttons size. By default it is set to 32 pixels, but you can set it smaller or bigger.</p>
+<p>Finally, to save all your changes, click on the OK button. If you want to discard all your changes, click on the Cancel button.</p>
+</body>
+</html>
diff --git a/plugins/python/workflow_buttons/__init__.py b/plugins/python/workflow_buttons/__init__.py
new file mode 100644
index 0000000000..833a36953b
--- /dev/null
+++ b/plugins/python/workflow_buttons/__init__.py
@@ -0,0 +1,6 @@
+# SPDX-FileCopyrightText: 2024 Timothée Giet <[email protected]>
+# Authors:
+# Timothée Giet <[email protected]>
+# SPDX-License-Identifier: GPL-3.0-or-later
+
+from .workflow_buttons import WorkflowButtons
diff --git a/plugins/python/workflow_buttons/buttons_settings_dialog.py b/plugins/python/workflow_buttons/buttons_settings_dialog.py
new file mode 100644
index 0000000000..420d9b575f
--- /dev/null
+++ b/plugins/python/workflow_buttons/buttons_settings_dialog.py
@@ -0,0 +1,529 @@
+# SPDX-FileCopyrightText: 2024 Timothée Giet <[email protected]>
+# Authors:
+# Timothée Giet <[email protected]>
+# SPDX-License-Identifier: GPL-3.0-or-later
+
+from PyQt5.QtCore import QSize
+from PyQt5.QtGui import QIcon
+from PyQt5.QtWidgets import (QDialog, QVBoxLayout, QHBoxLayout, QWidget, QScrollArea, QPushButton,
+ QToolButton, QLabel, QLineEdit, QComboBox, QDialogButtonBox,
+ QFileDialog)
+from krita import Krita, PresetChooser
+from .flow_layout import FlowLayout
+import copy
+
+LISTOFTOOLS = [
+ { "toolName": "", "toolIcon": "", "toolString": "" },
+ { "toolName": "InteractionTool", "toolIcon": "select", "toolString": "Select Shapes Tool" },
+ { "toolName": "SvgTextToo", "toolIcon": "draw-text", "toolString": "Text Tool" },
+ { "toolName": "PathTool", "toolIcon": "shape_handling", "toolString": "Edit Shapes Tool" },
+ { "toolName": "KarbonCalligraphyTool", "toolIcon": "calligraphy", "toolString": "Calligraphy" },
+ { "toolName": "KritaShape/KisToolBrush", "toolIcon": "krita_tool_freehand", "toolString": "Freehand Brush Tool" },
+ { "toolName": "KritaShape/KisToolLine", "toolIcon": "krita_tool_line", "toolString": "Line Tool" },
+ { "toolName": "KritaShape/KisToolRectangle", "toolIcon": "krita_tool_rectangle", "toolString": "Rectangle Tool" },
+ { "toolName": "KritaShape/KisToolEllipse", "toolIcon": "krita_tool_ellipse", "toolString": "Ellipse Tool" },
+ { "toolName": "KisToolPolygon", "toolIcon": "krita_tool_polygon", "toolString": "Polygon Tool" },
+ { "toolName": "KisToolPolyline", "toolIcon": "polyline", "toolString": "Polyline Tool" },
+ { "toolName": "KisToolPath", "toolIcon": "krita_draw_path", "toolString": "Bezier Curve Tool" },
+ { "toolName": "KisToolPencil", "toolIcon": "krita_tool_freehandvector", "toolString": "Freehand Path Tool" },
+ { "toolName": "KritaShape/KisToolDyna", "toolIcon": "krita_tool_dyna", "toolString": "Dynamic Brush Tool" },
+ { "toolName": "KritaShape/KisToolMultiBrush", "toolIcon": "krita_tool_multihand", "toolString": "Multibrush Tool" },
+ { "toolName": "KisToolTransform", "toolIcon": "krita_tool_transform", "toolString": "Transform Tool" },
+ { "toolName": "KritaTransform/KisToolMove", "toolIcon": "krita_tool_move", "toolString": "Move Tool" },
+ { "toolName": "KisToolCrop", "toolIcon": "tool_crop", "toolString": "Crop Tool" },
+ { "toolName": "KritaFill/KisToolGradient", "toolIcon": "krita_tool_gradient", "toolString": "Gradient Tool" },
+ { "toolName": "KritaSelected/KisToolColorSampler", "toolIcon": "krita_tool_color_sampler", "toolString": "Color Sampler" },
+ { "toolName": "KritaShape/KisToolLazyBrush", "toolIcon": "krita_tool_lazybrush", "toolString": "Colorize Mask Tool" },
+ { "toolName": "KritaShape/KisToolSmartPatch", "toolIcon": "krita_tool_smart_patch", "toolString": "Smart Patch Tool" },
+ { "toolName": "KritaFill/KisToolFill", "toolIcon": "krita_tool_color_fill", "toolString": "Fill Tool" },
+ { "toolName": "KisToolEncloseAndFill", "toolIcon": "krita_tool_enclose_and_fill", "toolString": "Enclose and Fill Tool" },
+ { "toolName": "KisAssistantTool", "toolIcon": "krita_tool_assistant", "toolString": "Assistant Tool" },
+ { "toolName": "KritaShape/KisToolMeasure", "toolIcon": "krita_tool_measure", "toolString": "Measurement Tool" },
+ { "toolName": "ToolReferenceImages", "toolIcon": "krita_tool_reference_images", "toolString": "Reference Images Tool" },
+ { "toolName": "KisToolSelectRectangular", "toolIcon": "tool_rect_selection", "toolString": "Rectangular Selection Tool" },
+ { "toolName": "KisToolSelectElliptical", "toolIcon": "tool_elliptical_selection", "toolString": "Elliptical Selection Tool" },
+ { "toolName": "KisToolSelectPolygonal", "toolIcon": "tool_polygonal_selection", "toolString": "Polygonal Selection Tool" },
+ { "toolName": "KisToolSelectOutline", "toolIcon": "tool_outline_selection", "toolString": "Freehand Selection Tool" },
+ { "toolName": "KisToolSelectContiguous", "toolIcon": "tool_contiguous_selection", "toolString": "Contiguous Selection Tool" },
+ { "toolName": "KisToolSelectSimilar", "toolIcon": "tool_similar_selection", "toolString": "Similar Color Selection Tool" },
+ { "toolName": "KisToolSelectPath", "toolIcon": "tool_path_selection", "toolString": "Bezier Curve Selection Tool" },
+ { "toolName": "KisToolSelectMagnetic", "toolIcon": "tool_magnetic_selection", "toolString": "Magnetic Selection Tool" },
+ { "toolName": "ZoomTool", "toolIcon": "tool_zoom", "toolString": "Zoom Tool" },
+ { "toolName": "PanTool", "toolIcon": "tool_pan", "toolString": "Pan Tool" }
+ ]
+
+LISTOFSIZES = [16, 22, 32, 48, 64]
+
+class ButtonsSettingsDialog(QDialog):
+ def __init__(self, parent=None, buttonsContentList=[], sizeIndex=2):
+ super().__init__(parent)
+ self.setWindowTitle(i18n("Workflow buttons settings"))
+ self.kritaInstance = Krita.instance()
+
+ mainLayout = QVBoxLayout(self)
+
+ self.buttonsContentList = copy.deepcopy(buttonsContentList)
+ self.defaultButtonContent = { "icon" : "", "tooltip": "", "toolIndex" : 0, "presetName" : "", "FGColorValues" : { "model":"","depth":"","components":[],"profile":"" }, "BGColorValues" : { "model":"","depth":"","components":[],"profile":"" }, "script" : "" }
+
+ # button ID starts at 1, 0 is no button selected when list is empty
+ self.selectedButtonID = 0
+ # if list is not empty, start with last button selected
+ if len(self.buttonsContentList) > 0:
+ self.selectedButtonID = len(self.buttonsContentList)
+
+ # list of custom buttons
+ buttonsScrollArea = QScrollArea(self)
+ self.buttonsWidget = QWidget(self)
+ self.buttonsLayout = FlowLayout(self.buttonsWidget)
+ buttonsScrollArea.setWidgetResizable(True)
+ buttonsScrollArea.setWidget(self.buttonsWidget)
+
+ mainLayout.addWidget(buttonsScrollArea)
+
+ self.sizeIndex = sizeIndex
+ self.globalButtonSize = QSize(LISTOFSIZES[self.sizeIndex], LISTOFSIZES[self.sizeIndex])
+
+ layoutForSelectorControls = QHBoxLayout()
+ controlsSize = QSize(22,22)
+
+ # label to show selected button id:
+ selectedButtonIDLabelTitle = QLabel(i18n("Selected button:"), self)
+ self.selectedButtonIDLabel = QLabel(str(self.selectedButtonID), self)
+ layoutForSelectorControls.addWidget(selectedButtonIDLabelTitle)
+ layoutForSelectorControls.addWidget(self.selectedButtonIDLabel)
+
+ # button to add a custom button
+ addButtonButton = QToolButton(self)
+ addButtonButton.setIconSize(controlsSize)
+ addButtonButton.setIcon(self.kritaInstance.icon('addlayer'))
+ addButtonButton.setToolTip(i18n("Add a workflow button"))
+ addButtonButton.clicked.connect(self.addButton)
+ layoutForSelectorControls.addWidget(addButtonButton)
+
+ # buttons to move selected button to left/right
+ moveButtonLeftButton = QToolButton(self)
+ moveButtonLeftButton.setIconSize(controlsSize)
+ moveButtonLeftButton.setIcon(self.kritaInstance.icon('arrow-left'))
+ moveButtonLeftButton.setToolTip(i18n("Move selected workflow button to the left"))
+ moveButtonLeftButton.clicked.connect(self.moveButtonLeft)
+ layoutForSelectorControls.addWidget(moveButtonLeftButton)
+ moveButtonRightButton = QToolButton(self)
+ moveButtonRightButton.setIconSize(controlsSize)
+ moveButtonRightButton.setIcon(self.kritaInstance.icon('arrow-right'))
+ moveButtonRightButton.setToolTip(i18n("Move selected workflow button to the right"))
+ moveButtonRightButton.clicked.connect(self.moveButtonRight)
+ layoutForSelectorControls.addWidget(moveButtonRightButton)
+
+ # button to delete selected button
+ deleteButtonButton = QToolButton(self)
+ deleteButtonButton.setIconSize(controlsSize)
+ deleteButtonButton.setIcon(self.kritaInstance.icon('deletelayer'))
+ deleteButtonButton.setToolTip(i18n("Delete selected workflow button"))
+ deleteButtonButton.clicked.connect(self.deleteButton)
+ layoutForSelectorControls.addWidget(deleteButtonButton)
+ mainLayout.addLayout(layoutForSelectorControls)
+
+ # set selected button's icon
+ layoutForIconSelection = QHBoxLayout()
+
+ addIconLabel = QLabel(i18n("Select an icon:"), self)
+ layoutForIconSelection.addWidget(addIconLabel)
+ self.iconPathInput = QLineEdit(self)
+ self.iconPathInput.setToolTip(i18n("Icon path"))
+ self.iconPathInput.editingFinished.connect(self.iconPathChanged)
+ layoutForIconSelection.addWidget(self.iconPathInput)
+
+ iconPathDialogButton = QPushButton(i18n("..."), self)
+ iconPathDialogButton.setToolTip(i18n("Select the icon"))
+ iconPathDialogButton.clicked.connect(self.selectIcon)
+ layoutForIconSelection.addWidget(iconPathDialogButton)
+
+ mainLayout.addLayout(layoutForIconSelection)
+
+ # set custom button's tooltip
+ layoutForToolTip = QHBoxLayout()
+ toolTipLabel = QLabel(i18n("Enter a Tooltip:"), self)
+ layoutForToolTip.addWidget(toolTipLabel)
+ self.toolTipInput = QLineEdit(self)
+ self.toolTipInput.setToolTip(i18n("Tooltip text"))
+ self.toolTipInput.editingFinished.connect(self.toolTipChanged)
+ layoutForToolTip.addWidget(self.toolTipInput)
+
+ mainLayout.addLayout(layoutForToolTip)
+
+ # set custom button's' toolName
+ layoutForToolSelector = QHBoxLayout()
+ toolSelectorLabel = QLabel(i18n("Select a tool:"), self)
+ layoutForToolSelector.addWidget(toolSelectorLabel)
+ self.toolSelector = QComboBox(self)
+ self.populateToolList()
+ self.toolSelector.activated.connect(self.toolChanged)
+ layoutForToolSelector.addWidget(self.toolSelector)
+
+ mainLayout.addLayout(layoutForToolSelector)
+
+ # set custom button's presetName
+ layoutForPresetSelector = QHBoxLayout()
+ presetSelectorLabel = QLabel(i18n("Select a brush preset:"), self)
+ layoutForPresetSelector.addWidget(presetSelectorLabel)
+ self.presetSelectorInput = QLineEdit(self)
+ self.presetSelectorInput.setToolTip(i18n("Brush preset name"))
+ self.presetSelectorInput.editingFinished.connect(self.presetChanged)
+ layoutForPresetSelector.addWidget(self.presetSelectorInput)
+
+ presetDialogButton = QPushButton(i18n("..."), self)
+ presetDialogButton.setToolTip(i18n("Select the brush preset"))
+ presetDialogButton.clicked.connect(self.selectPreset)
+ layoutForPresetSelector.addWidget(presetDialogButton)
+
+ mainLayout.addLayout(layoutForPresetSelector)
+
+ # set custom button's FGColorValues
+ layoutForFGColorInput = QHBoxLayout()
+ FGColorLabel = QLabel(i18n("Select foreground color:"), self)
+ layoutForFGColorInput.addWidget(FGColorLabel)
+ FGColorInputSelector = QPushButton(i18n("Load current foreground color"), self)
+ FGColorInputSelector.clicked.connect(self.selectFGColor)
+ layoutForFGColorInput.addWidget(FGColorInputSelector)
+ FGColorClear = QPushButton(i18n("Clear foreground color"), self)
+ FGColorClear.clicked.connect(self.clearFGColor)
+ layoutForFGColorInput.addWidget(FGColorClear)
+ mainLayout.addLayout(layoutForFGColorInput)
+
+ colorInfoToolTip = i18n("Color model ; depth ; profile ; components")
+
+ layoutForFGColorInfo = QHBoxLayout()
+ self.FGColorInfoLabel = QLabel(self)
+ self.FGColorInfoLabel.setToolTip(colorInfoToolTip)
+ layoutForFGColorInfo.addWidget(self.FGColorInfoLabel)
+ mainLayout.addLayout(layoutForFGColorInfo)
+
+ # set custom button's BGColorValues
+ layoutForBGColorInput = QHBoxLayout()
+ BGColorLabel = QLabel(i18n("Select backround color:"), self)
+ layoutForBGColorInput.addWidget(BGColorLabel)
+ BGColorInputSelector = QPushButton(i18n("Load current background color"), self)
+ BGColorInputSelector.clicked.connect(self.selectBGColor)
+ layoutForBGColorInput.addWidget(BGColorInputSelector)
+ BGColorClear = QPushButton(i18n("Clear background color"), self)
+ BGColorClear.clicked.connect(self.clearBGColor)
+ layoutForBGColorInput.addWidget(BGColorClear)
+ mainLayout.addLayout(layoutForBGColorInput)
+
+ layoutForBGColorInfo = QHBoxLayout()
+ self.BGColorInfoLabel = QLabel(self)
+ self.BGColorInfoLabel.setToolTip(colorInfoToolTip)
+ layoutForBGColorInfo.addWidget(self.BGColorInfoLabel)
+ mainLayout.addLayout(layoutForBGColorInfo)
+
+ # set custom button's extra script
+ layoutForScriptSelection = QHBoxLayout()
+
+ scriptLabel = QLabel(i18n("Select a script file:"), self)
+ layoutForScriptSelection.addWidget(scriptLabel)
+ self.scriptPathInput = QLineEdit(self)
+ self.scriptPathInput.setToolTip(i18n("Script path"))
+ self.scriptPathInput.editingFinished.connect(self.scriptPathChanged)
+ layoutForScriptSelection.addWidget(self.scriptPathInput)
+
+ scriptPathDialogButton = QPushButton(i18n("..."), self)
+ scriptPathDialogButton.setToolTip(i18n("Select the script"))
+ scriptPathDialogButton.clicked.connect(self.selectScript)
+ layoutForScriptSelection.addWidget(scriptPathDialogButton)
+
+ mainLayout.addLayout(layoutForScriptSelection)
+
+ # add bottom buttons
+ layoutForBottom = QHBoxLayout()
+
+ # button's size selector
+ buttonsSizeLabel = QLabel(i18n("Buttons size:"), self)
+ self.buttonsSizeSelector = QComboBox(self)
+ self.populateSizeList()
+ self.buttonsSizeSelector.setCurrentIndex(self.sizeIndex)
+ self.buttonsSizeSelector.activated.connect(self.buttonsSizeChanged)
+ layoutForBottom.addWidget(buttonsSizeLabel)
+ layoutForBottom.addWidget(self.buttonsSizeSelector)
+
+ # main dialog's default buttons
+ buttonBox = QDialogButtonBox(self)
+ buttonBox.setStandardButtons( QDialogButtonBox.Ok | QDialogButtonBox.Cancel)
+ buttonBox.accepted.connect(self.accept)
+ buttonBox.rejected.connect(self.reject)
+ layoutForBottom.addWidget(buttonBox)
+ mainLayout.addLayout(layoutForBottom)
+
+ self.populateButtons()
+ self.resize(640, 360)
+ # end of __init__
+
+ def populateToolList(self):
+ toolNumber = -1
+ for tool in LISTOFTOOLS:
+ toolNumber += 1
+ self.toolSelector.insertItem(toolNumber,
+ self.kritaInstance.icon(LISTOFTOOLS[toolNumber]["toolIcon"]),
+ i18n(LISTOFTOOLS[toolNumber]["toolString"]))
+
+ def populateSizeList(self):
+ listIndex = -1
+ for size in LISTOFSIZES:
+ listIndex += 1
+ self.buttonsSizeSelector.insertItem(listIndex,str(LISTOFSIZES[listIndex]))
+
+ def createButton(self, buttonToCreate, buttonID):
+ # print("create button with buttonID: " + str(buttonID))
+ buttonIcon = QIcon(buttonToCreate["icon"])
+ button = CustomButtonForSettings(self.buttonsWidget, buttonID)
+ button.setIconSize(self.globalButtonSize)
+ button.setIcon(buttonIcon)
+ button.clicked.connect(lambda state, x=button.buttonID: self.selectButton(x))
+ self.buttonsLayout.addWidget(button)
+
+ def clearButtons(self):
+ # print("clearButtons called")
+ for widget in self.buttonsWidget.children():
+ if isinstance(widget, CustomButtonForSettings):
+ widget.deleteLater()
+
+ def populateButtons(self):
+ # print("populateButtons called")
+ buttonID = 0
+ for buttonToCreate in self.buttonsContentList:
+ buttonID += 1
+ # print("create button id " + str(buttonID))
+ self.createButton(buttonToCreate, buttonID)
+ self.selectButton(self.selectedButtonID)
+
+ def refreshButtons(self):
+ # print("refreshButtons called")
+ self.clearButtons()
+ self.populateButtons()
+
+ def updateDialogFields(self):
+ # print("updateDialogFields called")
+ self.selectedButtonIDLabel.setText(str(self.selectedButtonID))
+ # add a line here for new dialog fields...
+ if self.selectedButtonID > 0:
+ self.iconPathInput.setText(self.buttonsContentList[self.selectedButtonID - 1]["icon"])
+ self.toolTipInput.setText(self.buttonsContentList[self.selectedButtonID - 1]["tooltip"])
+ self.toolSelector.setCurrentIndex(self.buttonsContentList[self.selectedButtonID - 1]["toolIndex"])
+ self.presetSelectorInput.setText(self.buttonsContentList[self.selectedButtonID - 1]["presetName"])
+ self.setFGColorInfoLabel(self.buttonsContentList[self.selectedButtonID - 1]["FGColorValues"])
+ self.setBGColorInfoLabel(self.buttonsContentList[self.selectedButtonID - 1]["BGColorValues"])
+ self.scriptPathInput.setText(self.buttonsContentList[self.selectedButtonID - 1]["script"])
+
+ def selectButton(self, buttonID):
+ # print("selectButton " + str(buttonID))
+ self.selectedButtonID = buttonID
+ for widget in self.buttonsWidget.children():
+ if isinstance(widget, CustomButtonForSettings):
+ if widget.buttonID == self.selectedButtonID:
+ widget.setChecked(True)
+ else:
+ widget.setChecked(False)
+ self.updateDialogFields()
+
+ def addButton(self):
+ # print("addButton pressed")
+ buttonID = len(self.buttonsContentList) + 1
+ self.selectedButtonID = buttonID
+ buttonContent = copy.deepcopy(self.defaultButtonContent)
+ self.buttonsContentList.append(buttonContent)
+ self.createButton(self.defaultButtonContent, buttonID)
+ self.refreshButtons()
+
+ def selectIcon(self):
+ # print("select icon dialog started")
+ if self.selectedButtonID < 1:
+ return
+ dialog = QFileDialog(self)
+ dialog.setNameFilter(i18n("Icon files (*.png, *.svg)"))
+
+ if dialog.exec_():
+ selectedFile = dialog.selectedFiles()[0]
+ self.iconPathInput.setText(selectedFile)
+ self.iconPathChanged()
+
+ def iconPathChanged(self):
+ # print("icon path edited...")
+ if self.selectedButtonID < 1:
+ return
+ self.buttonsContentList[self.selectedButtonID - 1]["icon"] = self.iconPathInput.text()
+ self.refreshButtons()
+
+ def toolTipChanged(self):
+ # print("tooltip edited...")
+ if self.selectedButtonID < 1:
+ return
+ self.buttonsContentList[self.selectedButtonID - 1]["tooltip"] = self.toolTipInput.text()
+
+ def toolChanged(self, toolIndex):
+ # print("tool changed")
+ if self.selectedButtonID < 1:
+ return
+ self.buttonsContentList[self.selectedButtonID - 1]["toolIndex"] = toolIndex
+
+ def selectPreset(self):
+ # print("select preset dialog started")
+ if self.selectedButtonID < 1:
+ return
+ dialog = QDialog(self)
+ dialogLayout = QVBoxLayout(dialog)
+ presetChooser = PresetChooser(dialog)
+ dialogLayout.addWidget(presetChooser)
+ buttonBox = QDialogButtonBox(dialog)
+ buttonBox.setStandardButtons( QDialogButtonBox.Ok | QDialogButtonBox.Cancel)
+ buttonBox.accepted.connect(dialog.accept)
+ buttonBox.rejected.connect(dialog.reject)
+ dialogLayout.addWidget(buttonBox)
+
+ dialog.exec_()
+ if dialog.result() == 1 and presetChooser.currentPreset():
+ self.presetSelectorInput.setText(presetChooser.currentPreset().name())
+ self.presetChanged()
+
+ def presetChanged(self):
+ # print("icon path edited...")
+ if self.selectedButtonID < 1:
+ return
+ self.buttonsContentList[self.selectedButtonID - 1]["presetName"] = self.presetSelectorInput.text()
+
+ def setFGColorInfoLabel(self, values):
+ colorInfoLabel = i18n("Color info: ")
+ colorModel = values["model"]
+ if colorModel == "":
+ self.FGColorInfoLabel.setText(colorInfoLabel)
+ else:
+ colorDepth = values["depth"]
+ colorProfile = values["profile"]
+ colorComponents = values["components"]
+ shortenedComponents = [ "%.3f" % component for component in colorComponents ]
+ separator = " ; "
+ self.FGColorInfoLabel.setText(colorInfoLabel + colorModel + separator + colorDepth + separator + colorProfile + separator + str(shortenedComponents))
+
+ def selectFGColor(self):
+ if self.selectedButtonID < 1:
+ return
+ # print("FGColor edited...")
+ savedColor = { "model":"", "depth":"", "components":[] }
+ currentFGColor = self.kritaInstance.activeWindow().activeView().foregroundColor()
+ savedColor["model"] = currentFGColor.colorModel()
+ savedColor["depth"] = currentFGColor.colorDepth()
+ savedColor["components"] = currentFGColor.components()
+ savedColor["profile"] = currentFGColor.colorProfile()
+ self.buttonsContentList[self.selectedButtonID - 1]["FGColorValues"] = savedColor
+ self.setFGColorInfoLabel(savedColor)
+
+ def clearFGColor(self):
+ if self.selectedButtonID < 1:
+ return
+ self.buttonsContentList[self.selectedButtonID - 1]["FGColorValues"] = self.defaultButtonContent["FGColorValues"]
+ self.setFGColorInfoLabel(self.buttonsContentList[self.selectedButtonID - 1]["FGColorValues"])
+
+ def setBGColorInfoLabel(self, values):
+ colorInfoLabel = i18n("Color info: ")
+ colorModel = values["model"]
+ if colorModel == "":
+ self.BGColorInfoLabel.setText(colorInfoLabel)
+ else:
+ colorDepth = values["depth"]
+ colorProfile = values["profile"]
+ colorComponents = values["components"]
+ shortenedComponents = [ "%.3f" % component for component in colorComponents ]
+ separator = " ; "
+ self.BGColorInfoLabel.setText(colorInfoLabel + colorModel + separator + colorDepth + separator + colorProfile + separator + str(shortenedComponents))
+
+ def selectBGColor(self):
+ if self.selectedButtonID < 1:
+ return
+ # print("BGColor edited...")
+ savedColor = { "model":"", "depth":"", "components":[] }
+ currentBGColor = self.kritaInstance.activeWindow().activeView().backgroundColor()
+ savedColor["model"] = currentBGColor.colorModel()
+ savedColor["depth"] = currentBGColor.colorDepth()
+ savedColor["components"] = currentBGColor.components()
+ savedColor["profile"] = currentBGColor.colorProfile()
+ self.buttonsContentList[self.selectedButtonID - 1]["BGColorValues"] = savedColor
+ self.setBGColorInfoLabel(savedColor)
+
+ def clearBGColor(self):
+ if self.selectedButtonID < 1:
+ return
+ self.buttonsContentList[self.selectedButtonID - 1]["BGColorValues"] = self.defaultButtonContent["BGColorValues"]
+ self.setBGColorInfoLabel(self.buttonsContentList[self.selectedButtonID - 1]["BGColorValues"])
+
+ def selectScript(self):
+ # print("select script dialog started")
+ if self.selectedButtonID < 1:
+ return
+ dialog = QFileDialog(self)
+ dialog.setNameFilter(i18n("Script files (*.py)"))
+
+ if dialog.exec_():
+ selectedFile = dialog.selectedFiles()[0]
+ self.scriptPathInput.setText(selectedFile)
+ self.scriptPathChanged()
+
+ def scriptPathChanged(self):
+ # print("icon path edited...")
+ if self.selectedButtonID < 1:
+ return
+ self.buttonsContentList[self.selectedButtonID - 1]["script"] = self.scriptPathInput.text()
+
+ def clearDialogFields(self):
+ # print("clear all dialog fields...")
+ # add a line here for new dialog fields...
+ self.selectedButtonIDLabel.setText("0")
+ self.iconPathInput.setText("")
+ self.toolTipInput.setText("")
+ self.toolSelector.setCurrentIndex(0)
+ self.presetSelectorInput.setText("")
+ self.setFGColorInfoLabel(self.defaultButtonContent["FGColorValues"])
+ self.setBGColorInfoLabel(self.defaultButtonContent["BGColorValues"])
+ self.scriptPathInput.setText("")
+
+ def deleteButton(self):
+ # print("delete button " + str(self.selectedButtonID))
+ if self.selectedButtonID < 1 :
+ return
+ del self.buttonsContentList[self.selectedButtonID - 1]
+ self.selectedButtonID -= 1
+ if len(self.buttonsContentList) < 1:
+ self.selectedButtonID = 0
+ self.refreshButtons()
+ self.clearDialogFields()
+ return
+ if self.selectedButtonID == 0:
+ self.selectedButtonID = 1
+ self.refreshButtons()
+
+ def moveButtonLeft(self):
+ # print("moveLeft button " + str(self.selectedButtonID))
+ if self.selectedButtonID <= 1:
+ return
+ self.buttonsContentList.insert(self.selectedButtonID - 2, self.buttonsContentList.pop(self.selectedButtonID - 1))
+ self.selectedButtonID -= 1
+ self.refreshButtons()
+
+ def moveButtonRight(self):
+ # print("moveRight button " + str(self.selectedButtonID))
+ if self.selectedButtonID >= len(self.buttonsContentList):
+ return
+ self.buttonsContentList.insert(self.selectedButtonID, self.buttonsContentList.pop(self.selectedButtonID - 1))
+ self.selectedButtonID += 1
+ self.refreshButtons()
+
+ def buttonsSizeChanged(self, sizeIndex):
+ # print("size changed")
+ self.sizeIndex = sizeIndex
+ self.globalButtonSize = QSize(LISTOFSIZES[sizeIndex], LISTOFSIZES[sizeIndex])
+ if self.selectedButtonID > 0:
+ self.refreshButtons()
+
+class CustomButtonForSettings(QToolButton):
+ # Class to define the custom buttons inside the dialog
+ def __init__(self, parent=None, buttonID=-1):
+ super().__init__(parent)
+ self.buttonID = buttonID
+ self.setCheckable(True)
diff --git a/plugins/python/workflow_buttons/flow_layout.py b/plugins/python/workflow_buttons/flow_layout.py
new file mode 100644
index 0000000000..35744c2be1
--- /dev/null
+++ b/plugins/python/workflow_buttons/flow_layout.py
@@ -0,0 +1,97 @@
+# Copyright (C) 2013 Riverbank Computing Limited.
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
+
+# FlowLayout class copied from https://doc.qt.io/qtforpython-6/examples/example_widgets_layouts_flowlayout.html
+
+from PyQt5.QtCore import Qt, QMargins, QPoint, QRect, QSize
+from PyQt5.QtWidgets import QLayout, QSizePolicy
+
+class FlowLayout(QLayout):
+ def __init__(self, parent=None):
+ super().__init__(parent)
+
+ if parent is not None:
+ self.setContentsMargins(QMargins(0, 0, 0, 0))
+
+ self._item_list = []
+
+ def __del__(self):
+ item = self.takeAt(0)
+ while item:
+ item = self.takeAt(0)
+
+ def addItem(self, item):
+ self._item_list.append(item)
+
+ def count(self):
+ return len(self._item_list)
+
+ def itemAt(self, index):
+ if 0 <= index < len(self._item_list):
+ return self._item_list[index]
+
+ return None
+
+ def takeAt(self, index):
+ if 0 <= index < len(self._item_list):
+ return self._item_list.pop(index)
+
+ return None
+
+ def expandingDirections(self):
+ return Qt.Orientation(0)
+
+ def hasHeightForWidth(self):
+ return True
+
+ def heightForWidth(self, width):
+ height = self._do_layout(QRect(0, 0, width, 0), True)
+ return height
+
+ def setGeometry(self, rect):
+ super(FlowLayout, self).setGeometry(rect)
+ self._do_layout(rect, False)
+
+ def sizeHint(self):
+ return self.minimumSize()
+
+ def minimumSize(self):
+ size = QSize()
+
+ for item in self._item_list:
+ size = size.expandedTo(item.minimumSize())
+
+ size += QSize(2 * self.contentsMargins().top(), 2 * self.contentsMargins().top())
+ return size
+
+ def _do_layout(self, rect, test_only):
+ x = rect.x()
+ y = rect.y()
+ line_height = 0
+ spacing = self.spacing()
+
+ for item in self._item_list:
+ style = item.widget().style()
+ layout_spacing_x = style.layoutSpacing(
+ QSizePolicy.PushButton, QSizePolicy.PushButton, Qt.Horizontal
+ )
+ layout_spacing_y = style.layoutSpacing(
+ QSizePolicy.PushButton, QSizePolicy.PushButton, Qt.Vertical
+ )
+ space_x = spacing + layout_spacing_x
+ space_y = spacing + layout_spacing_y
+ next_x = x + item.sizeHint().width() + space_x
+ if next_x - space_x > rect.right() and line_height > 0:
+ x = rect.x()
+ y = y + line_height + space_y
+ next_x = x + item.sizeHint().width() + space_x
+ line_height = 0
+
+ if not test_only:
+ item.setGeometry(QRect(QPoint(x, y), item.sizeHint()))
+
+ x = next_x
+ line_height = max(line_height, item.sizeHint().height())
+
+ return y + line_height - rect.y()
diff --git a/plugins/python/workflow_buttons/kritapykrita_workflow_buttons.desktop b/plugins/python/workflow_buttons/kritapykrita_workflow_buttons.desktop
new file mode 100644
index 0000000000..81489bc49e
--- /dev/null
+++ b/plugins/python/workflow_buttons/kritapykrita_workflow_buttons.desktop
@@ -0,0 +1,8 @@
+[Desktop Entry]
+Type=Service
+ServiceTypes=Krita/PythonPlugin
+X-KDE-Library=workflow_buttons
+X-Python-2-Compatible=false
+X-Krita-Manual=Manual.html
+Name=Workflow buttons
+Comment=A Python-based docker to create multi-action buttons to improve your workflow.
diff --git a/plugins/python/workflow_buttons/workflow_buttons.py b/plugins/python/workflow_buttons/workflow_buttons.py
new file mode 100644
index 0000000000..9818b8ac53
--- /dev/null
+++ b/plugins/python/workflow_buttons/workflow_buttons.py
@@ -0,0 +1,154 @@
+# SPDX-FileCopyrightText: 2024 Timothée Giet <[email protected]>
+# Authors:
+# Timothée Giet <[email protected]>
+# SPDX-License-Identifier: GPL-3.0-or-later
+
+from PyQt5.QtCore import QSize
+from PyQt5.QtGui import QIcon, QKeySequence
+from PyQt5.QtWidgets import QWidget, QVBoxLayout, QScrollArea, QToolButton, QShortcut
+from krita import Krita, DockWidget, DockWidgetFactory, DockWidgetFactoryBase, ManagedColor
+from .flow_layout import FlowLayout
+from .buttons_settings_dialog import LISTOFTOOLS, LISTOFSIZES, ButtonsSettingsDialog
+import ast
+
+DOCKER_NAME = 'Workflow buttons'
+DOCKER_ID = 'pykrita_workflow_buttons'
+INSTANCE = Krita.instance()
+
+class WorkflowButtons(DockWidget):
+ def __init__(self):
+ super().__init__()
+ self.setWindowTitle(DOCKER_NAME)
+ self.sizeIndex = 2
+ self.globalButtonSize = QSize(LISTOFSIZES[self.sizeIndex], LISTOFSIZES[self.sizeIndex])
+
+ # all widget and layout setup of the docker
+ mainWidget = QWidget(self)
+ self.setWidget(mainWidget)
+ mainLayout = QVBoxLayout(mainWidget)
+
+ buttonsScrollArea = QScrollArea(mainWidget)
+ buttonsScrollArea.setMinimumSize(self.globalButtonSize)
+ self.buttonsWidget = QWidget(buttonsScrollArea)
+ buttonsScrollArea.setWidgetResizable(True)
+ buttonsScrollArea.setWidget(self.buttonsWidget)
+
+ mainLayout.addWidget(buttonsScrollArea)
+ self.buttonsLayout = FlowLayout(self.buttonsWidget)
+
+ # Edit button setup
+ self.editButton = QToolButton(self.buttonsWidget)
+ self.editButton.setIconSize(self.globalButtonSize)
+ self.editButton.setIcon(INSTANCE.icon('properties'))
+ self.editButton.setToolTip(i18n("Open workflow buttons settings dialog"))
+ self.editButton.clicked.connect(self.openSettingsDialog)
+ self.buttonsLayout.addWidget(self.editButton)
+
+ self.buttonsContentList = []
+ self.readSettings()
+ self.populateButtons()
+
+ def canvasChanged(self, canvas):
+ pass
+
+ def readSettings(self):
+ savedSize = Application.readSetting("workflowbuttons", "buttonsSize", "")
+ if savedSize:
+ self.sizeIndex = int(savedSize)
+ self.refreshButtonsSize()
+ savedList = Application.readSetting("workflowbuttons", "buttons", "")
+ if savedList:
+ self.buttonsContentList = ast.literal_eval(savedList)
+
+ def writeSettings(self):
+ Application.writeSetting("workflowbuttons", "buttonsSize", str(self.sizeIndex))
+ Application.writeSetting("workflowbuttons", "buttons", str(self.buttonsContentList))
+
+ def clearButtons(self):
+ for widget in self.buttonsWidget.children():
+ if isinstance(widget, CustomButton):
+ widget.deleteLater()
+
+ def populateButtons(self):
+ buttonID = -1
+ for buttonToCreate in self.buttonsContentList:
+ buttonID += 1
+ buttonIcon = QIcon(buttonToCreate["icon"])
+ button = CustomButton(self.buttonsWidget, buttonID, buttonToCreate)
+ button.setIconSize(self.globalButtonSize)
+ button.setIcon(buttonIcon)
+ self.buttonsLayout.addWidget(button)
+
+ def refreshButtons(self):
+ self.clearButtons()
+ self.populateButtons()
+
+ def openSettingsDialog(self):
+ newDialog = ButtonsSettingsDialog(self, self.buttonsContentList, self.sizeIndex)
+ newDialog.exec_()
+ if newDialog.result() == 1:
+ self.buttonsContentList = newDialog.buttonsContentList
+ self.sizeIndex = newDialog.sizeIndex
+ self.refreshButtonsSize()
+ self.writeSettings()
+ self.refreshButtons()
+
+ def refreshButtonsSize(self):
+ self.globalButtonSize = QSize(LISTOFSIZES[self.sizeIndex], LISTOFSIZES[self.sizeIndex])
+ self.editButton.setIconSize(self.globalButtonSize)
+
+class CustomButton(QToolButton):
+ # Class to define the custom buttons inside the docker
+ def __init__(self, parent=None, buttonID=-1, values={}):
+ super().__init__(parent)
+ self.buttonID = buttonID
+ self.values = values
+ self.clicked.connect(self.triggeredFunction)
+ if self.values["tooltip"]:
+ self.setToolTip(values["tooltip"])
+
+ def triggeredFunction(self):
+ currentView = INSTANCE.activeWindow().activeView()
+ # select given tool
+ if self.values["toolIndex"] != "":
+ toolIndex = int(self.values["toolIndex"])
+ if(toolIndex > 0 and toolIndex < len(LISTOFTOOLS) - 1):
+ INSTANCE.action(LISTOFTOOLS[int(self.values["toolIndex"])]["toolName"]).trigger()
+
+ # get list of all presets
+ if self.values["presetName"] != "":
+ allBrushPresets = INSTANCE.resources('preset')
+ # find given preset by name
+ brushPreset = allBrushPresets[self.values["presetName"]]
+ # select the brush preset
+ currentView.setCurrentBrushPreset(brushPreset)
+
+ # set given FGColor
+ if self.values["FGColorValues"]["model"] != "":
+ colorToSelect = ManagedColor(self.values["FGColorValues"]["model"],
+ self.values["FGColorValues"]["depth"],
+ self.values["FGColorValues"]["profile"])
+ colorComponents = self.values["FGColorValues"]["components"]
+ colorToSelect.setComponents(colorComponents)
+ currentView.setForeGroundColor(colorToSelect)
+
+ # set given BGColor
+ if self.values["BGColorValues"]["model"] != "":
+ colorToSelect = ManagedColor(self.values["BGColorValues"]["model"],
+ self.values["BGColorValues"]["depth"],
+ self.values["BGColorValues"]["profile"])
+ colorComponents = self.values["BGColorValues"]["components"]
+ colorToSelect.setComponents(colorComponents)
+ currentView.setBackGroundColor(colorToSelect)
+
+ # run extra script
+ if self.values["script"] != "":
+ scriptPath = self.values["script"]
+ exec(open(scriptPath).read())
+
+
+dock_widget_factory = DockWidgetFactory(DOCKER_ID,
+ DockWidgetFactoryBase.DockRight,
+ WorkflowButtons)
+
+INSTANCE.addDockWidgetFactory(dock_widget_factory)