Class: Iconify::TerminalWindow
- Inherits:
-
Gtk::Window
- Object
- Gtk::Window
- Iconify::TerminalWindow
- 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
-
#state ⇒ Object
readonly
Returns the value of attribute state.
Instance Method Summary collapse
- #changed ⇒ Object
- #create_copy_button ⇒ Object
- #create_kill_button ⇒ Object
- #create_paste_button ⇒ Object
- #create_quit_button ⇒ Object
- #create_rerun_button ⇒ Object
- #create_vte_terminal ⇒ Object
- #exec ⇒ Object
-
#initialize(argv) ⇒ TerminalWindow
constructor
[String].
- #layout ⇒ Object
- #on_child_exited ⇒ Object
- #set_geometry_hints ⇒ Object
- #update_title ⇒ Object
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 = = = @terminal = create_vte_terminal = = layout set_geometry_hints end |
Instance Attribute Details
#state ⇒ Object (readonly)
Returns the value of attribute state.
15 16 17 |
# File 'lib/iconify.rb', line 15 def state @state end |
Instance Method Details
#changed ⇒ Object
117 118 119 120 121 122 123 124 |
# File 'lib/iconify.rb', line 117 def changed .sensitive = (@state == :stopped) .sensitive = (@state == :running) .sensitive = @terminal.has_selection? signal_emit('changed') end |
#create_copy_button ⇒ Object
65 66 67 68 69 70 71 72 |
# File 'lib/iconify.rb', line 65 def 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 ⇒ Object
83 84 85 86 87 88 89 90 91 |
# File 'lib/iconify.rb', line 83 def 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 ⇒ Object
74 75 76 77 78 79 80 81 |
# File 'lib/iconify.rb', line 74 def 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 ⇒ Object
103 104 105 106 107 108 109 110 111 |
# File 'lib/iconify.rb', line 103 def 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 ⇒ Object
93 94 95 96 97 98 99 100 101 |
# File 'lib/iconify.rb', line 93 def 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 ⇒ Object
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 |
#exec ⇒ Object
169 170 171 172 173 |
# File 'lib/iconify.rb', line 169 def exec @pid = @terminal.spawn(argv: @argv) @state = :running changed end |
#layout ⇒ Object
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) = .new .add() .add() .add(SeparatorToolItem.new) .add() .add() .add(SeparatorToolItem.new) .add() vbox.pack_start(, 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 ⇒ Object
162 163 164 165 166 167 |
# File 'lib/iconify.rb', line 162 def on_child_exited @state = :stopped @pid = nil .sensitive = true changed end |
#set_geometry_hints ⇒ Object
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_title ⇒ Object
113 114 115 |
# File 'lib/iconify.rb', line 113 def update_title self.title = "iconify - #{@argv[0]}" end |