pygtk-textview widget

1.textbuffer

startiter = textbuffer.get_start_iter()
enditer = textbuffer_get_end_iter()
startiter, enditer = textbuffer.get_bounds()
start, end = textbuffer.get_selection_bounds()textbuffer = TextBuffer(table=None)

 

line_count = textbuffer.get_line_count()

 

char_count = textbuffer.get_char_count()

 

modified = textbuffer.get_modified()

 

textbuffer.set_modified(setting)

 

2.TextIter定义了TextBuffer中的2个字符间的位置

iter = textbuffer.get_iter_at_offset(char_offset)
iter = textbuffer_get_iter_at_line(line_number)
iter = textbuffer.get_iter_at_line_offset(line_number, line_offset)
iter = textbuffer.get_iter_at_mark(mark)

 

 

startiter = textbuffer.get_start_iter()
enditer = textbuffer_get_end_iter()
startiter, enditer = textbuffer.get_bounds()
start, end = textbuffer.get_selection_bounds()

 

3.text插入,删除,选择

textbuffer.set_text(text)

textbuffer.insert(iter, text)

result = textbuffer.insert_interactive(iter, text, default_editable)

 

 

textbuffer.insert_at_cursor(text)
result = textbuffer.insert_at_cursor_interactive(text, default_editable)
textbuffer.insert_range(iter, start, end)
result = textbuffer.insert_range_interactive(iter, start, end,←-
default_editable)

 

textbuffer.insert_with_tags(iter, text, tag1, tag2, ...)
textbuffer.insert_with_tags_by_name(iter, text, tagname1, tagname2, ...)

 

textbuffer.delete(start, end)
result = textbuffer.delete_interactive(start, end, default_editable)

 

text = textbuffer.get_text(start, end, include_hidden_chars=TRUE)
text = textbuffer.get_slice(start, end, include_hidden_chars=TRUE)

 

insertmark = textbuffer.get_insert()
selection_boundmark = textbuffer.get_selection_bound()

 

textbuffer.place_cursor(where)

mark = textbuffer.create_mark(mark_name, where, left_gravity=FALSE)

 

textbuffer.move_mark(mark, where)
textbuffer.move_mark_by_name(name, where)

textbuffer.delete_mark(mark)
textbuffer.delete_mark_by_name(name)

 

mark = textbuffer.get_mark(name)

 

4.texttag

tag = textbuffer.create_tag(name=None, attr1=val1, attr2=val2, ...)

textbuffer.apply_tag(tag, start, end)
textbuffer.apply_tag_by_name(name, start, end)

textbuffer.remove_tag(tag, start, end)
textbuffer.remove_tag_by_name(name, start, end)

textbuffer.remove_all_tags(start, end)

textbuffer.insert_pixbuf(iter, pixbuf)

anchor = text_buffer.create_child_anchor(iter)

anchor = gtk.TextChildAnchor()
text_buffer.insert_child_anchor(iter, anchor)

text_view.add_child_at_anchor(child, anchor)

widget_list = anchor.get_widgets()

text_view.add_child_in_window(child, which_window, xpos, ypos)

其中which_windows为:

gtk.TEXT_WINDOW_TOP
gtk.TEXT_WINDOW_BOTTOM
gtk.TEXT_WINDOW_LEFT
gtk.TEXT_WINDOW_RIGHT
gtk.TEXT_WINDOW_TEXT
gtk.TEXT_WINDOW_WIDGET

5.TextIters

buffer = iter.get_buffer()

offset = iter.get_offset() # returns offset in buffer of iter
line_number = iter.get_line() # returns number of line at iter
line_offset = iter.get_line_offset() # returns iter offset in line
numchars = iter.get_chars_in_line() # returns number of chars in line

language = iter.get_language()

result = iter.get_attributes(values)

values = textview.get_default_attributes()

 

 

 bg_color background color
