Module: Ruiby_default_dialog

Includes:
Gtk
Included in:
Message::Embbeded, Ruiby, Ruiby_dialog, Ruiby_dsl
Defined in:
lib/ruiby_gtk/ruiby_default_dialog.rb,
lib/ruiby_gtk/ruiby_default_dialog3.rb

Overview

Creative Commons BY-SA : Regis d'Aubarede <regis.aubarede@gmail.com> LGPL

Instance Method Summary (collapse)

Instance Method Details

- (Object) alert(*txt)

modal popup with text (as html one!)



9
# File 'lib/ruiby_gtk/ruiby_default_dialog.rb', line 9

def alert(*txt) message(MessageDialog::INFO,*txt) end

- (Object) ask(*txt)

show a modal dialog, asking yes/no question, return boolean response



46
47
48
49
50
51
52
53
54
55
56
# File 'lib/ruiby_gtk/ruiby_default_dialog.rb', line 46

def ask(*txt) 
	text=txt.join(" ")
       md = MessageDialog.new(
           self,
           Dialog::DESTROY_WITH_PARENT,  Gtk::MessageDialog::QUESTION, 
           MessageDialog::BUTTONS_YES_NO, text)
	md.set_window_position(Window::POS_CENTER)
	rep=md.run
	md.destroy
	return( rep==-8 )
end

- (Object) ask_color

dialog asking a color



71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/ruiby_gtk/ruiby_default_dialog.rb', line 71

def ask_color
	cdia = ColorSelectionDialog.new("Select color")
	cdia.set_window_position(Window::POS_CENTER)
	response=cdia.run
	color=nil
       if response == Gtk::Dialog::RESPONSE_OK
           colorsel = cdia.colorsel
           color = colorsel.current_color
       end 		
	cdia.destroy
	color
end

- (Object) ask_dir_to_read(initial_dir = nil)



99
100
101
102
103
104
105
106
# File 'lib/ruiby_gtk/ruiby_default_dialog.rb', line 99

def ask_dir_to_read(initial_dir=nil)
	dialog_chooser(
			"Select existing Folder ...",
			Gtk::FileChooser::ACTION_SELECT_FOLDER,
			Gtk::Stock::OPEN) {|d| 
		d.filename=initial_dir if initial_dir && File.exists?(initial_dir)
	}
end

- (Object) ask_dir_to_write(initial_dir = nil)



107
108
109
110
111
112
113
114
# File 'lib/ruiby_gtk/ruiby_default_dialog.rb', line 107

def ask_dir_to_write(initial_dir=nil)
	dialog_chooser(
		"Select Folder or create one ...", 
		Gtk::FileChooser::ACTION_SELECT_FOLDER ,
		Gtk::Stock::OPEN) {|d|
		d.filename=initial_dir if initial_dir 
	}
end

- (Object) ask_file_to_read(dir, filter)

File dialog



93
94
95
# File 'lib/ruiby_gtk/ruiby_default_dialog.rb', line 93

def ask_file_to_read(dir,filter)
	dialog_chooser("Choose File (#{filter}) ...", Ruiby.gtk_version(3) ? :open : Gtk::FileChooser::ACTION_OPEN, Gtk::Stock::OPEN)
end

- (Object) ask_file_to_write(dir, filter)



96
97
98
# File 'lib/ruiby_gtk/ruiby_default_dialog.rb', line 96

def ask_file_to_write(dir,filter)
 dialog_chooser("Save File (#{filter}) ...", Ruiby.gtk_version(3) ? :save : Gtk::FileChooser::ACTION_SAVE, Gtk::Stock::SAVE)
end

- (Object) dialog_chooser(title, action, button) {|dialog| ... }

Yields:

  • (dialog)


115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
# File 'lib/ruiby_gtk/ruiby_default_dialog.rb', line 115

def dialog_chooser(title, action, button)
     if Ruiby.gtk_version(3)
       dialog = Gtk::FileChooserDialog.new(
           :title => title, 
           :parent => self, 
           :action => action, 
           :buttons => [ ##  ??
             [Gtk::Stock::CANCEL, Ruiby.gtk_version(3) ? :cancel : Gtk::Dialog::RESPONSE_CANCEL],
             [button, Gtk::Dialog::RESPONSE_ACCEPT]
           ])
     else
       dialog = Gtk::FileChooserDialog.new(
         title,
         self,
         action,
         nil,
         [Gtk::Stock::CANCEL, Ruiby.gtk_version(3) ? :cancel : Gtk::Dialog::RESPONSE_CANCEL],
         [button, Gtk::Dialog::RESPONSE_ACCEPT]
       )
   end
	dialog.set_window_position(Window::POS_CENTER)
	yield(dialog) if block_given?
    ret = ( dialog.run == Gtk::Dialog::RESPONSE_ACCEPT ? dialog.filename : nil )rescue false
    dialog.destroy
    ret ? ret.gsub('\\','/') : ""
end

- (Object) edit(filename)

dialog showing code editor



87
88
89
# File 'lib/ruiby_gtk/ruiby_default_dialog.rb', line 87

def edit(filename)
	Editor.new(self,filename)
end

- (Object) error(*txt)

modal popup with text and/or ruby Exception.



11
12
13
14
15
16
17
18
19
20
# File 'lib/ruiby_gtk/ruiby_default_dialog.rb', line 11

def error(*txt) 
	lt=txt.map { |o| 
		if Exception===o 
			o.to_s + " : \n  "+o.backtrace.join("\n  ")
		else
			o.to_s
		end
	}
	message(MessageDialog::ERROR,*lt) 
end

- (Object) message(style, *txt)



61
62
63
64
65
66
67
68
69
# File 'lib/ruiby_gtk/ruiby_default_dialog.rb', line 61

def message(style,*txt)
	text=txt.join(" ")
       md = MessageDialog.new(self,
           Dialog::DESTROY_WITH_PARENT, Gtk::MessageDialog::QUESTION, 
           ::Gtk::MessageDialog::BUTTONS_CLOSE, text)
	md.set_window_position(Window::POS_CENTER)
       md.run
       md.destroy
end

- (Object) prompt(txt, value = "")

show a modal dialogu, asking question, active bloc closure with text response



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/ruiby_gtk/ruiby_default_dialog.rb', line 22

def prompt(txt,value="") 
	 dialog = Dialog.new(
     title: "Message",
		parent: self,
		flags: [Dialog::DESTROY_WITH_PARENT],
		buttons: [ [Stock::OK,1], [:annulation,2] ]
   )

	label=Label.new(txt)
	entry=Entry.new().tap {|e| e.set_text(value) }
	dialog.vbox.add(label)
	dialog.vbox.add(entry)
	dialog.set_window_position(Window::POS_CENTER)

	dialog.signal_connect('response') do |w,e|
		rep=true
		rep=yield(entry.text) if block_given?
		dialog.destroy if rep
	end
	dialog.show_all	
end

- (Object) trace(*txt)

a warning alert



59
# File 'lib/ruiby_gtk/ruiby_default_dialog.rb', line 59

def trace(*txt) message(MessageDialog::WARNING,*txt) end