Gtk.TextView - Classes - Gtk 3.0 (original) (raw)
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 Gtk.Widget->Gtk.Container
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)
do_backspace () |
---|
do_copy_clipboard () |
do_cut_clipboard () |
do_delete_from_cursor (type, count) |
do_draw_layer (layer, cr) |
do_extend_selection (granularity, location, start, end) |
do_insert_at_cursor (str) |
do_insert_emoji () |
do_move_cursor (step, count, extend_selection) |
do_paste_clipboard () |
do_populate_popup (popup) |
do_set_anchor () |
do_toggle_overwrite () |
Properties¶
Inherited:
Gtk.Container (3), Gtk.Widget (39), Gtk.Scrollable (4)
Name | Type | Flags | Short Description |
---|---|---|---|
accepts-tab | bool | r/w/en | Whether Tab will result in a tab character being entered |
bottom-margin | int | r/w/en | Height of the bottom margin in pixels |
buffer | Gtk.TextBuffer | r/w | The buffer which is displayed |
cursor-visible | bool | r/w/en | If the insertion cursor is shown |
editable | bool | r/w/en | Whether the text can be modified by the user |
im-module | str | r/w | Which IM module should be used |
indent | int | r/w/en | Amount to indent the paragraph, in pixels |
input-hints | Gtk.InputHints | r/w/en | Hints for the text field behaviour |
input-purpose | Gtk.InputPurpose | r/w/en | Purpose of the text field |
justification | Gtk.Justification | r/w/en | Left, right, or center justification |
left-margin | int | r/w/en | Width of the left margin in pixels |
monospace | bool | r/w/en | Whether to use a monospace font |
overwrite | bool | r/w/en | Whether entered text overwrites existing contents |
pixels-above-lines | int | r/w/en | Pixels of blank space above paragraphs |
pixels-below-lines | int | r/w/en | Pixels of blank space below paragraphs |
pixels-inside-wrap | int | r/w/en | Pixels of blank space between wrapped lines in a paragraph |
populate-all | bool | r/w/en | Whether to emit ::populate-popup for touch popups |
right-margin | int | r/w/en | Width of the right margin in pixels |
tabs | Pango.TabArray | r/w | Custom tabs for this text |
top-margin | int | r/w/en | Height of the top margin in pixels |
wrap-mode | Gtk.WrapMode | r/w/en | Whether to wrap lines never, at word boundaries, or at character boundaries |
Style Properties¶
Inherited:
Name | Type | Default | Flags | Short Description |
---|---|---|---|---|
error-underline-color | Gdk.Color | None | r | Color with which to draw error-indication underlines |
Signals¶
Inherited:
Gtk.Container (4), Gtk.Widget (69), GObject.Object (1)
Name | Short Description |
---|---|
backspace | The ::backspace signal is a keybinding signal which gets emitted when the user asks for it. |
copy-clipboard | The ::copy-clipboard signal is a keybinding signal which gets emitted to copy the selection to the clipboard. |
cut-clipboard | The ::cut-clipboard signal is a keybinding signal which gets emitted to cut the selection to the clipboard. |
delete-from-cursor | The ::delete-from-cursor signal is a keybinding signal which gets emitted when the user initiates a text deletion. |
extend-selection | The ::extend-selection signal is emitted when the selection needs to be extended at location. |
insert-at-cursor | The ::insert-at-cursor signal is a keybinding signal which gets emitted when the user initiates the insertion of a fixed string at the cursor. |
insert-emoji | The ::insert-emoji signal is a keybinding signal which gets emitted to present the Emoji chooser for the text_view. |
move-cursor | The ::move-cursor signal is a keybinding signal which gets emitted when the user initiates a cursor movement. |
move-viewport | The ::move-viewport signal is a keybinding signal which can be bound to key combinations to allow the user to move the viewport, i.e. |
paste-clipboard | The ::paste-clipboard signal is a keybinding signal which gets emitted to paste the contents of the clipboard into the text view. |
populate-popup | The ::populate-popup signal gets emitted before showing the context menu of the text view. |
preedit-changed | If an input method is used, the typed text will not immediately be committed to the buffer. |
select-all | The ::select-all signal is a keybinding signal which gets emitted to select or unselect the complete contents of the text view. |
set-anchor | The ::set-anchor signal is a keybinding signal which gets emitted when the user initiates setting the “anchor” mark. |
toggle-cursor-visible | The ::toggle-cursor-visible signal is a keybinding signal which gets emitted to toggle the Gtk.TextView :cursor-visible property. |
toggle-overwrite | The ::toggle-overwrite signal is a keybinding signal which gets emitted to toggle the overwrite mode of the text view. |
Fields¶
Inherited:
Gtk.Container (4), Gtk.Widget (69), GObject.Object (1)
Name | Type | Access | Description |
---|---|---|---|
parent_instance | Gtk.Container | r |
Class Details¶
class Gtk.TextView(**kwargs)¶
Bases:
Abstract:
No
Structure:
You may wish to begin by reading thetext widget conceptual overviewwhich 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.
Returns:
a new Gtk.TextView
Return type:
Creates a new Gtk.TextView. If you don’t call Gtk.TextView.set_buffer() before using the text view, an empty default buffer will be created for you. Get the buffer with Gtk.TextView.get_buffer(). If you want to specify your own buffer, consider Gtk.TextView.new_with_buffer().
classmethod new_with_buffer(buffer)[source]¶
Parameters:
buffer (Gtk.TextBuffer) – a Gtk.TextBuffer
Returns:
a new Gtk.TextView.
Return type:
Creates a new Gtk.TextView widget displaying the bufferbuffer. One buffer can be shared among many widgets.buffer may be None to create a default buffer, in which case this function is equivalent to Gtk.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) – a Gtk.Widget
- anchor (Gtk.TextChildAnchor) – a Gtk.TextChildAnchor in the Gtk.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) – a Gtk.Widget
- which_window (Gtk.TextWindowType) – which window the child should appear in
- xpos (int) – X position of child in window coordinates
- ypos (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 (seeGtk.TextView.set_border_window_size()). Note that the child coordinates are given relative to scrolling. When placing a child in Gtk.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) – a Gtk.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 the Gtk.TextBuffer.
backward_display_line_start(iter)[source]¶
Parameters:
iter (Gtk.TextIter) – a Gtk.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 the Gtk.TextBuffer.
buffer_to_window_coords(win, buffer_x, buffer_y)[source]¶
Parameters:
- win (Gtk.TextWindowType) – a Gtk.TextWindowType, except Gtk.TextWindowType.PRIVATE
- buffer_x (int) – buffer x coordinate
- buffer_y (int) – buffer y coordinate
Returns:
window_x:
window x coordinate return location or None
window_y:
window y coordinate return location or None
Return type:
(window_x: int, window_y: int)
Converts coordinate (buffer_x, buffer_y) to coordinates for the windowwin, and stores the result in (window_x, window_y).
Note that you can’t convert coordinates for a nonexisting window (seeGtk.TextView.set_border_window_size()).
forward_display_line(iter)[source]¶
Parameters:
iter (Gtk.TextIter) – a Gtk.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 the Gtk.TextBuffer.
forward_display_line_end(iter)[source]¶
Parameters:
iter (Gtk.TextIter) – a Gtk.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 the Gtk.TextBuffer.
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. SeeGtk.TextView.set_border_window_size().
Returns:
bottom margin in pixels
Return type:
Gets the bottom margin for text in the self.
New in version 3.18.
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 or None) – a Gtk.TextIter
Returns:
strong:
location to store the strong cursor position (may be None)
weak:
location to store the weak cursor position (may be None)
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; useGtk.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.
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 toGtk.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().
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.
Returns:
pointer to the horizontal Gtk.Adjustment
Return type:
Gets the horizontal-scrolling Gtk.Adjustment.
New in version 2.22.
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.
Return type:
Gets the value of the Gtk.TextView :input-hints property.
New in version 3.6.
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 withGtk.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 withGtk.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) – a Gtk.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; useGtk.TextView.buffer_to_window_coords() to convert these coordinates to coordinates for one of the windows in the text view.
Returns:
default justification
Return type:
Gets the default justification of paragraphs in self. Tags in the buffer may override the default.
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.
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 with Gtk.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) – a Gtk.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().
Returns:
True if monospace fonts are desired
Return type:
Gets the value of the Gtk.TextView :monospace property.
New in version 3.16.
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().
Returns:
right margin in pixels
Return type:
Gets the default right margin for text in self. Tags in the buffer may override the default.
Returns:
copy of default tab array, or None if “standard” tabs are used; must be freed with Pango.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 with Pango.TabArray.free().
Returns:
top margin in pixels
Return type:
Gets the top margin for text in the self.
New in version 3.18.
Returns:
pointer to the vertical Gtk.Adjustment
Return type:
Gets the vertical-scrolling Gtk.Adjustment.
New in version 2.22.
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().
Parameters:
win (Gtk.TextWindowType) – window to get
Returns:
a Gdk.Window, or None
Return type:
Gdk.Window or None
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 are None 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.
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 returns True, 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 view
- xpos (int) – new X position in window coordinates
- ypos (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) – a Gtk.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) – a Gtk.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]¶
Returns:
True if the cursor had to be moved.
Return type:
Moves the cursor to the currently visible region of the buffer, it it isn’t there already.
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’sGtk.Widget ::key-press-event handler).
New in version 3.20.
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) – a Gtk.TextIter
- within_margin (float) – margin as a [0.0,0.5) fraction of screen size
- use_align (bool) – whether to use alignment arguments (if False, just get the mark onscreen)
- xalign (float) – horizontal alignment of mark within visible area
- yalign (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 sizewithin_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) – a Gtk.TextMark
- within_margin (float) – margin as a [0.0,0.5) fraction of screen size
- use_align (bool) – whether to use alignment arguments (if False, just get the mark onscreen)
- xalign (float) – horizontal alignment of mark within visible area
- yalign (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 sizewithin_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_tabis False 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 affect
- size (int) – width or height of the window
Sets the width of Gtk.TextWindowType.LEFT or Gtk.TextWindowType.RIGHT, or the height of Gtk.TextWindowType.TOP or Gtk.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 with Gtk.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.
Parameters:
buffer (Gtk.TextBuffer or None) – a Gtk.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.TextViewwill 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 theGtk.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.
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]¶
Parameters:
monospace (bool) – True to request monospace styling
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]¶
Parameters:
overwrite (bool) – True to turn on overwrite mode, False to turn it off
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.
Parameters:
tabs (Pango.TabArray) – tabs as a Pango.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) – a Gtk.WrapMode
Sets the line wrapping for the view.
starts_display_line(iter)[source]¶
Parameters:
iter (Gtk.TextIter) – a Gtk.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) – a Gtk.TextWindowType except Gtk.TextWindowType.PRIVATE
- window_x (int) – window x coordinate
- window_y (int) – window y coordinate
Returns:
buffer_x:
buffer x coordinate return location or None
buffer_y:
buffer y coordinate return location or None
Return type:
(buffer_x: int, buffer_y: int)
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 (seeGtk.TextView.set_border_window_size()).
do_backspace() virtual¶
The class handler for the Gtk.TextView ::backspacekeybinding 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-clipboardkeybinding signal
do_delete_from_cursor(type, count) virtual¶
Parameters:
- type (Gtk.DeleteType) –
- count (int) –
The class handler for the Gtk.TextView ::delete-from-cursorkeybinding 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 and Gtk.TextViewLayer.ABOVE_TEXTthe drawing is done in the buffer coordinate space, but the older (deprecated) layers Gtk.TextViewLayer.BELOW and Gtk.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-selectionsignal.
New in version 3.16.
do_insert_at_cursor(str) virtual¶
Parameters:
str (str) –
The class handler for the Gtk.TextView ::insert-at-cursorkeybinding 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-cursorkeybinding signal.
do_paste_clipboard() virtual¶
The class handler for the Gtk.TextView ::paste-clipboardkeybinding signal.
Parameters:
popup (Gtk.Widget) –
The class handler for the Gtk.TextView ::populate-popupsignal.
do_set_anchor() virtual¶
The class handler for the Gtk.TextView ::set-anchorkeybinding signal.
do_toggle_overwrite() virtual¶
The class handler for the Gtk.TextView ::toggle-overwritekeybinding 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 signalwhich 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 signalwhich 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 signalwhich 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 signal
- type (Gtk.DeleteType) – the granularity of the deletion, as a Gtk.DeleteType
- count (int) – the number of type units to delete
The ::delete-from-cursor signal is akeybinding signalwhich 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 signal
- granularity (Gtk.TextExtendSelection) – the granularity type
- location (Gtk.TextIter) – the location where to extend the selection
- start (Gtk.TextIter) – where the selection should start
- end (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 signal
- string (str) – the string to insert
The ::insert-at-cursor signal is akeybinding signalwhich 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 signalwhich 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 signal
- step (Gtk.MovementStep) – the granularity of the move, as a Gtk.MovementStep
- count (int) – the number of step units to move
- extend_selection (bool) – True if the move should extend the selection
The ::move-cursor signal is akeybinding signalwhich 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 signal
- step (Gtk.ScrollStep) – the granularity of the movement, as a Gtk.ScrollStep
- count (int) – the number of step units to move
The ::move-viewport signal is akeybinding signalwhich 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 signalwhich 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.
Signal Name:
populate-popup
Flags:
Parameters:
- text_view (Gtk.TextView) – The object which received the signal
- popup (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 is True, this signal will also be emitted to populate touch popups. In this case,popup will be a different container, e.g. a Gtk.Toolbar.
The signal handler should not make assumptions about the type of widget, but check whether popup is a Gtk.Menuor Gtk.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 signal
- preedit (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
- select (bool) – True to select, False to unselect
The ::select-all signal is akeybinding signalwhich 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 signalwhich 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 signalwhich gets emitted to toggle the Gtk.TextView :cursor-visibleproperty.
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 signalwhich 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:
READABLE, WRITABLE, EXPLICIT_NOTIFY
Whether Tab will result in a tab character being entered
Gtk.TextView.props.bottom_margin¶
Name:
bottom-margin
Type:
Default Value:
0
Flags:
READABLE, WRITABLE, EXPLICIT_NOTIFY
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:
READABLE, WRITABLE, EXPLICIT_NOTIFY
If the insertion cursor is shown
Gtk.TextView.props.editable¶
Name:
editable
Type:
Default Value:
Flags:
READABLE, WRITABLE, EXPLICIT_NOTIFY
Whether the text can be modified by the user
Gtk.TextView.props.im_module¶
Name:
im-module
Type:
Default Value:
Flags:
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 the Gtk.Settings Gtk.Settings :gtk-im-module property.
New in version 2.16.
Gtk.TextView.props.indent¶
Name:
indent
Type:
Default Value:
0
Flags:
READABLE, WRITABLE, EXPLICIT_NOTIFY
Amount to indent the paragraph, in pixels
Gtk.TextView.props.input_hints¶
Name:
input-hints
Type:
Default Value:
Flags:
READABLE, WRITABLE, EXPLICIT_NOTIFY
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:
READABLE, WRITABLE, EXPLICIT_NOTIFY
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:
READABLE, WRITABLE, EXPLICIT_NOTIFY
Left, right, or center justification
Gtk.TextView.props.left_margin¶
Name:
left-margin
Type:
Default Value:
0
Flags:
READABLE, WRITABLE, EXPLICIT_NOTIFY
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:
READABLE, WRITABLE, EXPLICIT_NOTIFY
Whether to use a monospace font
Gtk.TextView.props.overwrite¶
Name:
overwrite
Type:
Default Value:
Flags:
READABLE, WRITABLE, EXPLICIT_NOTIFY
Whether entered text overwrites existing contents
Gtk.TextView.props.pixels_above_lines¶
Name:
pixels-above-lines
Type:
Default Value:
0
Flags:
READABLE, WRITABLE, EXPLICIT_NOTIFY
Pixels of blank space above paragraphs
Gtk.TextView.props.pixels_below_lines¶
Name:
pixels-below-lines
Type:
Default Value:
0
Flags:
READABLE, WRITABLE, EXPLICIT_NOTIFY
Pixels of blank space below paragraphs
Gtk.TextView.props.pixels_inside_wrap¶
Name:
pixels-inside-wrap
Type:
Default Value:
0
Flags:
READABLE, WRITABLE, EXPLICIT_NOTIFY
Pixels of blank space between wrapped lines in a paragraph
Gtk.TextView.props.populate_all¶
Name:
populate-all
Type:
Default Value:
Flags:
READABLE, WRITABLE, EXPLICIT_NOTIFY
If :populate-all is True, the Gtk.TextView ::populate-popupsignal is also emitted for touch popups.
New in version 3.8.
Gtk.TextView.props.right_margin¶
Name:
right-margin
Type:
Default Value:
0
Flags:
READABLE, WRITABLE, EXPLICIT_NOTIFY
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:
READABLE, WRITABLE, EXPLICIT_NOTIFY
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:
READABLE, WRITABLE, EXPLICIT_NOTIFY
Whether to wrap lines never, at word boundaries, or at character boundaries