GtkSource.View¶
- Subclasses:
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 |
|
class |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Virtual Methods¶
- Inherited:
Gtk.TextView (13), Gtk.Container (10), Gtk.Widget (82), GObject.Object (7), Gtk.Buildable (10), Gtk.Scrollable (1)
|
|
|
|
|
|
|
|
|
Properties¶
- Inherited:
Gtk.TextView (21), Gtk.Container (3), Gtk.Widget (39), Gtk.Scrollable (4)
Name |
Type |
Flags |
Short Description |
---|---|---|---|
r/w |
Whether to enable auto indentation |
||
r/w |
Draw a specific background pattern on the view |
||
r |
The completion object associated with the view |
||
d/r/w |
Set if and how the spaces should be visualized |
||
r/w |
Whether to highlight the current line |
||
r/w |
Whether to indent the selected text when the tab key is pressed |
||
r/w |
Number of spaces to use for each step of indent |
||
r/w |
Whether to insert spaces instead of tabs |
||
r/w |
Position of the right margin |
||
r/w |
Whether to display line mark pixbufs |
||
r/w |
Whether to display line numbers |
||
r/w |
Whether to display the right margin |
||
r/w |
|||
r/w |
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 |
Width of a tab character expressed in spaces |
Style Properties¶
- Inherited:
Signals¶
- Inherited:
Gtk.TextView (16), Gtk.Container (4), Gtk.Widget (69), GObject.Object (1)
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 |
|
Keybinding signal to move the cursor to the matching bracket. |
|
The |
|
The |
|
Emitted when a the cursor was moved according to the smart home end setting. |
|
Fields¶
- Inherited:
Gtk.TextView (16), Gtk.Container (4), Gtk.Widget (69), GObject.Object (1)
Name |
Type |
Access |
Description |
---|---|---|---|
parent |
r |
Class Details¶
- class GtkSource.View(**kwargs)¶
- Bases:
- Abstract:
No
- Structure:
- classmethod new()¶
- Returns:
a new
GtkSource.View
.- Return type:
Creates a new
GtkSource.View
.By default, an empty
GtkSource.Buffer
will be lazily created and can be retrieved withGtk.TextView.get_buffer
().If you want to specify your own buffer, either override the
Gtk.TextViewClass
create_buffer factory method, or useGtkSource.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.New in version 3.16.
- get_completion()¶
- Returns:
the
GtkSource.Completion
associated with self.- Return type:
Gets the
GtkSource.Completion
associated with self. The returned object is guaranteed to be the same for the lifetime of self. EachGtkSource.View
object has a differentGtkSource.Completion
.
- get_draw_spaces()¶
- Returns:
the
GtkSource.DrawSpacesFlags
, 0 if no spaces should be drawn.- Return type:
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:
Returns the
GtkSource.Gutter
object associated with window_type for self. OnlyGtk.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.New in version 2.8.
- get_highlight_current_line()¶
-
Returns whether the current line is highlighted.
- 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
GtkSource.View.set_indent_width
() for details.
- 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.
New in version 2.2.
- 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.New in version 3.18.
- get_smart_home_end()¶
- Returns:
a
GtkSource.SmartHomeEndType
value.- Return type:
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:
Gets the
GtkSource.SpaceDrawer
associated with self. The returned object is guaranteed to be the same for the lifetime of self. EachGtkSource.View
object has a differentGtkSource.SpaceDrawer
.New in version 3.24.
- 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
GtkSource.View
: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.
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
) – theGtkSource.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
'sGtkSource.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 theGtkSource.View
:insert-spaces-instead-of-tabs
property andGtkSource.View
:tab-width
. An example will be clearer: if theGtkSource.View
:indent-width
is 4 andGtkSource.View
:tab-width
is 8 andGtkSource.View
:insert-spaces-instead-of-tabs
isFalse
, 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 (sinceGtkSource.View
:tab-width
is 8). On the other hand, ifGtkSource.View
:insert-spaces-instead-of-tabs
isTrue
, the second tab key pressed will insert 4 more spaces for a total of 8 spaces in theGtk.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 theGtk.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.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 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 aGtkSource.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.
New in version 3.16.
- do_line_mark_activated(iter, event) virtual¶
- Parameters:
iter (
Gtk.TextIter
) –event (
Gdk.Event
) –
- 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:
- 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.
New in version 3.16.
- 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.
New in version 3.16.
- 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.
New in version 3.16.
- GtkSource.View.signals.line_mark_activated(view, iter, event)¶
- Signal Name:
line-mark-activated
- Flags:
- Parameters:
view (
GtkSource.View
) – The object which received the signaliter (
Gtk.TextIter
) – aGtk.TextIter
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:
- Parameters:
view (
GtkSource.View
) – The object which received the signalcopy (
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 alwaysFalse
.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 alwaysFalse
) 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:
- 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.
New in version 3.16.
- 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
::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:
- Parameters:
view (
GtkSource.View
) – The object which received the signal
- GtkSource.View.signals.show_completion(view)¶
- Signal Name:
show-completion
- Flags:
- 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 pressingControl + space. This will create a
GtkSource.CompletionContext
with the activation type asGtkSource.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:
- 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
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:
- Parameters:
view (
GtkSource.View
) – The object which received the signal
Property Details¶
- GtkSource.View.props.auto_indent¶
-
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.
New in version 3.16.
- GtkSource.View.props.completion¶
- Name:
completion
- Type:
- Default Value:
- Flags:
The completion object associated with the view
- GtkSource.View.props.draw_spaces¶
- Name:
draw-spaces
- Type:
- Default Value:
0
- Flags:
Set if and how the spaces should be visualized.
For a finer-grained method, there is also the
GtkSource.Tag
'sGtkSource.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¶
-
Whether to highlight the current line
- GtkSource.View.props.indent_on_tab¶
-
Whether to indent the selected text when the tab key is pressed
- GtkSource.View.props.indent_width¶
-
Width of an indentation step expressed in number of spaces.
- GtkSource.View.props.insert_spaces_instead_of_tabs¶
-
Whether to insert spaces instead of tabs
- GtkSource.View.props.right_margin_position¶
-
Position of the right margin.
- GtkSource.View.props.show_line_marks¶
-
Whether to display line mark pixbufs
- GtkSource.View.props.show_line_numbers¶
-
Whether to display line numbers
- GtkSource.View.props.show_right_margin¶
-
Whether to display the right margin.
- GtkSource.View.props.smart_backspace¶
-
Whether smart Backspace should be used.
New in version 3.18.
- GtkSource.View.props.smart_home_end¶
- Name:
smart-home-end
- Type:
- Default Value:
- Flags:
Set the behavior of the HOME and END keys.
New in version 2.0.
- GtkSource.View.props.space_drawer¶
- Name:
space-drawer
- Type:
- Default Value:
- Flags:
The
GtkSource.SpaceDrawer
object associated with the view.New in version 3.24.