class Metasm::Gui::InputBox
Attributes
label[RW]
textwidget[RW]
Public Class Methods
new(owner, str, opts={}) { |strip| ... }
click to toggle source
shows a simplitic input box (eg window with a 1-line textbox + OK button), yields the text TODO history, dropdown, autocomplete, contexts, 3D stereo surround, etc
Calls superclass method
# File metasm/gui/gtk.rb, line 563 def initialize(owner, str, opts={}) owner ||= Gtk::Window.toplevels.first super(nil, owner, Gtk::Dialog::DESTROY_WITH_PARENT, [Gtk::Stock::OK, Gtk::Dialog::RESPONSE_ACCEPT], [Gtk::Stock::CANCEL, Gtk::Dialog::RESPONSE_REJECT]) self.title = opts[:title] if opts[:title] @label = Gtk::Label.new(str) @textwidget = Gtk::TextView.new if opts[:text] @textwidget.buffer.text = opts[:text].to_s text_select_all end @@history ||= {} histkey = opts[:history] || str[0, 10] @history = (@@history[histkey] ||= []) @history_off = @history.length @textwidget.signal_connect('key_press_event') { |w, ev| key = DrawableWidget::Keyboard_trad[ev.keyval] case key when :escape response(RESPONSE_REJECT) true when :enter @history << @textwidget.buffer.text.to_s @history.pop if @history.last == '' @history.pop if @history.last == @history[-2] response(RESPONSE_ACCEPT) true when :up, :down txt = @textwidget.buffer.text.to_s if (@history_off < @history.length or @history.last != txt) @history[@history_off] = txt end @history_off += (key == :up ? -1 : 1) @history_off %= @history.length @textwidget.buffer.text = @history[@history_off].to_s text_select_all end } signal_connect('response') { |win, id| resp = @textwidget.buffer.text if id == RESPONSE_ACCEPT destroy yield resp.strip if resp true } vbox.pack_start label, false, false, 8 vbox.pack_start @textwidget, false, false, 8 Gtk::Drag.dest_set(self, Gtk::Drag::DEST_DEFAULT_MOTION | Gtk::Drag::DEST_DEFAULT_DROP, [['text/plain', 0, 0], ['text/uri-list', 0, 0]], Gdk::DragContext::ACTION_COPY | Gdk::DragContext::ACTION_MOVE) signal_connect('drag_data_received') { |w, dc, x, y, data, info, time| dc.targets.each { |target| next if target.name != 'text/plain' and target.name != 'text/uri-list' data.data.each_line { |l| l = l.chomp.sub(%r{^file://}, '') self.text = l } } Gtk::Drag.finish(dc, true, false, time) } show_all present end
Public Instance Methods
initialize_window(prompt, opts={}, &b)
click to toggle source
# File metasm/gui/win32.rb, line 2757 def initialize_window(prompt, opts={}, &b) self.title = opts[:title] ? opts[:title] : 'input' self.widget = IBoxWidget.new(prompt, opts, &b) end
text()
click to toggle source
# File metasm/gui/gtk.rb, line 642 def text ; @textwidget.buffer.text ; end
text=(nt)
click to toggle source
# File metasm/gui/gtk.rb, line 643 def text=(nt) ; @textwidget.buffer.text = nt ; end
text_select_all()
click to toggle source
# File metasm/gui/gtk.rb, line 637 def text_select_all @textwidget.buffer.move_mark('selection_bound', @textwidget.buffer.start_iter) @textwidget.buffer.move_mark('insert', @textwidget.buffer.end_iter) end