Python gtk 模块,TextBuffer() 实例源码

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

项目:tools    作者:denglouping    | 项目源码 | 文件源码
def send_log(self,event,server):
        v = self.serverInfo[server]["vTerminal"]
        x,y = v.get_cursor_position()
        content = self.serverInfo[server]["vTerminal"].get_text_range(0, 0, y,x,lambda widget, col, row, junk: True)
        b = gtk.TextBuffer();
        b.set_text(content)
        #self.messageView.set_buffer(b);
项目:tools    作者:denglouping    | 项目源码 | 文件源码
def build_MessageView(self):
        MessageView = gtk.TextView();

        b = gtk.TextBuffer();
        b.set_text("test")

        MessageView.set_buffer(b);
        MessageView.show();

        return MessageView;
项目:barbieri-playground    作者:barbieri    | 项目源码 | 文件源码
def setup_gui_url_chooser(self):
        d = catota.ui.Dialog("Choose Location", self.parent_win)
        label = catota.ui.Label("<small><b>Enter location</b> to be "
                                "handled directly to underlying player engine"
                                "</small>")
        d.vbox.pack_start(label, fill=True, expand=False)
        label.show()

        self.gui_url_chooser_entry = gtk.TextBuffer()

        textview = gtk.TextView(self.gui_url_chooser_entry)
        textview.set_editable(True)
        textview.set_cursor_visible(True)
        textview.set_left_margin(2)
        textview.set_right_margin(2)
        textview.set_wrap_mode(gtk.WRAP_CHAR)

        sw = gtk.ScrolledWindow()
        sw.set_policy(hscrollbar_policy=gtk.POLICY_NEVER,
                      vscrollbar_policy=gtk.POLICY_AUTOMATIC)
        sw.set_shadow_type(gtk.SHADOW_IN)
        sw.add(textview)

        d.vbox.pack_start(sw, fill=True, expand=True)
        sw.show_all()

        self.gui_url_chooser = d
    # setup_gui_url_chooser()
项目:tintwizard    作者:vanadey    | 项目源码 | 文件源码
def createClockDisplayWidgets(self):
        """Create the Clock Display widgets."""
        self.tableClockDisplays = gtk.Table(rows=3, columns=3, homogeneous=False)
        self.tableClockDisplays.set_row_spacings(5)
        self.tableClockDisplays.set_col_spacings(5)

        createLabel(self.tableClockDisplays, text="Show", gridX=0, gridY=0, xPadding=10)
        self.clockCheckButton = createCheckButton(self.tableClockDisplays, active=True, gridX=1, gridY=0, xExpand=True, yExpand=False, handler=self.changeOccurred)

        createLabel(self.tableClockDisplays, text="Time 1 Format", gridX=0, gridY=1, xPadding=10)
        self.clock1Format = createEntry(self.tableClockDisplays, maxSize=50, width=20, text=CLOCK_FMT_1, gridX=1, gridY=1, xExpand=True, yExpand=False, handler=self.changeOccurred)
        self.clock1CheckButton = createCheckButton(self.tableClockDisplays, text="Show", active=True, gridX=2, gridY=1, xExpand=True, yExpand=False, handler=self.changeOccurred)
        self.registerComponent("time1_format", self.clock1Format)

        createLabel(self.tableClockDisplays, text="Time 1 Font", gridX=0, gridY=2, xPadding=10)
        self.clock1FontButton = createFontButton(self.tableClockDisplays, font=self.defaults["font"], gridX=1, gridY=2, handler=self.changeOccurred)
        self.registerComponent("time1_font", self.clock1FontButton)

        createLabel(self.tableClockDisplays, text="Time 2 Format", gridX=0, gridY=3, xPadding=10)
        self.clock2Format = createEntry(self.tableClockDisplays, maxSize=50, width=20, text=CLOCK_FMT_2, gridX=1, gridY=3, xExpand=True, yExpand=False, handler=self.changeOccurred)
        self.clock2CheckButton = createCheckButton(self.tableClockDisplays, text="Show", active=True, gridX=2, gridY=3, xExpand=True, yExpand=False, handler=self.changeOccurred)
        self.registerComponent("time2_format", self.clock2Format)

        createLabel(self.tableClockDisplays, text="Time 2 Font", gridX=0, gridY=4, xPadding=10)
        self.clock2FontButton = createFontButton(self.tableClockDisplays, font=self.defaults["font"], gridX=1, gridY=4, handler=self.changeOccurred)
        self.registerComponent("time2_font", self.clock2FontButton)

        createLabel(self.tableClockDisplays, text="Tooltip Format", gridX=0, gridY=5, xPadding=10)
        self.clockTooltipFormat = createEntry(self.tableClockDisplays, maxSize=50, width=20, text=CLOCK_TOOLTIP, gridX=1, gridY=5, xExpand=True, yExpand=False, handler=self.changeOccurred)
        self.clockTooltipCheckButton = createCheckButton(self.tableClockDisplays, text="Show", active=True, gridX=2, gridY=5, xExpand=True, yExpand=False, handler=self.changeOccurred)
        self.registerComponent("clock_tooltip", self.clockTooltipFormat)

        self.clockArea = gtk.ScrolledWindow()
        self.clockBuf = gtk.TextBuffer()
        self.clockTextView = gtk.TextView(self.clockBuf)
        self.clockBuf.insert_at_cursor("%H 00-23 (24-hour)    %I 01-12 (12-hour)    %l 1-12 (12-hour)    %M 00-59 (minutes)\n%S 00-59 (seconds)    %P am/pm    %b Jan-Dec    %B January-December\n%a Sun-Sat    %A Sunday-Saturday    %d 01-31 (day)    %e 1-31 (day)\n%y 2 digit year, e.g. 09    %Y 4 digit year, e.g. 2009")
        self.clockTextView.set_editable(False)
        self.clockArea.add_with_viewport(self.clockTextView)
        self.tableClockDisplays.attach(self.clockArea, 0, 3, 6, 7, xpadding=10)
