class TextviewDemo

# Copyright © 2017 Ruby-GNOME2 Project Team # This program is licenced under the same licence as Ruby-GNOME2. #

Text View/Multiple Views

The GtkTextView widget displays a GtkTextBuffer. One GtkTextBuffer
can be displayed by multiple GtkTextViews. This demo has two views
displaying a single buffer, and shows off the widget's text
formatting features.

Public Class Methods

new(main_window) click to toggle source
# File gtk3/sample/gtk-demo/textview.rb, line 14
def initialize(main_window)
  @window = Gtk::Window.new(:toplevel)
  @window.screen = main_window.screen
  @window.set_default_size(450, 450)
  @window.title = "Multiple Views"

  vpaned = Gtk::Paned.new(:vertical)
  @window.add(vpaned)

  # For convenience, we just use the autocreated buffer from
  # the first text view; you could also create the buffer
  # by itself Gtk::TextBuffer.new, then later create a view
  # widget.

  view1 = Gtk::TextView.new
  view2 = Gtk::TextView.new(view1.buffer)

  sw = Gtk::ScrolledWindow.new
  sw.set_policy(:automatic, :automatic)
  vpaned.add1(sw)
  sw.add(view1)

  sw = Gtk::ScrolledWindow.new
  sw.set_policy(:automatic, :automatic)
  vpaned.add2(sw)
  sw.add(view2)

  create_tags(view1.buffer)
  insert_text(view1.buffer)

  attach_widgets(view1)
  attach_widgets(view2)

  vpaned.show_all
end

Public Instance Methods

run() click to toggle source
# File gtk3/sample/gtk-demo/textview.rb, line 50
def run
  if !@window.visible?
    @window.show_all
  else
    @window.destroy
  end
  @window
end