[fxruby-users] Push a button programmatically

Thilko Richter thilko.richter at googlemail.com
Tue Sep 9 03:34:18 EDT 2008


Hello,

I have a dialog box with a FXTextField and two buttons(OK and Cancel).
The dialog should be closed if on of the buttons is pressed, or the
user hit "ENTER" in the textfield. My dialog is inherited from
FXDialogBox.

This are my two buttons:
...
 @connect_button = FXButton.new(buttons, "Connect", :target => self,
:selector => FXDialogBox::ID_ACCEPT, :opts => BUTTON_NORMAL |
LAYOUT_RIGHT)
 @cancel_button = FXButton.new(buttons, "Cancel", :target => self,
:selector => FXDialogBox::ID_CANCEL, :opts => BUTTON_NORMAL |
LAYOUT_RIGHT)
...

and this is my textfield:
...
@textfield = FXTextField.new(content, 10, :opts => LAYOUT_SIDE_RIGHT |
TEXTFIELD_ENTER_ONLY)
...

How can I "activate" the button when the user hits enter inthe
textfield? I already found some solution which says something like
this:
...
@connect_button.handle(nil, FXSEL(SEL_LEFTBUTTONPRESS, 0), nil)
@connect_button.handle(nil, FXSEL(SEL_LEFTBUTTONRELEASE, 0), nil)
...

to simulate a click on the button. Is this the best solution?

Thx,

Thilko


More information about the fxruby-users mailing list