Gtk.TextView¶
Example¶
- Subclasses:
None
Methods¶
- Inherited:
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)
Virtual Methods¶
- Inherited:
Gtk.Container (10), Gtk.Widget (82), GObject.Object (7), Gtk.Buildable (10), Gtk.Scrollable (1)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Properties¶
- Inherited:
Name |
Type |
Flags |
Short Description |
---|---|---|---|
r/w/en |
Whether Tab will result in a tab character being entered |
||
r/w/en |
Height of the bottom margin in pixels |
||
r/w |
The buffer which is displayed |
||
r/w/en |
If the insertion cursor is shown |
||
r/w/en |
Whether the text can be modified by the user |
||
r/w |
Which IM module should be used |
||
r/w/en |
Amount to indent the paragraph, in pixels |
||
r/w/en |
Hints for the text field behaviour |
||
r/w/en |
Purpose of the text field |
||
r/w/en |
Left, right, or center justification |
||
r/w/en |
Width of the left margin in pixels |
||
r/w/en |
Whether to use a monospace font |
||
r/w/en |
Whether entered text overwrites existing contents |
||
r/w/en |
Pixels of blank space above paragraphs |
||
r/w/en |
Pixels of blank space below paragraphs |
||
r/w/en |
Pixels of blank space between wrapped lines in a paragraph |
||
r/w/en |
Whether to emit |
||
r/w/en |
Width of the right margin in pixels |
||
r/w |
Custom tabs for this text |
||
r/w/en |
Height of the top margin in pixels |
||
r/w/en |
Whether to wrap lines never, at word boundaries, or at character boundaries |
Style Properties¶
- Inherited:
Name |
Type |
Default |
Flags |
Short Description |
---|---|---|---|---|
|
r |
Color with which to draw error-indication underlines |
Signals¶
- Inherited:
Name |
Short Description |
---|---|
The |
|
The |
|
The |
|
The |
|
The |
|
The |
|
The |
|
The |
|
The |
|
The |
|
The |
|
If an input method is used, the typed text will not immediately be committed to the buffer. |
|
The |
|
The |
|
The |
|
The |
Fields¶
- Inherited:
Name |
Type |
Access |
Description |
---|---|---|---|
parent_instance |
r |
Class Details¶
- class Gtk.TextView(**kwargs)¶
- Bases:
- Abstract:
No
- Structure:
You may wish to begin by reading the text widget conceptual overview which gives an overview of all the objects and data types related to the text widget and how they work together.
- CSS nodes
textview.view ├── border.top ├── border.left ├── text │ ╰── [selection] ├── border.right ├── border.bottom ╰── [window.popup]
Gtk.TextView
has a main css node with name textview and style class .view, and subnodes for each of the border windows, and the main text area, with names border and text, respectively. The border nodes each get one of the style classes .left, .right, .top or .bottom.A node representing the selection will appear below the text node.
If a context menu is opened, the window node will appear as a subnode of the main node.
- classmethod new()[source]¶
- Returns:
a new
Gtk.TextView
- Return type:
Creates a new
Gtk.TextView
. If you don’t callGtk.TextView.set_buffer
() before using the text view, an empty default buffer will be created for you. Get the buffer withGtk.TextView.get_buffer
(). If you want to specify your own buffer, considerGtk.TextView.new_with_buffer
().
- classmethod new_with_buffer(buffer)[source]¶
- Parameters:
buffer (
Gtk.TextBuffer
) – aGtk.TextBuffer
- Returns:
a new
Gtk.TextView
.- Return type:
Creates a new
Gtk.TextView
widget displaying the buffer buffer. One buffer can be shared among many widgets. buffer may beNone
to create a default buffer, in which case this function is equivalent toGtk.TextView.new
(). The text view adds its own reference count to the buffer; it does not take over an existing reference.
- add_child_at_anchor(child, anchor)[source]¶
- Parameters:
child (
Gtk.Widget
) – aGtk.Widget
anchor (
Gtk.TextChildAnchor
) – aGtk.TextChildAnchor
in theGtk.TextBuffer
for self
Adds a child widget in the text buffer, at the given anchor.
- add_child_in_window(child, which_window, xpos, ypos)[source]¶
- Parameters:
child (
Gtk.Widget
) – aGtk.Widget
which_window (
Gtk.TextWindowType
) – which window the child should appear inxpos (
int
) – X position of child in window coordinatesypos (
int
) – Y position of child in window coordinates
Adds a child at fixed coordinates in one of the text widget’s windows.
The window must have nonzero size (see
Gtk.TextView.set_border_window_size
()). Note that the child coordinates are given relative to scrolling. When placing a child inGtk.TextWindowType.WIDGET
, scrolling is irrelevant, the child floats above all scrollable areas. But when placing a child in one of the scrollable windows (border windows or text window) it will move with the scrolling as needed.
- backward_display_line(iter)[source]¶
- Parameters:
iter (
Gtk.TextIter
) – aGtk.TextIter
- Returns:
True
if iter was moved and is not on the end iterator- Return type:
Moves the given iter backward by one display (wrapped) line. A display line is different from a paragraph. Paragraphs are separated by newlines or other paragraph separator characters.
xlib.Display
lines are created by line-wrapping a paragraph. If wrapping is turned off, display lines and paragraphs will be the same.xlib.Display
lines are divided differently for each view, since they depend on the view’s width; paragraphs are the same in all views, since they depend on the contents of theGtk.TextBuffer
.
- backward_display_line_start(iter)[source]¶
- Parameters:
iter (
Gtk.TextIter
) – aGtk.TextIter
- Returns:
True
if iter was moved and is not on the end iterator- Return type:
Moves the given iter backward to the next display line start. A display line is different from a paragraph. Paragraphs are separated by newlines or other paragraph separator characters.
xlib.Display
lines are created by line-wrapping a paragraph. If wrapping is turned off, display lines and paragraphs will be the same.xlib.Display
lines are divided differently for each view, since they depend on the view’s width; paragraphs are the same in all views, since they depend on the contents of theGtk.TextBuffer
.
- buffer_to_window_coords(win, buffer_x, buffer_y)[source]¶
- Parameters:
win (
Gtk.TextWindowType
) – aGtk.TextWindowType
, exceptGtk.TextWindowType.PRIVATE
buffer_x (
int
) – buffer x coordinatebuffer_y (
int
) – buffer y coordinate
- Returns:
- Return type:
Converts coordinate (buffer_x, buffer_y) to coordinates for the window win, and stores the result in (window_x, window_y).
Note that you can’t convert coordinates for a nonexisting window (see
Gtk.TextView.set_border_window_size
()).
- forward_display_line(iter)[source]¶
- Parameters:
iter (
Gtk.TextIter
) – aGtk.TextIter
- Returns:
True
if iter was moved and is not on the end iterator- Return type:
Moves the given iter forward by one display (wrapped) line. A display line is different from a paragraph. Paragraphs are separated by newlines or other paragraph separator characters.
xlib.Display
lines are created by line-wrapping a paragraph. If wrapping is turned off, display lines and paragraphs will be the same.xlib.Display
lines are divided differently for each view, since they depend on the view’s width; paragraphs are the same in all views, since they depend on the contents of theGtk.TextBuffer
.
- forward_display_line_end(iter)[source]¶
- Parameters:
iter (
Gtk.TextIter
) – aGtk.TextIter
- Returns:
True
if iter was moved and is not on the end iterator- Return type:
Moves the given iter forward to the next display line end. A display line is different from a paragraph. Paragraphs are separated by newlines or other paragraph separator characters.
xlib.Display
lines are created by line-wrapping a paragraph. If wrapping is turned off, display lines and paragraphs will be the same.xlib.Display
lines are divided differently for each view, since they depend on the view’s width; paragraphs are the same in all views, since they depend on the contents of theGtk.TextBuffer
.
- get_accepts_tab()[source]¶
- Returns:
True
if pressing the Tab key inserts a tab character,False
if pressing the Tab key moves the keyboard focus.- Return type:
Returns whether pressing the Tab key inserts a tab characters.
Gtk.TextView.set_accepts_tab
().New in version 2.4.
- get_border_window_size(type)[source]¶
- Parameters:
type (
Gtk.TextWindowType
) – window to return size from- Returns:
width of window
- Return type:
Gets the width of the specified border window. See
Gtk.TextView.set_border_window_size
().
- get_bottom_margin()[source]¶
- Returns:
bottom margin in pixels
- Return type:
Gets the bottom margin for text in the self.
New in version 3.18.
- get_buffer()[source]¶
- Returns:
- Return type:
Returns the
Gtk.TextBuffer
being displayed by this text view. The reference count on the buffer is not incremented; the caller of this function won’t own a new reference.
- get_cursor_locations(iter)[source]¶
- Parameters:
iter (
Gtk.TextIter
orNone
) – aGtk.TextIter
- Returns:
- Return type:
(strong:
Gdk.Rectangle
, weak:Gdk.Rectangle
)
Given an iter within a text layout, determine the positions of the strong and weak cursors if the insertion point is at that iterator. The position of each cursor is stored as a zero-width rectangle. The strong cursor location is the location where characters of the directionality equal to the base direction of the paragraph are inserted. The weak cursor location is the location where characters of the directionality opposite to the base direction of the paragraph are inserted.
If iter is
None
, the actual cursor position is used.Note that if iter happens to be the actual cursor position, and there is currently an IM preedit sequence being entered, the returned locations will be adjusted to account for the preedit cursor’s offset within the preedit sequence.
The rectangle position is in buffer coordinates; use
Gtk.TextView.buffer_to_window_coords
() to convert these coordinates to coordinates for one of the windows in the text view.New in version 3.0.
- get_cursor_visible()[source]¶
- Returns:
whether the insertion mark is visible
- Return type:
Find out whether the cursor should be displayed.
- get_default_attributes()[source]¶
- Returns:
a new
Gtk.TextAttributes
- Return type:
Obtains a copy of the default text attributes. These are the attributes used for text unless a tag overrides them. You’d typically pass the default attributes in to
Gtk.TextIter.get_attributes
() in order to get the attributes in effect at a given text position.The return value is a copy owned by the caller of this function, and should be freed with
Gtk.TextAttributes.unref
().
- get_editable()[source]¶
- Returns:
whether text is editable by default
- Return type:
Returns the default editability of the
Gtk.TextView
. Tags in the buffer may override this setting for some ranges of text.
- get_hadjustment()[source]¶
- Returns:
pointer to the horizontal
Gtk.Adjustment
- Return type:
Gets the horizontal-scrolling
Gtk.Adjustment
.New in version 2.22.
Deprecated since version 3.0: Use
Gtk.Scrollable.get_hadjustment
()
- get_indent()[source]¶
- Returns:
number of pixels of indentation
- Return type:
Gets the default indentation of paragraphs in self. Tags in the view’s buffer may override the default. The indentation may be negative.
- get_input_hints()[source]¶
- Return type:
Gets the value of the
Gtk.TextView
:input-hints
property.New in version 3.6.
- get_input_purpose()[source]¶
- Return type:
Gets the value of the
Gtk.TextView
:input-purpose
property.New in version 3.6.
- get_iter_at_location(x, y)[source]¶
- Parameters:
- Returns:
True
if the position is over text- iter:
- Return type:
(
bool
, iter:Gtk.TextIter
)
Retrieves the iterator at buffer coordinates x and y. Buffer coordinates are coordinates for the entire buffer, not just the currently-displayed portion. If you have coordinates from an event, you have to convert those to buffer coordinates with
Gtk.TextView.window_to_buffer_coords
().
- get_iter_at_position(x, y)[source]¶
- Parameters:
- Returns:
True
if the position is over text- iter:
- trailing:
if non-
None
, location to store an integer indicating where in the grapheme the user clicked. It will either be zero, or the number of characters in the grapheme. 0 represents the trailing edge of the grapheme.
- Return type:
(
bool
, iter:Gtk.TextIter
, trailing:int
)
Retrieves the iterator pointing to the character at buffer coordinates x and y. Buffer coordinates are coordinates for the entire buffer, not just the currently-displayed portion. If you have coordinates from an event, you have to convert those to buffer coordinates with
Gtk.TextView.window_to_buffer_coords
().Note that this is different from
Gtk.TextView.get_iter_at_location
(), which returns cursor locations, i.e. positions between characters.New in version 2.6.
- get_iter_location(iter)[source]¶
- Parameters:
iter (
Gtk.TextIter
) – aGtk.TextIter
- Returns:
bounds of the character at iter
- Return type:
location:
Gdk.Rectangle
Gets a rectangle which roughly contains the character at iter. The rectangle position is in buffer coordinates; use
Gtk.TextView.buffer_to_window_coords
() to convert these coordinates to coordinates for one of the windows in the text view.
- get_justification()[source]¶
- Returns:
default justification
- Return type:
Gets the default justification of paragraphs in self. Tags in the buffer may override the default.
- get_left_margin()[source]¶
- Returns:
left margin in pixels
- Return type:
Gets the default left margin size of paragraphs in the self. Tags in the buffer may override the default.
- get_line_at_y(y)[source]¶
- Parameters:
y (
int
) – a y coordinate- Returns:
- target_iter:
- line_top:
return location for top coordinate of the line
- Return type:
(target_iter:
Gtk.TextIter
, line_top:int
)
Gets the
Gtk.TextIter
at the start of the line containing the coordinate y. y is in buffer coordinates, convert from window coordinates withGtk.TextView.window_to_buffer_coords
(). If non-None
, line_top will be filled with the coordinate of the top edge of the line.
- get_line_yrange(iter)[source]¶
- Parameters:
iter (
Gtk.TextIter
) – aGtk.TextIter
- Returns:
- y:
return location for a y coordinate
- height:
return location for a height
- Return type:
Gets the y coordinate of the top of the line containing iter, and the height of the line. The coordinate is a buffer coordinate; convert to window coordinates with
Gtk.TextView.buffer_to_window_coords
().
- get_monospace()[source]¶
-
Gets the value of the
Gtk.TextView
:monospace
property.New in version 3.16.
- get_overwrite()[source]¶
- Returns:
whether self is in overwrite mode or not.
- Return type:
Returns whether the
Gtk.TextView
is in overwrite mode or not.New in version 2.4.
- get_pixels_above_lines()[source]¶
- Returns:
default number of pixels above paragraphs
- Return type:
Gets the default number of pixels to put above paragraphs. Adding this function with
Gtk.TextView.get_pixels_below_lines
() is equal to the line space between each paragraph.
- get_pixels_below_lines()[source]¶
- Returns:
default number of blank pixels below paragraphs
- Return type:
Gets the value set by
Gtk.TextView.set_pixels_below_lines
().The line space is the sum of the value returned by this function and the value returned by
Gtk.TextView.get_pixels_above_lines
().
- get_pixels_inside_wrap()[source]¶
- Returns:
default number of pixels of blank space between wrapped lines
- Return type:
Gets the value set by
Gtk.TextView.set_pixels_inside_wrap
().
- get_right_margin()[source]¶
- Returns:
right margin in pixels
- Return type:
Gets the default right margin for text in self. Tags in the buffer may override the default.
- get_tabs()[source]¶
- Returns:
copy of default tab array, or
None
if “standard” tabs are used; must be freed withPango.TabArray.free
().- Return type:
Gets the default tabs for self. Tags in the buffer may override the defaults. The returned array will be
None
if “standard” (8-space) tabs are used. Free the return value withPango.TabArray.free
().
- get_top_margin()[source]¶
- Returns:
top margin in pixels
- Return type:
Gets the top margin for text in the self.
New in version 3.18.
- get_vadjustment()[source]¶
- Returns:
pointer to the vertical
Gtk.Adjustment
- Return type:
Gets the vertical-scrolling
Gtk.Adjustment
.New in version 2.22.
Deprecated since version 3.0: Use
Gtk.Scrollable.get_vadjustment
()
- get_visible_rect()[source]¶
- Returns:
rectangle to fill
- Return type:
visible_rect:
Gdk.Rectangle
Fills visible_rect with the currently-visible region of the buffer, in buffer coordinates. Convert to window coordinates with
Gtk.TextView.buffer_to_window_coords
().
- get_window(win)[source]¶
- Parameters:
win (
Gtk.TextWindowType
) – window to get- Returns:
a
Gdk.Window
, orNone
- Return type:
Gdk.Window
orNone
Retrieves the
Gdk.Window
corresponding to an area of the text view; possible windows include the overall widget window, child windows on the left, right, top, bottom, and the window that displays the text buffer. Windows areNone
and nonexistent if their width or height is 0, and are nonexistent before the widget has been realized.
- get_window_type(window)[source]¶
- Parameters:
window (
Gdk.Window
) – a window type- Returns:
the window type.
- Return type:
Usually used to find out which window an event corresponds to.
If you connect to an event signal on self, this function should be called on
event->window
to see which window it was.
- get_wrap_mode()[source]¶
- Returns:
the line wrap setting
- Return type:
Gets the line wrapping for the view.
- im_context_filter_keypress(event)[source]¶
- Parameters:
event (
Gdk.EventKey
) – the key event- Returns:
True
if the input method handled the key event.- Return type:
Allow the
Gtk.TextView
input method to internally handle key press and release events. If this function returnsTrue
, then no further processing should be done for this key event. SeeGtk.IMContext.filter_keypress
().Note that you are expected to call this function from your handler when overriding key event handling. This is needed in the case when you need to insert your own key handling between the input method and the default key event handling of the
Gtk.TextView
.static gboolean gtk_foo_bar_key_press_event (GtkWidget *widget, GdkEventKey *event) { guint keyval; gdk_event_get_keyval ((GdkEvent*)event, &keyval); if (keyval == GDK_KEY_Return || keyval == GDK_KEY_KP_Enter) { if (gtk_text_view_im_context_filter_keypress (GTK_TEXT_VIEW (widget), event)) return TRUE; } // Do some stuff return GTK_WIDGET_CLASS (gtk_foo_bar_parent_class)->key_press_event (widget, event); }
New in version 2.22.
- move_child(child, xpos, ypos)[source]¶
- Parameters:
child (
Gtk.Widget
) – child widget already added to the text viewxpos (
int
) – new X position in window coordinatesypos (
int
) – new Y position in window coordinates
Updates the position of a child, as for
Gtk.TextView.add_child_in_window
().
- move_mark_onscreen(mark)[source]¶
- Parameters:
mark (
Gtk.TextMark
) – aGtk.TextMark
- Returns:
True
if the mark moved (wasn’t already onscreen)- Return type:
Moves a mark within the buffer so that it’s located within the currently-visible text area.
- move_visually(iter, count)[source]¶
- Parameters:
iter (
Gtk.TextIter
) – aGtk.TextIter
count (
int
) – number of characters to move (negative moves left, positive moves right)
- Returns:
True
if iter moved and is not on the end iterator- Return type:
Move the iterator a given number of characters visually, treating it as the strong cursor position. If count is positive, then the new strong cursor position will be count positions to the right of the old cursor position. If count is negative then the new strong cursor position will be count positions to the left of the old cursor position.
In the presence of bi-directional text, the correspondence between logical and visual order will depend on the direction of the current run, and there may be jumps when the cursor is moved off of the end of a run.
- place_cursor_onscreen()[source]¶
-
Moves the cursor to the currently visible region of the buffer, it it isn’t there already.
- reset_cursor_blink()[source]¶
Ensures that the cursor is shown (i.e. not in an ‘off’ blink interval) and resets the time that it will stay blinking (or visible, in case blinking is disabled).
This function should be called in response to user input (e.g. from derived classes that override the textview’s
Gtk.Widget
::key-press-event
handler).New in version 3.20.
- reset_im_context()[source]¶
Reset the input method context of the text view if needed.
This can be necessary in the case where modifying the buffer would confuse on-going input method behavior.
New in version 2.22.
- scroll_mark_onscreen(mark)[source]¶
- Parameters:
mark (
Gtk.TextMark
) – a mark in the buffer for self
Scrolls self the minimum distance such that mark is contained within the visible area of the widget.
- scroll_to_iter(iter, within_margin, use_align, xalign, yalign)[source]¶
- Parameters:
iter (
Gtk.TextIter
) – aGtk.TextIter
within_margin (
float
) – margin as a [0.0,0.5) fraction of screen sizeuse_align (
bool
) – whether to use alignment arguments (ifFalse
, just get the mark onscreen)xalign (
float
) – horizontal alignment of mark within visible areayalign (
float
) – vertical alignment of mark within visible area
- Returns:
True
if scrolling occurred- Return type:
Scrolls self so that iter is on the screen in the position indicated by xalign and yalign. An alignment of 0.0 indicates left or top, 1.0 indicates right or bottom, 0.5 means center. If use_align is
False
, the text scrolls the minimal distance to get the mark onscreen, possibly not scrolling at all. The effective screen for purposes of this function is reduced by a margin of size within_margin.Note that this function uses the currently-computed height of the lines in the text buffer. Line heights are computed in an idle handler; so this function may not have the desired effect if it’s called before the height computations. To avoid oddness, consider using
Gtk.TextView.scroll_to_mark
() which saves a point to be scrolled to after line validation.
- scroll_to_mark(mark, within_margin, use_align, xalign, yalign)[source]¶
- Parameters:
mark (
Gtk.TextMark
) – aGtk.TextMark
within_margin (
float
) – margin as a [0.0,0.5) fraction of screen sizeuse_align (
bool
) – whether to use alignment arguments (ifFalse
, just get the mark onscreen)xalign (
float
) – horizontal alignment of mark within visible areayalign (
float
) – vertical alignment of mark within visible area
Scrolls self so that mark is on the screen in the position indicated by xalign and yalign. An alignment of 0.0 indicates left or top, 1.0 indicates right or bottom, 0.5 means center. If use_align is
False
, the text scrolls the minimal distance to get the mark onscreen, possibly not scrolling at all. The effective screen for purposes of this function is reduced by a margin of size within_margin.
- set_accepts_tab(accepts_tab)[source]¶
- Parameters:
accepts_tab (
bool
) –True
if pressing the Tab key should insert a tab character,False
, if pressing the Tab key should move the keyboard focus.
Sets the behavior of the text widget when the Tab key is pressed. If accepts_tab is
True
, a tab character is inserted. If accepts_tab isFalse
the keyboard focus is moved to the next widget in the focus chain.New in version 2.4.
- set_border_window_size(type, size)[source]¶
- Parameters:
type (
Gtk.TextWindowType
) – window to affectsize (
int
) – width or height of the window
Sets the width of
Gtk.TextWindowType.LEFT
orGtk.TextWindowType.RIGHT
, or the height ofGtk.TextWindowType.TOP
orGtk.TextWindowType.BOTTOM
. Automatically destroys the corresponding window if the size is set to 0, and creates the window if the size is set to non-zero. This function can only be used for the “border windows”, and it won’t work withGtk.TextWindowType.WIDGET
,Gtk.TextWindowType.TEXT
, orGtk.TextWindowType.PRIVATE
.
- set_bottom_margin(bottom_margin)[source]¶
- Parameters:
bottom_margin (
int
) – bottom margin in pixels
Sets the bottom margin for text in self.
Note that this function is confusingly named. In CSS terms, the value set here is padding.
New in version 3.18.
- set_buffer(buffer)[source]¶
- Parameters:
buffer (
Gtk.TextBuffer
orNone
) – aGtk.TextBuffer
Sets buffer as the buffer being displayed by self. The previous buffer displayed by the text view is unreferenced, and a reference is added to buffer. If you owned a reference to buffer before passing it to this function, you must remove that reference yourself;
Gtk.TextView
will not “adopt” it.
- set_cursor_visible(setting)[source]¶
- Parameters:
setting (
bool
) – whether to show the insertion cursor
Toggles whether the insertion point should be displayed. A buffer with no editable text probably shouldn’t have a visible cursor, so you may want to turn the cursor off.
Note that this property may be overridden by the
Gtk.Settings
:gtk-keynave-use-caret
settings.
- set_editable(setting)[source]¶
- Parameters:
setting (
bool
) – whether it’s editable
Sets the default editability of the
Gtk.TextView
. You can override this default setting with tags in the buffer, using the “editable” attribute of tags.
- set_indent(indent)[source]¶
- Parameters:
indent (
int
) – indentation in pixels
Sets the default indentation for paragraphs in self. Tags in the buffer may override the default.
- set_input_hints(hints)[source]¶
- Parameters:
hints (
Gtk.InputHints
) – the hints
Sets the
Gtk.TextView
:input-hints
property, which allows input methods to fine-tune their behaviour.New in version 3.6.
- set_input_purpose(purpose)[source]¶
- Parameters:
purpose (
Gtk.InputPurpose
) – the purpose
Sets the
Gtk.TextView
:input-purpose
property which can be used by on-screen keyboards and other input methods to adjust their behaviour.New in version 3.6.
- set_justification(justification)[source]¶
- Parameters:
justification (
Gtk.Justification
) – justification
Sets the default justification of text in self. Tags in the view’s buffer may override the default.
- set_left_margin(left_margin)[source]¶
- Parameters:
left_margin (
int
) – left margin in pixels
Sets the default left margin for text in self. Tags in the buffer may override the default.
Note that this function is confusingly named. In CSS terms, the value set here is padding.
- set_monospace(monospace)[source]¶
-
Sets the
Gtk.TextView
:monospace
property, which indicates that the text view should use monospace fonts.New in version 3.16.
- set_overwrite(overwrite)[source]¶
-
Changes the
Gtk.TextView
overwrite mode.New in version 2.4.
- set_pixels_above_lines(pixels_above_lines)[source]¶
- Parameters:
pixels_above_lines (
int
) – pixels above paragraphs
Sets the default number of blank pixels above paragraphs in self. Tags in the buffer for self may override the defaults.
- set_pixels_below_lines(pixels_below_lines)[source]¶
- Parameters:
pixels_below_lines (
int
) – pixels below paragraphs
Sets the default number of pixels of blank space to put below paragraphs in self. May be overridden by tags applied to self’s buffer.
- set_pixels_inside_wrap(pixels_inside_wrap)[source]¶
- Parameters:
pixels_inside_wrap (
int
) – default number of pixels between wrapped lines
Sets the default number of pixels of blank space to leave between display/wrapped lines within a paragraph. May be overridden by tags in self’s buffer.
- set_right_margin(right_margin)[source]¶
- Parameters:
right_margin (
int
) – right margin in pixels
Sets the default right margin for text in the text view. Tags in the buffer may override the default.
Note that this function is confusingly named. In CSS terms, the value set here is padding.
- set_tabs(tabs)[source]¶
- Parameters:
tabs (
Pango.TabArray
) – tabs as aPango.TabArray
Sets the default tab stops for paragraphs in self. Tags in the buffer may override the default.
- set_top_margin(top_margin)[source]¶
- Parameters:
top_margin (
int
) – top margin in pixels
Sets the top margin for text in self.
Note that this function is confusingly named. In CSS terms, the value set here is padding.
New in version 3.18.
- set_wrap_mode(wrap_mode)[source]¶
- Parameters:
wrap_mode (
Gtk.WrapMode
) – aGtk.WrapMode
Sets the line wrapping for the view.
- starts_display_line(iter)[source]¶
- Parameters:
iter (
Gtk.TextIter
) – aGtk.TextIter
- Returns:
True
if iter begins a wrapped line- Return type:
Determines whether iter is at the start of a display line. See
Gtk.TextView.forward_display_line
() for an explanation of display lines vs. paragraphs.
- window_to_buffer_coords(win, window_x, window_y)[source]¶
- Parameters:
win (
Gtk.TextWindowType
) – aGtk.TextWindowType
exceptGtk.TextWindowType.PRIVATE
window_x (
int
) – window x coordinatewindow_y (
int
) – window y coordinate
- Returns:
- Return type:
Converts coordinates on the window identified by win to buffer coordinates, storing the result in (buffer_x,`buffer_y`).
Note that you can’t convert coordinates for a nonexisting window (see
Gtk.TextView.set_border_window_size
()).
- do_backspace() virtual¶
The class handler for the
Gtk.TextView
::backspace
keybinding signal.
- do_copy_clipboard() virtual¶
The class handler for the #GtkTextview::copy-clipboard keybinding signal.
- do_cut_clipboard() virtual¶
The class handler for the
Gtk.TextView
::cut-clipboard
keybinding signal
- do_delete_from_cursor(type, count) virtual¶
- Parameters:
type (
Gtk.DeleteType
) –count (
int
) –
The class handler for the
Gtk.TextView
::delete-from-cursor
keybinding signal.
- do_draw_layer(layer, cr) virtual¶
- Parameters:
layer (
Gtk.TextViewLayer
) –cr (
cairo.Context
) –
The draw_layer vfunc is called before and after the text view is drawing its own text. Applications can override this vfunc in a subclass to draw customized content underneath or above the text. In the
Gtk.TextViewLayer.BELOW_TEXT
andGtk.TextViewLayer.ABOVE_TEXT
the drawing is done in the buffer coordinate space, but the older (deprecated) layersGtk.TextViewLayer.BELOW
andGtk.TextViewLayer.ABOVE
work in viewport coordinates, which makes them unnecessarily hard to use.New in version 3.14.
- do_extend_selection(granularity, location, start, end) virtual¶
- Parameters:
granularity (
Gtk.TextExtendSelection
) –location (
Gtk.TextIter
) –start (
Gtk.TextIter
) –end (
Gtk.TextIter
) –
- Return type:
The class handler for the
Gtk.TextView
::extend-selection
signal.New in version 3.16.
- do_insert_at_cursor(str) virtual¶
- Parameters:
str (
str
) –
The class handler for the
Gtk.TextView
::insert-at-cursor
keybinding signal.
- do_insert_emoji() virtual¶
- do_move_cursor(step, count, extend_selection) virtual¶
- Parameters:
step (
Gtk.MovementStep
) –count (
int
) –extend_selection (
bool
) –
The class handler for the
Gtk.TextView
::move-cursor
keybinding signal.
- do_paste_clipboard() virtual¶
The class handler for the
Gtk.TextView
::paste-clipboard
keybinding signal.
- do_populate_popup(popup) virtual¶
- Parameters:
popup (
Gtk.Widget
) –
The class handler for the
Gtk.TextView
::populate-popup
signal.
- do_set_anchor() virtual¶
The class handler for the
Gtk.TextView
::set-anchor
keybinding signal.
- do_toggle_overwrite() virtual¶
The class handler for the
Gtk.TextView
::toggle-overwrite
keybinding signal.
Signal Details¶
- Gtk.TextView.signals.backspace(text_view)¶
- Signal Name:
backspace
- Flags:
- Parameters:
text_view (
Gtk.TextView
) – The object which received the signal
The
::backspace
signal is akeybinding signal
which gets emitted when the user asks for it.The default bindings for this signal are Backspace and Shift-Backspace.
- Gtk.TextView.signals.copy_clipboard(text_view)¶
- Signal Name:
copy-clipboard
- Flags:
- Parameters:
text_view (
Gtk.TextView
) – The object which received the signal
The
::copy-clipboard
signal is akeybinding signal
which gets emitted to copy the selection to the clipboard.The default bindings for this signal are Ctrl-c and Ctrl-Insert.
- Gtk.TextView.signals.cut_clipboard(text_view)¶
- Signal Name:
cut-clipboard
- Flags:
- Parameters:
text_view (
Gtk.TextView
) – The object which received the signal
The
::cut-clipboard
signal is akeybinding signal
which gets emitted to cut the selection to the clipboard.The default bindings for this signal are Ctrl-x and Shift-Delete.
- Gtk.TextView.signals.delete_from_cursor(text_view, type, count)¶
- Signal Name:
delete-from-cursor
- Flags:
- Parameters:
text_view (
Gtk.TextView
) – The object which received the signaltype (
Gtk.DeleteType
) – the granularity of the deletion, as aGtk.DeleteType
count (
int
) – the number of type units to delete
The
::delete-from-cursor
signal is akeybinding signal
which gets emitted when the user initiates a text deletion.If the type is
Gtk.DeleteType.CHARS
, GTK+ deletes the selection if there is one, otherwise it deletes the requested number of characters.The default bindings for this signal are Delete for deleting a character, Ctrl-Delete for deleting a word and Ctrl-Backspace for deleting a word backwords.
- Gtk.TextView.signals.extend_selection(text_view, granularity, location, start, end)¶
- Signal Name:
extend-selection
- Flags:
- Parameters:
text_view (
Gtk.TextView
) – The object which received the signalgranularity (
Gtk.TextExtendSelection
) – the granularity typelocation (
Gtk.TextIter
) – the location where to extend the selectionstart (
Gtk.TextIter
) – where the selection should startend (
Gtk.TextIter
) – where the selection should end
- Returns:
Gdk.EVENT_STOP
to stop other handlers from being invoked for the event.Gdk.EVENT_PROPAGATE
to propagate the event further.- Return type:
The
::extend-selection
signal is emitted when the selection needs to be extended at location.New in version 3.16.
- Gtk.TextView.signals.insert_at_cursor(text_view, string)¶
- Signal Name:
insert-at-cursor
- Flags:
- Parameters:
text_view (
Gtk.TextView
) – The object which received the signalstring (
str
) – the string to insert
The
::insert-at-cursor
signal is akeybinding signal
which gets emitted when the user initiates the insertion of a fixed string at the cursor.This signal has no default bindings.
- Gtk.TextView.signals.insert_emoji(text_view)¶
- Signal Name:
insert-emoji
- Flags:
- Parameters:
text_view (
Gtk.TextView
) – The object which received the signal
The
::insert-emoji
signal is akeybinding signal
which gets emitted to present the Emoji chooser for the text_view.The default bindings for this signal are Ctrl-. and Ctrl-;
New in version 3.22.27.
- Gtk.TextView.signals.move_cursor(text_view, step, count, extend_selection)¶
- Signal Name:
move-cursor
- Flags:
- Parameters:
text_view (
Gtk.TextView
) – The object which received the signalstep (
Gtk.MovementStep
) – the granularity of the move, as aGtk.MovementStep
count (
int
) – the number of step units to moveextend_selection (
bool
) –True
if the move should extend the selection
The
::move-cursor
signal is akeybinding signal
which gets emitted when the user initiates a cursor movement. If the cursor is not visible in text_view, this signal causes the viewport to be moved instead.Applications should not connect to it, but may emit it with g_signal_emit_by_name() if they need to control the cursor programmatically.
The default bindings for this signal come in two variants, the variant with the Shift modifier extends the selection, the variant without the Shift modifer does not. There are too many key combinations to list them all here.
Arrow keys move by individual characters/lines
Ctrl-arrow key combinations move by words/paragraphs
Home/End keys move to the ends of the buffer
PageUp/PageDown keys move vertically by pages
Ctrl-PageUp/PageDown keys move horizontally by pages
- Gtk.TextView.signals.move_viewport(text_view, step, count)¶
- Signal Name:
move-viewport
- Flags:
- Parameters:
text_view (
Gtk.TextView
) – The object which received the signalstep (
Gtk.ScrollStep
) – the granularity of the movement, as aGtk.ScrollStep
count (
int
) – the number of step units to move
The
::move-viewport
signal is akeybinding signal
which can be bound to key combinations to allow the user to move the viewport, i.e. change what part of the text view is visible in a containing scrolled window.There are no default bindings for this signal.
- Gtk.TextView.signals.paste_clipboard(text_view)¶
- Signal Name:
paste-clipboard
- Flags:
- Parameters:
text_view (
Gtk.TextView
) – The object which received the signal
The
::paste-clipboard
signal is akeybinding signal
which gets emitted to paste the contents of the clipboard into the text view.The default bindings for this signal are Ctrl-v and Shift-Insert.
- Gtk.TextView.signals.populate_popup(text_view, popup)¶
- Signal Name:
populate-popup
- Flags:
- Parameters:
text_view (
Gtk.TextView
) – The object which received the signalpopup (
Gtk.Widget
) – the container that is being populated
The
::populate-popup
signal gets emitted before showing the context menu of the text view.If you need to add items to the context menu, connect to this signal and append your items to the popup, which will be a
Gtk.Menu
in this case.If
Gtk.TextView
:populate-all
isTrue
, this signal will also be emitted to populate touch popups. In this case, popup will be a different container, e.g. aGtk.Toolbar
.The signal handler should not make assumptions about the type of widget, but check whether popup is a
Gtk.Menu
orGtk.Toolbar
or another kind of container.
- Gtk.TextView.signals.preedit_changed(text_view, preedit)¶
- Signal Name:
preedit-changed
- Flags:
- Parameters:
text_view (
Gtk.TextView
) – The object which received the signalpreedit (
str
) – the current preedit string
If an input method is used, the typed text will not immediately be committed to the buffer. So if you are interested in the text, connect to this signal.
This signal is only emitted if the text at the given position is actually editable.
New in version 2.20.
- Gtk.TextView.signals.select_all(text_view, select)¶
- Signal Name:
select-all
- Flags:
- Parameters:
text_view (
Gtk.TextView
) – The object which received the signal
The
::select-all
signal is akeybinding signal
which gets emitted to select or unselect the complete contents of the text view.The default bindings for this signal are Ctrl-a and Ctrl-/ for selecting and Shift-Ctrl-a and Ctrl-\ for unselecting.
- Gtk.TextView.signals.set_anchor(text_view)¶
- Signal Name:
set-anchor
- Flags:
- Parameters:
text_view (
Gtk.TextView
) – The object which received the signal
The
::set-anchor
signal is akeybinding signal
which gets emitted when the user initiates setting the “anchor” mark. The “anchor” mark gets placed at the same position as the “insert” mark.This signal has no default bindings.
- Gtk.TextView.signals.toggle_cursor_visible(text_view)¶
- Signal Name:
toggle-cursor-visible
- Flags:
- Parameters:
text_view (
Gtk.TextView
) – The object which received the signal
The
::toggle-cursor-visible
signal is akeybinding signal
which gets emitted to toggle theGtk.TextView
:cursor-visible
property.The default binding for this signal is F7.
- Gtk.TextView.signals.toggle_overwrite(text_view)¶
- Signal Name:
toggle-overwrite
- Flags:
- Parameters:
text_view (
Gtk.TextView
) – The object which received the signal
The
::toggle-overwrite
signal is akeybinding signal
which gets emitted to toggle the overwrite mode of the text view.The default bindings for this signal is Insert.
Property Details¶
- Gtk.TextView.props.accepts_tab¶
- Name:
accepts-tab
- Type:
- Default Value:
- Flags:
Whether Tab will result in a tab character being entered
- Gtk.TextView.props.bottom_margin¶
- Name:
bottom-margin
- Type:
- Default Value:
0
- Flags:
The bottom margin for text in the text view.
Note that this property is confusingly named. In CSS terms, the value set here is padding, and it is applied in addition to the padding from the theme.
Don’t confuse this property with
Gtk.Widget
:margin-bottom
.New in version 3.18.
- Gtk.TextView.props.buffer¶
- Name:
buffer
- Type:
- Default Value:
- Flags:
The buffer which is displayed
- Gtk.TextView.props.cursor_visible¶
- Name:
cursor-visible
- Type:
- Default Value:
- Flags:
If the insertion cursor is shown
- Gtk.TextView.props.editable¶
- Name:
editable
- Type:
- Default Value:
- Flags:
Whether the text can be modified by the user
- Gtk.TextView.props.im_module¶
-
Which IM (input method) module should be used for this text_view. See
Gtk.IMContext
.Setting this to a non-
None
value overrides the system-wide IM module setting. See theGtk.Settings
Gtk.Settings
:gtk-im-module
property.New in version 2.16.
- Gtk.TextView.props.indent¶
- Name:
indent
- Type:
- Default Value:
0
- Flags:
Amount to indent the paragraph, in pixels
- Gtk.TextView.props.input_hints¶
- Name:
input-hints
- Type:
- Default Value:
- Flags:
Additional hints (beyond
Gtk.TextView
:input-purpose
) that allow input methods to fine-tune their behaviour.New in version 3.6.
- Gtk.TextView.props.input_purpose¶
- Name:
input-purpose
- Type:
- Default Value:
- Flags:
The purpose of this text field.
This property can be used by on-screen keyboards and other input methods to adjust their behaviour.
New in version 3.6.
- Gtk.TextView.props.justification¶
- Name:
justification
- Type:
- Default Value:
- Flags:
Left, right, or center justification
- Gtk.TextView.props.left_margin¶
- Name:
left-margin
- Type:
- Default Value:
0
- Flags:
The default left margin for text in the text view. Tags in the buffer may override the default.
Note that this property is confusingly named. In CSS terms, the value set here is padding, and it is applied in addition to the padding from the theme.
Don’t confuse this property with
Gtk.Widget
:margin-left
.
- Gtk.TextView.props.monospace¶
- Name:
monospace
- Type:
- Default Value:
- Flags:
Whether to use a monospace font
- Gtk.TextView.props.overwrite¶
- Name:
overwrite
- Type:
- Default Value:
- Flags:
Whether entered text overwrites existing contents
- Gtk.TextView.props.pixels_above_lines¶
- Name:
pixels-above-lines
- Type:
- Default Value:
0
- Flags:
Pixels of blank space above paragraphs
- Gtk.TextView.props.pixels_below_lines¶
- Name:
pixels-below-lines
- Type:
- Default Value:
0
- Flags:
Pixels of blank space below paragraphs
- Gtk.TextView.props.pixels_inside_wrap¶
- Name:
pixels-inside-wrap
- Type:
- Default Value:
0
- Flags:
Pixels of blank space between wrapped lines in a paragraph
- Gtk.TextView.props.populate_all¶
- Name:
populate-all
- Type:
- Default Value:
- Flags:
If
:populate-all
isTrue
, theGtk.TextView
::populate-popup
signal is also emitted for touch popups.New in version 3.8.
- Gtk.TextView.props.right_margin¶
- Name:
right-margin
- Type:
- Default Value:
0
- Flags:
The default right margin for text in the text view. Tags in the buffer may override the default.
Note that this property is confusingly named. In CSS terms, the value set here is padding, and it is applied in addition to the padding from the theme.
Don’t confuse this property with
Gtk.Widget
:margin-right
.
- Gtk.TextView.props.tabs¶
- Name:
tabs
- Type:
- Default Value:
- Flags:
Custom tabs for this text
- Gtk.TextView.props.top_margin¶
- Name:
top-margin
- Type:
- Default Value:
0
- Flags:
The top margin for text in the text view.
Note that this property is confusingly named. In CSS terms, the value set here is padding, and it is applied in addition to the padding from the theme.
Don’t confuse this property with
Gtk.Widget
:margin-top
.New in version 3.18.
- Gtk.TextView.props.wrap_mode¶
- Name:
wrap-mode
- Type:
- Default Value:
- Flags:
Whether to wrap lines never, at word boundaries, or at character boundaries