# wxRuby + wxFormBuilder

**URL:** <https://www.ruby-forum.com/t/wxruby-wxformbuilder/197332>\
**Category:** wxRuby\
**Created:** [October 12, 2010, 9:31pm UTC](https://www.ruby-forum.com/t/wxruby-wxformbuilder/197332 "2010-10-12T21:31:52Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![okkezSS](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/o/85f322/32.png) [@okkezSS](https://www.ruby-forum.com/u/okkezSS)\
**Post date:** [October 12, 2010, 9:31pm UTC](https://www.ruby-forum.com/t/wxruby-wxformbuilder/197332/1 "2010-10-12T21:31:52Z")

</div>

Hello. I have a problems. Can you help me?

I create GUI-program, based on wxWidgets, in wxFormBuilder.

1.jpg) I create a form in wxFormBuilder, it will see as left part of  
image. If i test it on View-\>XRC WIndow, it see as the right part of  
1.jpg. What is it?

2.jpg) I generated code and start compilize it. But it failed. Why?

Thanks in advance

---

<div class="post-metadata">

**Author:** ![rarstd](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/65b543/32.png) [@rarstd](https://www.ruby-forum.com/u/rarstd)\
**Post date:** [October 13, 2010, 8:49am UTC](https://www.ruby-forum.com/t/wxruby-wxformbuilder/197332/2 "2010-10-13T08:49:38Z")

</div>

Else one problem.

1. I create an application by Ctrl-C from one of lessons:

* * *

require ‘wx’  
include Wx

class MyFrame \< Frame  
def initialize()  
super(nil, -1, ‘My Frame Title’)  
# First create the controls  
@my\_panel = Panel.new(self)  
@my\_label = StaticText.new(@my\_panel, -1, ‘My Label Text’,  
DEFAULT\_POSITION, DEFAULT\_SIZE, ALIGN\_CENTER)  
@my\_textbox = TextCtrl.new(@my\_panel, -1, ‘Default Textbox  
Value’)  
@my\_combo = ComboBox.new(@my\_panel, -1, ‘Default Combo Text’,  
DEFAULT\_POSITION, DEFAULT\_SIZE, [‘Item 1’, ‘Item 2’, ‘Item 3’])  
@my\_button = Button.new(@my\_panel, -1, ‘My Button Text’)  
# Bind controls to functions  
evt\_button(@my\_button.get\_id()) { |event|  
my\_button\_click(event)}  
# Now do the layout  
@my\_panel\_sizer = BoxSizer.new(VERTICAL)  
@my\_panel.set\_sizer(@my\_panel\_sizer)  
@my\_panel\_sizer.add(@my\_label, 0, GROW|ALL, 2)  
@my\_panel\_sizer.add(@my\_textbox, 0, GROW|ALL, 2)  
@my\_panel\_sizer.add(@my\_combo, 0, GROW|ALL, 2)  
@my\_panel\_sizer.add(@my\_button, 0, GROW|ALL, 2)  
show()  
end

```
def my_button_click(event)
    # Your code here
end

```

end

class MyApp \< App  
def on\_init  
MyFrame.new  
end  
end

MyApp.new.main\_loop()

* * *

I run it, but it window doesn’t open. In command prompt all work fint,  
but doesn’t open. What’s matter?

---

<div class="post-metadata">

**Author:** ![rarstd](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/65b543/32.png) [@rarstd](https://www.ruby-forum.com/u/rarstd)\
**Post date:** [October 13, 2010, 10:34am UTC](https://www.ruby-forum.com/t/wxruby-wxformbuilder/197332/3 "2010-10-13T10:34:45Z")

</div>

Hello Again Misha,

On Tue, Oct 12, 2010 at 3:31 PM, Misha O. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> Hello. I have a problems. Can you help me?
> 
> I create GUI-program, based on wxWidgets, in wxFormBuilder.
> 
> 1.jpg) I create a form in wxFormBuilder, it will see as left part of  
> image. If i test it on View-\>XRC WIndow, it see as the right part of  
> 1.jpg. What is it?

1.jpg) This is the cause of the fact that in your XRC Design, you do not  
have a root Layout manager, meaning that the window needs to have a  
VerticalSizer or a HorizontalSizer as the root item, in order to manage  
layouts of all the controls in your window, otherwise, you have to do  
the  
management of the layout yourself, meaning you need to keep tabs on the  
window sizes, and control positions, and re-positioning your controls  
yourself. This also means that wxWidgets will not manage the window  
size,  
and therefore, will allocate the minimal size for your window, which  
gives  
you the issues you are seeing in 1.jpg.

> 2.jpg) I generated code and start compilize it. But it failed. Why?

This is an issue with Ruby 1.9.1, they made String where it is no longer  
Enumerable, meaning that there is no .each method, that will parse  
through  
each actual line of text in the code, as is done in Ruby 1.8. I will  
see  
about getting a new gem built, with a patch to fix that soon.

> Thanks in advance
> 
> –  
> Posted via [http://www.ruby-forum.com/](http://www.ruby-forum.com/).
> 
> * * *
> 
> wxruby-users mailing list  
> [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
> [http://rubyforge.org/mailman/listinfo/wxruby-users](http://rubyforge.org/mailman/listinfo/wxruby-users)

hth,

---

<div class="post-metadata">

**Author:** ![rarstd](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/65b543/32.png) [@rarstd](https://www.ruby-forum.com/u/rarstd)\
**Post date:** [October 13, 2010, 10:34am UTC](https://www.ruby-forum.com/t/wxruby-wxformbuilder/197332/4 "2010-10-13T10:34:45Z")

</div>

Hello Misha,

First off, welcome to wxRuby community. I’ll answer your other question  
in  
a few, first we’ll cover this one.

On Wed, Oct 13, 2010 at 2:49 AM, Misha O. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> def initialize()  
> # Bind controls to functions  
> end
> 
> def my\_button\_click(event)  
> # Your code here  
> end
> 
> end
> 
> class MyApp \< App  
> def on\_init  
> MyFrame.new

end

> end
> 
> MyApp.new.main\_loop()
> 
> * * *
> 
> I run it, but it window doesn’t open. In command prompt all work fint,  
> but doesn’t open. What’s matter?

First off, this is correct in the code, till you get to your on\_init  
method.  
I can tell you, that your Window is being created, and everything, but  
your  
not showing it to the user. There’s two ways in which you can do this.

The first, is to simply do: MyFrame.new.show() Which will show your  
frame  
to the user, after it is created.  
The second, is to store the instance of your Window in a variable, and  
call  
show in it, like this:  
myframe = MyFrame.new  
myframe.show

In both cases, you need to call the show method on your Frame, in order  
to  
have your frame actually be displayed. It isn’t done automatically,  
cause  
there may be times, where you want to create a window, but not show it,  
in  
such cases as having a Tray Icon on Windows / Linux, and a Dock Icon on  
OS X  
(EG The Bottom bar.)

hth with this one,

Mario

---

<div class="post-metadata">

**Author:** ![rarstd](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/65b543/32.png) [@rarstd](https://www.ruby-forum.com/u/rarstd)\
**Post date:** [October 14, 2010, 6:36pm UTC](https://www.ruby-forum.com/t/wxruby-wxformbuilder/197332/5 "2010-10-14T18:36:45Z")

</div>

Thanks. Now I’m a new wx’er.

BTW, Misha on russian equivalent Michael in english 🙂

How you do the letters green?

1. I create forms now in DialogBlocks 4.39 (next - DB). If I do not  
create a menubar, it’s OK. If I add it, I need to change a PLATFORM  
value on it from any to some. It’s normal?

2. Conversion is normal in DB - in my opinion, the question is closed.

3. I copy code, but it not works:

* * *

require ‘wx’  
include Wx

class MyFrame \< Frame  
def initialize()  
super(nil, -1, ‘My Frame Title’)  
# First create the controls  
@my\_panel = Panel.new(self)  
@my\_label = StaticText.new(@my\_panel, -1, ‘My Label Text’,  
DEFAULT\_POSITION, DEFAULT\_SIZE, ALIGN\_CENTER)  
@my\_textbox = TextCtrl.new(@my\_panel, -1, ‘Default Textbox  
Value’)  
@my\_combo = ComboBox.new(@my\_panel, -1, ‘Default Combo Text’,  
DEFAULT\_POSITION, DEFAULT\_SIZE, [‘Item 1’, ‘Item 2’, ‘Item 3’])  
@my\_button = Button.new(@my\_panel, -1, ‘My Button Text’)  
# Bind controls to functions  
evt\_button(@my\_button.get\_id()) { |event|  
my\_button\_click(event)}  
# Now do the layout  
@my\_panel\_sizer = BoxSizer.new(VERTICAL)  
@my\_panel.set\_sizer(@my\_panel\_sizer)  
@my\_panel\_sizer.add(@my\_label, 0, GROW|ALL, 2)  
@my\_panel\_sizer.add(@my\_textbox, 0, GROW|ALL, 2)  
@my\_panel\_sizer.add(@my\_combo, 0, GROW|ALL, 2)  
@my\_panel\_sizer.add(@my\_button, 0, GROW|ALL, 2)  
show()  
end

```
def my_button_click(event)
    # Your code here
end

```

end

class MyApp \< App  
def on\_init  
MyFrame.new  
end  
end

MyApp.new.main\_loop()

myframe = MyFrame.new.show()

* * *

There isn’t a .xrc file in this folder. It’s only .rb file. It doesn’t  
work…

Can you give me some working simple window code to Copy-Paste in .rb  
file as example of ruby-GUI-application.

Sorry for my english, Misha.

---

<div class="post-metadata">

**Author:** ![rarstd](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/65b543/32.png) [@rarstd](https://www.ruby-forum.com/u/rarstd)\
**Post date:** [October 17, 2010, 12:45pm UTC](https://www.ruby-forum.com/t/wxruby-wxformbuilder/197332/6 "2010-10-17T12:45:22Z")

</div>

> Can you give me some working simple window code to Copy-Paste in .rb  
> file as example of ruby-GUI-application.

Into the installation of wxruby gem, you can find many examples to try  
on.

bio.

---

<div class="post-metadata">

**Author:** ![rarstd](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/65b543/32.png) [@rarstd](https://www.ruby-forum.com/u/rarstd)\
**Post date:** [October 17, 2010, 12:58am UTC](https://www.ruby-forum.com/t/wxruby-wxformbuilder/197332/7 "2010-10-17T00:58:16Z")

</div>

Why everyone is silent?

---

<div class="post-metadata">

**Author:** ![rarstd](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/65b543/32.png) [@rarstd](https://www.ruby-forum.com/u/rarstd)\
**Post date:** [October 17, 2010, 7:16pm UTC](https://www.ruby-forum.com/t/wxruby-wxformbuilder/197332/8 "2010-10-17T19:16:37Z")

</div>

This code:

#!/usr/bin/env ruby  
require ‘rubygems’  
require ‘wx’

class MyApp \< Wx::App  
def on\_init  
@frame = Wx::Frame.new( nil, -1, “Application” )  
@frame.show  
end  
end

app = MyApp.new  
app.main\_loop  
app.show

Doesn’t work. It show only command prompt with ruby, which close after  
working code. I didn’t see GUI window. Why?

Maybe I don’t install something? What I must install to wxruby gui start  
to work?

---

<div class="post-metadata">

**Author:** ![rarstd](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/65b543/32.png) [@rarstd](https://www.ruby-forum.com/u/rarstd)\
**Post date:** [October 17, 2010, 11:25pm UTC](https://www.ruby-forum.com/t/wxruby-wxformbuilder/197332/9 "2010-10-17T23:25:34Z")

</div>

Piture is error message. This is testing of my application.

---

<div class="post-metadata">

**Author:** ![rarstd](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/65b543/32.png) [@rarstd](https://www.ruby-forum.com/u/rarstd)\
**Post date:** [October 17, 2010, 9:33pm UTC](https://www.ruby-forum.com/t/wxruby-wxformbuilder/197332/10 "2010-10-17T21:33:12Z")

</div>

On 17/10/2010 18:16, Misha O. wrote:

> This code:  
> …

> Doesn’t work. It show only command prompt with ruby, which close after  
> working code. I didn’t see GUI window. Why?

Run it in a command prompt and _post the error message_, then we can  
help. There is a sample called ‘minimal.rb’ in the distribution that you  
can use as a basis for testing and the starting point for your own apps.

a

---

<div class="post-metadata">

**Author:** ![rarstd](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/65b543/32.png) [@rarstd](https://www.ruby-forum.com/u/rarstd)\
**Post date:** [October 18, 2010, 12:07am UTC](https://www.ruby-forum.com/t/wxruby-wxformbuilder/197332/11 "2010-10-18T00:07:44Z")

</div>

My friend talk me what was the problem. Now it’s cloded. Thanks for your  
helps to me.

Michael
