GtkSource.SpaceDrawer¶
- Subclasses:
None
Methods¶
- Inherited:
- Structs:
class |
|
|
|
|
|
|
|
|
|
|
|
|
Virtual Methods¶
- Inherited:
Properties¶
Name |
Type |
Flags |
Short Description |
|---|---|---|---|
r/w/c |
|||
r/w/c |
Signals¶
- Inherited:
Fields¶
- Inherited:
Class Details¶
- class GtkSource.SpaceDrawer(**kwargs)¶
- Bases:
- Abstract:
No
- Structure:
Represent white space characters with symbols.
GtkSource.SpaceDrawerprovides a way to visualize white spaces, by drawing symbols.Call [method`View`.get_space_drawer] to get the
GtkSourceSpaceDrawerinstance of a certain [class`View`].By default, no white spaces are drawn because the [property`SpaceDrawer`:py:data::enable-matrix<GtkSource.SpaceDrawer.props.enable_matrix>] is
False.To draw white spaces, [method`SpaceDrawer`.set_types_for_locations] can be called to set the [property`SpaceDrawer`:py:data::matrix<GtkSource.SpaceDrawer.props.matrix>] property (by default all space types are enabled at all locations). Then call [method`SpaceDrawer`.set_enable_matrix].
For a finer-grained method, there is also the [class`Tag`]’s [property`Tag`:py:data::draw-spaces<GtkSource.SpaceDrawer.props.draw_spaces>] property.
- Example
To draw non-breaking spaces everywhere and draw all types of trailing spaces except newlines: ```c
GtkSource.SpaceDrawer.set_types_for_locations(space_drawer,GtkSource.SpaceLocationFlags.ALL,GtkSource.SpaceTypeFlags.NBSP);GtkSource.SpaceDrawer.set_types_for_locations(space_drawer,GtkSource.SpaceLocationFlags.TRAILING,GtkSource.SpaceTypeFlags.ALL& ~:obj:GtkSource.SpaceTypeFlags.NEWLINE);GtkSource.SpaceDrawer.set_enable_matrix(space_drawer,True); `` ``python space_drawer.set_types_for_locations( locations=GtkSource.SpaceLocationFlags.ALL, types=GtkSource.SpaceTypeFlags.NBSP, )all_types_except_newline = GtkSource.SpaceTypeFlags( int(GtkSource.SpaceTypeFlags.ALL) & ~int(GtkSource.SpaceTypeFlags.NEWLINE) ) space_drawer.set_types_for_locations( locations=GtkSource.SpaceLocationFlags.TRAILING, types=all_types_except_newline, )
space_drawer.set_enable_matrix(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.
- classmethod new()¶
- Returns:
a new
GtkSource.SpaceDrawer.- Return type:
Creates a new
GtkSource.SpaceDrawerobject.Useful for storing space drawing settings independently of a [class`View`].
- bind_matrix_setting(settings, key, flags)¶
- Parameters:
settings (
Gio.Settings) – aGio.Settingsobject.key (
str) – the settings key to bind.flags (
Gio.SettingsBindFlags) – flags for the binding.
Binds the [property`SpaceDrawer`:py:data::matrix<GtkSource.SpaceDrawer.props.matrix>] property to a [class`Gio`.Settings] key.
The [class`Gio`.Settings] key must be of the same type as the [property`SpaceDrawer`:py:data::matrix<GtkSource.SpaceDrawer.props.matrix>] property, that is,
"au".The [method`Gio`.Settings.bind] function cannot be used, because the default GIO mapping functions don’t support [struct`GLib`.Variant] properties (maybe it will be supported by a future GIO version, in which case this function can be deprecated).
- get_enable_matrix()¶
- Returns:
whether the
GtkSource.SpaceDrawer:matrixproperty is enabled.- Return type:
- get_matrix()¶
- Returns:
the
GtkSource.SpaceDrawer:matrixvalue as a new floatingGLib.Variantinstance.- Return type:
Gets the value of the [property`SpaceDrawer`:py:data::matrix<GtkSource.SpaceDrawer.props.matrix>] property, as a [struct`GLib`.Variant].
An empty array can be returned in case the matrix is a zero matrix.
The [method`SpaceDrawer`.get_types_for_locations] function may be more convenient to use.
- get_types_for_locations(locations)¶
- Parameters:
locations (
GtkSource.SpaceLocationFlags) – one or severalGtkSource.SpaceLocationFlags.- Returns:
a combination of
GtkSource.SpaceTypeFlags.- Return type:
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 [property`SpaceDrawer`:py:data::matrix<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.
- set_enable_matrix(enable_matrix)¶
- Parameters:
enable_matrix (
bool) – the new value.
Sets whether the [property`SpaceDrawer`:py:data::matrix<GtkSource.SpaceDrawer.props.matrix>] property is enabled.
- set_matrix(matrix)¶
- Parameters:
matrix (
GLib.VariantorNone) – the new matrix value, orNone.
Sets a new value to the [property`SpaceDrawer`:py:data::matrix<GtkSource.SpaceDrawer.props.matrix>] property, as a [struct`GLib`.Variant].
If matrix is
None, then an empty array is set.If matrix is floating, it is consumed.
The [method`SpaceDrawer`.set_types_for_locations] function may be more convenient to use.
- set_types_for_locations(locations, types)¶
- Parameters:
locations (
GtkSource.SpaceLocationFlags) – one or severalGtkSource.SpaceLocationFlags.types (
GtkSource.SpaceTypeFlags) – a combination ofGtkSource.SpaceTypeFlags.
Modifies the [property`SpaceDrawer`:py:data::matrix<GtkSource.SpaceDrawer.props.matrix>] property at the specified locations.
Property Details¶
- GtkSource.SpaceDrawer.props.enable_matrix¶
-
Whether the [property`SpaceDrawer`:py:data::matrix<GtkSource.SpaceDrawer.props.matrix>] property is enabled.
- GtkSource.SpaceDrawer.props.matrix¶
- Name:
matrix- Type:
- Default Value:
GLib.Variant('au', [15, 15, 15])- Flags:
The property is a [struct`GLib`.Variant] property to specify where and what kind of white spaces to draw.
The [struct`GLib`.Variant] is of type
"au", an array of unsigned integers. Each integer is a combination of [flags`SpaceTypeFlags`]. There is one integer for each [flags`SpaceLocationFlags`], in the same order as they are defined in the enum (GtkSource.SpaceLocationFlags.NONEandGtkSource.SpaceLocationFlags.ALLare not taken into account).If the array is shorter than the number of locations, then the value for the missing locations will be
GtkSource.SpaceTypeFlags.NONE.By default,
GtkSource.SpaceTypeFlags.ALLis set for all locations.4