# FxRuby

**URL:** <https://www.ruby-forum.com/t/fxruby/122102>\
**Category:** Ruby\
**Created:** [December 4, 2007, 4:58pm UTC](https://www.ruby-forum.com/t/fxruby/122102 "2007-12-04T16:58:04Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![ernsttanaka](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/46a35a/32.png) [@ernsttanaka](https://www.ruby-forum.com/u/ernsttanaka)\
**Post date:** [December 4, 2007, 4:58pm UTC](https://www.ruby-forum.com/t/fxruby/122102/1 "2007-12-04T16:58:04Z")

</div>

I have a big favor to ask. I am new to ruby and have managed to build an  
application which manages my Option Trades.  
Now I get to the point were I want to make a GUI for my application.  
Based on all the info provide I have decided for FxRuby. Studying FxRuby  
I miss the first step documentation.

I have managed to build a demo screen with FoxGui (see below), but I am  
struggling to write a program that handles this window.

On the forum I see a lot of us (newbie’s) struggling with the first  
Fxruby steps. Would one of you please be so kind and write a little  
program using my enclose Demo Window.

Let the program handle the following actions.  
At Init move value ‘1’ to button one, ‘2’ to button ‘2’ and ‘3’ to  
button ‘3’, ‘a’ to text1, ‘b’ to text2 and ‘c’ to text3.  
On click of button1. Swap the strings from button2 and button3 and text2  
and text3.  
On click of button2. swap the strings from button1 and button3 plus  
text1 and text3.  
On click of button3. swap 1 and 2.

A picture is worth a 1000 words equals to an example hold the value of a  
book.

Thanks a million in advance.

Ernst

* * *

# source generated by foxGUIb 0.7.1

class MainWindow  
def initialize( parent)  
construct\_widget\_tree( parent)  
init if respond\_to? ‘init’  
end

def construct\_widget\_tree( parent)  
@topwin=  
FX::MainWindow.new(parent){|w|  
@mainWindow=w  
w.wdg\_name=‘mainWindow’  
w.width=532  
w.shown=true  
w.y=312  
w.height=536  
w.x=390  
FX::HorizontalFrame.new(@mainWindow){|w|  
@horizontalframe1=w  
w.wdg\_name=‘horizontalframe1’  
w.width=532  
w.height=536  
FX::VerticalFrame.new(@horizontalframe1){|w|  
@verticalframe1=w  
w.wdg\_name=‘verticalframe1’  
w.width=231  
w.height=536  
FX::Button.new(@verticalframe1){|w|  
@button1=w  
w.wdg\_name=‘button1’  
w.width=40  
w.height=21  
}  
FX::Button.new(@verticalframe1){|w|  
@button2=w  
w.wdg\_name=‘button2’  
w.width=40  
w.y=21  
w.height=21  
}  
FX::Button.new(@verticalframe1){|w|  
@button3=w  
w.wdg\_name=‘button3’  
w.width=40  
w.y=42  
w.height=21  
}  
}  
FX::VerticalFrame.new(@horizontalframe1){|w|  
@verticalframe2=w  
w.wdg\_name=‘verticalframe2’  
w.width=301  
w.height=536  
w.x=231  
FX::Text.new(@verticalframe2){|w|  
@text2=w  
w.wdg\_name=‘text2’  
w.width=301  
w.height=178  
}  
FX::Text.new(@verticalframe2){|w|  
@text4=w  
w.wdg\_name=‘text4’  
w.width=301  
w.y=178  
w.height=179  
}  
FX::Text.new(@verticalframe2){|w|  
@text5=w  
w.wdg\_name=‘text5’  
w.width=301  
w.y=357  
w.height=179  
}  
}  
}  
}  
end  
attr\_reader :topwin  
attr\_reader :mainWindow  
attr\_reader :horizontalframe1  
attr\_reader :verticalframe1  
attr\_reader :button1  
attr\_reader :button2  
attr\_reader :button3  
attr\_reader :verticalframe2  
attr\_reader :text2  
attr\_reader :text4  
attr\_reader :text5  
end

#unit test  
if **FILE** ==$0  
require ‘libGUIb16’  
app=FX::App.new  
w=MainWindow.new app  
w.topwin.show(Fox::PLACEMENT\_SCREEN)  
app.create  
app.run  
end

---

<div class="post-metadata">

**Author:** ![ernsttanaka](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/46a35a/32.png) [@ernsttanaka](https://www.ruby-forum.com/u/ernsttanaka)\
**Post date:** [December 5, 2007, 2:38am UTC](https://www.ruby-forum.com/t/fxruby/122102/2 "2007-12-05T02:38:45Z")

</div>

On 12/4/07, Ernst T. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> I have managed to build a demo screen with FoxGui (see below), but I am  
> struggling to write a program that handles this window.
> 
> On the forum I see a lot of us (newbie’s) struggling with the first  
> Fxruby steps.

What “forum” are you talking about?

> Would one of you please be so kind and write a little  
> program using my enclose Demo Window.
> 
> Let the program handle the following actions.  
> At Init move value ‘1’ to button one, ‘2’ to button ‘2’ and ‘3’ to  
> button ‘3’, ‘a’ to text1, ‘b’ to text2 and ‘c’ to text3.

The code is difficult to follow because it’s not using the standard  
FXRuby API. If you’re asking how to change the label text for an  
FXButton or FXTextField widget, however, you can use:

@button1.text = “1”  
@button2.text = “2”  
@button3.text = “3”  
@text1.text = “a”  
@text2.text = “b”  
@text3.text = “c”

I am assuming that what your code calls FX::Button and FX::Text are  
the same things as FXButton and FXText (or maybe FXTextField).

> On click of button1. Swap the strings from button2 and button3 and text2  
> and text3.

@button1.connect(SEL\_COMMAND) do  
tmp = @button2.text  
@button2.text = @button3.text  
@button3.text = tmp  
tmp = @text2.text  
@text2.text = @text3.text  
@text3.text = tmp  
end

> On click of button2. swap the strings from button1 and button3 plus  
> text1 and text3.

@button2.connect(SEL\_COMMAND) do  
tmp = @button1.text  
@button1.text = @button3.text  
@button3.text = tmp  
tmp = @text1.text  
@text1.text = @text3.text  
@text3.text = tmp  
end

> On click of button3. swap 1 and 2.

@button3.connect(SEL\_COMMAND) do  
tmp = @button1.text  
@button1.text = @button2.text  
@button2.text = tmp  
tmp = @text1.text  
@text1.text = @text2.text  
@text2.text = tmp  
end

> A picture is worth a 1000 words equals to an example hold the value of a  
> book.

I need to remember that one.

> Thanks a million in advance.

Hope this helps. I would also recommend subscribing to the FXRuby  
Users mailing list. The information can be found on the FXRuby Home  
Page, at [http://www.fxruby.org](http://www.fxruby.org).

---

<div class="post-metadata">

**Author:** ![ernsttanaka](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/46a35a/32.png) [@ernsttanaka](https://www.ruby-forum.com/u/ernsttanaka)\
**Post date:** [December 5, 2007, 4:21pm UTC](https://www.ruby-forum.com/t/fxruby/122102/3 "2007-12-05T16:21:02Z")

</div>

Thank you Lyle for you help.

I have my little demo working. I have included the working code.

You said I was using the standard Fxruby API. That could be true; but I  
did not realize it. I generated the MainWindow class code with FOXGuiB.  
I was under the presumption that this was giving me FxRuby code.

I found your mail list on [fxruby.org](http://fxruby.org) that is a great help.

As always in full appreciation of all the help I am getting from the  
Ruby Seniors!

Thanks,  
Ernst

require ‘fox16’  
include Fox  
#require ‘c:\rubydev\ch06\monitor\demo.rb’  
require ‘demo’  
STDOUT.sync = true  
class MainWindow  
def init  
@button1.text = “1”  
@button2.text = “2”  
@button3.text = “3”  
@text2.text = “a”  
@text4.text = “b”  
@text5.text = “c”  
@button1.connect(SEL\_COMMAND) do  
tmp = @button2.text  
@button2.text = @button3.text  
@button3.text = tmp  
tmp = @text4.text  
@text4.text = @text5.text  
@text5.text = tmp  
end  
@button2.connect(SEL\_COMMAND) do  
tmp = @button1.text  
@button1.text = @button3.text  
@button3.text = tmp  
tmp = @text2.text  
@text2.text = @text5.text  
@text5.text = tmp  
end  
@button3.connect(SEL\_COMMAND) do  
tmp = @button1.text  
@button1.text = @button2.text  
@button2.text = tmp  
tmp = @text2.text  
@text2.text = @text4.text  
@text4.text = tmp  
end

end  
end  
require ‘libGUIb16’  
app=FX::App.new  
w=MainWindow.new app  
w.topwin.show(Fox::PLACEMENT\_SCREEN)  
app.create  
app.run

---

<div class="post-metadata">

**Author:** ![ernsttanaka](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/46a35a/32.png) [@ernsttanaka](https://www.ruby-forum.com/u/ernsttanaka)\
**Post date:** [December 9, 2007, 1:59pm UTC](https://www.ruby-forum.com/t/fxruby/122102/4 "2007-12-09T13:59:00Z")

</div>

On 12/5/07, Lyle J. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:  
[…]

> I am assuming that what your code calls FX::Button and FX::Text are  
> the same things as FXButton and FXText (or maybe FXTextField).

Yes, it can be assumed. FoxGUIb has subclassed most of the FXRuby  
widgets. The convention is that Fox::FXText is subclassed by FX::Text  
and Fox::FXTextField by FX::TextField. What has been added by libGUIb  
are just convenience constructors and other convenience stuff. But the  
subclassed widgets of course expose the standard FXRuby API. No big  
deal.

– Henon