项目:python-3-for-absolute-begs    作者:Apress    | 项目源码 | 文件源码
def get_selection(self):
        """get_selection

        Creates text appropriate to choices
        """
        # get selection from listview
        self.choice = self.treeview1.get_selection()
        self.choice.set_mode(gtk.SELECTION_SINGLE)
        self.model, self.row_reference = self.choice.get_selected()
        self.choice = self.liststore.get_value(self.row_reference, 0)

        # Create command line
        command_ref = "self." + self.choice.replace(' ','_') + "_func"
        command = eval(command_ref)

        # GUI output
        # Make clean textbuffer
        self.textbuffer = gtk.TextBuffer(None)
        # Create headline style
        self.headline = self.textbuffer.create_tag('headline', 
                            weight=700, scale=pango.SCALE_LARGE)
        # navigate to start of buffer
        place = self.textbuffer.get_start_iter()
        # Create pixbuf icon reference
        icon = eval("self." + self.choice.replace(' ','_') + "_image")
        # Insert icon at top of page
        self.textbuffer.insert_pixbuf(place, icon)
        # Print appropriate text underneath
        text = " " + self.choice + ": \n\n" + commands.getoutput(command)
        self.textbuffer.insert_at_cursor(text)
        iter0 = self.textbuffer.get_iter_at_line(0)
        iter1 = self.textbuffer.get_iter_at_line(1)
        self.textbuffer.apply_tag(self.headline,iter0,iter1)
        self.textview1.set_buffer(self.textbuffer)
        return
项目:chirp_fork    作者:mach327    | 项目源码 | 文件源码
def show_diff_blob(title, result):
    d = gtk.Dialog(title=title,
                   buttons=(gtk.STOCK_OK, gtk.RESPONSE_OK))
    b = gtk.TextBuffer()

    tags = b.get_tag_table()
    for color in ["red", "blue", "green", "grey"]:
        tag = gtk.TextTag(color)
        tag.set_property("foreground", color)
        tags.add(tag)
    tag = gtk.TextTag("bold")
    tag.set_property("weight", pango.WEIGHT_BOLD)
    tags.add(tag)

    try:
        fontsize = CONF.get_int("diff_fontsize", "developer")
    except Exception:
        fontsize = 11
    if fontsize < 4 or fontsize > 144:
        LOG.info("Unsupported diff_fontsize %i. Using 11." % fontsize)
        fontsize = 11

    lines = result.split(os.linesep)
    for line in lines:
        if line.startswith("-"):
            tags = ("red", "bold")
        elif line.startswith("+"):
            tags = ("blue", "bold")
        else:
            tags = ()
        b.insert_with_tags_by_name(b.get_end_iter(), line + os.linesep, *tags)
    v = gtk.TextView(b)
    fontdesc = pango.FontDescription("Courier %i" % fontsize)
    v.modify_font(fontdesc)
    v.set_editable(False)
    v.show()
    s = gtk.ScrolledWindow()
    s.add(v)
    s.show()
    d.vbox.pack_start(s, 1, 1, 1)
    d.set_size_request(600, 400)
    d.run()
    d.destroy()