class Iconify::TerminalWindow

メインウィンドウ

Constants

COLORS

the shimbun color scheme

Attributes

state[R]

Public Class Methods

new(argv) click to toggle source
String
Calls superclass method
# File lib/iconify.rb, line 18
def initialize(argv)
  super()

  @argv = argv
  @state = :stopped

  update_title

  @rerun_button = create_rerun_button
  @kill_button  = create_kill_button
  @quit_button  = create_quit_button
  @terminal     = create_vte_terminal
  @copy_button  = create_copy_button
  @paste_button = create_paste_button

  layout

  set_geometry_hints
end

Public Instance Methods

changed() click to toggle source
# File lib/iconify.rb, line 117
def changed
  @rerun_button.sensitive = (@state == :stopped)
  @kill_button.sensitive  = (@state == :running)

  @copy_button.sensitive = @terminal.has_selection?

  signal_emit('changed')
end
create_copy_button() click to toggle source
# File lib/iconify.rb, line 65
def create_copy_button
  ToolButton.new(stock_id: Stock::COPY).tap do |b|
    b.tooltip_text = 'Copy'
    b.signal_connect('clicked') do
      @terminal.copy_clipboard
    end
  end
end
create_kill_button() click to toggle source
# File lib/iconify.rb, line 83
def create_kill_button
  ToolButton.new(label: 'Kill').tap do |b|
    b.icon_name = Stock::STOP
    b.tooltip_text = 'Stop the child process by sending the QUIT signal.'
    b.signal_connect('clicked') do
      Process.kill('KILL', @pid) if @pid
    end
  end
end
create_paste_button() click to toggle source
# File lib/iconify.rb, line 74
def create_paste_button
  ToolButton.new(stock_id: Stock::PASTE).tap do |b|
    b.tooltip_text = 'Paste'
    b.signal_connect('clicked') do
      @terminal.paste_clipboard
    end
  end
end
create_quit_button() click to toggle source
# File lib/iconify.rb, line 103
def create_quit_button
  ToolButton.new(label: 'Quit').tap do |b|
    b.icon_name = Stock::QUIT
    b.tooltip_text = 'Stop the program and quit.'
    b.signal_connect('clicked') do
      Gtk.main_quit
    end
  end
end
create_rerun_button() click to toggle source
# File lib/iconify.rb, line 93
def create_rerun_button
  ToolButton.new(label: 'Rerun').tap do |b|
    b.icon_name = Stock::REFRESH
    b.tooltip_text = 'Rerun the program.'
    b.signal_connect('clicked') do
      exec
    end
  end
end
create_vte_terminal() click to toggle source
# File lib/iconify.rb, line 145
def create_vte_terminal
  Vte::Terminal.new.tap do |t|
    t.font = Pango::FontDescription.new('monospace 14')
    t.set_size_request(t.char_width * 40, t.char_height * 12)
    t.set_size(80, 24)
    t.cursor_blink_mode = Vte::CursorBlinkMode::OFF
    t.set_colors(COLORS[0], COLORS[15], COLORS)

    t.signal_connect('child-exited') do
      on_child_exited
    end
    t.signal_connect('selection-changed') do
      changed
    end
  end
end
exec() click to toggle source
# File lib/iconify.rb, line 169
def exec
  @pid = @terminal.spawn(argv: @argv)
  @state = :running
  changed
end
layout() click to toggle source
# File lib/iconify.rb, line 43
def layout
  vbox = Box.new(:vertical)
  toolbar = Toolbar.new

  toolbar.add(@rerun_button)
  toolbar.add(@kill_button)
  toolbar.add(SeparatorToolItem.new)
  toolbar.add(@copy_button)
  toolbar.add(@paste_button)
  toolbar.add(SeparatorToolItem.new)
  toolbar.add(@quit_button)
  vbox.pack_start(toolbar, expand: false)

  padding_box = Box.new(:vertical)
  padding_box.pack_start(@terminal, expand: true, fill: true)
  padding_box.border_width = 18
  override_background_color(StateFlags::NORMAL, COLORS[15])
  vbox.pack_start(padding_box, expand: true, fill: true)

  add vbox
end
on_child_exited() click to toggle source
# File lib/iconify.rb, line 162
def on_child_exited
  @state = :stopped
  @pid = nil
  @rerun_button.sensitive = true
  changed
end
set_geometry_hints() click to toggle source
# File lib/iconify.rb, line 38
def set_geometry_hints
  @terminal.realize
  @terminal.set_geometry_hints_for_window(self)
end
update_title() click to toggle source
# File lib/iconify.rb, line 113
def update_title
  self.title = "iconify - #{@argv[0]}"
end