:right-sidebar: True TypeModule =================================================================== .. currentmodule:: gi.repository.GObject .. class:: TypeModule(**properties: ~typing.Any) :no-contents-entry: Superclasses: :class:`~gi.repository.GObject.Object` Implemented Interfaces: :class:`~gi.repository.GObject.TypePlugin` ``GTypeModule`` provides a simple implementation of the ``GTypePlugin`` interface. The model of ``GTypeModule`` is a dynamically loaded module which implements some number of types and interface implementations. When the module is loaded, it registers its types and interfaces using :obj:`~gi.repository.GObject.TypeModule.register_type` and :obj:`~gi.repository.GObject.TypeModule.add_interface`\. As long as any instances of these types and interface implementations are in use, the module is kept loaded. When the types and interfaces are gone, the module may be unloaded. If the types and interfaces become used again, the module will be reloaded. Note that the last reference cannot be released from within the module code, since that would lead to the caller's code being unloaded before ``g_object_unref()`` returns to it. Keeping track of whether the module should be loaded or not is done by using a use count - it starts at zero, and whenever it is greater than zero, the module is loaded. The use count is maintained internally by the type system, but also can be explicitly controlled by :obj:`~gi.repository.GObject.TypeModule.use` and :obj:`~gi.repository.GObject.TypeModule.unuse`\. Typically, when loading a module for the first type, ``g_type_module_use()`` will be used to load it so that it can initialize its types. At some later point, when the module no longer needs to be loaded except for the type implementations it contains, ``g_type_module_unuse()`` is called. ``GTypeModule`` does not actually provide any implementation of module loading and unloading. To create a particular module type you must derive from ``GTypeModule`` and implement the load and unload functions in ``GTypeModuleClass``\. Methods ------- .. rst-class:: interim-class .. class:: TypeModule :no-index: .. method:: add_interface(instance_type: ~gobject.GType, interface_type: ~gobject.GType, interface_info: ~gi.repository.GObject.InterfaceInfo) -> None Registers an additional interface for a type, whose interface lives in the given type plugin. If the interface was already registered for the type in this plugin, nothing will be done. As long as any instances of the type exist, the type plugin will not be unloaded. Since 2.56 if ``module`` is :const:`None` this will call :func:`~gi.repository.GObject.type_add_interface_static` instead. This can be used when making a static build of the module. :param instance_type: type to which to add the interface. :param interface_type: interface type to add :param interface_info: type information structure .. method:: do_load(self) -> bool .. method:: do_unload(self) -> None .. method:: register_enum(name: str, const_static_values: ~gi.repository.GObject.EnumValue) -> ~gobject.GType Looks up or registers an enumeration that is implemented with a particular type plugin. If a type with name ``type_name`` was previously registered, the :obj:`~gi.repository.GObject.Type` identifier for the type is returned, otherwise the type is newly registered, and the resulting :obj:`~gi.repository.GObject.Type` identifier returned. As long as any instances of the type exist, the type plugin will not be unloaded. Since 2.56 if ``module`` is :const:`None` this will call :func:`~gi.repository.GObject.type_register_static` instead. This can be used when making a static build of the module. .. versionadded:: 2.6 :param name: name for the type :param const_static_values: an array of :obj:`~gi.repository.GObject.EnumValue` structs for the possible enumeration values. The array is terminated by a struct with all members being 0. .. method:: register_flags(name: str, const_static_values: ~gi.repository.GObject.FlagsValue) -> ~gobject.GType Looks up or registers a flags type that is implemented with a particular type plugin. If a type with name ``type_name`` was previously registered, the :obj:`~gi.repository.GObject.Type` identifier for the type is returned, otherwise the type is newly registered, and the resulting :obj:`~gi.repository.GObject.Type` identifier returned. As long as any instances of the type exist, the type plugin will not be unloaded. Since 2.56 if ``module`` is :const:`None` this will call :func:`~gi.repository.GObject.type_register_static` instead. This can be used when making a static build of the module. .. versionadded:: 2.6 :param name: name for the type :param const_static_values: an array of :obj:`~gi.repository.GObject.FlagsValue` structs for the possible flags values. The array is terminated by a struct with all members being 0. .. method:: register_type(parent_type: ~gobject.GType, type_name: str, type_info: ~gi.repository.GObject.TypeInfo, flags: ~gi.repository.GObject.TypeFlags) -> ~gobject.GType Looks up or registers a type that is implemented with a particular type plugin. If a type with name ``type_name`` was previously registered, the :obj:`~gi.repository.GObject.Type` identifier for the type is returned, otherwise the type is newly registered, and the resulting :obj:`~gi.repository.GObject.Type` identifier returned. When reregistering a type (typically because a module is unloaded then reloaded, and reinitialized), ``module`` and ``parent_type`` must be the same as they were previously. As long as any instances of the type exist, the type plugin will not be unloaded. Since 2.56 if ``module`` is :const:`None` this will call :func:`~gi.repository.GObject.type_register_static` instead. This can be used when making a static build of the module. :param parent_type: the type for the parent class :param type_name: name for the type :param type_info: type information structure :param flags: flags field providing details about the type .. method:: set_name(name: str) -> None Sets the name for a :obj:`~gi.repository.GObject.TypeModule` :param name: a human-readable name to use in error messages. .. method:: unuse() -> None Decreases the use count of a :obj:`~gi.repository.GObject.TypeModule` by one. If the result is zero, the module will be unloaded. (However, the :obj:`~gi.repository.GObject.TypeModule` will not be freed, and types associated with the :obj:`~gi.repository.GObject.TypeModule` are not unregistered. Once a :obj:`~gi.repository.GObject.TypeModule` is initialized, it must exist forever.) .. method:: use() -> bool Increases the use count of a :obj:`~gi.repository.GObject.TypeModule` by one. If the use count was zero before, the plugin will be loaded. If loading the plugin fails, the use count is reset to its prior value. Virtual Methods --------------- .. rst-class:: interim-class .. class:: TypeModule :no-index: .. method:: do_load() -> bool The type of the None singleton. .. method:: do_unload() -> None The type of the None singleton. Fields ------ .. rst-class:: interim-class .. class:: TypeModule :no-index: .. attribute:: interface_infos .. attribute:: name The name of the module .. attribute:: parent_instance .. attribute:: type_infos .. attribute:: use_count