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

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

项目:ns3-rdma    作者:bobzhuyb    | 项目源码 | 文件源码
def __init__(self):
    gtk.TextView.__init__(self)
    self.modify_font(pango.FontDescription('Mono'))
    self.set_cursor_visible(True)
    self.text_buffer = self.get_buffer()
    self.mark = self.text_buffer.create_mark('scroll_mark',
                                             self.text_buffer.get_end_iter(),
                                             False)
    for code in ansi_colors:
      self.text_buffer.create_tag(code,
                                  foreground=ansi_colors[code],
                                  weight=700)
    self.text_buffer.create_tag('0')
    self.text_buffer.create_tag('notouch', editable=False)
    self.color_pat = re.compile('\x01?\x1b\[(.*?)m\x02?')
    self.line_start = \
                self.text_buffer.create_mark('line_start',
                        self.text_buffer.get_end_iter(), True
                )
    self.connect('key-press-event', self._onKeypress)
    self.last_cursor_pos = 0
项目:learning-texas-holdem    作者:gjgregory    | 项目源码 | 文件源码
def _set_text(self, widget, text):
        """Helper function to change the text in a TextView."""
        buf = widget.get_buffer()
        buf.set_text(text)
        widget.set_buffer(buf)
        widget.show()
项目:learning-texas-holdem    作者:gjgregory    | 项目源码 | 文件源码
def _player_move(self, opt, move):
        """Performs a move by the player when an action button is clicked."""
        if move == 'FOLD':
            if self.game.fold(self.player) == False:
                return False
        elif move == 'CHECK':
            if self.game.check(self.player) == False:
                return False
        elif move == 'CALL':
            if self.game.call(self.player) == False:
                return False
        elif move == 'RAISE_BID':
            #get text from TextView
            buf = self.bid_text.get_buffer()
            start = buf.get_start_iter()
            end = buf.get_end_iter()
            #do move
            if self.game.make_bid(self.player, int(buf.get_text(start, end))) == False:
                return False

        self._update_display(False)
        if self.game.finished:
            self._update_display(not self.player.folded)
            self._toggle_interface(False)
            return True
        elif self.game.is_next(self.cpu):
            self._cpu_move()
            self._update_display(False)
            if self.game.finished:
                self._update_display(not self.cpu.folded)
                self._toggle_interface(False)
        return True
项目:tools    作者:denglouping    | 项目源码 | 文件源码
def build_MessageView(self):
        MessageView = gtk.TextView();

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

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

        return MessageView;
项目:ecel    作者:ARL-UTEP-OC    | 项目源码 | 文件源码
def __init__(self):
        super(ProgressBarDetails, self).__init__()

        #Configure the Window
        self.set_resizable(False)
        self.connect("destroy", self.destroy_progress)
        self.set_title("Progress Bar")
        self.set_position(gtk.WIN_POS_CENTER)
        self.set_size_request(460, 150)
        self.set_border_width(0)

        #Create the VBox in case we want to add additional items later
        self.vbox = gtk.VBox(False, 5)
        self.vbox.set_border_width(10)
        self.add(self.vbox)
        self.vbox.show()

        #create the scrolled window
        self.scrolled_window =gtk.ScrolledWindow()
        self.scrolled_window.set_usize(460, 100)
        self.vbox.add(self.scrolled_window)
        self.scrolled_window.show()

        self.text_view = gtk.TextView()
        self.msg_i = 0
        self.text_buffer = self.text_view.get_buffer()
        self.scrolled_window.add_with_viewport(self.text_view)
        self.text_view.connect("size-allocate", self.autoscroll)
        self.text_view.show()

        # Create the ProgressBar
        self.pbar = gtk.ProgressBar()
        #self.pbar.set_usize(460, 40)
        self.pbar.set_fraction(0.0)
        self.vbox.add(self.pbar)
        self.pbar.show()

        #Display the Window
        self.show()
项目: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)
项目:griffith    作者:Strit    | 项目源码 | 文件源码
def __init__(self, window):
        self.dialog = gtk.Dialog('Debug Window', window, gtk.DIALOG_MODAL, ())
        self.dialog.set_destroy_with_parent(True)
        self.dialog.set_transient_for(window)
        self.dialog.set_modal(False)
        self.textview = gtk.TextView()
        self.textview.set_editable(False)
        self.textview.set_wrap_mode(gtk.WRAP_WORD_CHAR)
        self.textview.set_scroll_adjustments(gtk.Adjustment(1.0, 1.0, 100.0, 1.0, 10.0, 10.0), gtk.Adjustment(1.0, 1.0, 100.0, 1.0, 10.0, 10.0))
        self.scrolledwindow = gtk.ScrolledWindow(None, None)
        self.scrolledwindow.add(self.textview)
        self.dialog.vbox.pack_start(self.scrolledwindow)
        self.dialog.set_default_size(640, 480)
