GtkSource.View

g Atk.ImplementorIface Atk.ImplementorIface Gtk.Widget Gtk.Widget Atk.ImplementorIface->Gtk.Widget GObject.GInterface GObject.GInterface GObject.GInterface->Atk.ImplementorIface Gtk.Buildable Gtk.Buildable GObject.GInterface->Gtk.Buildable Gtk.Scrollable Gtk.Scrollable GObject.GInterface->Gtk.Scrollable GObject.InitiallyUnowned GObject.InitiallyUnowned GObject.InitiallyUnowned->Gtk.Widget GObject.Object GObject.Object GObject.Object->GObject.InitiallyUnowned Gtk.Buildable->Gtk.Widget Gtk.Container Gtk.Container Gtk.TextView Gtk.TextView Gtk.Container->Gtk.TextView Gtk.Scrollable->Gtk.TextView GtkSource.View GtkSource.View Gtk.TextView->GtkSource.View Gtk.Widget->Gtk.Container

Subclasses:

GtkSource.Map

Methods

Inherited:

Gtk.TextView (73), Gtk.Container (35), Gtk.Widget (278), GObject.Object (37), Gtk.Buildable (10), Gtk.Scrollable (9)

Structs:

Gtk.ContainerClass (5), Gtk.WidgetClass (12), GObject.ObjectClass (5)

class

new ()

class

new_with_buffer (buffer)

get_auto_indent ()

get_background_pattern ()

get_completion ()

get_draw_spaces ()

get_gutter (window_type)

get_highlight_current_line ()

get_indent_on_tab ()

get_indent_width ()

get_insert_spaces_instead_of_tabs ()

get_mark_attributes (category, priority)

get_right_margin_position ()

get_show_line_marks ()

get_show_line_numbers ()

get_show_right_margin ()

get_smart_backspace ()

get_smart_home_end ()

get_space_drawer ()

get_tab_width ()

get_visual_column (iter)

indent_lines (start, end)

set_auto_indent (enable)

set_background_pattern (background_pattern)

set_draw_spaces (flags)

set_highlight_current_line (highlight)

set_indent_on_tab (enable)

set_indent_width (width)

set_insert_spaces_instead_of_tabs (enable)

set_mark_attributes (category, attributes, priority)

set_right_margin_position (pos)

set_show_line_marks (show)

set_show_line_numbers (show)

set_show_right_margin (show)

set_smart_backspace (smart_backspace)

set_smart_home_end (smart_home_end)

set_tab_width (width)

unindent_lines (start, end)

Virtual Methods

Inherited:

Gtk.TextView (13), Gtk.Container (10), Gtk.Widget (82), GObject.Object (7), Gtk.Buildable (10), Gtk.Scrollable (1)

do_line_mark_activated (iter, event)

do_move_lines (copy, step)

do_move_words (step)

do_redo ()

do_show_completion ()

do_undo ()

Properties

Inherited:

Gtk.TextView (21), Gtk.Container (3), Gtk.Widget (39), Gtk.Scrollable (4)

Name

Type

Flags

Short Description

auto-indent

bool

r/w

Whether to enable auto indentation

background-pattern

GtkSource.BackgroundPatternType

r/w

Draw a specific background pattern on the view

completion

GtkSource.Completion

r

The completion object associated with the view

draw-spaces

GtkSource.DrawSpacesFlags

d/r/w

Set if and how the spaces should be visualized deprecated

highlight-current-line

bool

r/w

Whether to highlight the current line

indent-on-tab

bool

r/w

Whether to indent the selected text when the tab key is pressed

indent-width

int

r/w

Number of spaces to use for each step of indent

insert-spaces-instead-of-tabs

bool

r/w

Whether to insert spaces instead of tabs

right-margin-position

int

r/w

Position of the right margin

show-line-marks

bool

r/w

Whether to display line mark pixbufs

show-line-numbers

bool

r/w

Whether to display line numbers

show-right-margin

bool

r/w

Whether to display the right margin

smart-backspace

bool

r/w

smart-home-end

GtkSource.SmartHomeEndType

r/w

HOME and END keys move to first/last non whitespace characters on line before going to the start/end of the line

space-drawer

GtkSource.SpaceDrawer

r

tab-width

int

r/w

Width of a tab character expressed in spaces

Style Properties

Inherited:

Gtk.TextView (1), Gtk.Widget (17)

Signals

Inherited:

Gtk.TextView (16), Gtk.Container (4), Gtk.Widget (69), GObject.Object (1)

Name

Short Description

change-case

