Krita Source Code Documentation
Loading...
Searching...
No Matches
krita_script_starter.krita_script_starter Namespace Reference

Classes

class  KritaScriptStarter
 

Functions

 load_ui (ui_file)
 

Variables

 app = QApplication([])
 
str CLASS_NAME = "class_name"
 
bool CONTEXT_KRITA = True
 
str DESKTOP_TEMPLATE
 
str DOCKER_TEMPLATE
 
 EXTENSION = krita.Extension
 
 extension = KritaScriptStarter(None)
 
str EXTENSION_TEMPLATE
 
str INIT_TEMPLATE_DOCKER
 
str INIT_TEMPLATE_EXTENSION
 
str KRITA_ID = "krita_id"
 
str LIBRARY_NAME = "library_name"
 
str MAIN_KRITA_ID = "Krita Script Starter"
 
str MAIN_KRITA_MENU_ENTRY = "Krita Script Starter"
 
str MANUAL_TEMPLATE
 
str MENU_ENTRY = "menu_entry"
 
str PYTHON_FILE_NAME = "python_file"
 
str SCRIPT_COMMENT = "script_comment"
 
str SCRIPT_DOCKER = "Docker`"
 
str SCRIPT_EXTENSION = "Extension"
 
str SCRIPT_NAME = "script_name"
 
str SCRIPT_SETTINGS = 'python'
 
str SCRIPT_TYPE = "script_type"
 
bool TESTING = False
 
str UI_FILE = "bbdkss.ui"
 

Detailed Description

BBD's Krita script starter

This script does the boring stuff involved in creating a script for Krita.
it creates
* a directory for the script in the correct Krita resources subdirectory,
* populates that directory with:
-- a __init__.py file,
-- a skeleton file for the script proper
-- a Manual.html file
* creates a .desktop file for the script
It also:
* correctly imports the script proper nto __init__.py, creates
* creates basic skeleton code depending on whether the script is intended
to be an extension or a docker
* creates skeleton code in the Manual.html file
* (optionally) automatically enables the script in the Krita menu

Script can be run from the command line. This can be used to
bootstrap the script into a Krita menu entry - create a new script
called Krita Script Starter, then copy the script (and the .ui file)
into the directory you have just created, overwriting the existing
files.

BBD
16 March 2018

Function Documentation

◆ load_ui()

