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

#_goooooooooooObject



6
7
# File 'lib/ruiby_gtk/ruiby_default_dialog3.rb', line 6

def _gooooooooooo 
end

#alert(*txt) ⇒ Object

alert(txt): modal popup with text (as in html)



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

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

#ask(*txt) ⇒ Object

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

#ask_colorObject

modal 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

#ask_dir_to_read(initial_dir = nil) ⇒ Object

ask a existent dir name



117
118
119
120
121
122
123
124
# File 'lib/ruiby_gtk/ruiby_default_dialog3.rb', line 117

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

#ask_dir_to_write(initial_dir = nil) ⇒ Object

ask a dir name



127
128
129
130
131
132
133
134
# File 'lib/ruiby_gtk/ruiby_default_dialog3.rb', line 127

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

#ask_file_to_read(dir, filter) ⇒ Object

ask a existent file name



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

#ask_file_to_write(dir, filter) ⇒ Object

ask a filename for creation/modification



112
113
114
# File 'lib/ruiby_gtk/ruiby_default_dialog3.rb', line 112

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

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

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

#edit(filename) ⇒ Object

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

#error(*txt) ⇒ Object

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

#message(style, *txt) ⇒ Object



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

#prompt(txt, value = "") ⇒ Object

show a modal dialog, asking question, active bloc closure with text response in parameters prompt(“Age ?”) { |n| alert(“Your age is #n-1, bravo !”)



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

#trace(*txt) ⇒ Object

travce() : like alert(), but with a warning icone



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

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