Référence de codage
Démarrage rapide
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)Phase d'amorçage
Importations obligatoires
Importation de modules communautaires
Définition de la classe
Attributs & méthodes principaux
Block.op_code: str
Block.op_code: strBlock.tooltip: str
Block.tooltip: strBlock.init(self) -> None
Block.init(self) -> NoneBlock.run(self) -> None
Block.run(self) -> NoneSockets et flux de données
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]Composants (UI du bloc)
Block.param: dict[str, Component]
Block.param: dict[str, Component]Chemins de ressources
Block.register_resource(name: str = "", path: str = "") -> str
Block.register_resource(name: str = "", path: str = "") -> strArgument
Signification
Block.get_resource(name: str = "") -> str
Block.get_resource(name: str = "") -> strDialogues de fichiers
QAFileDialog
QAFileDialogQAFileDialog.getOpenFileName(**kwargs)
QAFileDialog.getOpenFileName(**kwargs)Argument
Signification
QAFileDialog.getExistingDirectory(**kwargs)
QAFileDialog.getExistingDirectory(**kwargs)Argument
Signification
Enregistrement
add_block(My_Block.op_code, My_Block)
add_block(My_Block.op_code, My_Block)Mis à jour