![]() |
Converting the API doc to Python - Printable Version +- Gimp-Forum.net (https://www.gimp-forum.net) +-- Forum: GIMP (https://www.gimp-forum.net/Forum-GIMP) +--- Forum: Tutorials and tips (https://www.gimp-forum.net/Forum-Tutorials-and-tips) +--- Thread: Converting the API doc to Python (/Thread-Converting-the-API-doc-to-Python) |
Converting the API doc to Python - Ofnuts - 04-03-2025 A little bit of C. In C you have two kinds of data types.
Code: gboolean Where GimpDrawable is a "complex" type, and gboolean and gint are "native" type (just names for machine-size integers). * the function returns a boolean * the first argument is a pointer/reference to GimpDrawable. Since GimpDrawable is a complex type it is a simple "input" argument. * offset_x and offset_y are references to native types, and so are outputs to the function. In Python your inputs are immutable, so this is converted to extra return values, and the method returns a tuple. So this would be called as: boolean_success, offset_x,offset_y= get_offsets(layer: Gimp.Drawable) But since the first argument is of the type described, in Python this method call on a Gimp.Drawable object, so it is passed implicitly when calling the method. boolean_success, offset_x,offset_y= layer.get_offsets() The returned boolean here is a bit artificial. This is probably because the method has to use output arguments to return X and Y, so this is the only way to check that the memory locations passed for the offsets have been updated. This can still be ignored in the vast majority of cases by writing: _, offset_x,offset_y= layer.get_offsets() where _ is the Python convention to indicate that you don't really care about this value. Slightly harder: Code: GimpLayer*
def get_layer_by_name(name: str) -> Gimp.Layer Raising the bar: Code: GimpLayer ** Here the call return a pointer to a pointer to GimpLayer... this is really a pointer to an array of GimpLayer, so for Python just a list of Gimp.Layer. So this is just: def get_selected_layers() -> list[Gimp.Layer] Gotcha: Note that some calls are defined as functions and not as object methods. For instance: Code: gboolean This is a plain function in the Gimp namespace that takes 4 explicit arguments. |