Module: Kernel

Defined in:
lib/Ruiby.rb,
lib/ruiby_gtk/ruiby_dsl3.rb

Instance Method Summary collapse

Instance Method Details

#__(filter = //) ⇒ Object



39
40
41
# File 'lib/ruiby_gtk/ruiby_dsl3.rb', line 39

def __(filter=//)
   $__mainwindow__.show_methods(self,filter)
end

#ruiby_require(*gems) ⇒ Object

do a gem require, and if fail, try to load the gem from internet. asking permission is done for each gem. the output of ‘gem install’ id show in ruiby log window



207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
# File 'lib/Ruiby.rb', line 207

def ruiby_require(*gems)
  w=nil
  gems=gems.map {|g| g.split(/\s+/)}.flatten
  gems.each do|gem| 
    begin
      require gem
    rescue LoadError 
      w=Ruiby_dialog.new unless w
      rep=Message.ask("Loading #{gems.join(', ')}\n\n'#{gem}' package is missing. Can I load it from internet ?")
      exit(0) unless rep
      Ruiby.update
      require 'open3'
      w.log("gem install  #{gem} --no-ri --no-rdoc")
      Ruiby.update
      Open3.popen3("gem install  #{gem} --no-ri --no-rdoc") { |si,so,se| 
        q=Queue.new
        Thread.new { loop {q.push(so.gets) } rescue p $!; q.push(nil)}
        Thread.new { loop {q.push(se.gets) } rescue p $!; q.push(nil)}
        str=""
        while str
          (timeout(90) { str=q.pop } ) rescue p $!
          (w.log(str);str="") if str && str.size>0
          Ruiby.update						
        end
      }
      w.log "done!"
      Ruiby.update
      Gem.clear_paths() 
      begin
        require(gem) 
        w.log("loading '#{gem}' ok!")
        Ruiby.update
      rescue Exception => e
        Message.alert("Gem #{gem} unknown ! #{e}")
        exit(-1)
      end
    end		
  end
  w.destroy() if w
  Ruiby.update
end

#secure_mainObject

run gtk mainloop with trapping gtk/callback error used by sketchi.rb, not good see Ruiby.secure_main { } if EventMachine is present, do loop with wixed EM/main_iteration



252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
# File 'lib/Ruiby.rb', line 252

def secure_main()
  if defined?(EM)
      puts "Ruiby mainloop: EM is detected, mainloop while be mixed EM/Gtk"
      EM::run do
        give_tick = proc do
          begin
            Gtk::main_iteration
            EM.next_tick(give_tick); 
          rescue Exception => e
            exit(0) if e.to_s=="exit"
            $__mainwindow__.error("Error GTK : "+e.to_s + " :\n     " +  e.backtrace[0..10].join("\n     "))
          end
        end
        give_tick.call
      end
  else
    eend=false
    begin 
      Gtk.main 
      exit(0)
    rescue Exception => e
      exit(0) if e.to_s=="exit"
      puts("Error GTK : "+e.to_s + " :\n     " +  e.backtrace.join("\n     "))
    end while ! eend
  end
end