krita_script_starter.krita_script_starter.load_ui ( ui_file)
If this script has been distributed with a ui file in the same
directory, then find that directory (since it will likely be
different from krita's current working directory) and use that to
load the ui file.

return the loaded ui

Definition at line 80 of file krita_script_starter.py.

80def load_ui(ui_file):
81 """If this script has been distributed with a ui file in the same
82 directory, then find that directory (since it will likely be
83 different from krita's current working directory) and use that to
84 load the ui file.
85
86 return the loaded ui
87 """
88 abs_path = os.path.dirname(os.path.realpath(__file__))
89 ui_file = os.path.join(abs_path, UI_FILE)
90 return uic.loadUi(ui_file)
91
92

Variable Documentation

◆ app

krita_script_starter.krita_script_starter.app = QApplication([])

Definition at line 419 of file krita_script_starter.py.

◆ CLASS_NAME

str krita_script_starter.krita_script_starter.CLASS_NAME = "class_name"

Definition at line 65 of file krita_script_starter.py.

◆ CONTEXT_KRITA

bool krita_script_starter.krita_script_starter.CONTEXT_KRITA = True

Definition at line 44 of file krita_script_starter.py.

◆ DESKTOP_TEMPLATE

str krita_script_starter.krita_script_starter.DESKTOP_TEMPLATE
Initial value:
1= """[Desktop Entry]
2Type=Service
3ServiceTypes=Krita/PythonPlugin
4X-KDE-Library={library_name}
5X-Krita-Manual=Manual.html
6Name={script_name}
7Comment={script_comment}
8"""

Definition at line 93 of file krita_script_starter.py.

◆ DOCKER_TEMPLATE

str krita_script_starter.krita_script_starter.DOCKER_TEMPLATE
Initial value:
1= """#BBD's Krita Script Starter Feb 2018
2from krita import DockWidget, DockWidgetFactory, DockWidgetFactoryBase
3
4DOCKER_NAME = '{script_name}'
5DOCKER_ID = '{krita_id}'
6
7
8class {class_name}(DockWidget):
9
10 def __init__(self):
11 super().__init__()
12 self.setWindowTitle(DOCKER_NAME)
13
14 def canvasChanged(self, canvas):
15 pass
16
17
18instance = Krita.instance()
19dock_widget_factory = DockWidgetFactory(DOCKER_ID,
20 DockWidgetFactoryBase.DockPosition.DockRight,
21 {class_name})
22
23instance.addDockWidgetFactory(dock_widget_factory)
24"""

Definition at line 144 of file krita_script_starter.py.

◆ EXTENSION

krita_script_starter.krita_script_starter.EXTENSION = krita.Extension

Definition at line 45 of file krita_script_starter.py.

◆ extension

krita_script_starter.krita_script_starter.extension = KritaScriptStarter(None)

Definition at line 421 of file krita_script_starter.py.

◆ EXTENSION_TEMPLATE

str krita_script_starter.krita_script_starter.EXTENSION_TEMPLATE
Initial value:
1= """# BBD's Krita Script Starter Feb 2018
2
3from krita import Extension
4
5EXTENSION_ID = '{krita_id}'
6MENU_ENTRY = '{menu_entry}'
7
8
9class {class_name}(Extension):
10
11 def __init__(self, parent):
12 # Always initialise the superclass.
13 # This is necessary to create the underlying C++ object
14 super().__init__(parent)
15
16 def setup(self):
17 pass
18
19 def createActions(self, window):
20 action = window.createAction(EXTENSION_ID, MENU_ENTRY, "tools/scripts")
21 # parameter 1 = the name that Krita uses to identify the action
22 # parameter 2 = the text to be added to the menu entry for this script
23 # parameter 3 = location of menu entry
24 action.triggered.connect(self.action_triggered)
25
26 def action_triggered(self):
27 pass # your active code goes here.
28"""

Definition at line 115 of file krita_script_starter.py.

◆ INIT_TEMPLATE_DOCKER

str krita_script_starter.krita_script_starter.INIT_TEMPLATE_DOCKER
Initial value:
1= """from .{library_name} import {class_name}
2"""

Definition at line 111 of file krita_script_starter.py.

◆ INIT_TEMPLATE_EXTENSION

str krita_script_starter.krita_script_starter.INIT_TEMPLATE_EXTENSION
Initial value:
1= """from .{library_name} import {class_name}
2
3# And add the extension to Krita's list of extensions:
4app = Krita.instance()
5# Instantiate your class:
6extension = {class_name}(parent = app)
7app.addExtension(extension)
8"""

Definition at line 102 of file krita_script_starter.py.

◆ KRITA_ID

str krita_script_starter.krita_script_starter.KRITA_ID = "krita_id"

Definition at line 60 of file krita_script_starter.py.

◆ LIBRARY_NAME

str krita_script_starter.krita_script_starter.LIBRARY_NAME = "library_name"

Definition at line 61 of file krita_script_starter.py.

◆ MAIN_KRITA_ID

str krita_script_starter.krita_script_starter.MAIN_KRITA_ID = "Krita Script Starter"

Definition at line 55 of file krita_script_starter.py.

◆ MAIN_KRITA_MENU_ENTRY

str krita_script_starter.krita_script_starter.MAIN_KRITA_MENU_ENTRY = "Krita Script Starter"

Definition at line 56 of file krita_script_starter.py.

◆ MANUAL_TEMPLATE

str krita_script_starter.krita_script_starter.MANUAL_TEMPLATE
Initial value:
1= """<?xml version="1.0" encoding="utf-8"?>
2<!DOCTYPE html>
3
4<html xmlns="http://www.w3.org/1999/xhtml">
5<!--BBD's Krita Script Starter, Feb 2018 -->
6<head><title>{script_name}</title>
7</head>
8<body>
9<h3>{script_name}</h3>
10Tell people about what your script does here.
11This is an html document so you can format it with html tags.
12<h3>Usage</h3>
13Tell people how to use your script here.
14
15</body>
16</html>"""

Definition at line 169 of file krita_script_starter.py.

◆ MENU_ENTRY

str krita_script_starter.krita_script_starter.MENU_ENTRY = "menu_entry"

Definition at line 62 of file krita_script_starter.py.

◆ PYTHON_FILE_NAME

str krita_script_starter.krita_script_starter.PYTHON_FILE_NAME = "python_file"

Definition at line 64 of file krita_script_starter.py.

◆ SCRIPT_COMMENT

str krita_script_starter.krita_script_starter.SCRIPT_COMMENT = "script_comment"

Definition at line 59 of file krita_script_starter.py.

◆ SCRIPT_DOCKER

str krita_script_starter.krita_script_starter.SCRIPT_DOCKER = "Docker`"

Definition at line 73 of file krita_script_starter.py.

◆ SCRIPT_EXTENSION

str krita_script_starter.krita_script_starter.SCRIPT_EXTENSION = "Extension"

Definition at line 72 of file krita_script_starter.py.

◆ SCRIPT_NAME

str krita_script_starter.krita_script_starter.SCRIPT_NAME = "script_name"

Definition at line 58 of file krita_script_starter.py.

◆ SCRIPT_SETTINGS

str krita_script_starter.krita_script_starter.SCRIPT_SETTINGS = 'python'

Definition at line 75 of file krita_script_starter.py.

◆ SCRIPT_TYPE

str krita_script_starter.krita_script_starter.SCRIPT_TYPE = "script_type"

Definition at line 63 of file krita_script_starter.py.

◆ TESTING

bool krita_script_starter.krita_script_starter.TESTING = False

Definition at line 53 of file krita_script_starter.py.

◆ UI_FILE

str krita_script_starter.krita_script_starter.UI_FILE = "bbdkss.ui"

Definition at line 77 of file krita_script_starter.py.