Class: Iconify::TerminalWindow

Inherits:
Gtk::Window
  • Object
show all
Includes:
Gtk
Defined in:
lib/iconify.rb

Overview

メインウィンドウ

Constant Summary collapse

COLORS =

the shimbun color scheme

[[0x30, 0x30, 0x30],
 [0xbe, 0x11, 0x37],
 [0x29, 0x73, 0x2c],
 [0xc9, 0x5c, 0x26],
 [0x2a, 0x5a, 0xa2],
 [0xcd, 0x3a, 0x93],
 [0x07, 0x86, 0x92],
 [0xd0, 0xd0, 0xd0],
 [0x50, 0x50, 0x50],
 [0xe6, 0x2b, 0x5d],
 [0x40, 0x9e, 0x01],
 [0xec, 0x75, 0x42],
 [0x17, 0x7f, 0xe0],
 [0xe9, 0x53, 0xba],
 [0x00, 0xa9, 0xb2],
 [0xf2, 0xf2, 0xf2]]
.map { |rgb| Gdk::RGBA.new(*rgb.map { |n| n.fdiv(255) }, 1.0) }

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(argv) ⇒ TerminalWindow

String


18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# 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

Instance Attribute Details

#stateObject (readonly)

Returns the value of attribute state.



15
16
17
# File 'lib/iconify.rb', line 15

def state
  @state
end

Instance Method Details

#changedObject



117
118
119
120
121
122
123
124
# 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_buttonObject



65
66
67
68
69
70
71
72
# 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_buttonObject



83
84
85
86
87
88
89
90
91
# 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_buttonObject



74
75
76
77
78
79
80
81
# 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_buttonObject



103
104
105
106
107
108
109
110
111
# 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_buttonObject



93
94
95
96
97
98
99
100
101
# 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_terminalObject



145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
# 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

#execObject



169
170
171
172
173
# File 'lib/iconify.rb', line 169

def exec
  @pid = @terminal.spawn(argv: @argv)
  @state = :running
  changed
end

#layoutObject



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# 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_exitedObject



162
163
164
165
166
167
# File 'lib/iconify.rb', line 162

def on_child_exited
  @state = :stopped
  @pid = nil
  @rerun_button.sensitive = true
  changed
end

#set_geometry_hintsObject



38
39
40
41
# File 'lib/iconify.rb', line 38

def set_geometry_hints
  @terminal.realize
  @terminal.set_geometry_hints_for_window(self)
end

#update_titleObject



113
114
115
# File 'lib/iconify.rb', line 113

def update_title
  self.title = "iconify - #{@argv[0]}"
end