本文整理汇总了Python中gi.repository.Gtk.TextBuffer方法的典型用法代码示例。如果您正苦于以下问题:Python Gtk.TextBuffer方法的具体用法?Python Gtk.TextBuffer怎么用?Python Gtk.TextBuffer使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类gi.repository.Gtk
的用法示例。
在下文中一共展示了Gtk.TextBuffer方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from gi.repository import Gtk [as 别名]
# 或者: from gi.repository.Gtk import TextBuffer [as 别名]
def __init__(self, *args, **kwargs):
self.label = Gtk.Label(label='Send')
"""The :py:class:`Gtk.Label` representing this tabs name."""
super(MailSenderSendTab, self).__init__(*args, **kwargs)
self.textview = self.gobjects['textview_mail_sender_progress']
"""The :py:class:`Gtk.TextView` object that renders text status messages."""
self.textview.modify_font(Pango.FontDescription(self.config['text_font']))
self.textbuffer = self.textview.get_buffer()
"""The :py:class:`Gtk.TextBuffer` instance associated with :py:attr:`~.MailSenderSendTab.textview`."""
self.textbuffer_iter = self.textbuffer.get_start_iter()
self.progressbar = self.gobjects['progressbar_mail_sender']
"""The :py:class:`Gtk.ProgressBar` instance which is used to display progress of sending messages."""
self.pause_button = self.gobjects['togglebutton_mail_sender_pause']
self.sender_thread = None
"""The :py:class:`.MailSenderThread` instance that is being used to send messages."""
self.application.connect('exit', self.signal_kpc_exit)
self.application.connect('exit-confirm', self.signal_kpc_exit_confirm)
self.textview.connect('populate-popup', self.signal_textview_populate_popup)
示例2: on_menuitem_custom_activate
# 需要导入模块: from gi.repository import Gtk [as 别名]
# 或者: from gi.repository.Gtk import TextBuffer [as 别名]
def on_menuitem_custom_activate(self, widget):
self.custom_window = Gtk.Window()
self.custom_window.set_default_size(640, 480)
self.custom_window.set_position(Gtk.WindowPosition.CENTER)
self.custom_window.set_title("Custom CSS")
self.custom_vbox = Gtk.VBox()
self.custom_scroller = Gtk.ScrolledWindow()
self.custom_button = Gtk.Button("Apply")
self.custom_vbox.pack_end(self.custom_button, False, False, 0)
self.custom_text_view = Gtk.TextView()
self.custom_text_buffer = Gtk.TextBuffer()
self.custom_text_buffer.set_text(self.custom_css)
self.custom_text_view.set_buffer(self.custom_text_buffer)
self.custom_scroller.add(self.custom_text_view)
self.custom_vbox.pack_start(self.custom_scroller, True, True, 0)
self.custom_window.add(self.custom_vbox)
self.custom_window.show_all()
self.custom_button.connect("clicked", self.apply_custom_css, self.custom_window, self.custom_text_buffer)
示例3: error_callback
# 需要导入模块: from gi.repository import Gtk [as 别名]
# 或者: from gi.repository.Gtk import TextBuffer [as 别名]
def error_callback(self, msg):
def f():
dialogWindow = Gtk.MessageDialog(self.win,
Gtk.DialogFlags.MODAL | Gtk.DialogFlags.DESTROY_WITH_PARENT,
Gtk.MessageType.INFO,
Gtk.ButtonsType.OK,
'\nGnomecast encountered an error converting your file.')
dialogWindow.set_title('Transcoding Error')
dialogWindow.set_default_size(1, 400)
dialogBox = dialogWindow.get_content_area()
buffer1 = Gtk.TextBuffer()
buffer1.set_text(msg)
text_view = Gtk.TextView(buffer=buffer1)
text_view.set_editable(False)
scrolled_window = Gtk.ScrolledWindow()
scrolled_window.set_border_width(5)
# we scroll only if needed
scrolled_window.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC)
scrolled_window.add(text_view)
dialogBox.pack_end(scrolled_window, True, True, 0)
dialogWindow.show_all()
response = dialogWindow.run()
dialogWindow.destroy()
GLib.idle_add(f)
示例4: __init__
# 需要导入模块: from gi.repository import Gtk [as 别名]
# 或者: from gi.repository.Gtk import TextBuffer [as 别名]
def __init__(self):
Gtk.TextBuffer.__init__(self)
self._max_length = 0
示例5: do_insert_text
# 需要导入模块: from gi.repository import Gtk [as 别名]
# 或者: from gi.repository.Gtk import TextBuffer [as 别名]
def do_insert_text(self, location, text, length):
max_length = self.max_length
buffer_char_count = self.get_char_count()
if max_length > 0 and (buffer_char_count + length) > max_length:
new_length = max_length - buffer_char_count
new_text = text[:new_length]
else:
new_length = length
new_text = text
Gtk.TextBuffer.do_insert_text(
self, location, new_text, new_length
)
return False
示例6: __init__
# 需要导入模块: from gi.repository import Gtk [as 别名]
# 或者: from gi.repository.Gtk import TextBuffer [as 别名]
def __init__(self):
"""
we'll need empty stacks for undo/redo and some state keeping
"""
Gtk.TextBuffer.__init__(self)
self.undo_stack = []
self.redo_stack = []
self.not_undoable_action = False
self.undo_in_progress = False
self.connect('insert-text', self.on_insert_text)
self.connect('delete-range', self.on_delete_range)
示例7: create_text_buffer
# 需要导入模块: from gi.repository import Gtk [as 别名]
# 或者: from gi.repository.Gtk import TextBuffer [as 别名]
def create_text_buffer():
text_buffer = Gtk.TextBuffer()
text_buffer.create_tag("default", font="Monospace 10", pixels_below_lines=2)
text_buffer.create_tag("warning", foreground=global_gui_config.colors["WARNING_COLOR"])
text_buffer.create_tag("error", foreground=global_gui_config.colors["ERROR_COLOR"])
text_buffer.create_tag("debug", foreground=global_gui_config.colors["RAFCON_COLOR"])
text_buffer.create_tag("info", foreground=global_gui_config.colors["SUCCESS_COLOR"])
text_buffer.create_tag("tertiary_text", foreground=global_gui_config.colors["TERTIARY_TEXT_COLOR"])
text_buffer.create_tag("text", foreground=global_gui_config.colors["TEXT_COLOR"])
return text_buffer
示例8: __init__
# 需要导入模块: from gi.repository import Gtk [as 别名]
# 或者: from gi.repository.Gtk import TextBuffer [as 别名]
def __init__(self, attrib, data):
Gtk.TextBuffer.__init__(self)
self.object_attrib = attrib
self.set_text(data)
示例9: find_heading
# 需要导入模块: from gi.repository import Gtk [as 别名]
# 或者: from gi.repository.Gtk import TextBuffer [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
示例10: select_section
# 需要导入模块: from gi.repository import Gtk [as 别名]
# 或者: from gi.repository.Gtk import TextBuffer [as 别名]
def select_section(self, buffer, path):
'''Select all text between two headings
@param buffer: the C{Gtk.TextBuffer} to select in
@param path: the C{Gtk.TreePath} for the heading of the section
'''
model = self.treeview.get_model()
n = model.get_nth_heading(path)
nextpath = Gtk.TreePath(path[:-1] + [path[-1] + 1])
try:
aiter = model.get_iter(nextpath)
except ValueError:
endtext = None
else:
endtext = model[aiter][TEXT_COL]
textview = self.pageview.textview
buffer = textview.get_buffer()
start = find_heading(buffer, n, self.include_hr)
if start is None:
return
end = find_heading(buffer, n + 1, self.include_hr)
if end is None:
end = buffer.get_end_iter()
buffer.select_range(start, end)
示例11: open_file
# 需要导入模块: from gi.repository import Gtk [as 别名]
# 或者: from gi.repository.Gtk import TextBuffer [as 别名]
def open_file(self, file):
if self.textview.get_buffer().get_modified():
self.save_file()
self.file = file
buffer = Gtk.TextBuffer()
print('Reading %s' % self.file)
buffer.set_text(open(self.file).read())
self.textview.set_buffer(buffer)
buffer.create_tag('translated', background='green')
buffer.create_tag('untranslated', background='red')
buffer.create_tag('notsure', background='orange')
translated, untranslated, notsure = self.tokenize()
self.status_label.set_text(
"%i translated, %i untranslated, %i not sure"
% (len(translated), len(untranslated), len(notsure))
)
def get_iter(coord):
row, col = coord
row -= 1
iter = buffer.get_iter_at_line(row)
iter.forward_chars(col)
return iter
for start, end in translated:
start, end = list(map(get_iter, (start, end)))
buffer.apply_tag_by_name('translated', start, end)
for start, end in untranslated:
start, end = list(map(get_iter, (start, end)))
buffer.apply_tag_by_name('untranslated', start, end)
for start, end in notsure:
start, end = list(map(get_iter, (start, end)))
buffer.apply_tag_by_name('notsure', start, end)
buffer.place_cursor(buffer.get_iter_at_offset(0))
示例12: init
# 需要导入模块: from gi.repository import Gtk [as 别名]
# 或者: from gi.repository.Gtk import TextBuffer [as 别名]
def init(self):
"""
Constructs the GUI, consisting of an entry, a text view and
a Run button.
"""
# filename and selector
self.__base_path = USER_HOME
self.__file_name = "test.gramps"
self.entry = Gtk.Entry()
self.entry.set_text(os.path.join(self.__base_path, self.__file_name))
self.button = Gtk.Button()
image = Gtk.Image()
image.set_from_stock(Gtk.STOCK_OPEN, Gtk.IconSize.BUTTON)
self.button.add(image)
self.button.connect('clicked', self.__select_file)
# GUI setup:
vbox = Gtk.VBox()
hbox = Gtk.HBox()
# area
self.import_text = Gtk.TextView()
self.import_text.set_wrap_mode(Gtk.WrapMode.WORD)
self.import_text.set_editable(False)
self.text = Gtk.TextBuffer()
self.text.set_text(_('No file loaded...'))
self.import_text.set_buffer(self.text)
vbox.pack_start(self.import_text, True, True, 0) # v1
# button
button = Gtk.Button(_("Run"))
button.connect("clicked", self.run)
vbox.pack_start(button, False, False, 0) # v2
# build
hbox.pack_start(self.entry, True, True, 0)
hbox.pack_end(self.button, False, False, 0)
vbox.pack_end(hbox, False, False, 0) # v3
self.gui.get_container_widget().remove(self.gui.textview)
self.gui.get_container_widget().add_with_viewport(vbox)
vbox.show_all()
示例13: init
# 需要导入模块: from gi.repository import Gtk [as 别名]
# 或者: from gi.repository.Gtk import TextBuffer [as 别名]
def init(self):
"""
Constructs the GUI, consisting of an entry, a text view and
a Run button.
"""
self.last = 5
# filename and selector
self.__base_path = USER_HOME
self.__file_name = "test.gramps"
self.entry = Gtk.Entry()
self.entry.set_text(os.path.join(self.__base_path, self.__file_name))
self.button = Gtk.Button()
image = Gtk.Image()
image.set_from_stock(Gtk.STOCK_OPEN, Gtk.IconSize.BUTTON)
self.button.add(image)
self.button.connect('clicked', self.__select_file)
# GUI setup:
vbox = Gtk.VBox()
hbox = Gtk.HBox()
# area
self.import_text = Gtk.TextView()
self.import_text.set_wrap_mode(Gtk.WrapMode.WORD)
self.import_text.set_editable(False)
self.text = Gtk.TextBuffer()
self.text.set_text(_('No file parsed...'))
self.import_text.set_buffer(self.text)
vbox.pack_start(self.import_text, True, True, 0) # v1
# button
button = Gtk.Button(_("Run"))
button.connect("clicked", self.run)
vbox.pack_start(button, False, False, 0) # v2
# build
hbox.pack_start(self.entry, True, True, 0)
hbox.pack_end(self.button, False, False, 0)
vbox.pack_end(hbox, False, False, 0) # v3
self.gui.get_container_widget().remove(self.gui.textview)
self.gui.get_container_widget().add_with_viewport(vbox)
vbox.show_all()
示例14: add_links_to_textview_from_clipboard
# 需要导入模块: from gi.repository import Gtk [as 别名]
# 或者: from gi.repository.Gtk import TextBuffer [as 别名]
def add_links_to_textview_from_clipboard(app_obj, textbuffer, mark_start=None,
mark_end=None, drag_drop_text=None):
"""Called by mainwin.AddVideoDialogue.__init__(),
.on_window_drag_data_received() and .clipboard_timer_callback().
Function to add valid URLs from the clipboard to a Gtk.TextView, ignoring
anything that is not a valid URL, and ignoring duplicate URLs.
If some text is supplied as an argument, uses that text rather than the
clipboard text
Args:
app_obj (mainapp.TartubeApp): The main application
textbuffer (Gtk.TextBuffer): The textbuffer to which valis URLs should
be added (unless they are duplicates)
mark_start, mark_end (Gtk.TextMark): The marks at the start/end of the
buffer (using marks rather than iters prevents Gtk errors)
drag_drop_text (str): If specified, use this text and ignore the
clipboard
"""
if drag_drop_text is None:
# Get text from the system clipboard
clipboard = Gtk.Clipboard.get(Gdk.SELECTION_CLIPBOARD)
cliptext = clipboard.wait_for_text()
else:
# Ignore the clipboard, and use the specified text
cliptext = drag_drop_text
# Pass the text on to the next function, first converting it into a list
if cliptext is not None:
add_links_to_textview(
app_obj,
cliptext.split('\n'),
textbuffer,
mark_start,
mark_end,
)
示例15: show_file_info
# 需要导入模块: from gi.repository import Gtk [as 别名]
# 或者: from gi.repository.Gtk import TextBuffer [as 别名]
def show_file_info(self, b=None):
print('show_file_info')
fmd = self.get_fmd()
msg = '\n' + fmd.details()
if self.cast:
msg += '\nDevice: %s (%s)' % (self.cast.device.model_name, self.cast.device.manufacturer)
msg += '\nChromecast: v%s' % (__version__)
dialogWindow = Gtk.MessageDialog(self.win,
Gtk.DialogFlags.MODAL | Gtk.DialogFlags.DESTROY_WITH_PARENT,
Gtk.MessageType.INFO,
Gtk.ButtonsType.OK,
msg)
dialogWindow.set_title('File Info')
dialogWindow.set_default_size(1, 400)
if self.cast:
title = 'Error playing %s' % os.path.basename(self.fn)
body = '''
[Please describe what happened here...]
[Please link to the download here...]
```
[If possible, please run `ffprobe -i <fn>` and paste the output here...]
```
------------------------------------------------------------
%s
%s
```%s```''' % (msg, fmd, fmd._important_ffmpeg)
url = 'https://github.com/keredson/gnomecast/issues/new?title=%s&body=%s' % (urllib.parse.quote(title), urllib.parse.quote(body))
dialogWindow.add_action_widget(Gtk.LinkButton(url, label="Report File Doesn't Play"), 10)
dialogBox = dialogWindow.get_content_area()
buffer1 = Gtk.TextBuffer()
buffer1.set_text(fmd._ffmpeg_output)
text_view = Gtk.TextView(buffer=buffer1)
text_view.set_editable(False)
scrolled_window = Gtk.ScrolledWindow()
scrolled_window.set_border_width(5)
# we scroll only if needed
scrolled_window.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC)
scrolled_window.add(text_view)
dialogBox.pack_end(scrolled_window, True, True, 0)
dialogWindow.show_all()
response = dialogWindow.run()
dialogWindow.destroy()