Python gi.repository.Gtk 模块,TextBuffer() 实例源码

我们从Python开源项目中,提取了以下8个代码示例,用于说明如何使用gi.repository.Gtk.TextBuffer()

项目:Remarkable    作者:jamiemcg    | 项目源码 | 文件源码
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)
项目:Solfege    作者:RannyeriDev    | 项目源码 | 文件源码
def __init__(self):
        Gtk.ScrolledWindow.__init__(self)
        self.g_textbuffer = Gtk.TextBuffer()
        self.g_textbuffer.create_tag('h1', weight=Pango.Weight.BOLD,
            size=16*Pango.SCALE)
        self.g_textview = Gtk.TextView(buffer=self.g_textbuffer)
        self.add(self.g_textview)
项目:apturl    作者:linuxmint    | 项目源码 | 文件源码
def askInstallPackage(self, package, summary, description, homepage):
        # populate the dialog
        dia = self.dia
        dia_xml = self.dia_xml
        header = _("Install additional software?")
        body = _("Do you want to install package '%s'?") % package
        dia.set_title('')
        header_label = dia_xml.get_object('header_label')
        header_label.set_markup("<b><big>%s</big></b>" % header)
        body_label = dia_xml.get_object('body_label')
        body_label.set_label(body)
        description_text_view = dia_xml.get_object('description_text_view')
        tbuf = Gtk.TextBuffer()
        desc = "%s\n\n%s" % (summary, Helpers.format_description(description))
        tbuf.set_text(desc)
        description_text_view.set_buffer(tbuf)
        dia.set_icon(Gtk.IconTheme.get_default().load_icon('package-x-generic', 16, False))

        # check if another package manager is already running
        # FIXME: just checking for the existance of the file is
        #        not sufficient, it need to be tested if it can
        #        be locked via apt_pkg.get_lock()
        #        - but that needs to run as root
        #        - a dbus helper might be the best answer here
        #args = (update_button_status, dia_xml.get_object("yes_button"),
        #    dia_xml.get_object("infolabel"))
        #args[0](*args[1:])
        #timer_id = GObject.timeout_add(750, *args )

        # show the dialog
        res = dia.run()
        #GObject.source_remove(timer_id)
        if res != Gtk.ResponseType.YES:
            dia.hide()
            return False

        return True

    # progress etc
项目:MPV-VJ2    作者:paulguy    | 项目源码 | 文件源码
def setWindow(self, logWindow):
        if logWindow is not None:
            self.textBuffer = Gtk.TextBuffer()
            for item in self.logItems:
                self.textBuffer.insert(self.textBuffer.get_end_iter(), item)
            logWindow.set_buffer(self.textBuffer)
        else:
            self.textBuffer = None
项目:ibus-typing-booster    作者:mike-fabian    | 项目源码 | 文件源码
def __init__(self, parent=None,
                 title='', description='', long_description=''):
        Gtk.Window.__init__(self, title=title)
        self.set_parent(parent)
        self.set_transient_for(parent)
        self.set_destroy_with_parent(False)
        self.set_default_size(600, 500)
        self.vbox = Gtk.VBox(spacing=0)
        self.add(self.vbox)
        self.text_buffer = Gtk.TextBuffer()
        self.text_buffer.insert_at_cursor(description)
        self.text_buffer.insert_at_cursor(
            '\n\n'
            + '############################################################'
            + '\n')
        self.text_buffer.insert_at_cursor(
            'Complete file implementing the input method follows here:\n')
        self.text_buffer.insert_at_cursor(
            '############################################################'
            + '\n')
        self.text_buffer.insert_at_cursor(long_description)
        self.text_view = Gtk.TextView()
        self.text_view.set_buffer(self.text_buffer)
        self.text_view.set_editable(False)
        self.text_view.set_cursor_visible(False)
        self.text_view.set_justification(Gtk.Justification.LEFT)
        self.text_view.set_wrap_mode(Gtk.WrapMode.WORD)
        self.scrolledwindow = Gtk.ScrolledWindow()
        self.scrolledwindow.set_hexpand(True)
        self.scrolledwindow.set_vexpand(True)
        self.scrolledwindow.add(self.text_view)
        self.vbox.pack_start(self.scrolledwindow, True, True, 0)
        self.close_button = Gtk.Button(stock=Gtk.STOCK_CLOSE)
        self.close_button.connect("clicked", self.on_close_button_clicked)
        self.hbox = Gtk.HBox(spacing=0)
        self.hbox.pack_end(self.close_button, False, False, 0)
        self.vbox.pack_start(self.hbox, False, False, 5)
