Update connect/disconnect action states.
[kaya.git] / lib / console.rb
blob427d2e0b54dfc33889ef1a82b8bdb7afd9631bf0
1 # Copyright (c) 2009 Paolo Capriotti <p.capriotti@gmail.com>
2
3 # This program is free software; you can redistribute it and/or modify
4 # it under the terms of the GNU General Public License as published by
5 # the Free Software Foundation; either version 2 of the License, or
6 # (at your option) any later version.
8 require 'toolkit'
10 class Console < Qt::Widget
11   include Observable
13   def initialize(parent)
14     super(parent)
15     
16     layout = Qt::VBoxLayout.new
17     @output = Qt::TextEdit.new(self)
18     @input = Qt::LineEdit.new(self)
19     
20     layout.add_widget(@output)
21     layout.add_widget(@input)
22     setLayout layout
23     
24     @output.read_only = true
25     f = @output.font
26     f.family = 'monospace'
27     f.point_size = 8
28     @output.font = f
29     @output.current_font = f
30     @bold_font = f
31     @bold_font.bold = true
33     @input.on(:return_pressed) do
34       write_line(@input.text)
35     end
36   end
38   def with_font(font)
39     old = @output.current_font
40     @output.current_font = font
41     yield
42     @output.current_font = old
43   end
44   
45   def append(text)
46     @output.append(text)
47   end
48   
49   def write_line(text)
50     with_font(@bold_font) do
51       @output.append text
52     end
53     @input.text = ''
54     fire :input => text
55   end
56 end