Wxruby, XRC, DialogBlock

I’ve been trying to figure out the best method for generating GUI’s with
Ruby. I ended up using DialogBlock because it seems like the fastest
way. But not I have to work backwards and have not done this before.
How do I go from the file I generate in DialogBlock to a code in Ruby?

Joshua L. wrote:

I’ve been trying to figure out the best method for generating GUI’s with
Ruby. I ended up using DialogBlock because it seems like the fastest
way. But not I have to work backwards and have not done this before.
How do I go from the file I generate in DialogBlock to a code in Ruby?

The wxruby example samples/xrc/xrc_sample.rb shows how to load an
XRC-based layout into a wxRuby program.

To save time, I also recommend that you have a look at the tool
‘xrcise’. This automatically creates ruby code to load XRC layouts and
link to specific controls within the XML file:

http://wxruby.rubyforge.org/wiki/wiki.pl?UsingXRCise

alex

Alex F. wrote:

The wxruby example samples/xrc/xrc_sample.rb shows how to load an
XRC-based layout into a wxRuby program.

To save time, I also recommend that you have a look at the tool
‘xrcise’.
alex

Thanks for your help. I am slowly learning how to do this.

I followed your suggestions. I am able to generate the XRC file from
DialogBLock. Then, I am able to generate the my_frame.rb file. But,
when I try to integrate it by using the code posted on the tutorial in
the creating a code in SciTE. I get the following syntax error in two
lines of the source:

