Coding Reference
Quick Start
from studio.custom_block import *
try:
import numpy as np
except ImportError:
np = None
class Example_Block(Block):
op_code = "Example_Block" # Must match the class name
def init(self) -> None:
self.width = 200
self.height = 150
self.tooltip = "Adds a constant to the input image."
# Socket names become keys for self.input[...] and self.output[...]
self.input_sockets = [SocketTypes.ImageAny("Input Image")]
self.output_sockets = [SocketTypes.ImageAny("Output Image")]
# Components are stored by name in self.param
self.param["Increment"] = TextInput(
text="1",
place_holder="integer",
tool_tip="Value added to every pixel.",
)
def run(self) -> None:
if np is None:
return
img = self.input["Input Image"].data
inc = int(self.param["Increment"].value)
self.output["Output Image"].data = img + inc
add_block(Example_Block.op_code, Example_Block)
Bootstrap Phase
Mandatory Imports
Importing Community Modules
Class Definition
Core Attributes & Methods
Block.op_code: str
Block.op_code: strBlock.tooltip: str
Block.tooltip: str
Block.init(self) -> None
Block.init(self) -> NoneBlock.run(self) -> None
Block.run(self) -> NoneSockets & Data Flow
Block.input_sockets: list[SocketType]
Block.input_sockets: list[SocketType]Block.output_sockets: list[SocketType]
Block.output_sockets: list[SocketType]Block.input: dict[str, object]
Block.input: dict[str, object]Block.output: dict[str, object]
Block.output: dict[str, object]Components (Block UI)
Block.param: dict[str, Component]
Block.param: dict[str, Component]Resource Paths
Block.register_resource(name: str = "", path: str = "") -> str
Block.register_resource(name: str = "", path: str = "") -> strArgument
Meaning
Block.get_resource(name: str = "") -> str
Block.get_resource(name: str = "") -> strFile Dialogs
QAFileDialog
QAFileDialogQAFileDialog.getOpenFileName(**kwargs)
QAFileDialog.getOpenFileName(**kwargs)Argument
Meaning
QAFileDialog.getExistingDirectory(**kwargs)
QAFileDialog.getExistingDirectory(**kwargs)Argument
Meaning
Registration
add_block(My_Block.op_code, My_Block)
add_block(My_Block.op_code, My_Block)Last updated