fg_color foreground color
bg_stipple background stipple bitmap
fg_stipple foreground stipple bitmap
rise offset of text above baseline
underline style of underline
strikethrough whether text is strikethrough
draw_bg TRUE if some tags affect the drawing of the background
justification style of justification
direction which direction the text runs
font PangoFontDescription in use
font_scale scale of the font in use
left_margin location of left margin
right_margin location of right margin
pixels_above_lines pixels spacing above a line
pixels_below_lines pixel spacing below a line
pixels_inside_wrap pixel spacing between wrapped lines
tabs PangoTabArray in use
wrap_mode mode of wrap in use
language PangoLanguage in use
invisible whether text is invisible (not implemented in GTK+ 2.0)
bg_full_height whether background is fit to full line height
editable whether the text is editable
realized text is realized
pad1
pad2
pad3
pad4

 

6.

iter_copy = iter.copy()

char = iter.get_char() # returns char or 0 if at end of buffer
text = start.get_slice(end) # returns the text between start and end iters
text = start.get_text(end) # returns the text between start and end iters
pixbuf = iter.get_pixbuf() # returns the pixbuf at the location (or None)

anchor = iter.get_child_anchor() # returns the child anchor (or None)
mark_list = iter.get_marks() # returns a list of marks
tag_list = iter.get_toggled_tags()
# returns a list of tags that are toggled on or off
tag_list = iter.get_tags() # returns a prioritized list of tags

result = iter.begins_tag(tag=None) # TRUE if tag is toggled on at iter
result = iter.ends_tag(tag=None) # TRUE if tag is toggled off at iter
result = iter.toggles_tag(tag=None) # TRUE if tag is toggled on or off at iter
result = iter.has_tag(tag) # TRUE if tag is active at iter

result = iter.editable()
result = iter.can_insert(default_editability)

default_editability = textview.get_editable()

are_equal = lhs.equal(rhs)

result = lhs.compare(rhs)

result = iter.in_range(start, end)

first.order(second)

 

 

result = iter.starts_word()
result = iter.ends_word()
result = iter.inside_word()
result = iter.starts_sentence()
result = iter.ends_sentence()
result = iter.inside_sentence()
result = starts_line()
result = iter.ends_line()

 

result = iter.is_start()

result = iter.is_end()

result = iter.is_cursor_position()

result = iter.forward_char() # forward by one character
result = iter.backward_char() # backward by one character
result = iter.forward_word_end() # forward to the end of the word
result = iter.backward_word_start() # backward to the start of the word
result = iter.forward_sentence_end() # forward to the end of the sentence
result = iter.backward_sentence_start() # backward to the start of the senten
result = iter.forward_line() # forward to the start of the next line
result = iter.backward_line() # backward to the start of the previous line
result = iter.forward_to_line_end() # forward to the end of the line
result = iter.forward_cursor_position() # forward by one cursor position
result = iter.backward_cursor_position() # forward by one cursor position

result = iter.forward_chars(count)
result = iter.backward_chars(count)

result = iter.forward_word_ends(count)
result = iter.backward_word_starts(count)
result = iter.forward_sentence_ends(count)
result = iter.backward_sentence_starts(count)
result = iter.forward_lines(count)
result = iter.backward_lines(count)
result = iter.forward_cursor_positions(count)
result = iter.backward_cursor_positions(count)

 

 

iter.set_offset(char_offset) # move to given character offset
iter.set_line(line_number) # move to start of given line
iter.set_line_offset(char_on_line)
# move to given character offset in current line
iter.forward_to_end() # move to end of the buffer

result = iter.forward_to_tag_toggle(tag)
result = iter.backward_to_tag_taoggle(tag)

 

match_start, match_end = iter.forward_search(str, flags, limit=None)

match_start, match_end = iter.backward_search(str, flags, limit=None)

search中flag的标志为:

gtk.TEXT_SEARCH_VISIBLE_ONLY # invisible characters are ignored
gtk.TEXT_SEARCH_TEXT_ONLY # pixbufs and child anchors are ignored

 

name = textmark.get_name()

setting = textmark.get_visible()
textmark.set_visible(setting)

 

buffer = textmark.get_buffer()

