Found some Gtk/Ruby signal stuff.


(For gtk2+ruby, I used the Windows installer package)

For some reason, I'm trying to learn a portable language/toolkit.

First, I had to find the correct signal to connect to.  Looks like focus_out_event is it.


currentMileage.signal_connect("focus_out_event") {
  mileagePerDay.text=((targetMileage.text.to_f  – currentMileage.text.to_f)
   /(Time.parse(targetDate.text)-Time.now)*3600*24).to_s
}

signal_connect vs signal_connect_after…  apparently, improper usage of signal_connect (for "focus_out_event") will generate the following warning which the signal occurs
Gtk-WARNING **: GtkEntry – did not receive focus-out-event

From the description, what has happened is a timeout with a now invalid pointer (because of the signal's redirect).  Using signal_connect_after() ensures that the default handler has run first.

currentMileage.signal_connect_after("focus_out_event") {
  mileagePerDay.text=((targetMileage.text.to_f  – currentMileage.text.to_f)
   /(Time.parse(targetDate.text)-Time.now)*3600*24).to_s
}


Next up:  Encapsulate some of this stuff.  In this exercise, I realized that I forgot some of the basics, like how variable scope is defined in Ruby:  http://www.informit.com/articles/article.aspx?p=18225&seqNum=2.

Some additional Ruby links…
Rubyist reference
RubyDocs reference to global variables
6 Ways to Run Shell Commands in Ruby


Leave a Reply

%d bloggers like this: