Changeset View
Changeset View
Standalone View
Standalone View
user_manual/python_scripting/krita_python_plugin_howto.rst
Show First 20 Lines • Show All 98 Lines • ▼ Show 20 Line(s) | |||||
99 | 99 | | |||
100 | Creating an extension | 100 | Creating an extension | ||
101 | --------------------- | 101 | --------------------- | ||
102 | 102 | | |||
103 | `Extensions <https://api.kde.org/extragear-api/graphics-apidocs/krita/libs/libkis/html/classExtension.html>`_ are relatively simple python scripts that run on Krita start. They are made by extending the Extension class, and the most barebones extension looks like this: | 103 | `Extensions <https://api.kde.org/extragear-api/graphics-apidocs/krita/libs/libkis/html/classExtension.html>`_ are relatively simple python scripts that run on Krita start. They are made by extending the Extension class, and the most barebones extension looks like this: | ||
104 | 104 | | |||
105 | .. code:: python | 105 | .. code:: python | ||
106 | 106 | | |||
107 | import sys | | |||
108 | from krita import * | 107 | from krita import * | ||
109 | 108 | | |||
110 | class MyExtension(Extension): | 109 | class MyExtension(Extension): | ||
111 | 110 | | |||
112 | def __init__(self, parent): | 111 | def __init__(self, parent): | ||
113 | #This is initialising the parent, always important when subclassing. | 112 | #This is initialising the parent, always important when subclassing. | ||
114 | super().__init__(parent) | 113 | super().__init__(parent) | ||
115 | 114 | | |||
Show All 40 Lines | 151 | if doc is not None: | |||
156 | # InfoObject is a dictionary with specific export options, but when we make an empty one Krita will use the export defaults. | 155 | # InfoObject is a dictionary with specific export options, but when we make an empty one Krita will use the export defaults. | ||
157 | doc.exportImage(fileName, InfoObject()) | 156 | doc.exportImage(fileName, InfoObject()) | ||
158 | 157 | | |||
159 | 158 | | |||
160 | And add the import for QFileDialog above with the imports: | 159 | And add the import for QFileDialog above with the imports: | ||
161 | 160 | | |||
162 | .. code:: python | 161 | .. code:: python | ||
163 | 162 | | |||
164 | import sys | | |||
165 | from krita import * | 163 | from krita import * | ||
166 | from PyQt5.QtWidgets import QFileDialog | 164 | from PyQt5.QtWidgets import QFileDialog | ||
167 | 165 | | |||
168 | Then, to connect the action to the new export document: | 166 | Then, to connect the action to the new export document: | ||
169 | 167 | | |||
170 | .. code:: python | 168 | .. code:: python | ||
171 | 169 | | |||
172 | def createActions(self, window): | 170 | def createActions(self, window): | ||
▲ Show 20 Lines • Show All 64 Lines • ▼ Show 20 Line(s) | |||||
237 | 235 | | |||
238 | Creating a docker | 236 | Creating a docker | ||
239 | ----------------- | 237 | ----------------- | ||
240 | 238 | | |||
241 | Creating a custom `docker <https://api.kde.org/extragear-api/graphics-apidocs/krita/libs/libkis/html/classDockWidget.html>`_ is much like creating an extension. Dockers are in some ways a little easier, but they also require more use of widgets. This is the barebones docker code: | 239 | Creating a custom `docker <https://api.kde.org/extragear-api/graphics-apidocs/krita/libs/libkis/html/classDockWidget.html>`_ is much like creating an extension. Dockers are in some ways a little easier, but they also require more use of widgets. This is the barebones docker code: | ||
242 | 240 | | |||
243 | .. code:: python | 241 | .. code:: python | ||
244 | 242 | | |||
245 | import sys | | |||
246 | from PyQt5.QtWidgets import * | 243 | from PyQt5.QtWidgets import * | ||
247 | from krita import * | 244 | from krita import * | ||
248 | 245 | | |||
249 | class MyDocker(DockWidget): | 246 | class MyDocker(DockWidget): | ||
250 | 247 | | |||
251 | def __init__(self): | 248 | def __init__(self): | ||
252 | super().__init__() | 249 | super().__init__() | ||
253 | self.setWindowTitle("My Docker") | 250 | self.setWindowTitle("My Docker") | ||
▲ Show 20 Lines • Show All 105 Lines • Show Last 20 Lines |