lib/rabbit/logger/gui.rb in rabbit-2.2.1 vs lib/rabbit/logger/gui.rb in rabbit-3.0.0

- old
+ new

@@ -9,11 +9,10 @@ class GUI include Base attr_accessor :start_gui_main_loop_automatically def initialize(level=nil, width=450, height=400) - Gtk.init super(*[level].compact) @width = width @height = height @start_gui_main_loop_automatically = false init_dialog @@ -59,46 +58,45 @@ append(message, "message") append("\n") end def append(text, *tags) - iter = @buffer.get_iter_at_offset(-1) - @buffer.insert_with_tags(iter, text.encode("UTF-8"), *tags) + iter = @buffer.get_iter_at(offset: -1) + @buffer.insert(iter, text.encode("UTF-8"), tags: tags) end def title _("Rabbit Error Dialog") end def init_dialog(width=@width, height=@height) - flags = 0 - buttons = [ - [Gtk::Stock::CLEAR, Gtk::Dialog::RESPONSE_CANCEL], - [Gtk::Stock::CLOSE, Gtk::Dialog::RESPONSE_CLOSE], - ] - @dialog = Gtk::Dialog.new(title, nil, flags, *buttons) - @dialog.vbox.add(init_buffer) + @dialog = Gtk::Dialog.new(title: title, + buttons: [ + [Gtk::Stock::CLEAR, :cancel], + [Gtk::Stock::CLOSE, :close], + ]) + @dialog.child.add(init_buffer) @dialog.set_default_size(width, height) @dialog.title = title set_dialog_delete set_dialog_response set_dialog_accel_group end def set_dialog_delete @dialog.signal_connect("destroy") do |widget, event| - exit if @current_severity >= Severity::FATAL + exit(false) if @current_severity >= Severity::FATAL true end end def set_dialog_response @dialog.signal_connect("response") do |widget, event| case event - when Gtk::Dialog::RESPONSE_CANCEL + when Gtk::ResponseType::CANCEL clear_buffer - when Gtk::Dialog::RESPONSE_CLOSE + when Gtk::ResponseType::CLOSE quit end true end end @@ -107,52 +105,52 @@ accel_group = Gtk::AccelGroup.new mod = Gdk::ModifierType.new flags = Gtk::AccelFlags::VISIBLE Keys::QUIT_KEYS.each do |val| accel_group.connect(val, mod, flags) do - @dialog.signal_emit("response", Gtk::Dialog::RESPONSE_CLOSE) + @dialog.signal_emit("response", Gtk::ResponseType::CLOSE) true end end @dialog.add_accel_group(accel_group) end def init_buffer textview = Gtk::TextView.new textview.set_editable(false) - textview.set_wrap_mode(Gtk::TextTag::WrapMode::WORD) + textview.set_wrap_mode(:word) @buffer = textview.buffer create_tags scrolled_window = Gtk::ScrolledWindow.new - scrolled_window.set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC) + scrolled_window.set_policy(:automatic, :automatic) scrolled_window.add(textview) scrolled_window end def create_tags @buffer.create_tag("DEBUG", - "weight" => Pango::FontDescription::WEIGHT_BOLD, + "weight" => :bold, "foreground" => "blue") @buffer.create_tag("INFO", "foreground" => "blue") - @buffer.create_tag("WARN", "foreground" => "red") + @buffer.create_tag("WARNING", "foreground" => "red") @buffer.create_tag("ERROR", - "weight" => Pango::FontDescription::WEIGHT_BOLD, + "weight" => :bold, "foreground" => "red") @buffer.create_tag("FATAL", "foreground" => "yellow", "background" => "black") @buffer.create_tag("UNKNOWN", - "weight" => Pango::FontDescription::WEIGHT_BOLD, + "weight" => :bold, "foreground" => "yellow", "background" => "black") @buffer.create_tag("ANY", - "weight" => Pango::FontDescription::WEIGHT_BOLD) + "weight" => :bold) @buffer.create_tag("prog_name", - "weight" => Pango::FontDescription::WEIGHT_BOLD, + "weight" => :bold, "foreground" => "blue", "left_margin" => 10) @buffer.create_tag("message", - "weight" => Pango::FontDescription::WEIGHT_BOLD, + "weight" => :bold, "left_margin" => 10, "right_margin" => 10) end end end