syntax error, unexpected ‘\n’, expecting tCOLON2 or ‘[’ or ‘.’

I tried figuring out how to change the code myself to resolve this
error, but I’m just not good enough…yet

Joshua L. wrote:

I get the following syntax error in two
lines of the source:

syntax error, unexpected ‘\n’, expecting tCOLON2 or ‘[’ or ‘.’

Please could you post your XRC file and the generated code. Thanks.

alex

Joshua L. wrote:

syntax error, unexpected ‘\n’, expecting tCOLON2 or ‘[’ or ‘.’
Please could you post your XRC file and the generated code. Thanks.

Alex, here’s the code (from the XRCise tutorial)


require ‘wx’

load in the generated code

require ‘my_frame’

Mix-in for a Wx::TextCtrl

module CaseChangeTextCtrl?

convert all the text in the control to upper case

def upcase!
self.value = self.value.upcase
end

convert all the text in the control to lower case

def downcase!
self.value = self.value.downcase
end
end

Inherit from the generated base class and set up event handlers

class CaseChangeFrame? < TextFrameBase?
def initialize
super
evt_button(upper_bt) { text_box.upcase! }
evt_button(lower_bt) { text_box.downcase! }
end
end

Run the class

Wx::App.run do
CaseChangeFrame?.new.show
end

Josh

Joshua L. wrote:

Alex, here’s the code (from the XRCise tutorial)


require ‘wx’

load in the generated code

require ‘my_frame’

Mix-in for a Wx::TextCtrl

module CaseChangeTextCtrl?

Ah, sorry, looks like the wiki has mangled some of the ruby code by
adding ? - there shouldn’t be one here. I’ve corrected the formatting on
the wiki, can you try to copy and paste again please?

thanks
alex

Hi,

On 06.03.2008, at 23:22, Joshua L. wrote:

I gave it another shot and it still wasn’t working. So, I tried
removing all of the ‘?’ characters from the ruby source code. This
worked, but I don’t see any buttons. My question is, the wiki page
shows ‘?’ characters for working in the DialogBlock and for the ruby
source. Perhaps just clarifying where a ‘?’ does and doesn’t belong
will fix everything.

? is just a wiki link for creating a new page for CaseChangeTextCtrl.
The wiki editor has to quote the wiki-text. If it’s a TWiki then you
should
quote it with ‘!’: !CaseChangeTextCtrl (IIRC).

hth. regards, sandor

require ‘wx’

load in the generated code

require ‘my_frame’

Mix-in for a Wx::TextCtrl

module CaseChangeTextCtrl?

Ah, sorry, looks like the wiki has mangled some of the ruby code by
adding ? - there shouldn’t be one here. I’ve corrected the formatting on
the wiki, can you try to copy and paste again please?

thanks
alex

I gave it another shot and it still wasn’t working. So, I tried
removing all of the ‘?’ characters from the ruby source code. This
worked, but I don’t see any buttons. My question is, the wiki page
shows ‘?’ characters for working in the DialogBlock and for the ruby
source. Perhaps just clarifying where a ‘?’ does and doesn’t belong
will fix everything.

Still, for a really green programmer, just getting it to work at all was
very satisfying. If I complete this project, I hope to have something
to give back to the open source community.

Thanks!

Alex F. wrote:

Joshua L. wrote:

I gave it another shot and it still wasn’t working. So, I tried
removing all of the ‘?’ characters from the ruby source code. This
worked, but I don’t see any buttons. My question is, the wiki page
shows ‘?’ characters for working in the DialogBlock and for the ruby
source. Perhaps just clarifying where a ‘?’ does and doesn’t belong
will fix everything.
REalised I hadn’t saved the changes to the wiki page. The source code
should be correct now without ‘?’

alex

The code works, but I still do not see the buttons in the window that I
produce. I followed the wiki as instructed from start to finish. Is
there some functionality I was supposed to give to the buttons that
perhaps I didn’t?

Joshua L. wrote:

I gave it another shot and it still wasn’t working. So, I tried
removing all of the ‘?’ characters from the ruby source code. This
worked, but I don’t see any buttons. My question is, the wiki page
shows ‘?’ characters for working in the DialogBlock and for the ruby
source. Perhaps just clarifying where a ‘?’ does and doesn’t belong
will fix everything.
REalised I hadn’t saved the changes to the wiki page. The source code
should be correct now without ‘?’

alex

Joshua L. wrote:

The code works, but I still do not see the buttons in the window that I
produce. I followed the wiki as instructed from start to finish. Is
there some functionality I was supposed to give to the buttons that
perhaps I didn’t?
Your buttons and the textctrl need to be arranged in a Sizer. In
DialogBlocks you should see in the palette of addable elements a
“Sizers” tab. Add a vertical sizer to the main frame. Then, in order,
add the TextCtrl and the two buttons to it.

I guess the tutorial should be more explicit about this but I’d think
that the result you have at the moment doesn’t look right in the preview
shown in DialogBlocks?

alex

Alex F. wrote:

Joshua L. wrote:

The code works, but I still do not see the buttons in the window that I
produce. I followed the wiki as instructed from start to finish. Is
there some functionality I was supposed to give to the buttons that
perhaps I didn’t?
Your buttons and the textctrl need to be arranged in a Sizer. In
DialogBlocks you should see in the palette of addable elements a
“Sizers” tab. Add a vertical sizer to the main frame. Then, in order,
add the TextCtrl and the two buttons to it.

I guess the tutorial should be more explicit about this but I’d think
that the result you have at the moment doesn’t look right in the preview
shown in DialogBlocks?

alex

I’ll play with it and I think I can figure it out from what you wrote.
I think these types of problems–where you’re not explicit about
something–is more an issue for people like me who are really new to
programming and trying to teach themselves everything. People who have
experience with programming probably would have picked up on this issue.
I’ll let you know the results. Thanks.

Your buttons and the textctrl need to be arranged in a Sizer. In
DialogBlocks you should see in the palette of addable elements a
“Sizers” tab. Add a vertical sizer to the main frame. Then, in order,
add the TextCtrl and the two buttons to it.

SUCCESS!

Now, I just have to understand it all and get to my own code.

Thanks for your help. I was just about ready to throw in the towel.
Help and OCD prevail.

Joshua L. wrote:

SUCCESS!

Now, I just have to understand it all and get to my own code.

Thanks for your help. I was just about ready to throw in the towel.

Great, glad it worked out. Feel free to ask for help; this is a friendly
list for people with all levels of experience

Good luck
alex

Alex F. wrote:

Joshua L. wrote:

SUCCESS!

Now, I just have to understand it all and get to my own code.

Thanks for your help. I was just about ready to throw in the towel.

Great, glad it worked out. Feel free to ask for help; this is a friendly
list for people with all levels of experience

Good luck
alex

I tried to move on to apply what I learned and make my own simple
application. I started off more simple than the XRCise tutorial
example, just creating a frame through DialogBlock, then applied XRCise.
When I get to writing the ruby source code that mixes in the ruby class
file generated from XRCise, I get nowhere. I’m thinking that I’m not
just going to be able to pick this up as easily as I hoped and was
wondering if there are particular books (or chapters of books) or
websites I should be looking at to learn the basics–with respect to
GUI. I have the “pickaxe”, the Ruby Way (and a couple of others), and
I’ve been all over the web, so I have a general feel for all the info
that’s out there–there’s so much out there, I’m not sure what to focus
on at this point. Any advice is much appreciated.

Mario S. wrote:

Hello Joshua,

May I inquire as to the reasoning behind needing to use DialogBlocks?
Is it
purely so that you can see instantly what is being created, or
reusability,
etc, etc, etc? I might recommend, till you get yourself comfortable
with
wxRuby, that you try building frames, and user interfaces by hand,
through
actual Ruby Code. But if you absolutely need to have a User Interface
generated by DialogBlocks, and xrcise is not working for you… Can you
explain what the problem is more specifically?

A lot of times, when building interfaces with XRC, you need to know what
you
are doing, and how xrcise is going to translate that into Ruby code for
you.

L8ers,

Mario, thanks for the input. I do need to have a GUI for my final app,
but it doesn’t have to be via DialogBlocks/XRCise. I guess my question
is, if I learn about GUI in say Tk, how easily will i be able to apply
that to any of the other GUI aps–fxruby, wxruby, etc.?

Hello Joshua,

May I inquire as to the reasoning behind needing to use DialogBlocks?
Is it
purely so that you can see instantly what is being created, or
reusability,
etc, etc, etc? I might recommend, till you get yourself comfortable
with
wxRuby, that you try building frames, and user interfaces by hand,
through
actual Ruby Code. But if you absolutely need to have a User Interface
generated by DialogBlocks, and xrcise is not working for you… Can you
explain what the problem is more specifically?

A lot of times, when building interfaces with XRC, you need to know what
you
are doing, and how xrcise is going to translate that into Ruby code for
you.

L8ers,

Hello Joshua,

On 3/9/08, Joshua L. [email protected] wrote:

Mario, thanks for the input. I do need to have a GUI for my final app,
but it doesn’t have to be via DialogBlocks/XRCise. I guess my question
is, if I learn about GUI in say Tk, how easily will i be able to apply
that to any of the other GUI aps–fxruby, wxruby, etc.?

Just a note, but when reffering to other GUI Toolkits, like Tk, FXRuby
and
wxRuby, they are technically GUI Libraries. As to your particular
question,
I strongly, very very strongly recommend staying with 1 GUI Toolkit.
The
reason for this, is that each GUI Toolkit library has it’s own API
Interface, it’s own set of Controls, it’s own way of handling Events
that
come from the GUI elements. Also, there’s certain advantages and
dis-advantages to using each Toolkit. Tk, is a very low level GUI
Toolkit,
and heavily relies on having the TK/TCL Framework installed along side
Ruby
in order to work. GUI Apps that are created with TK, do not truely have
a
native OS feel to it, and can tend to be over-complicated.

FXRuby, has a Single GUI Look and Feel, so it’s garunteed to look the
same
across all platforms, though that is not always a good thing. The
reason
why it looks the same no matter what platform you run on, is cause Fox
does
all of it’s own drawing for all the controls that it has associated with
it. I have found many times over, that with this method of drawing
controls, can lend to be a main cause for bottlenecks in programs
developed
in Ruby. Everything is compiled in with the Extension, so you don’t
need to
re-distribute a whole bunch of stuff, just a single .so file and a few
.rb
files, which makes it a lot easier to port.

wxRuby on the other hand, utilizes Native OS Controls wherever possible,
only substituting for controls that do not exist on the platform in
question. It’s very fast, and has very few bottlenecks, cause it’s not
custom drawing every single control, outside of the main Window. This
is
favorable, cause it will retain the user’s preferences for Font size,
control colors, layout, etc, etc. Also, as with FXRuby, wxRuby has a
single
SO File, and a few .rb files, making distrobution easier.

Going between these three toolkits, can be very fustrating when your
trying
to develop apps. Do note, that these are my own opinions, and
experiences
from using these three Toolkits, and even though I develop soley with
wxRuby, I encourage people to experiment with other libraries, but only
pick
1 toolkit in which to do any programming with, otherwise, it will get
harder
and more frustrating in which to do stuff, any other way.

If you have any other questions, please feel free to ask away!
L8ers,

Tim, Mario,

Thanks for your informative input. I think I’ll stick to trying to
learn wxruby. I will try learning to code everything manually. I’ll
follow the online tutorials and decipher the examples as best as I can.
Any other suggestions are greatly appreciated.

Mario S. wrote:

I strongly, very very strongly recommend staying with 1 GUI Toolkit.

I can’t second that enough… :slight_smile:

I came to Ruby/wxRuby from Windows (VB6, .NET), Java , and then Qt3/C++
development… so I was accustomed to really only having 1 choice for
the gui toolkit… Well, with Ruby I had many to choose from and it was
hard to decide at first.

I looked at the Qt bindings for Ruby since I was working with Qt3 at the
time… I found them to be okay (well, a bit quirky and incomplete on
the Mac), but I did not want to lock myself into the “GPL or pay”
licensing scheme that using Qt requires.

I then looked at FOX (no Mac support, somewhat visually unappealing), Tk
(ugly code grin, no Ruby support yet for new, nice looking widgets),
GTK (spurious errors, deployment headaches)… I was intially avoiding
wxWindows, thinking it had pretty much run out of steam. However, I am
glad to find I was wrong. It seems to me to have the best blend of
features, looks nice on every platform, and it is very easy to deploy
with a Ruby app via the binary gems…

Oh, yeah, back to my point :slight_smile: In order to test, I wrote a little app in
all of the toolkits I evaluated … each got to various stages of
completion as I hit obstacles or lost interest in subjecting myself to
the pain encountered in working with them… and by the time I gave
wxWidgets/wxRuby a go, my head was spinning with so many varied
approaches to events, naming, threading and so on … I ended up
struggling more with wxRuby than I might have otherwise… :slight_smile:

All in all, though, my evaluation experiences proved helpful. I am much
more inclined now to work through any issues I may encounter with wxRuby
because I know the “grass is not greener” with any other toolkit.

Cheers,
Tim