:right-sidebar: True SpaceDrawer =================================================================== .. currentmodule:: gi.repository.GtkSource .. class:: SpaceDrawer(**properties: ~typing.Any) :no-contents-entry: Superclasses: :class:`~gi.repository.GObject.Object` Represent white space characters with symbols. :obj:`~gi.repository.GtkSource.SpaceDrawer` provides a way to visualize white spaces, by drawing symbols. Call :obj:`~gi.repository.View.get_space_drawer` to get the ``GtkSourceSpaceDrawer`` instance of a certain :obj:`~gi.repository.GtkSource.View`\. By default, no white spaces are drawn because the :obj:`~gi.repository.GtkSource.SpaceDrawer.props.enable_matrix` is :const:`False`. To draw white spaces, :obj:`~gi.repository.SpaceDrawer.set_types_for_locations` can be called to set the :obj:`~gi.repository.GtkSource.SpaceDrawer.props.matrix` property (by default all space types are enabled at all locations). Then call :obj:`~gi.repository.SpaceDrawer.set_enable_matrix`\. For a finer-grained method, there is also the :obj:`~gi.repository.GtkSource.Tag`\'s :obj:`~gi.repository.GtkSource.Tag.props.draw_spaces` property. Example -------------------------------------------------------------------------------- To draw non-breaking spaces everywhere and draw all types of trailing spaces except newlines: .. code-block:: c :dedent: gtk_source_space_drawer_set_types_for_locations (space_drawer, GTK_SOURCE_SPACE_LOCATION_ALL, GTK_SOURCE_SPACE_TYPE_NBSP); gtk_source_space_drawer_set_types_for_locations (space_drawer, GTK_SOURCE_SPACE_LOCATION_TRAILING, GTK_SOURCE_SPACE_TYPE_ALL & ~GTK_SOURCE_SPACE_TYPE_NEWLINE); gtk_source_space_drawer_set_enable_matrix (space_drawer, TRUE); Use-case: draw unwanted white spaces -------------------------------------------------------------------------------- A possible use-case is to draw only unwanted white spaces. Examples: - Draw all trailing spaces. - If the indentation and alignment must be done with spaces, draw tabs. And non-breaking spaces can always be drawn, everywhere, to distinguish them from normal spaces. Constructors ------------ .. rst-class:: interim-class .. class:: SpaceDrawer :no-index: .. classmethod:: new() -> ~gi.repository.GtkSource.SpaceDrawer Creates a new :obj:`~gi.repository.GtkSource.SpaceDrawer` object. Useful for storing space drawing settings independently of a :obj:`~gi.repository.GtkSource.View`\. Methods ------- .. rst-class:: interim-class .. class:: SpaceDrawer :no-index: .. method:: bind_matrix_setting(settings: ~gi.repository.Gio.Settings, key: str, flags: ~gi.repository.Gio.SettingsBindFlags) -> None Binds the :obj:`~gi.repository.GtkSource.SpaceDrawer.props.matrix` property to a :obj:`~gi.repository.Gio.Settings` key. The :obj:`~gi.repository.Gio.Settings` key must be of the same type as the :obj:`~gi.repository.GtkSource.SpaceDrawer.props.matrix` property, that is, ``"au"``\. The :obj:`~gi.repository.Gio.Settings.bind` function cannot be used, because the default GIO mapping functions don't support :obj:`~gi.repository.GLib.Variant` properties (maybe it will be supported by a future GIO version, in which case this function can be deprecated). :param settings: a :obj:`~gi.repository.Gio.Settings` object. :param key: the ``settings`` key to bind. :param flags: flags for the binding. .. method:: get_enable_matrix() -> bool .. method:: get_matrix() -> ~gi.repository.GLib.Variant Gets the value of the :obj:`~gi.repository.GtkSource.SpaceDrawer.props.matrix` property, as a :obj:`~gi.repository.GLib.Variant`\. An empty array can be returned in case the matrix is a zero matrix. The :obj:`~gi.repository.SpaceDrawer.get_types_for_locations` function may be more convenient to use. .. method:: get_types_for_locations(locations: ~gi.repository.GtkSource.SpaceLocationFlags) -> ~gi.repository.GtkSource.SpaceTypeFlags If only one location is specified, this function returns what kind of white spaces are drawn at that location. The value is retrieved from the :obj:`~gi.repository.GtkSource.SpaceDrawer.props.matrix` property. If several locations are specified, this function returns the logical AND for those locations. Which means that if a certain kind of white space is present in the return value, then that kind of white space is drawn at all the specified ``locations``\. :param locations: one or several :obj:`~gi.repository.GtkSource.SpaceLocationFlags`\. .. method:: set_enable_matrix(enable_matrix: bool) -> None Sets whether the :obj:`~gi.repository.GtkSource.SpaceDrawer.props.matrix` property is enabled. :param enable_matrix: the new value. .. method:: set_matrix(matrix: ~gi.repository.GLib.Variant | None = None) -> None Sets a new value to the :obj:`~gi.repository.GtkSource.SpaceDrawer.props.matrix` property, as a :obj:`~gi.repository.GLib.Variant`\. If ``matrix`` is :const:`None`, then an empty array is set. If ``matrix`` is floating, it is consumed. The :obj:`~gi.repository.SpaceDrawer.set_types_for_locations` function may be more convenient to use. :param matrix: the new matrix value, or :const:`None`. .. method:: set_types_for_locations(locations: ~gi.repository.GtkSource.SpaceLocationFlags, types: ~gi.repository.GtkSource.SpaceTypeFlags) -> None Modifies the :obj:`~gi.repository.GtkSource.SpaceDrawer.props.matrix` property at the specified ``locations``\. :param locations: one or several :obj:`~gi.repository.GtkSource.SpaceLocationFlags`\. :param types: a combination of :obj:`~gi.repository.GtkSource.SpaceTypeFlags`\. Properties ---------- .. rst-class:: interim-class .. class:: SpaceDrawer :no-index: .. attribute:: props.enable_matrix :type: bool The type of the None singleton. .. attribute:: props.matrix :type: ~gi.repository.GLib.Variant The type of the None singleton.