[fxruby-users] Ruby Fox newbie query

Lyle Johnson lyle.johnson at gmail.com
Wed Aug 22 10:51:31 EDT 2007


On Aug 22, 2007, at 7:01 AM, David Kirkpatrick wrote:

> I'm trying to get to grips with a Ruby GUI and have plunked for Fox  
> and/or FoxGUIb. I'm having problems at the moment trying to do  
> something simple which I can't find in the samples or tutorials how  
> to do...

<snip>

> ...... My menu option.......
>
> mymenu = FXMenuPane.new(self)
>     FXMenuTitle.new(menubar, "&Target", nil, mymenu, LAYOUT_LEFT)
>     details=FXMenuCommand.new(mymenu, "&Details").connect 
> (SEL_COMMAND) do
>        FXTextField.new(@group1, 10, :opts => FRAME_SUNKEN| 
> FRAME_THICK|LAYOUT_FILL_X)
>     end
>
> What I thought should have happend in the above snippet was that on  
> selecting the 'mymenu' option, a new text field would be entered  
> into the vertical frame '@group1'. However this doesnt happen.  
> Nothing happens.

You need to add a call to create() for the dynamically created text  
fields, e.g.

	details = FXMenuCommand.new(...)
	details.connect(SEL_COMMAND) do
		textfield = FXTextField.new(@group1, ...)
		textfield.create
		@group1.recalc
	end

The create() creates the server-side resources (windows) for the  
newly constructed widgets, and calling recalc() on the group box  
marks its layout as dirty.

> Ideally, I'd like the command on selecting the menu option to go to  
> a function that changes the look of the vertical frame i.e, showing  
> different text fields dependant on the menu chosen. Im sure its a  
> syntex issue.
>
> Can you point me to an example on how this can be done?

I'm not sure I follow you. You can just call a function from inside  
the connect() block, e.g.

	details.connect(SEL_COMMAND) { update_groupbox_contents }

and then, somewhere else:

	def update_groupbox_contents
		textfield = FXTextField.new(@group1, ...)
		textfield.create
		@group1.recalc
	end

Hope this helps,

Lyle


More information about the fxruby-users mailing list