Class#
Superclasses: Object
A JSSClass represents a custom JavaScript class registered by the user in a Context.
It allows to create new JavaScripts objects whose instances are created by the user using
this API.
It’s possible to add constructors, properties and methods for a JSSClass by providing
Callback<!– –>s to implement them.
Methods#
- class Class
- add_constructor(name: str | None, callback: Callable[[], None], user_data: Any, return_type: GType, parameter_types: list[GType] | None = None) Value#
Add a constructor to
jsc_class. IfnameisNone, the class name will be used. When <function>new</function> is used with the constructor orconstructor_call()is called,callbackis invoked receiving the parameters anduser_dataas the last parameter. When the constructor object is cleared in theClasscontext,destroy_notifyis called withuser_dataas parameter.This function creates the constructor, which needs to be added to an object as a property to be able to use it. Use
set_value()to make the constructor available in the global object.Note that the value returned by
callbackis adopted byjsc_class, and theDestroyNotifypassed toregister_class()is responsible for disposing of it.- Parameters:
name – the constructor name or
Nonecallback – a
Callbackto be called to create an instance ofjsc_classuser_data – user data to pass to
callbackreturn_type – the
Typeof the constructor return valueparameter_types
- add_constructor_variadic(name: str | None, callback: Callable[[], None], user_data: Any, return_type: GType) Value#
Add a constructor to
jsc_class. IfnameisNone, the class name will be used. When <function>new</function> is used with the constructor orconstructor_call()is called,callbackis invoked receiving aGPtrArrayofValue<!– –>s as arguments anduser_dataas the last parameter. When the constructor object is cleared in theClasscontext,destroy_notifyis called withuser_dataas parameter.This function creates the constructor, which needs to be added to an object as a property to be able to use it. Use
set_value()to make the constructor available in the global object.Note that the value returned by
callbackis adopted byjsc_class, and theDestroyNotifypassed toregister_class()is responsible for disposing of it.- Parameters:
name – the constructor name or
Nonecallback – a
Callbackto be called to create an instance ofjsc_classuser_data – user data to pass to
callbackreturn_type – the
Typeof the constructor return value
- add_method(name: str, callback: Callable[[], None], user_data: Any, return_type: GType, parameter_types: list[GType] | None = None) None#
Add method with
nametojsc_class. When the method is called by JavaScript orobject_invoke_method(),callbackis called receiving the class instance as first parameter, followed by the method parameters and thenuser_dataas last parameter. When the method is cleared in theClasscontext,destroy_notifyis called withuser_dataas parameter.Note that the value returned by
callbackmust be transfer full. In case of non-refcounted boxed types, you should use %G_TYPE_POINTER instead of the actual boxedTypeto ensure that the instance owned byClassis used. If you really want to return a new copy of the boxed type, useJSC_TYPE_VALUEand return aValuecreated withnew_object()that receives the copy as the instance parameter.- Parameters:
name – the method name
callback – a
Callbackto be called to invoke methodnameofjsc_classuser_data – user data to pass to
callbackreturn_type – the
Typeof the method return value, or %G_TYPE_NONE if the method is void.parameter_types
- add_method_variadic(name: str, callback: Callable[[], None], user_data: Any, return_type: GType) None#
Add method with
nametojsc_class. When the method is called by JavaScript orobject_invoke_method(),callbackis called receiving the class instance as first parameter, followed by aGPtrArrayofValue<!– –>s with the method arguments and thenuser_dataas last parameter. When the method is cleared in theClasscontext,destroy_notifyis called withuser_dataas parameter.Note that the value returned by
callbackmust be transfer full. In case of non-refcounted boxed types, you should use %G_TYPE_POINTER instead of the actual boxedTypeto ensure that the instance owned byClassis used. If you really want to return a new copy of the boxed type, useJSC_TYPE_VALUEand return aValuecreated withnew_object()that receives the copy as the instance parameter.- Parameters:
name – the method name
callback – a
Callbackto be called to invoke methodnameofjsc_classuser_data – user data to pass to
callbackreturn_type – the
Typeof the method return value, or %G_TYPE_NONE if the method is void.
- add_property(name: str, property_type: GType, getter: Callable[[], None] | None = None, setter: Callable[[], None] | None = None, user_data: Any = None) None#
Add a property with
nametojsc_class. When the property value needs to be getted,getteris called receiving the the class instance as first parameter anduser_dataas last parameter. When the property value needs to be set,setteris called receiving the the class instance as first parameter, followed by the value to be set and thenuser_dataas the last parameter. When the property is cleared in theClasscontext,destroy_notifyis called withuser_dataas parameter.Note that the value returned by
gettermust be transfer full. In case of non-refcounted boxed types, you should use %G_TYPE_POINTER instead of the actual boxedTypeto ensure that the instance owned byClassis used. If you really want to return a new copy of the boxed type, useJSC_TYPE_VALUEand return aValuecreated withnew_object()that receives the copy as the instance parameter.- Parameters:
name – the property name
property_type – the
Typeof the property valuegetter – a
Callbackto be called to get the property valuesetter – a
Callbackto be called to set the property valueuser_data – user data to pass to
getterandsetter