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_terminal.rb,
lib/ruiby_gtk/ruiby_default_dialog3.rb
Overview
Creative Commons BY-SA : Regis d’Aubarede <[email protected]> LGPL
Instance Method Summary collapse
- #_gooooooooooo ⇒ Object
- #_process_terminal_key(w, ev, termBuffer) ⇒ Object
-
#alert(*txt) ⇒ Object
alert(txt): modal popup with text (as in html).
-
#ask(*txt) ⇒ Object
show a modal dialog, asking yes/no question, return boolean response.
-
#ask_color ⇒ Object
modal dialog asking a color.
-
#ask_dir_to_read(initial_dir = nil) ⇒ Object
ask a existent dir name.
-
#ask_dir_to_write(initial_dir = nil) ⇒ Object
ask a dir name.
-
#ask_file_to_read(dir, filter) ⇒ Object
ask a existent file name.
-
#ask_file_to_write(dir, filter) ⇒ Object
ask a filename for creation/modification.
- #dialog_chooser(title, action, button) {|dialog| ... } ⇒ Object
-
#edit(filename, &blk) ⇒ Object
dialog showing code editor, call back is called on exit button, edit(“x.txt”) { |content| compile(content) ? true : (alert(“error!”);false) }.
-
#error(*txt) ⇒ Object
modal popup with text and/or ruby Exception.
- #message(style, *txt) ⇒ Object
-
#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 !”).
- #promptSync(txt, value = "") ⇒ Object
-
#terminal(title = "Terminal") ⇒ Object
create a terminal window INTO the process : gtk terminal for acces to internal state of the current process type help command.
-
#trace(*txt) ⇒ Object
travce() : like alert(), but with a warning icone.
Instance Method Details
#_gooooooooooo ⇒ Object
6 7 |
# File 'lib/ruiby_gtk/ruiby_default_dialog3.rb', line 6 def _gooooooooooo end |
#_process_terminal_key(w, ev, termBuffer) ⇒ Object
159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 |
# File 'lib/ruiby_gtk/ruiby_terminal.rb', line 159 def _process_terminal_key(w,ev,termBuffer) char=(ev.keyval.chr rescue nil) #p ["%08X" % ev.keyval , char] up=65362 down=65364 enter=65293 if ev.keyval==up w.terminal.set_history(-1) return true end if ev.keyval==down w.terminal.set_history(1) return true end if ev.keyval==enter w.terminal.execute() return true end false rescue Exception => e w.terminal.append_and_prompt(e.to_s+"\n "+e.backtrace.join("\n ")) true 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) (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_color ⇒ Object
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
151 152 153 154 155 156 157 158 |
# File 'lib/ruiby_gtk/ruiby_default_dialog3.rb', line 151 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
161 162 163 164 165 166 167 168 |
# File 'lib/ruiby_gtk/ruiby_default_dialog3.rb', line 161 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
146 147 148 |
# File 'lib/ruiby_gtk/ruiby_default_dialog3.rb', line 146 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
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, ) 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], [, 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], [, 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, &blk) ⇒ Object
dialog showing code editor, call back is called on exit button, edit(“x.txt”) { |content| compile(content) ? true : (alert(“error!”);false) }
87 88 89 |
# File 'lib/ruiby_gtk/ruiby_default_dialog.rb', line 87 def edit(filename,&blk) Editor.new(self,filename,350,&blk) 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 } (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 (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 |
#promptSync(txt, value = "") ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/ruiby_gtk/ruiby_default_dialog3.rb', line 55 def promptSync(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(:center) dialog.show_all rep=dialog.run response=entry.text dialog.destroy if block_given? && rep==1 yield(reponse) else rep==1 ? response : nil end end |
#terminal(title = "Terminal") ⇒ Object
create a terminal window INTO the process : gtk terminal for acces to internal state of the current process type help command.
136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 |
# File 'lib/ruiby_gtk/ruiby_terminal.rb', line 136 def terminal(title="Terminal") wdlog = Dialog.new(title: title, parent: nil, flags: 0 ) sw=ScrolledWindow.new() sw.set_width_request(800) sw.set_height_request(300) sw.set_policy(:automatic,:always) termBuffer = TextBuffer.new tv=TextView.new(termBuffer) tv.override_font( Pango::FontDescription.new("courier bold 10")) sw.(tv) tv.signal_connect('key-press-event') do |w,ev| _process_terminal_key(w,ev,termBuffer) end Terminal.new(tv,self) wdlog.child.pack_start(sw,true,true) wdlog.signal_connect('response') { wdlog.destroy } wdlog.show_all wdlog 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) (MessageDialog::WARNING,*txt) end |