#!/usr/bin/env ruby =begin Copyright (c) 2011 Michal Suchanek Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. =end require 'gtk2' class Dialog < Gtk::Window def self.toplevel= toplevel @@toplevel = toplevel end attr :builder def initialize(path_or_data, root = nil, domain = nil, localedir = nil, flag = nil) super(Gtk::Window::TOPLEVEL) @window = nil gtkversion = [2, 12, 0] # 2.12 should have most recent features. Set to later if needed. available = Gtk.check_version? *gtkversion if available label = Gtk::Label.new("If you can see this message there was an error loading interface description #{path_or_data.inspect}.") else label = Gtk::Label.new("You need GTK+ >= #{gtkversion.join '.'} to run this application.") end add(label) return unless available @builder = Gtk::Builder.new @builder << path_or_data @builder.connect_signals {|name| method(name)} @window = @builder[@@toplevel] end def show @window = self unless @window @window.show_all @window.signal_connect("destroy") { Gtk.main_quit } rescue nil @window.signal_connect("cancel") { Gtk.main_quit } rescue nil # GtkAssistant uses cancel instead of destroy end end def glade_preprocess data return data unless require 'nokogiri' return data unless data.include? '