Keybinding signal to change case of the text at the current cursor position.

change-number

Keybinding signal to edit a number at the current cursor position.

join-lines

Keybinding signal to join the lines currently selected.

line-mark-activated

Emitted when a line mark has been activated (for instance when there was a button press in the line marks gutter).

move-lines

The ::move-lines signal is a keybinding which gets emitted when the user initiates moving a line.

move-to-matching-bracket

Keybinding signal to move the cursor to the matching bracket.

move-words

The ::move-words signal is a keybinding which gets emitted when the user initiates moving a word.

redo

show-completion

The ::show-completion signal is a key binding signal which gets emitted when the user requests a completion, by pressing Control + space.

smart-home-end

Emitted when a the cursor was moved according to the smart home end setting.

undo

Fields

Inherited:

Gtk.TextView (16), Gtk.Container (4), Gtk.Widget (69), GObject.Object (1)

Name

Type

Access

Description

parent

Gtk.TextView

r

Class Details

class GtkSource.View(**kwargs)
Bases:

Gtk.TextView

Abstract:

No

Structure:

GtkSource.ViewClass

classmethod new()
Returns:

a new GtkSource.View.

Return type:

Gtk.Widget

Creates a new GtkSource.View.

By default, an empty GtkSource.Buffer will be lazily created and can be retrieved with Gtk.TextView.get_buffer().

If you want to specify your own buffer, either override the Gtk.TextViewClass create_buffer factory method, or use GtkSource.View.new_with_buffer().

classmethod new_with_buffer(buffer)
Parameters:

buffer (GtkSource.Buffer) – a GtkSource.Buffer.

Returns:

a new GtkSource.View.

Return type:

Gtk.Widget

Creates a new GtkSource.View widget displaying the buffer buffer. One buffer can be shared among many widgets.

get_auto_indent()
Returns:

True if auto indentation is enabled.

Return type:

bool

Returns whether auto-indentation of text is enabled.

get_background_pattern()
Returns:

the GtkSource.BackgroundPatternType.

Return type:

GtkSource.BackgroundPatternType

Returns the GtkSource.BackgroundPatternType specifying if and how the background pattern should be displayed for this self.

New in version 3.16.

get_completion()
Returns:

the GtkSource.Completion associated with self.

Return type:

GtkSource.Completion

Gets the GtkSource.Completion associated with self. The returned object is guaranteed to be the same for the lifetime of self. Each GtkSource.View object has a different GtkSource.Completion.

get_draw_spaces()
Returns:

the GtkSource.DrawSpacesFlags, 0 if no spaces should be drawn.

Return type:

GtkSource.DrawSpacesFlags

Returns the GtkSource.DrawSpacesFlags specifying if and how spaces should be displayed for this self.

Deprecated since version 3.24: Use GtkSource.SpaceDrawer.get_types_for_locations() instead.

get_gutter(window_type)
Parameters:

window_type (Gtk.TextWindowType) – the gutter window type.

Returns:

the GtkSource.Gutter.

Return type:

GtkSource.Gutter

Returns the GtkSource.Gutter object associated with window_type for self. Only Gtk.TextWindowType.LEFT and Gtk.TextWindowType.RIGHT are supported, respectively corresponding to the left and right gutter. The line numbers and mark category icons are rendered in the left gutter.

New in version 2.8.

get_highlight_current_line()
Returns:

True if the current line is highlighted.

Return type:

bool

Returns whether the current line is highlighted.

get_indent_on_tab()
Returns:

True if the selection is indented when tab is pressed.

Return type:

bool

Returns whether when the tab key is pressed the current selection should get indented instead of replaced with the \t character.

get_indent_width()
Returns:

indent width.

Return type:

int

Returns the number of spaces to use for each step of indent. See GtkSource.View.set_indent_width() for details.

get_insert_spaces_instead_of_tabs()
Returns:

True if spaces are inserted instead of tabs.

Return type:

bool

Returns whether when inserting a tabulator character it should be replaced by a group of space characters.

get_mark_attributes(category, priority)
Parameters:
  • category (str) – the category.

  • priority (int) – place where priority of the category will be stored.

Returns:

GtkSource.MarkAttributes for the category. The object belongs to self, so it must not be unreffed.

Return type:

GtkSource.MarkAttributes

Gets attributes and priority for the category.

get_right_margin_position()
Returns:

the position of the right margin.

Return type:

int

Gets the position of the right margin in the given self.

get_show_line_marks()
Returns:

True if the line marks are displayed.

Return type:

bool

Returns whether line marks are displayed beside the text.

