本文整理汇总了Python中gi.repository.Gtk.TextIter方法的典型用法代码示例。如果您正苦于以下问题:Python Gtk.TextIter方法的具体用法?Python Gtk.TextIter怎么用?Python Gtk.TextIter使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类gi.repository.Gtk
的用法示例。
在下文中一共展示了Gtk.TextIter方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: extract
# 需要导入模块: from gi.repository import Gtk [as 别名]
# 或者: from gi.repository.Gtk import TextIter [as 别名]
def extract(self, context):
"""
Used to extract the text according to the :py:attr:`.left_delimiter` and
:py:attr:`.extraction_regex`. If the extraction regular expression does
not match, None is returned.
:param context: The context for the completion.
:type context: :py:class:`GtkSource.CompletionContext`
:return: The resulting match from the :py:attr:`.extraction_regex`.
:rtype: :py:class:`re.MatchObject`
"""
end_iter = context.get_iter()
if not isinstance(end_iter, Gtk.TextIter):
_, end_iter = context.get_iter()
if not end_iter:
return
buf = end_iter.get_buffer()
mov_iter = end_iter.copy()
limit_iter = end_iter.copy()
if self.left_limit:
limit_iter.backward_chars(self.left_limit)
mov_iter = mov_iter.backward_search(self.left_delimiter, Gtk.TextSearchFlags.VISIBLE_ONLY, limit=limit_iter)
if not mov_iter:
return
mov_iter, _ = mov_iter
if self.left_delimiter_adjustment > 0:
mov_iter.forward_chars(self.left_delimiter_adjustment)
elif self.left_delimiter_adjustment < 0:
mov_iter.backward_chars(abs(self.left_delimiter_adjustment))
left_text = buf.get_text(mov_iter, end_iter, True)
return self.extraction_regex.match(left_text)
示例2: get_text_of_line
# 需要导入模块: from gi.repository import Gtk [as 别名]
# 或者: from gi.repository.Gtk import TextIter [as 别名]
def get_text_of_line(self, line_number_or_iter):
text_buffer = self.text_view.get_buffer()
if isinstance(line_number_or_iter, Gtk.TextIter):
line_iter = line_number_or_iter
line_end_iter = text_buffer.get_iter_at_line(line_iter.get_line())
else:
line_number = line_number_or_iter
line_iter = text_buffer.get_iter_at_line(line_number)
line_end_iter = text_buffer.get_iter_at_line(line_number)
line_end_iter.forward_to_line_end()
text = text_buffer.get_text(line_iter, line_end_iter, True)
return text
示例3: find_heading
# 需要导入模块: from gi.repository import Gtk [as 别名]
# 或者: from gi.repository.Gtk import TextIter [as 别名]
def find_heading(buffer, n, include_hr):
'''Find the C{n}th heading in the buffer
@param buffer: the C{Gtk.TextBuffer}
@param n: an integer
@returns: a C{Gtk.TextIter} for the line start of the heading or C{None}
'''
iter = buffer.get_start_iter()
i = 1 if _is_heading_or_line(iter, include_hr) else 0
while i < n:
iter.forward_line()
while not _is_heading_or_line(iter, include_hr):
if not iter.forward_line():
return None
i += 1
return iter
示例4: select_heading
# 需要导入模块: from gi.repository import Gtk [as 别名]
# 或者: from gi.repository.Gtk import TextIter [as 别名]
def select_heading(self, path):
'''Returns a C{Gtk.TextIter} for a C{Gtk.TreePath} pointing to a heading
or C{None}.
'''
model = self.treeview.get_model()
n = model.get_nth_heading(path)
textview = self.pageview.textview
buffer = textview.get_buffer()
if select_heading(buffer, n, self.include_hr):
textview.scroll_to_mark(buffer.get_insert(), SCROLL_TO_MARK_MARGIN, False, 0, 0)
return True
else:
return False
示例5: motion_notify_event
# 需要导入模块: from gi.repository import Gtk [as 别名]
# 或者: from gi.repository.Gtk import TextIter [as 别名]
def motion_notify_event(self, widget, event):
"""
The method defines the applicable cursor (standard/hand)
"""
if self.textview.get_window_type(event.window) not in (
Gtk.TextWindowType.TEXT, Gtk.TextWindowType.PRIVATE):
event.window.set_cursor(self.cursor_standard)
return True
if (event.is_hint):
# (x, y, state) = event.window.get_pointer()
(ign, x, y, state) = event.window.get_pointer()
else:
x = event.x
y = event.y
# state = event.get_state()
(x, y) = self.textview.window_to_buffer_coords(
Gtk.TextWindowType.WIDGET, int(x), int(y))
ret = self.textview.get_iter_at_position(x, y)
if len(ret) == 3:
pos_is_over_text, it_at_pos, trailing = ret
else:
it_at_pos, trailing = ret
if it_at_pos.get_child_anchor() is not None:
event.window.set_cursor(self.cursor_hand)
return True
it = self.textview.get_iter_at_location(x, y)
# https://gramps-project.org/bugs/view.php?id=9335
if isinstance(it, Gtk.TextIter):
offset = it.get_offset()
else:
offset = it[1].get_offset()
for node in self.nodelist:
if offset >= node["start"] and offset < node["end"] and "vari" not in node:
event.window.set_cursor(self.cursor_hand)
return True
event.window.set_cursor(self.cursor_standard)
return True
示例6: _build_search
# 需要导入模块: from gi.repository import Gtk [as 别名]
# 或者: from gi.repository.Gtk import TextIter [as 别名]
def _build_search(self, widget):
'''Builds the search bar.'''
self.srchtab = Gtk.HBox()
# close button
close = Gtk.Image()
close.set_from_stock(Gtk.STOCK_CLOSE, Gtk.IconSize.MENU)
eventbox = Gtk.EventBox()
eventbox.add(close)
eventbox.connect("button-release-event", self._close)
self.srchtab.pack_start(eventbox, False, False, 3)
# label
label = Gtk.Label(label="Find:")
self.srchtab.pack_start(label, False, False, 3)
# entry
self.search_entry = Gtk.Entry()
self.search_entry.set_tooltip_text("Type here the phrase you want to find")
self.search_entry.connect("activate", self._find, "next")
self.search_entry.connect("changed", self._find_cb, "find")
self.srchtab.pack_start(self.search_entry, False, False, 3)
# find next button
if self.small:
but_text = ''
else:
but_text = 'Next'
butn = SemiStockButton(but_text, Gtk.STOCK_GO_DOWN)
butn.set_relief(Gtk.ReliefStyle.NONE)
butn.connect("clicked", self._find, "next")
butn.set_tooltip_text("Find the next ocurrence of the phrase")
self.srchtab.pack_start(butn, False, False, 3)
# find previous button
if self.small:
but_text = ''
else:
but_text = ('Previous')
butp = SemiStockButton(but_text, Gtk.STOCK_GO_UP)
butp.set_relief(Gtk.ReliefStyle.NONE)
butp.connect("clicked", self._find, "previous")
butp.set_tooltip_text("Find the previous ocurrence of the phrase")
self.srchtab.pack_start(butp, False, False, 3)
# make last two buttons equally width
# MEOW
wn,hn = butn.get_preferred_size()
wp,hp = butp.get_preferred_size()
newwidth = max(wn.width, wp.width)
butn.set_size_request(newwidth, hn.height)
butp.set_size_request(newwidth, hp.height)
# Match case CheckButton
butCase = Gtk.CheckButton(('Match case'))
butCase.set_active(self._matchCaseValue)
butCase.connect("clicked", self._matchCase)
# FIXME
# current version of Gtk.TextIter doesn't support SEARCH_CASE_INSENSITIVE
#butCase.show()
#self.srchtab.pack_start(butCase, expand=False, fill=False, padding=3)
self.pack_start(self.srchtab, False, False, 0)
# Results
self._resultsLabel = Gtk.Label(label="")
self.srchtab.pack_start(self._resultsLabel, False, False, 3)
self.searching = False