Module: Gtk

Defined in:
lib/Gtk.rb

Overview

this file is part of manqod-server-console manqod is distributed under the CDDL licence the author of manqod is Dobai-Pataky Balint([email protected])

Defined Under Namespace

Classes: Table

Class Method Summary collapse

Class Method Details

.ask(question) ⇒ Object



34
35
36
37
38
39
40
41
42
43
# File 'lib/Gtk.rb', line 34

def self.ask(question)
		print question,": "
		dialog=Gtk::MessageDialog.new(nil,Gtk::Dialog::Flags::MODAL,Gtk::MessageDialog::QUESTION,Gtk::MessageDialog::ButtonsType::YES_NO,question)
#		dialog.set_size_request(400,300)
		dialog.show_all
		ret=dialog.run == Gtk::Dialog::ResponseType::YES
		dialog.destroy
		print ret,"\n"
	ret
end

.warn(subject, details = nil, level = INFO, canretry = false) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/Gtk.rb', line 6

def self.warn(subject,details=nil,level=INFO,canretry=false)
	subject="#{subject}\n#{details.message}" if details && details.class != String
	print "#{subject}\n"
	details="#{details.backtrace.join("\n\t")}" if details && details.class != String
	print "#{details}\n" unless details.nil?

		dialog=Gtk::MessageDialog.new(nil,Gtk::Dialog::Flags::MODAL,
			case level
				when ERROR then Gtk::MessageDialog::ERROR
				when WARNING then Gtk::MessageDialog::WARNING
				when INFO then Gtk::MessageDialog::INFO
				else Gtk::MessageDialog::OTHER
			end,
			if canretry
				Gtk::MessageDialog::ButtonsType::YES_NO
				else
				Gtk::MessageDialog::ButtonsType::CLOSE
			end,
			subject)
#		dialog.set_secondary_text("please report it!")
		dialog.vbox.pack_start(expander=Gtk::Expander.new("details",true).add(Gtk::TextView.new(Gtk::TextBuffer.new.set_text(details)))) unless details.nil?
		dialog.vbox.pack_end(Gtk::Label.new("retry?"),false,false) if canretry
#		dialog.set_size_request(400,300)
		dialog.show_all
		ret=dialog.run
		dialog.destroy
		ret == Gtk::Dialog::ResponseType::YES
end