New in version 2.2.

get_show_line_numbers()
Returns:

True if the line numbers are displayed.

Return type:

bool

Returns whether line numbers are displayed beside the text.

get_show_right_margin()
Returns:

True if the right margin is shown.

Return type:

bool

Returns whether a right margin is displayed.

get_smart_backspace()
Returns:

True if smart Backspace handling is enabled.

Return type:

bool

Returns True if pressing the Backspace key will try to delete spaces up to the previous tab stop.

New in version 3.18.

get_smart_home_end()
Returns:

a GtkSource.SmartHomeEndType value.

Return type:

GtkSource.SmartHomeEndType

Returns a GtkSource.SmartHomeEndType end value specifying how the cursor will move when HOME and END keys are pressed.

get_space_drawer()
Returns:

the GtkSource.SpaceDrawer associated with self.

Return type:

GtkSource.SpaceDrawer

Gets the GtkSource.SpaceDrawer associated with self. The returned object is guaranteed to be the same for the lifetime of self. Each GtkSource.View object has a different GtkSource.SpaceDrawer.

New in version 3.24.

get_tab_width()
Returns:

width of tab.

Return type:

int

Returns the width of tabulation in characters.

get_visual_column(iter)
Parameters:

iter (Gtk.TextIter) – a position in self.

Returns:

the visual column at iter.

Return type:

int

Determines the visual column at iter taking into consideration the GtkSource.View :tab-width of self.

indent_lines(start, end)
Parameters:

Inserts one indentation level at the beginning of the specified lines. The empty lines are not indented.

New in version 3.16.

set_auto_indent(enable)
Parameters:

enable (bool) – whether to enable auto indentation.

If True auto-indentation of text is enabled.

When Enter is pressed to create a new line, the auto-indentation inserts the same indentation as the previous line. This is not a “smart indentation” where an indentation level is added or removed depending on the context.

set_background_pattern(background_pattern)
Parameters:

background_pattern (GtkSource.BackgroundPatternType) – the GtkSource.BackgroundPatternType.

Set if and how the background pattern should be displayed.

New in version 3.16.

set_draw_spaces(flags)
Parameters:

flags (GtkSource.DrawSpacesFlags) – GtkSource.DrawSpacesFlags specifing how white spaces should be displayed

Set if and how the spaces should be visualized. Specifying flags as 0 will disable display of spaces.

For a finer-grained method, there is also the GtkSource.Tag's GtkSource.Tag :draw-spaces property.

Deprecated since version 3.24: Use GtkSource.SpaceDrawer.set_types_for_locations() instead.

set_highlight_current_line(highlight)
Parameters:

highlight (bool) – whether to highlight the current line.

If highlight is True the current line will be highlighted.

set_indent_on_tab(enable)
Parameters:

enable (bool) – whether to indent a block when tab is pressed.

If True, when the tab key is pressed when several lines are selected, the selected lines are indented of one level instead of being replaced with a \t character. Shift+Tab unindents the selection.

If the first or last line is not selected completely, it is also indented or unindented.

When the selection doesn’t span several lines, the tab key always replaces the selection with a normal \t character.

set_indent_width(width)
Parameters:

width (int) – indent width in characters.

Sets the number of spaces to use for each step of indent when the tab key is pressed. If width is -1, the value of the GtkSource.View :tab-width property will be used.

The GtkSource.View :indent-width interacts with the GtkSource.View :insert-spaces-instead-of-tabs property and GtkSource.View :tab-width. An example will be clearer: if the GtkSource.View :indent-width is 4 and GtkSource.View :tab-width is 8 and GtkSource.View :insert-spaces-instead-of-tabs is False, then pressing the tab key at the beginning of a line will insert 4 spaces. So far so good. Pressing the tab key a second time will remove the 4 spaces and insert a \t character instead (since GtkSource.View :tab-width is 8). On the other hand, if GtkSource.View :insert-spaces-instead-of-tabs is True, the second tab key pressed will insert 4 more spaces for a total of 8 spaces in the Gtk.TextBuffer.

The test-widget program (available in the GtkSource.View repository) may be useful to better understand the indentation settings (enable the space drawing!).

set_insert_spaces_instead_of_tabs(enable)
Parameters:

enable (bool) – whether to insert spaces instead of tabs.

If True a tab key pressed is replaced by a group of space characters. Of course it is still possible to insert a real \t programmatically with the Gtk.TextBuffer API.

set_mark_attributes(category, attributes, priority)
Parameters:

Sets attributes and priority for the category.

set_right_margin_position(pos)
Parameters:

pos (int) – the width in characters where to position the right margin.

Sets the position of the right margin in the given self.

set_show_line_marks(show)
Parameters:

show (bool) – whether line marks should be displayed.

If True line marks will be displayed beside the text.

New in version 2.2.

set_show_line_numbers(show)
Parameters:

show (bool) – whether line numbers should be displayed.

If True line numbers will be displayed beside the text.

set_show_right_margin(show)
Parameters:

show (bool) – whether to show a right margin.

If True a right margin is displayed.

set_smart_backspace(smart_backspace)
Parameters:

smart_backspace (bool) – whether to enable smart Backspace handling.

When set to True, pressing the Backspace key will try to delete spaces up to the previous tab stop.

New in version 3.18.

set_smart_home_end(smart_home_end)
Parameters:

smart_home_end (GtkSource.SmartHomeEndType) – the desired behavior among GtkSource.SmartHomeEndType.

Set the desired movement of the cursor when HOME and END keys are pressed.

set_tab_width(width)
Parameters:

width (int) – width of tab in characters.

Sets the width of tabulation in characters. The Gtk.TextBuffer still contains \t characters, but they can take a different visual width in a GtkSource.View widget.

unindent_lines(start, end)
Parameters:

Removes one indentation level at the beginning of the specified lines.

New in version 3.16.

do_line_mark_activated(iter, event) virtual
Parameters:
do_move_lines(copy, step) virtual
Parameters:
do_move_words(step) virtual
Parameters:

step (int) –

do_redo() virtual
do_show_completion() virtual
do_undo() virtual

Signal Details

GtkSource.View.signals.change_case(view, case_type)
Signal Name:

change-case

Flags:

RUN_LAST, ACTION

Parameters:

Keybinding signal to change case of the text at the current cursor position.

New in version 3.16.

GtkSource.View.signals.change_number(view, count)
Signal Name:

change-number

Flags:

RUN_LAST, ACTION

Parameters:
  • view (GtkSource.View) – The object which received the signal

  • count (int) – the number to add to the number at the current position

Keybinding signal to edit a number at the current cursor position.

New in version 3.16.

GtkSource.View.signals.join_lines(view)
Signal Name:

join-lines

Flags:

RUN_LAST, ACTION

Parameters:

view (GtkSource.View) – The object which received the signal

Keybinding signal to join the lines currently selected.

New in version 3.16.

GtkSource.View.signals.line_mark_activated(view, iter, event)
Signal Name:

line-mark-activated

Flags:

RUN_LAST

Parameters:

Emitted when a line mark has been activated (for instance when there was a button press in the line marks gutter). You can use iter to determine on which line the activation took place.

GtkSource.View.signals.move_lines(view, copy, count)
Signal Name:

move-lines

Flags:

RUN_LAST, ACTION

Parameters:
  • view (GtkSource.View) – The object which received the signal

  • copy (bool) – True if the line should be copied, False if it should be moved. This parameter is deprecated and will be removed in a later version, it should be always False.

  • count (int) – the number of lines to move over. Only 1 and -1 are supported.

The ::move-lines signal is a keybinding which gets emitted when the user initiates moving a line. The default binding key is Alt+Up/Down arrow. And moves the currently selected lines, or the current line by count. For the moment, only count of -1 or 1 is valid.

The copy parameter is deprecated, it has never been used by GtkSource.View (the value is always False) and was buggy.

New in version 2.10.

GtkSource.View.signals.move_to_matching_bracket(view, extend_selection)
Signal Name:

move-to-matching-bracket

Flags:

RUN_LAST, ACTION

Parameters:
  • view (GtkSource.View) – The object which received the signal

  • extend_selection (bool) – True if the move should extend the selection

Keybinding signal to move the cursor to the matching bracket.

New in version 3.16.

GtkSource.View.signals.move_words(view, count)
Signal Name:

move-words

Flags:

RUN_LAST, ACTION

Parameters:
  • view (GtkSource.View) – The object which received the signal

  • count (int) – the number of words to move over

The ::move-words signal is a keybinding which gets emitted when the user initiates moving a word. The default binding key is Alt+Left/Right Arrow and moves the current selection, or the current word by one word.

New in version 3.0.

GtkSource.View.signals.redo(view)
Signal Name:

redo

Flags:

RUN_LAST, ACTION

Parameters:

view (GtkSource.View) – The object which received the signal

GtkSource.View.signals.show_completion(view)
Signal Name:

show-completion

Flags:

RUN_LAST, ACTION

Parameters:

view (GtkSource.View) – The object which received the signal

The ::show-completion signal is a key binding signal which gets emitted when the user requests a completion, by pressing

Control + space. This will create a GtkSource.CompletionContext with the activation type as GtkSource.CompletionActivation.USER_REQUESTED.

Applications should not connect to it, but may emit it with g_signal_emit_by_name() if they need to activate the completion by another means, for example with another key binding or a menu entry.

GtkSource.View.signals.smart_home_end(view, iter, count)
Signal Name:

smart-home-end

Flags:

RUN_LAST

Parameters:

Emitted when a the cursor was moved according to the smart home end setting. The signal is emitted after the cursor is moved, but during the Gtk.TextView ::move-cursor action. This can be used to find out whether the cursor was moved by a normal home/end or by a smart home/end.

New in version 3.0.

GtkSource.View.signals.undo(view)
Signal Name:

undo

Flags:

RUN_LAST, ACTION

Parameters:

view (GtkSource.View) – The object which received the signal

Property Details

GtkSource.View.props.auto_indent
Name:

auto-indent

Type:

bool

Default Value:

False

Flags:

READABLE, WRITABLE

Whether to enable auto indentation

GtkSource.View.props.background_pattern
Name:

background-pattern

Type:

GtkSource.BackgroundPatternType

Default Value:

GtkSource.BackgroundPatternType.NONE

Flags:

READABLE, WRITABLE

Draw a specific background pattern on the view.

New in version 3.16.

GtkSource.View.props.completion
Name:

completion

Type:

GtkSource.Completion

Default Value:

None

Flags:

READABLE

The completion object associated with the view

GtkSource.View.props.draw_spaces
Name:

draw-spaces

Type:

GtkSource.DrawSpacesFlags

Default Value:

0

Flags:

DEPRECATED, READABLE, WRITABLE

Set if and how the spaces should be visualized.

For a finer-grained method, there is also the GtkSource.Tag's GtkSource.Tag :draw-spaces property.

New in version 2.4.

Deprecated since version 3.24: Use the GtkSource.SpaceDrawer :matrix property instead.

GtkSource.View.props.highlight_current_line
Name:

highlight-current-line

Type:

bool

Default Value:

False

Flags:

READABLE, WRITABLE

Whether to highlight the current line

GtkSource.View.props.indent_on_tab
Name:

indent-on-tab

Type:

bool

Default Value:

True

Flags:

READABLE, WRITABLE

Whether to indent the selected text when the tab key is pressed

GtkSource.View.props.indent_width
Name:

indent-width

Type:

int

Default Value:

-1

Flags:

READABLE, WRITABLE

Width of an indentation step expressed in number of spaces.

GtkSource.View.props.insert_spaces_instead_of_tabs
Name:

insert-spaces-instead-of-tabs

Type:

bool

Default Value:

False

Flags:

READABLE, WRITABLE

Whether to insert spaces instead of tabs

GtkSource.View.props.right_margin_position
Name:

right-margin-position

Type:

int

Default Value:

80

Flags:

READABLE, WRITABLE

Position of the right margin.

GtkSource.View.props.show_line_marks
Name:

show-line-marks

Type:

bool

Default Value:

False

Flags:

READABLE, WRITABLE

Whether to display line mark pixbufs

GtkSource.View.props.show_line_numbers
Name:

show-line-numbers

Type:

bool

Default Value:

False

Flags:

READABLE, WRITABLE

Whether to display line numbers

GtkSource.View.props.show_right_margin
Name:

show-right-margin

Type:

bool

Default Value:

False

Flags:

READABLE, WRITABLE

Whether to display the right margin.

GtkSource.View.props.smart_backspace
Name:

smart-backspace

Type:

bool

Default Value:

False

Flags:

READABLE, WRITABLE

Whether smart Backspace should be used.

New in version 3.18.

GtkSource.View.props.smart_home_end
Name:

smart-home-end

Type:

GtkSource.SmartHomeEndType

Default Value:

GtkSource.SmartHomeEndType.DISABLED

Flags:

READABLE, WRITABLE

Set the behavior of the HOME and END keys.

New in version 2.0.

GtkSource.View.props.space_drawer
Name:

space-drawer

Type:

GtkSource.SpaceDrawer

Default Value:

None

Flags:

READABLE

The GtkSource.SpaceDrawer object associated with the view.

New in version 3.24.

GtkSource.View.props.tab_width
Name:

tab-width

Type:

int

Default Value:

8

Flags:

READABLE, WRITABLE

Width of a tab character expressed in number of spaces.