项目:chirp_fork    作者:mach327    | 项目源码 | 文件源码
def _add_text(d, text):
    v = gtk.TextView()
    v.get_buffer().set_text(text)
    v.set_editable(False)
    v.set_cursor_visible(False)
    v.show()
    sw = gtk.ScrolledWindow()
    sw.add(v)
    sw.show()
    d.vbox.pack_start(sw, 1, 1, 1)
    return v
项目:inkscapeMadeEasy    作者:fsmMLK    | 项目源码 | 文件源码
def cb_ok(self, widget, data=None):
            buf = self._text.get_buffer()
            self.text = buf.get_text(buf.get_start_iter(),
                                     buf.get_end_iter())
            if isinstance(self._preamble, gtk.FileChooser):
                self.preamble_file = self._preamble.get_filename()
                if not self.preamble_file:
                    self.preamble_file = ""
            else:
                self.preamble_file = self._preamble.get_text()

            if self.scale_factor is not None:
                self.scale_factor = self._scale_adj.get_value()

            try:
                self.callback(self.text, self.preamble_file, self.scale_factor)
            except StandardError, e:
                err_msg = traceback.format_exc()
                dlg = gtk.Dialog("Textext Error", self._window, 
                                 gtk.DIALOG_MODAL)
                dlg.set_default_size(600, 400)
                btn = dlg.add_button(gtk.STOCK_OK, gtk.RESPONSE_CLOSE)
                btn.connect("clicked", lambda w, d=None: dlg.destroy())
                msg = gtk.Label()
                msg.set_markup("<b>Error occurred while converting text from Latex to SVG:</b>")

                txtw = gtk.ScrolledWindow()
                txtw.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
                txtw.set_shadow_type(gtk.SHADOW_IN)
                txt = gtk.TextView()
                txt.set_editable(False)
                txt.get_buffer().set_text(err_msg)
                txtw.add(txt)

                dlg.vbox.pack_start(msg, expand=False, fill=True)
                dlg.vbox.pack_start(txtw, expand=True, fill=True)
                dlg.show_all()
                dlg.run()
                return False

            gtk.main_quit()
            return False
项目:wahcade    作者:sairuk    | 项目源码 | 文件源码
def _info(type, value, tb):
    """display exception"""
    #ungrab a potentially "grabbed" mouse pointer
    gtk.gdk.pointer_ungrab()
    #create dialog
    dialog = gtk.MessageDialog(
        parent = None,
        flags = 0,
        type = gtk.MESSAGE_WARNING,
        buttons = gtk.BUTTONS_NONE,
        message_format = _("<big><b>Error</b></big>"))
    dialog.set_title(_("Bug Detected"))
    dialog.vbox.get_children()[0].get_children()[1].get_children()[0].set_property("use-markup", True)
    dialog.add_button(gtk.STOCK_CLOSE, gtk.RESPONSE_CLOSE)
    #details
    textview = gtk.TextView() 
    textview.show()
    textview.set_editable(False)
    textview.modify_font(pango.FontDescription("Monospace"))
    sw = gtk.ScrolledWindow() 
    sw.show()
    sw.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
    sw.add(textview)
    frame = gtk.Frame()
    frame.set_shadow_type(gtk.SHADOW_IN)
    frame.add(sw)
    frame.set_border_width(6)
    dialog.vbox.add(frame)
    textbuffer = textview.get_buffer()
    trace = StringIO.StringIO()
    traceback.print_exception(type, value, tb, None, trace)
    textbuffer.set_text(trace.getvalue())
    textview.set_size_request(gtk.gdk.screen_width()/2, gtk.gdk.screen_height()/3)
    dialog.details = frame
    dialog.set_position(gtk.WIN_POS_CENTER)
    dialog.set_gravity(gtk.gdk.GRAVITY_CENTER)
    dialog.details.show()
    #display the dialog
    resp = dialog.run()
    if resp == gtk.RESPONSE_CLOSE:
        pass
    dialog.destroy()
    sys.exit(1)

#sys.excepthook = _info
项目: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()