GimelStudio / GimelStudio

Non-destructive, node based 2D image editor with an API for custom nodes

Home Page:https://gimelstudio.github.io

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Add cleaner way of adding Properties in API

Correct-Syntax opened this issue · comments

The current way of adding properties is repetitive and a bit messy for more than a few properties. Implement a better, all-in-one AddProperty method to make adding new properties easier and cleaner.

Example pseudo-code snippets:

def AddProperty(idname: str, default, type_: str = "" fpb_label: str = "", expanded: bool = True, visible: bool = False, use_custom_prop: bool = False, custom_prop: Property = None, **kwargs) -> dict:
    if not use_custom_prop:
        if type_ == "String":
            new_prop = api.StringProp(...)
        elif ...
        else:
            return
    else:
        if custom_prop is not None:
            new_prop = custom_prop(...)
        else:
            pass
    
    self.properties[new_prop.IdName] = new_prop
    return self.properties
new_prop = custom_prop(..., **kwargs)

(where ... represents the default parameters like idname, default etc.)

Hey, if you don't mind can you further elaborate on what do mean by "adding Properties to API".

@Nightfurex sorry, I meant adding Properties in the API. (Nodes are created via what we call the API)

Currently, Node Properties are added like so in the node API (the example below is from here):

    def NodeInitProps(self):
        image = api.ImageProp(
            idname="in_image",
        )
        filter_type = api.ChoiceProp(
            idname="filter_type",
            default="Box",
            choices=["Box", "Gaussian"],
            fpb_label="Filter Type"
        )
        kernel = api.VectorProp(
            idname="kernel", 
            default=(5, 5, 0), 
            labels=("Kernel X", "Kernel Y"),
            min_vals=(1, 1, 0), 
            max_vals=(600, 600, 0),
            show_p=False, 
            fpb_label="Blur Kernel"
        )
        self.NodeAddProp(image)
        self.NodeAddProp(filter_type)
        self.NodeAddProp(kernel)

This gets a bit repetitive so we thought a cleaner way to do add properties would be like:

    def NodeInitProps(self):
        self.NodeAddProp(type="image", idname="in_image")
...

If you have ideas or suggestions on how it could be better, we'd love to hear them. 🙂