GtkSource.View¶
- Subclasses:
Methods¶
- Inherited:
Gtk.TextView (73), Gtk.Widget (181), GObject.Object (37), Gtk.Accessible (15), Gtk.Buildable (1), Gtk.Scrollable (9)
- Structs:
class |
|
class |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Virtual Methods¶
- Inherited:
Gtk.TextView (12), Gtk.Widget (25), GObject.Object (7), Gtk.Accessible (6), Gtk.Buildable (9), Gtk.Scrollable (1)
|
|
|
|
|
|
|
|
Properties¶
- Inherited:
Gtk.TextView (21), Gtk.Widget (34), Gtk.Accessible (1), Gtk.Scrollable (4)
Name |
Type |
Flags |
Short Description |
---|---|---|---|
r/w/en |
Whether to enable auto indentation |
||
r/w/en |
Draw a specific background pattern on the view |
||
r |
The completion object associated with the view |
||
r/w/en |
Whether to enable snippet expansion |
||
r/w/en |
Whether to highlight the current line |
||
r/w/en |
Whether to indent the selected text when the tab key is pressed |
||
r/w/en |
Number of spaces to use for each step of indent |
||
r/w/en |
A indenter to use to indent typed text |
||
r/w/en |
Whether to insert spaces instead of tabs |
||
r/w/en |
Position of the right margin |
||
r/w/en |
Whether to display line mark pixbufs |
||
r/w/en |
Whether to display line numbers |
||
r/w/en |
Whether to display the right margin |
||
r/w/en |
|||
r/w/en |
HOME and END keys move to first/last non whitespace characters on line before going to the start/end of the line |
||
r |
|||
r/w/en |
Width of a tab character expressed in spaces |
Signals¶
- Inherited:
Name |
Short Description |
---|---|
Keybinding signal to change case of the text at the current cursor position. |
|
Keybinding signal to edit a number at the current cursor position. |
|
Keybinding signal to join the lines currently selected. |
|
Emitted when a line mark has been activated (for instance when there was a button press in the line marks gutter). |
|
The signal is a keybinding which gets emitted when the user initiates moving a line. |
|
Keybinding signal to move the cursor to the matching bracket. |
|
The signal is a keybinding which gets emitted when the user initiates moving a word. |
|
The signal is emitted to insert a new snippet into the view. |
|
The signal is a key binding signal which gets emitted when the user requests a completion, by pressing Control + space. |
|
Emitted when a the cursor was moved according to the smart home end setting. |
Fields¶
- Inherited:
Name |
Type |
Access |
Description |
---|---|---|---|
parent_instance |
r |
Class Details¶
- class GtkSource.View(**kwargs)¶
- Bases:
- Abstract:
No
- Structure:
Subclass of [class`Gtk`.TextView].
GtkSourceView
is the main class of theGtkSource.View
library. Use a [class`Buffer`] to display text with aGtkSourceView
.This class provides:
Show the line numbers;
Show a right margin;
Highlight the current line;
Indentation settings;
Configuration for the Home and End keyboard keys;
Configure and show line marks;
And a few other things.
An easy way to test all these features is to use the test-widget mini-program provided in the
GtkSource.View
repository, in the tests/ directory.The
GtkSource.View
implementation of the [iface`Gtk`.Buildable] interface exposes the [property`View`:py:data::completion<GtkSource.View.props.completion>] object with the internal-child “completion”.An example of a UI definition fragment with
GtkSource.View
: ```xml4 True
False </object> </child> </object> ```
- Changing the Font
Gtk CSS provides the best way to change the font for a
GtkSourceView
in a manner that allows for components like [class`Map`] to scale the desired font.``c GtkCssProvider *provider = gtk_css_provider_new (); gtk_css_provider_load_from_data (provider,
“textview { font-family: Monospace; font-size: 8pt; }”, -1, NULL);
- gtk_style_context_add_provider (gtk_widget_get_style_context (view),
GTK_STYLE_PROVIDER (provider), GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
g_object_unref (provider); ``
If you need to adjust the font or size of font within a portion of the document only, you should use a [class`Gtk`.TextTag] with the [property`Gtk`.TextTag:family] or [property`Gtk`.TextTag:scale] set so that the font size may be scaled relative to the default font set in CSS.
- classmethod new()¶
- Returns:
a new
GtkSource.View
.- Return type:
Creates a new
GtkSourceView
.By default, an empty [class`Buffer`] will be lazily created and can be retrieved with [method`Gtk`.TextView.get_buffer].
If you want to specify your own buffer, either override the [vfunc`Gtk`.TextView.create_buffer] factory method, or use [ctor`View`.new_with_buffer].
- classmethod new_with_buffer(buffer)¶
- Parameters:
buffer (
GtkSource.Buffer
) – aGtkSource.Buffer
.- Returns:
a new
GtkSource.View
.- Return type:
Creates a new
GtkSource.View
widget displaying the buffer buffer.One buffer can be shared among many widgets.
- get_auto_indent()¶
-
Returns whether auto-indentation of text is enabled.
- get_background_pattern()¶
- Returns:
- Return type:
Returns the
GtkSource.BackgroundPatternType
specifying if and how the background pattern should be displayed for this self.
- get_completion()¶
- Returns:
the
GtkSource.Completion
associated with self.- Return type:
Gets the [class`Completion`] associated with self.
The returned object is guaranteed to be the same for the lifetime of self. Each
GtkSourceView
object has a different [class`Completion`].
- get_enable_snippets()¶
-
Gets the [property`View`:py:data::enable-snippets<GtkSource.View.props.enable_snippets>] property.
If
True
, matching snippets found in the [class`SnippetManager`] may be expanded when the user presses Tab after a word in the [class`View`].
- get_gutter(window_type)¶
- Parameters:
window_type (
Gtk.TextWindowType
) – the gutter window type.- Returns:
the
GtkSource.Gutter
.- Return type:
Returns the [class`Gutter`] object associated with window_type for self.
Only
Gtk.TextWindowType.LEFT
andGtk.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.
- get_highlight_current_line()¶
-
Returns whether the current line is highlighted.
- get_hover()¶
- Returns:
a
GtkSource.Hover
associated with self.- Return type:
Gets the [class`Hover`] associated with self.
The returned object is guaranteed to be the same for the lifetime of self. Each [class`View`] object has a different [class`Hover`].
- get_indent_on_tab()¶
-
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:
Returns the number of spaces to use for each step of indent.
See [method`View`.set_indent_width] for details.
- get_indenter()¶
- Returns:
a
GtkSource.Indenter
orNone
- Return type:
Gets the [property`View`:py:data::indenter<GtkSource.View.props.indenter>] property.
- get_insert_spaces_instead_of_tabs()¶
-
Returns whether when inserting a tabulator character it should be replaced by a group of space characters.
- get_mark_attributes(category, priority)¶
- Parameters:
- Returns:
GtkSource.MarkAttributes
for the category. The object belongs to self, so it must not be unreffed.- Return type:
Gets attributes and priority for the category.
- get_right_margin_position()¶
- Returns:
the position of the right margin.
- Return type:
Gets the position of the right margin in the given self.
- get_show_line_marks()¶
-
Returns whether line marks are displayed beside the text.
- get_show_line_numbers()¶
-
Returns whether line numbers are displayed beside the text.
- get_show_right_margin()¶
-
Returns whether a right margin is displayed.
- get_smart_backspace()¶
-
Returns
True
if pressing the Backspace key will try to delete spaces up to the previous tab stop.
- get_smart_home_end()¶
- Returns:
a
GtkSource.SmartHomeEndType
value.- Return type:
Returns a [enum`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:
Gets the [class`SpaceDrawer`] associated with self.
The returned object is guaranteed to be the same for the lifetime of self. Each [class`View`] object has a different [class`SpaceDrawer`].
- get_tab_width()¶
- Returns:
width of tab.
- Return type:
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:
Determines the visual column at iter taking into consideration the [property`View`:py:data::tab-width<GtkSource.View.props.tab_width>] of self.
- indent_lines(start, end)¶
- Parameters:
start (
Gtk.TextIter
) –Gtk.TextIter
of the first line to indentend (
Gtk.TextIter
) –Gtk.TextIter
of the last line to indent
Inserts one indentation level at the beginning of the specified lines. The empty lines are not indented.
- push_snippet(snippet, location)¶
- Parameters:
snippet (
GtkSource.Snippet
) – aGtkSource.Snippet
location (
Gtk.TextIter
orNone
) – aGtk.TextIter
orNone
for the cursor position
Inserts a new snippet at location
If another snippet was already active, it will be paused and the new snippet will become active. Once the focus positions of snippet have been exhausted, editing will return to the previous snippet.
- 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
) – theGtkSource.BackgroundPatternType
.
Set if and how the background pattern should be displayed.
- set_enable_snippets(enable_snippets)¶
- Parameters:
enable_snippets (
bool
) – if snippets should be enabled
Sets the [property`View`:py:data::enable-snippets<GtkSource.View.props.enable_snippets>] property.
If enable_snippets is
True
, matching snippets found in the [class`SnippetManager`] may be expanded when the user presses Tab after a word in the [class`View`].
- 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 [property`View`:py:data::tab-width<GtkSource.View.props.tab_width>] property will be used.
The [property`View`:py:data::indent-width<GtkSource.View.props.indent_width>] interacts with the [property`View`:py:data::insert-spaces-instead-of-tabs<GtkSource.View.props.insert_spaces_instead_of_tabs>] property and [property`View`:py:data::tab-width<GtkSource.View.props.tab_width>]. An example will be clearer:
If the [property`View`:py:data::indent-width<GtkSource.View.props.indent_width>] is 4 and [property`View`:py:data::tab-width<GtkSource.View.props.tab_width>] is 8 and [property`View`:py:data::insert-spaces-instead-of-tabs<GtkSource.View.props.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 [property`View`:py:data::tab-width<GtkSource.View.props.tab_width>] is 8). On the other hand, if [property`View`:py:data::insert-spaces-instead-of-tabs<GtkSource.View.props.insert_spaces_instead_of_tabs>] isTrue
, the second tab key pressed will insert 4 more spaces for a total of 8 spaces in the [class`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_indenter(indenter)¶
- Parameters:
indenter (
GtkSource.Indenter
orNone
) – aGtkSource.Indenter
orNone
Sets the indenter for self to indenter.
Note that the indenter will not be used unless
GtkSource.View
:auto-indent
has been set toTrue
.
- 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 [class`Gtk`.TextBuffer] API.
- set_mark_attributes(category, attributes, priority)¶
- Parameters:
category (
str
) – the category.attributes (
GtkSource.MarkAttributes
) – mark attributes.priority (
int
) – priority of the category.
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.
- 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.
- set_smart_home_end(smart_home_end)¶
- Parameters:
smart_home_end (
GtkSource.SmartHomeEndType
) – the desired behavior amongGtkSource.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 [class`View`] widget.
- unindent_lines(start, end)¶
- Parameters:
start (
Gtk.TextIter
) –Gtk.TextIter
of the first line to indentend (
Gtk.TextIter
) –Gtk.TextIter
of the last line to indent
Removes one indentation level at the beginning of the specified lines.
- do_line_mark_activated(iter, button, state, n_presses) virtual¶
- Parameters:
iter (
Gtk.TextIter
) –button (
int
) –state (
Gdk.ModifierType
) –n_presses (
int
) –
- do_push_snippet(snippet, location) virtual¶
- Parameters:
snippet (
GtkSource.Snippet
) – aGtkSource.Snippet
location (
Gtk.TextIter
orNone
) – aGtk.TextIter
orNone
for the cursor position
Inserts a new snippet at location
If another snippet was already active, it will be paused and the new snippet will become active. Once the focus positions of snippet have been exhausted, editing will return to the previous snippet.
- do_show_completion() virtual¶
Signal Details¶
- GtkSource.View.signals.change_case(view, case_type)¶
- Signal Name:
change-case
- Flags:
- Parameters:
view (
GtkSource.View
) – The object which received the signalcase_type (
GtkSource.ChangeCaseType
) – the case to use
Keybinding signal to change case of the text at the current cursor position.
- GtkSource.View.signals.change_number(view, count)¶
- Signal Name:
change-number
- Flags:
- Parameters:
view (
GtkSource.View
) – The object which received the signalcount (
int
) – the number to add to the number at the current position
Keybinding signal to edit a number at the current cursor position.
- GtkSource.View.signals.join_lines(view)¶
- Signal Name:
join-lines
- Flags:
- Parameters:
view (
GtkSource.View
) – The object which received the signal
Keybinding signal to join the lines currently selected.
- GtkSource.View.signals.line_mark_activated(view, iter, button, state, n_presses)¶
- Signal Name:
line-mark-activated
- Flags:
- Parameters:
view (
GtkSource.View
) – The object which received the signaliter (
Gtk.TextIter
) – aGtk.TextIter
button (
int
) – the button that was pressedstate (
Gdk.ModifierType
) – the modifier state, if anyn_presses (
int
) – the number of presses
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, down)¶
- Signal Name:
move-lines
- Flags:
- Parameters:
view (
GtkSource.View
) – The object which received the signal
The 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 up or down by one line.
- GtkSource.View.signals.move_to_matching_bracket(view, extend_selection)¶
- Signal Name:
move-to-matching-bracket
- Flags:
- Parameters:
view (
GtkSource.View
) – The object which received the signalextend_selection (
bool
) –True
if the move should extend the selection
Keybinding signal to move the cursor to the matching bracket.
- GtkSource.View.signals.move_words(view, count)¶
- Signal Name:
move-words
- Flags:
- Parameters:
view (
GtkSource.View
) – The object which received the signalcount (
int
) – the number of words to move over
The 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.
- GtkSource.View.signals.push_snippet(view, snippet, location)¶
- Signal Name:
push-snippet
- Flags:
- Parameters:
view (
GtkSource.View
) – The object which received the signalsnippet (
GtkSource.Snippet
) – aGtkSource.Snippet
location (
Gtk.TextIter
) – aGtk.TextIter
- Returns:
- Return type:
location:
Gtk.TextIter
The signal is emitted to insert a new snippet into the view.
If another snippet was active, it will be paused until all focus positions of snippet have been exhausted.
location will be updated to point at the end of the snippet.
- GtkSource.View.signals.show_completion(view)¶
- Signal Name:
show-completion
- Flags:
- Parameters:
view (
GtkSource.View
) – The object which received the signal
The signal is a key binding signal which gets emitted when the user requests a completion, by pressing
Control + space. This will create a [class`CompletionContext`] with the activation type as
GtkSource.CompletionActivation.USER_REQUESTED
.Applications should not connect to it, but may emit it with [func`GObject`.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:
- Parameters:
view (
GtkSource.View
) – The object which received the signaliter (
Gtk.TextIter
) – aGtk.TextIter
count (
int
) – the count
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 [signal`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.
Property Details¶
- GtkSource.View.props.auto_indent¶
- Name:
auto-indent
- Type:
- Default Value:
- Flags:
Whether to enable auto indentation
- GtkSource.View.props.background_pattern¶
- Name:
background-pattern
- Type:
- Default Value:
- Flags:
Draw a specific background pattern on the view.
- GtkSource.View.props.completion¶
- Name:
completion
- Type:
- Default Value:
- Flags:
The completion object associated with the view
- GtkSource.View.props.enable_snippets¶
- Name:
enable-snippets
- Type:
- Default Value:
- Flags:
The property denotes if snippets should be expanded when the user presses Tab after having typed a word matching the snippets found in [class`SnippetManager`].
The user may tab through focus-positions of the snippet if any are available by pressing Tab repeatedly until the desired focus position is selected.
- GtkSource.View.props.highlight_current_line¶
- Name:
highlight-current-line
- Type:
- Default Value:
- Flags:
Whether to highlight the current line
- GtkSource.View.props.indent_on_tab¶
- Name:
indent-on-tab
- Type:
- Default Value:
- Flags:
Whether to indent the selected text when the tab key is pressed
- GtkSource.View.props.indent_width¶
- Name:
indent-width
- Type:
- Default Value:
-1
- Flags:
Width of an indentation step expressed in number of spaces.
- GtkSource.View.props.indenter¶
- Name:
indenter
- Type:
- Default Value:
- Flags:
The property is a [iface`Indenter`] to use to indent as the user types into the [class`View`].
- GtkSource.View.props.insert_spaces_instead_of_tabs¶
- Name:
insert-spaces-instead-of-tabs
- Type:
- Default Value:
- Flags:
Whether to insert spaces instead of tabs
- GtkSource.View.props.right_margin_position¶
- Name:
right-margin-position
- Type:
- Default Value:
80
- Flags:
Position of the right margin.
- GtkSource.View.props.show_line_marks¶
- Name:
show-line-marks
- Type:
- Default Value:
- Flags:
Whether to display line mark pixbufs
- GtkSource.View.props.show_line_numbers¶
- Name:
show-line-numbers
- Type:
- Default Value:
- Flags:
Whether to display line numbers
- GtkSource.View.props.show_right_margin¶
- Name:
show-right-margin
- Type:
- Default Value:
- Flags:
Whether to display the right margin.
- GtkSource.View.props.smart_backspace¶
- Name:
smart-backspace
- Type:
- Default Value:
- Flags:
Whether smart Backspace should be used.
- GtkSource.View.props.smart_home_end¶
- Name:
smart-home-end
- Type:
- Default Value:
- Flags:
Set the behavior of the HOME and END keys.
- GtkSource.View.props.space_drawer¶
- Name:
space-drawer
- Type:
- Default Value:
- Flags:
The [class`SpaceDrawer`] object associated with the view.4
- GtkSource.View.props.tab_width¶
- Name:
tab-width
- Type:
- Default Value:
8
- Flags:
Width of a tab character expressed in number of spaces.