Hello I’m following the Krita scripting guide. It says to create a script, use Tools- Scripts- Scripter. But Scripter doesn’t show up in the Scripts menu.
Also how do I know what are the code names of buttons/commands? For example, I have the Levels button on the Krita toolbar and I want to add an icon for it but I don’t know what the name or tag is.
The scriptor is a native plugin so you need to activated it to do that.
as to change the things outside I am not the person to tell you about it but you probably need to build Krita yourself to make that happen, because you will have to hack it otherwise that is not a good option. I would focus on making something than modifying what exists with python.
Krita’s own scripting guide says you can change/add the icons, and shows an example code which is this:
from PyQt5.QtWidgets import QDialog, QHBoxLayout, QPushButton
# add button and layout for button
layoutForButtons = QHBoxLayout()
newButton = QPushButton()
newButton.setIcon( Krita.instance().icon('animation_play') )
#newButton.setText( "Press me" )
layoutForButtons.addWidget(newButton)
# create dialog and show it
newDialog = QDialog()
newDialog.setLayout(layoutForButtons)
newDialog.exec_() # show the dialog
Maybe this plugin helps with finding out some things? I know that at least one user utilized it for the task you named.
Michelist
Thanks. So I see that this inspector is a lot like the developer tools for Firefox, which I’ve used before. So far I’ve found the property QIcon [from QAbstractButton]. But I’m at a loss where to add this code to this:
# add button and layout for button
layoutForButtons = QHBoxLayout()
newButton = QPushButton()
newButton.setIcon( Krita.instance().icon(‘animation_play’) )
#newButton.setText( “Press me” )
layoutForButtons.addWidget(newButton)
Unless I’m supposed to create a new code. All I’m trying to do is add icons to the Text buttons on the toolbar.
Sorry, but I’m no coder, only can juggle with some scripts, but can not support you further with this. It is an aid to help you code and find out many things, but coding you have to learn or know by yourself.
Michelist
Not a coding person myself, just trying to help. You can check here - Krita Scripting School
the page has some instructions for adding icons to buttons. That might help you. Also pinging @ahmet_tabak since they seem to have done some work with custom icon and scripting as shown here - Actuator - Automate Sequences of Actions : Krita Plugin [paid] - #23 by ahmet_tabak
P.S. I also took the liberty to properly add a title to your thread, writing merely “scripting” as title will not get much attention and attract possible answers. This title would also help other people or yourself when you will search for it another time in this forum. I also moved it to proper category.
Thanks. I did check out the Krita scripting school already, and pasted the code in earlier replies. Unfortunately it doesn’t go in depth about icon tags and how to apply them. The plugin you linked to- some people say it doesn’t work. And it was last updated in 2021. For $10, I think i’ll pass for now.
The plugin is not a that I was suggesting. In that thread someone has done custom icon and I pinged them here, hoping that they will answer your query.
Sorry for the late response (been busy and for some reason my browser notifications broke, shrug), not sure if you found your issue or not. But the Developer Tools has a “Get Code” button. Which generates code to get to that item(albeit it isn’t 100% but works most of the time and gives you hints)
For changing icons, the video for the plugin literally shows an example of how to change an icon
I don’t know why people think scripting is easy. But this is what I got from the Get Code button:
qwin = Krita.instance().activeWindow().qwindow()
pobj = qwin.findChild(QToolBar,'mainToolBar')
# TODO QToolBar > QToolButton
I still don’t know how to work with that. All this tells me are tags that I do not know where to put anywhere to edit icons. What video? I saw no video at the github page. For developer tools?
The video was in the post itself, but the button you want to get is a bit more tricky since it has no name to go of.
Assuming you are on english language setting, you can do this:
from krita import *
qwin = Krita.instance().activeWindow().qwindow()
pobj = qwin.findChild(QToolBar,'mainToolBar')
for child in pobj.findChildren(QToolButton):
if child.text() == 'Levels':
child.setIcon( Krita.instance().icon('animation_play') )
You run it either in Script->Scripter or in Console
Okay. So now I edited the Levels button to have a custom icon. How do I get Krita to load the script automatically? And how do I remove the Levels text?
some tips:
plugin developer plugin is good for hunting down names for krita i con set.
QToolbutton QPushButton have setIcon method.
nameofbutton.setIcon(icon)
icon is an object of type QIcon i think… so you can get one of the set krita icon by
Krita.instance().icon(‘name of krita icon’)
ie . Krita.instance().icon(‘view-list-text’)
so something like
nameofbutton.setIcon( Krita.instance().icon(‘view-list-text’) )
refer to @KnowZero example.
Now for custom icons - thats a bit more work. I only have experience in making sets from svg.
for that I followed Krita style of svg as much as possible.
Which is create 22x22 px svg icon set and save them in a folder inside your plugin. [one for light background one for dark]
Also you need to create a custom class, to pick up the image, this include a dictionary of name a method that will make the svg become QIcon. It helps if you pattern it to krita with the icon method returning an icon object.
converting an svg to QIcon:
QIcon icon1 = QIcon()
icon1.addFile(path_to_icon_file, size_of_icon)
if you are interested with custom icons, I can offer my plugin CompactBrushToggler as reference. I have a class name CBT_Icon that can be use to pattern your code.
Won’t it be simpler to put it in an action-file? If I have understood it right, all this was “only” about to give an action an icon for a representation with a smaller “footprint” of that action in a toolbar (so instead of text). If I’m right, there is no plugin that needs icons. But I may be wrong and there will be a plugin, @Kracov?
Michelist
@Michelist
Possibly. But there might be a button or two that needs custom icons. Although I could probably use the default icons. Anyway, how do I create action files? The scripting school is pretty hard to follow.
Okay, the custom icons must of course first be “made known” to Krita in order to access them. There may be other ways, but I would have to learn programming first. I’ll better stick to juggling scripts then. ![]()
Michelist
action files are the easiest also using krita icon set.
I added my plugin specially the cbt_icon class as I feel OP would like to experiment with custom icons. cbt_icon class I coded can be used even without a docker since its just make the svg file to qicon and provide a way to easily pick up the one you wanted in similar manner to krita’s native way.
for me i just create filename.action with this code pattern inside and save beside my file.
<?xml version="1.0" encoding="UTF-8"?>
<ActionCollection version="2" name="Scripts">
<Actions category="Scripts">
<text>Custom Action</text>
<Action name="set_stabilizer_brush_smoothing">
<icon>smoothing-stabilizer</icon>
<text>Brush Smoothing: Stabilizer</text>
<whatsThis/>
<toolTip>Brush Smoothing: Stabilizer</toolTip>
<iconText>Brush Smoothing: Stabilizer</iconText>
<shortcut/>
<isCheckable>false</isCheckable>
<statusTip/>
</Action>
</Actions>
</ActionCollection>
Yep, that is what I did so far, I’m a very lazy guy, why reinvent the wheel when it is already there?
Michelist