I’m writing GIMP 2.99 python plugins. All of the arguments in a Gimp Procedure are held as an array of GParamSpec instances. I want to assert that each argument value is the type I expect. My problem is that the type information is a GType and it is unclear how to use that in Python to compare types.
For example, I want to know that arg[0] is a “Gimp.RunMode”
def assert_layers_procedure(procedure):
# An array of GParamSpec
procedure_args_raw = procedure.get_arguments()
# The first GParamSpec
arg_zero_raw = procedure_args_raw[0]
# Apparently, arg_zero_type is a "GType GimpRunMode (4194814752)"
arg_zero_type = arg_zero_raw.value_type # type: GObject.GType
if arg_zero_type is not Gimp.RunMode: # Yes, I know this is wrong. What should it be?
raise TypeError('procedure %s argument %d is not the correct type Gimp.RunMode, instead, it is type %s.'
% (proc_name, 0, arg_zero_type))
The TypeError is always raised, because “GType GimpRunMode” is not Gimp.RunMode, nor anything I have guessed at. I don’t know how to obtain a GType of a GIMP class, nor compare GTypes (assuming GType.is_a()) in Python 3.0.
What might work?
Thanks in advance!