class TextBuffer(Gtk.TextBuffer): (source)
Method | __init__ |
Constructor |
Method | append_parsetree |
Append a ParseTree to the buffer |
Method | clear |
Undocumented |
Method | copy_clipboard |
Copy current selection to a clipboard |
Method | cut_clipboard |
Cut current selection to a clipboard |
Method | do_begin_insert_tree |
Undocumented |
Method | do_end_insert_tree |
Undocumented |
Method | do_end_user_action |
Undocumented |
Method | do_insert_child_anchor |
Undocumented |
Method | do_insert_pixbuf |
Undocumented |
Method | do_insert_text |
Signal handler for insert-text signal |
Method | do_mark_set |
Undocumented |
Method | do_post_delete_range |
Undocumented |
Method | do_pre_delete_range |
Undocumented |
Method | find_anchor |
Searches the current page for an anchor with the requested name. |
Method | find_implicit_anchor |
No summary |
Method | foreach_line_in_selection |
Convenience function to call a function for each line that is currently selected |
Method | get_anchor_data |
Undocumented |
Method | get_anchor_for_location |
No summary |
Method | get_anchor_or_object_id |
Undocumented |
Method | get_bullet |
Get the bullet type on a specific line, if any |
Method | get_bullet_at_iter |
Return the bullet type in a specific location |
Method | get_has_link_selection |
Check whether a link is selected or not @returns: link attributes when succcessful, None otherwise |
Method | get_has_selection |
Check if there is a selection |
Method | get_image_data |
Get the attributes for an image at a specific position, if any |
Method | get_indent |
Get the indent level for a specific line |
Method | get_indent_at_cursor |
Get the indent level at the cursor |
Method | get_insert_iter |
Get a Gtk.TextIter for the current cursor position |
Method | get_iter_at_line |
No summary |
Method | get_line_bounds |
Get the TextIters at start and end of line |
Method | get_line_is_empty |
Check for empty lines |
Method | get_link_data |
Get the link attributes for a link at a specific position, if any |
Method | get_link_tag |
Get the Gtk.TextTag for a link at a specific position, if any |
Method | get_link_text |
Undocumented |
Method | get_objectanchor |
Undocumented |
Method | get_objectanchor_at_cursor |
Undocumented |
Method | get_parsetree |
Get a ParseTree representing the buffer contents |
Method | get_tag |
Get the Gtk.TextTag for a zim type at a specific position, if any |
Method | get_tag_bounds |
Undocumented |
Method | get_tag_data |
Get the attributes for a tag at a specific position, if any |
Method | get_tag_tag |
Get the Gtk.TextTag for a tag at a specific position, if any |
Method | get_tag_text |
Undocumented |
Method | get_textstyles |
Get the name of the formatting style that will be applied to newly inserted text |
Method | indent |
Increase the indent for a given line |
Method | insert_anchor |
Insert a "link anchor" with id name at iter |
Method | insert_anchor_at_cursor |
Insert a "link anchor" with id name |
Method | insert_child_anchor |
Undocumented |
Method | insert_image |
Insert an image in the buffer |
Method | insert_image_at_cursor |
Insert an image in the buffer |
Method | insert_link |
Insert a link into the buffer |
Method | insert_link_at_cursor |
Insert a link into the buffer |
Method | insert_object_at_cursor |
No summary |
Method | insert_object_model_at_cursor |
Undocumented |
Method | insert_objectanchor |
Undocumented |
Method | insert_objectanchor_at_cursor |
Undocumented |
Method | insert_parsetree |
Insert a ParseTree in the buffer |
Method | insert_parsetree_at_cursor |
Insert a ParseTree in the buffer |
Method | insert_pixbuf |
Undocumented |
Method | insert_tag |
Insert a tag into the buffer |
Method | insert_tag_at_cursor |
Insert a tag into the buffer |
Method | iter_anchors_for_range |
Undocumented |
Method | iter_backward_word_start |
No summary |
Method | iter_forward_past_bullet |
Move an TextIter past a bullet |
Method | iter_forward_word_end |
No summary |
Method | iter_get_zim_tags |
Replacement for Gtk.TextIter.get_tags() which returns zim specific tags |
Method | iter_in_selection |
Check if a specific TextIter is within the selection |
Method | list_objectanchors |
Undocumented |
Method | paste_clipboard |
Paste data from a clipboard into the buffer |
Method | range_has_tag |
Check if a certain TextTag appears anywhere in a range |
Method | range_has_tags |
No summary |
Method | remove_link |
Removes any links between in a range |
Method | remove_textstyle_tags |
Removes all format style TexTags from a range |
Method | renumber_list |
Renumber list from this line downward |
Method | renumber_list_after_indent |
Like renumber_list() , but more complex rules because indent change has different heuristics. |
Method | select_line |
Selects a line @param line: line number; if None current line will be selected @returns: True when successful |
Method | select_lines |
No summary |
Method | select_link |
Selects the current link, if any @returns: link attributes when succcessful, None otherwise |
Method | select_word |
Selects the current word, if any |
Method | set_bullet |
Sets the bullet type for a line |
Method | set_indent |
Set the indenting for a specific line. |
Method | set_parsetree |
Load a new ParseTree in the buffer |
Method | set_textstyles |
Sets the current text format style. |
Method | smart_remove_tags |
This method removes tags over a range based on a function |
Method | strip_selection |
Shrinks the selection to exclude any whitespace on start and end. If only white space was selected this function will not change the selection. @returns: True when this function changed the selection. |
Method | tmp_cursor |
Get a SaveCursorContext object |
Method | toggle_checkbox |
Toggles the state of the checkbox at a specific line, if any |
Method | toggle_checkbox_for_cursor_or_selection |
Like toggle_checkbox() but applies to current line or current selection. Intended for interactive use. |
Method | toggle_textstyle |
Toggle the current textstyle |
Method | unindent |
Decrease the indent level for a given line |
Method | unset_selection |
Remove any selection in the buffer |
Method | update_editmode |
Updates the text style and indenting applied to newly indented text based on the current cursor position |
Method | update_indent_tag |
Update the indent TextTag for a given line |
Method | whole_range_has_tag |
Check if a certain TextTag is applied to the whole range or not |
Class Variable | __gsignals__ |
Undocumented |
Class Variable | pixels_indent |
Undocumented |
Class Variable | tag_attributes |
Undocumented |
Class Variable | tag_styles |
Undocumented |
Instance Variable | finder |
Undocumented |
Instance Variable | notebook |
Undocumented |
Instance Variable | page |
Undocumented |
Instance Variable | showing_template |
Undocumented |
Instance Variable | undostack |
Undocumented |
Instance Variable | user_action |
Undocumented |
Property | hascontent |
Undocumented |
Method | _create_link_tag |
Creates an anonymouse TextTag for a link |
Method | _create_tag_tag |
Creates an anonymous TextTag for a tag |
Method | _do_lines_merged |
Undocumented |
Method | _find_base_dir |
Undocumented |
Method | _fix_pre_selection |
Undocumented |
Method | _get_bullet_at_iter |
Undocumented |
Method | _get_close_anchor_or_object_id |
Undocumented |
Method | _get_heading_text |
Undocumented |
Method | _get_implict_anchor_if_heading |
Undocumented |
Method | _get_indent_tag |
Undocumented |
Method | _insert_bullet_at_cursor |
No summary |
Method | _insert_element_children |
Undocumented |
Method | _insert_table_element_at_cursor |
Undocumented |
Method | _iter_forward_past_bullet |
Undocumented |
Method | _remove_indent |
Undocumented |
Method | _renumber_list |
Undocumented |
Method | _replace_bullet |
Undocumented |
Method | _search_bullet |
Undocumented |
Method | _set_indent |
Undocumented |
Method | _sort_nesting_style_tags |
Undocumented |
Method | _split_nesting_style_tags |
Undocumented |
Class Variable | _nesting_style_tags |
Undocumented |
Class Variable | _static_style_tags |
Undocumented |
Class Variable | _static_tag_after_tags |
Undocumented |
Class Variable | _static_tag_before_links |
Undocumented |
Instance Variable | _check_renumber |
Undocumented |
Instance Variable | _deleted_editmode_mark |
Undocumented |
Instance Variable | _deleted_line_end |
Undocumented |
Instance Variable | _editmode_tags |
Undocumented |
Instance Variable | _insert_tree_in_progress |
Undocumented |
Instance Variable | _renumbering |
Undocumented |
Append a ParseTree
to the buffer
Like insert_parsetree()
but inserts at the end of the current buffer.
Searches the current page for an anchor with the requested name.
Explicit anchors are being searched with precedence over implicit anchors derived from heading elements.
Parameters | |
name | the name of the anchor to look for |
Returns | |
a Gtk.TextIter pointing to the start of the heading or None. |
Parameters | |
name | the name of the anchor |
Returns | |
a Gtk.TextIter pointing to the start of the heading or None. |
Parameters | |
func | function which will be called as: func(line, *args, **kwargs) where line is the line number |
*args | additional argument for func |
**kwarg | additional keyword argument for func |
Returns | |
False if there is no selection, True otherwise |
Parameters | |
iter | the location to refer to |
Returns | |
an anchor name if any anchor object or heading is found, else None |
Parameters | |
line | the line number |
Returns | |
the bullet type, if any, or None. The bullet type can be any of: BULLET UNCHECKED_BOX CHECKED_BOX XCHECKED_BOX MIGRATED_BOX TRANSMIGRATED_BOX or a numbered list bullet (test with |
Return the bullet type in a specific location
Like get_bullet()
Parameters | |
iter | a Gtk.TextIter |
Returns | |
a bullet type, or None |
Check if there is a selection
Method available in Gtk.TextBuffer for gtk version >= 2.10 reproduced here for backward compatibility.
Returns | |
True when there is a selection |
Parameters | |
iter | a Gtk.TextIter object |
Returns | |
a dict with image properties or None |
Parameters | |
line | the line number |
Returns | |
a number for the indenting level |
Parameters | |
line | an integer line number counting from 0 |
Returns | |
a Gtk.TextIter | |
Raises | |
ValueError | when line is not within the buffer |
Parameters | |
line | the line number |
Returns | |
a 2-tuple of Gtk.TextIter for start and end of the line |
Parameters | |
iter | a Gtk.TextIter |
raw | Undocumented |
Returns | |
a dict with link properties if there is a link at iter, None otherwise |
Parameters | |
iter | a Gtk.TextIter |
Returns | |
a Gtk.TextTag if there is a link at iter, None otherwise |
ParseTree
representing the buffer contentsParameters | |
bounds | a 2-tuple with two Gtk.TextIter specifying a range in the buffer (e.g. current selection). If None the whole buffer is returned. |
raw | if True you get a tree that is not nicely cleaned up. This raw tree should result in the exact same contents in the buffer when reloaded. However such a 'raw' tree may cause problems when passed to one of the format modules. So it is intended only for internal use between the buffer and e.g. the Raw parsetrees have an attribute to flag them as a raw tree, so on insert we can make sure they are inserted in the same way. When raw is False reloading the same tree may have subtle differences. |
Returns | |
a ParseTree object |
Parameters | |
iter | a Gtk.TextIter |
type | the zim type to look for ('style', 'link', 'tag', 'indent', 'anchor') |
Returns | |
a Gtk.TextTag if there is a tag at iter, None otherwise |
Parameters | |
iter | a Gtk.TextIter |
Returns | |
a dict with tag properties if there is a link at iter, None otherwise |
Parameters | |
iter | a Gtk.TextIter |
Returns | |
a Gtk.TextTag if there is a tag at iter, None otherwise |
Get the name of the formatting style that will be applied to newly inserted text
This style may change as soon as the cursor position changes, so only relevant for current cursor position.
Increase the indent for a given line
Can be used as function for foreach_line_in_selection()
.
Parameters | |
line | the line number |
interactive | hint if indenting is result of user interaction, or automatic action |
Returns | |
True if successful |
Parameters | |
iter | a Gtk.TextIter for the insert position |
file | a File object or a absolute file path or URI, if None the file will be resolved based on src relative to the notebook and page |
src | the file path the show to the user If the image is e.g. specified in the page source as a relative link, file should give the absolute path the link resolves to, while src gives the relative path. |
**attrib | any other image properties |
Insert an image in the buffer
Like insert_image()
but inserts at the current cursor position
Parameters | |
file | a File object or a file path or URI |
src | the file path the show to the user |
**attrib | any other image properties |
Parameters | |
iter | a Gtk.TextIter for the insert position |
text | the text for the link as string |
href | the target (URL, pagename) of the link as string |
**attrib | any other link attributes |
Insert a link into the buffer
Like insert_link() but inserts at the current cursor position
Parameters | |
text | the text for the link as string |
href | the target (URL, pagename) of the link as string |
**attrib | any other link attributes |
Parameters | |
attrib | dict with object attributes |
data | string data of object |
raw | boolean for "raw" parsetree insert |
Insert a ParseTree
in the buffer
This method inserts a parsetree at a specific place in the buffer.
Parameters | |
iter | a Gtk.TextIter for the insert position |
tree | a ParseTree object |
interactive | Boolean which determines how current state in the buffer is handled. If not interactive we break any existing tags and insert the tree, otherwise we insert using the formatting tags that that are present at iter. For example when a parsetree is inserted because the user pastes content from the clipboard interactive should be True. |
Insert a ParseTree
in the buffer
Like insert_parsetree()
but inserts at the current cursor position.
Parameters | |
tree | a ParseTree object |
interactive | Boolean which determines how current state in the buffer is handled. |
Insert a tag into the buffer
Insert a tag in the buffer (not a TextTag, but a tag like "@foo")
Parameters | |
iter | a Gtk.TextIter object |
text | The text for the tag |
**attrib | any other tag attributes |
Insert a tag into the buffer
Like insert_tag() but inserts at the current cursor position
Parameters | |
text | The text for the tag |
**attrib | any other tag attributes |
Parameters | |
iter | a Gtk.TextIter, the position of this iter will be modified |
Returns | |
True when successful |
Move an TextIter past a bullet
This method is useful because we typically want to insert new text on a line with a bullet after the bullet. This method can help to find that position.
Parameters | |
iter | a Gtk.TextIter. The position of this iter will be modified by this method. |
Parameters | |
iter | a Gtk.TextIter, the position of this iter will be modified |
Returns | |
True when successful |
Replacement for Gtk.TextIter.get_tags() which returns zim specific tags
In contrast to Gtk.TextIter.get_tags() this method assumes "left gravity" for TextTags. This means that it returns TextTags ending to the left of the iter position but not TextTags starting to the right.
For TextTags that should be applied per line (like 'indent', 'h', 'pre') some additional logic is used to keep them consistent. So at the start of the line, we do copy TextTags starting to the right and not inadvertently copy formatting from the previous line which ends on the left.
This method is for example used by update_editmode()
to determine which TextTags should be applied to newly inserted text at at a specific location.
Parameters | |
iter | a Gtk.TextIter |
Returns | |
a list of Gtk.TextTags (sorted by priority) |
Parameters | |
iter | a Gtk.TextIter |
Returns | |
True if there is a selection and iter is within the range of the selection |
Parameters | |
tag | a Gtk.TextTag |
start | a Gtk.TextIter |
end | a Gtk.TextIter |
range_has_tag()
but uses a function to check for multiple tags. The function gets called for each TextTag in the range and the method returns as soon as the function returns True for any tag. There are a number of lambda functions defined in the module to test categories of TextTags.Parameters | |
func | a function that is called as: func(tag) for each TextTag in the range |
start | a Gtk.TextIter |
end | a Gtk.TextIter |
Parameters | |
line | line number; if None current line will be selected |
Returns | |
True when successful |
Parameters | |
first | line number first line |
last | line number last line |
Returns | |
True when successful |
Sets the bullet type for a line
Replaces any bullet that may already be present on the line. Set bullet None to remove any bullet at this line.
Parameters | |
line | the line number |
bullet | the bullet type, one of: BULLET UNCHECKED_BOX CHECKED_BOX XCHECKED_BOX MIGRATED_BOX TRANSMIGRATED_BOX NUMBER_BULLET None or a numbered bullet, like "1." |
indent | optional indent to set after inserting the bullet, but before renumbering |
Set the indenting for a specific line.
May also trigger renumbering for numbered lists.
Parameters | |
line | the line number |
level | the indenting level as a number, 0 for no indenting, 1 for the equivalent of 1 tab, etc. |
interactive | hint if indenting is result of user interaction, or automatic action If interactive, the line will be forced to end with a newline. Reason is that if the last line of the buffer is empty and does not end with a newline, the indenting will not be visible, giving the impression that it failed. |
Returns | |
True for success (e.g. indenting a heading is not allowed, if you try it will fail and return False here) |
Parameters | |
names | the name of the format style This style will be applied to text inserted at the cursor. Use set_textstyles(None) to reset to normal text. |
This method removes tags over a range based on a function
So range_has_tags()
for a details on such a test function.
Please use this method instead of remove_tag() when you are not sure if specific tags are present in the first place. Calling remove_tag() will emit signals which make the UndoStackManager
assume the tag was there. If this was not the case the undo stack gets messed up.
Returns | |
True when this function changed the selection. |
SaveCursorContext
objectParameters | |
iter | a Gtk.TextIter for the new (temporary) cursor position |
gravity | give mark left or right "gravity" compared to new inserted text, default is "left" which means new text goes after the cursor position |
Parameters | |
line | the line number |
checkbox_type | the checkbox type that we want to toggle: one of CHECKED_BOX, XCHECKED_BOX, MIGRATED_BOX, TRANSMIGRATED_BOX. If checkbox_type is given, it toggles between this type and unchecked. Otherwise it rotates through unchecked, checked and xchecked. As a special case when the checkbox_type ir UNCHECKED_BOX the box is always unchecked. |
recursive | When True any child items in the list will also be upadted accordingly (see TextBufferList.set_bullet() |
Returns | |
True for success, False if no checkbox was found. |
toggle_checkbox()
but applies to current line or current selection. Intended for interactive use.Parameters | |
checkbox_type | the checkbox type that we want to toggle |
recursive | When True any child items in the list will also be upadted accordingly (see TextBufferList.set_bullet() |
Toggle the current textstyle
If there is a selection toggle the text style of the selection, otherwise toggle the text style for newly inserted text.
This method is mainly to change the behavior for interactive editing. E.g. it is called indirectly when the user clicks one of the formatting buttons in the EditBar.
For selections we remove the format if the whole range has the format already. If some part of the range does not have the format we apply the format to the whole tange. This makes the behavior of the format buttons consistent if a single tag applies to any range.
Parameters | |
name | the format style name |
Decrease the indent level for a given line
Can be used as function for foreach_line_in_selection()
.
Parameters | |
line | the line number |
interactive | hint if indenting is result of user interaction, or automatic action |
Returns | |
True if successful |
Updates the text style and indenting applied to newly indented text based on the current cursor position
This method is triggered automatically when the cursor is moved, but there are some cases where you may need to call it manually to force a consistent state.
Update the indent TextTag for a given line
The TextTags used for indenting differ between normal indented paragraphs and indented items in a bullet list. The reason for this is that the line wrap behavior of list items should be slightly different to align wrapped text with the bullet.
This method does not change the indent level for a specific line, but it makes sure the correct TextTag is applied. Typically called e.g. after inserting or deleting a bullet.
Parameters | |
line | the line number |
bullet | the bullet type for this line, or None |
Parameters | |
tag | a Gtk.TextTag |
start | a Gtk.TextIter |
end | a Gtk.TextIter |
Insert a bullet plus a space at the cursor position. If 'raw' is True the space will be omitted and the check that cursor position must be at the start of a line will not be enforced.
External interface should use set_bullet(line, bullet) instead of calling this method directly.