Lars M. wrote:
I want my FXRuby application to close when the user hits any key (the
application does not require any other interaction at all).
I tried to connect the FXMainWindow with “SEL_KEYPRESS”, but that “event”
does never occur.
Widgets that the user typically interacts with, like text fields and
push buttons, are enabled for events by default. In other words, they
are “listening” for user interface events like key presses and mouse
buttons clicks. Other widgets, like the main window, are not enabled by
default, but can be enabled by calling the enable() method. So if you
want your application’s main window to be sensitive to key presses in
general, you’ll need to enable it first, e.g.
myMainWindow = FXMainWindow.new(...)
myMainWindow.enable
I can, however, successfully connect an FXLabel widget with
“SEL_LEFTBUTTONPRESS” and make the application quit when the user clicks on
the label. Oddly enough I cannot connect the FXLabel widget with
“SEL_CLICKED”.
For a list of all the messages that widgets might forward to their
message targets, see this note:
http://www.knology.net/~lyle/fox/1.0/FoxMessages.pdf.gz
Note that inheritance comes into play for this list; i.e. since a
FXLabel is-a FXWindow, it will forward SEL_LEFTBUTTONPRESS messages to
its message target since FXWindow does. On the other hand, only a few
widgets send SEL_CLICKED to their message targets, and FXLabel (and its
ancestors) are not among those.
So how can I make my application quit when any key is pressed?
myMainWindow.enable
myMainWindow.connect(SEL_KEYPRESS) { |sender, sel, event|
# some key was pressed, so quit
exit
}
Hope this helps,
Lyle