setting = textmark.get_deleted()

setting = textmark.get_left_gravity()

 

tag = gtk.TextTag(name=None)

 

TextTag的属性

name Read / Write Name of the text tag. None if anonymous.
background Write Background color as a string
foreground Write Foreground color as a string
background-gdk Read / Write Background color as a GdkColor
foreground-gdk Read / Write Foreground color as a GdkColor
background-stipple Read / Write Bitmap to use as a mask when drawing the text background
foreground-stipple Read / Write Bitmap to use as a mask when drawing the text foreground
font Read / Write Font description as a string, e.g. "Sans Italic 12"
font-desc Read / Write Font description as a PangoFontDescription
family Read / Write Name of the font family, e.g. Sans, Helvetica, Times, Monospace
style Read / Write Font style as a PangoStyle, e.g. pango.STYLE_ITALIC.
variant Read / Write Font variant as a PangoVariant, e.g. pango.VARIANT_SMALL_CAPS.
weight Read / Write Font weight as an integer, see predefined values in PangoWeight; for
example, pango.WEIGHT_BOLD.
stretch Read / Write Font stretch as a PangoStretch, e.g. pango.STRETCH_CONDENSED.
size Read / Write Font size in Pango units.
size-points Read / Write Font size in points
scale Read / Write Font size as a scale factor relative to the default font size. This properly
adapts to theme changes etc. so is recommended. Pango predefines some
scales such as pango.SCALE_X_LARGE.
pixels-above-lines Read / Write Pixels of blank space above paragraphs
pixels-below-lines Read / Write Pixels of blank space below paragraphs
pixels-inside-wrap Read / Write Pixels of blank space between wrapped lines in a paragraph
editable Read / Write Whether the text can be modified by the user
wrap-mode Read / Write Whether to wrap lines never, at word boundaries, or at character
boundaries
justification Read / Write Left, right, or center justification
direction Read / Write Text direction, e.g. right-to-left or left-to-right
left-margin Read / Write Width of the left margin in pixels
indent Read / Write Amount to indent the paragraph, in pixels
strikethrough Read / Write Whether to strike through the text
right-margin Read / Write Width of the right margin in pixels 

 indent Read / Write Amount to indent the paragraph, in pixels
strikethrough Read / Write Whether to strike through the text
right-margin Read / Write Width of the right margin in pixels
underline Read / Write Style of underline for this text
rise Read / Write Offset of text above the baseline (below the baseline if rise is negative)
in pixels
background-full-height Read / Write Whether the background color fills the entire line height or only the
height of the tagged characters
language Read / Write The language this text is in, as an ISO code. Pango can use this as a
hint when rendering the text. If you don’t understand this parameter, you
probably don’t need it.
tabs Read / Write Custom tabs for this text
invisible Read / Write Whether this text is hidden. Not implemented in GTK+ 2.0

 

 

tag.set_property(name, value)

value = tag.get_property(name)

 

 

tag的属性

background-set Read / Write
foreground-set Read / Write
background-stipple-set Read / Write
foreground-stipple-set Read / Write
family-set Read / Write
style-set Read / Write
variant-set Read / Write
weight-set Read / Write
stretch-set Read / Write
size-set Read / Write
scale-set Read / Write
pixels-above-lines-set Read / Write
pixels-below-lines-set Read / Write
pixels-inside-wrap-set Read / Write
editable-set Read / Write
wrap-mode-set Read / Write
justification-set Read / Write
direction-set Read / Write
left-margin-set Read / Write
indent-set Read / Write
strikethrough-set Read / Write
right-margin-set Read / Write
underline-set Read / Write
rise-set Read / Write
background-full-height-set Read / Write
language-set Read / Write
tabs-set Read / Write
invisible-set Read / Write

 

if tag.get_property("justification-set"):
justification = tag.get_property("justification")

priority = tag.get_priority()

tag.set_priority(priority)

table = TextTagTable()

table.add(tag)

tag = table.lookup(name)

table.remove(tag)

size = table.get_size()

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值