项目:Remarkable    作者:jamiemcg    | 项目源码 | 文件源码
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)
项目:jcchess    作者:johncheetham    | 项目源码 | 文件源码
def __init__(self):
        glade_dir = gv.jcchess.get_glade_dir()
        self.glade_file = os.path.join(glade_dir, "engine_output.glade")
        Engine_Output.engine_output_ref = self

        self.builder = Gtk.Builder()
        self.builder.set_translation_domain(gv.domain)
        self.builder.add_from_file(self.glade_file)
        self.builder.connect_signals(self)

        self.window = self.builder.get_object("engine_output_window")
        self.tv = [Gtk.TextView(), Gtk.TextView()]
        self.tv[0] = self.builder.get_object("engine_output_textview1")
        self.tv[1] = self.builder.get_object("engine_output_textview2")
        self.tv[0].set_editable(False)
        self.tv[1].set_editable(False)

        tabs = Pango.TabArray.new(4, True)
        tabs.set_tab(0, Pango.TabAlign.LEFT, 40)
        tabs.set_tab(1, Pango.TabAlign.LEFT, 160)
        tabs.set_tab(2, Pango.TabAlign.LEFT, 230)
        tabs.set_tab(3, Pango.TabAlign.LEFT, 280)

        self.tv[0].set_tabs(tabs)
        self.tv[1].set_tabs(tabs)

        self.tb = [Gtk.TextBuffer(), Gtk.TextBuffer()]
        self.tb[0] = self.tv[0].get_buffer()
        self.tb[1] = self.tv[1].get_buffer()
        # self.tb[0].set_text("")
        # self.tb[1].set_text("")

        self.nps_lbl = [Gtk.Label(), Gtk.Label()]
        self.nps_lbl[0] = self.builder.get_object("engine_output_nodes_lbl1")
        self.nps_lbl[1] = self.builder.get_object("engine_output_nodes_lbl2")

        self.engine_name_lbl = [Gtk.Label(), Gtk.Label()]
        self.engine_name_lbl[0] = self.builder.get_object(
            "engine_output_engine_name_lbl1")
        self.engine_name_lbl[1] = self.builder.get_object(
            "engine_output_engine_name_lbl2")

        self.ponder_move_lbl = [Gtk.Label(), Gtk.Label()]
        self.ponder_move_lbl[0] = self.builder.get_object(
            "engine_output_ponder_move_lbl1")
        self.ponder_move_lbl[1] = self.builder.get_object(
            "engine_output_ponder_move_lbl2")

        self.currmove_lbl = [Gtk.Label(), Gtk.Label()]
        self.currmove_lbl[0] = self.builder.get_object(
            "engine_output_currmove_lbl1")
        self.currmove_lbl[1] = self.builder.get_object(
            "engine_output_currmove_lbl2")

        # self.window.show_all()

    # user has closed the window
    # just hide it
项目:ACYLS    作者:worron    | 项目源码 | 文件源码
def __init__(self, filters, config):
        # Color page filters
        self.filters = filters

        # Filter edit helper
        self.filter_editor = RawFilterEditor(config.get("Editor", "preview"))

        # File dialog
        self.filechooser = FileChooser(acyls.dirs['filters'], "filter.xml")

        # Read icon size settins from config
        self.PREVIEW_ICON_SIZE = int(config.get("PreviewSize", "single"))

        # Load GUI
        self.builder = Gtk.Builder()
        self.builder.add_from_file(os.path.join(acyls.dirs['gui'], "editor.glade"))

        gui_elements = (
            'editor_grid', 'editor_textview', 'editor_preview_icon', 'filter_info_label',
        )
        self.gui = {element: self.builder.get_object(element) for element in gui_elements}
        self.gui['editor_textview'].modify_font(Pango.FontDescription("Monospace"))

        # Build buffer
        self.buffer = Gtk.TextBuffer(text="Enter filter source here")
        self.gui['editor_textview'].set_buffer(self.buffer)

        # Mainpage buttnons hanlers
        self.mhandlers = dict()
        self.mhandlers['refresh_button'] = self.on_refresh_click

        # Toolbar buttnons hanlers
        self.bhandlers = dict()
        self.bhandlers['edit_filter_toolbutton'] = self.on_edit_filter_button_click
        self.bhandlers['load_filter_toolbutton'] = self.on_load_filter_button_click
        self.bhandlers['revert_filter_toolbutton'] = self.on_revert_filter_button_click
        self.bhandlers['save_filter_toolbutton'] = self.on_save_filter_button_click
        self.bhandlers['save_as_filter_toolbutton'] = self.on_save_as_filter_button_click

        # Fill up GUI
        pixbuf = PixbufCreator.new_single_at_size(self.filter_editor.preview, self.PREVIEW_ICON_SIZE)
        self.gui['editor_preview_icon'].set_from_pixbuf(pixbuf)

    # Support functions