# WxRuby and DialogBlocks Questions

**URL:** <https://www.ruby-forum.com/t/wxruby-and-dialogblocks-questions/181951>\
**Category:** Ruby\
**Created:** [January 20, 2010, 5:12pm UTC](https://www.ruby-forum.com/t/wxruby-and-dialogblocks-questions/181951 "2010-01-20T17:12:17Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![elricstorm](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/da6949/32.png) [@elricstorm](https://www.ruby-forum.com/u/elricstorm)\
**Post date:** [January 20, 2010, 5:12pm UTC](https://www.ruby-forum.com/t/wxruby-and-dialogblocks-questions/181951/1 "2010-01-20T17:12:17Z")

</div>

Hi everyone,

I’m using DialogBlocks as my GUI designer for creating XRC files that I  
will use with WxRuby and wx\_sugar to create my UI ruby file with. I’ve  
gone through several tutorials to understand how Ruby and WX work  
together, along with DialogBlocks and am feeling a bit more comfortable  
with it all.

But, I have some questions for more seasoned veterans that are using a  
similar setup as I am. I am a very organized person so I like to start  
with organization in my projects. As I’ve never created a Ruby built  
GUI before, let me start with a few areas that I’d like to address and  
gather some input from those that respond.

Project Outline:

My first project is going to be porting over some code I created in  
another language and adding quite a few revisions to it. My goal is to  
create a cross-platform program that can be used on Windows, Linux, and  
Mac. The old source program is composed of one file only, and was built  
using AutoIt, which utilizes a similar build for GUI elements that WX  
uses. For instance, AutoIt starts with a parent frame and WX starts  
with a parent frame. I already have the entire look created and so  
designing that look in DialogBlocks should be fairly simple.

Project Organizational Structure:

This is my first concern. I’m not sure how I should setup my folder  
structures for my project. I could do:

\project  
…\lib  
…\icons  
…\images  
…\ui  
etc…

… but I’m not sure how I should piece this out so that it’s compatible  
with WxRuby. I figured I could put my xrc and rb UI files in \ui. I  
could put icons in icons, images in images, and lib could contain the  
meat of my rb project files. But, I’m not sure this is the proper way  
to go and so I’d like some feedback on how some of the veterans setup  
their project workspace and what they do to fit it all together.

DialogBlocks:

I took some notes from some of the wikis I browsed and put together the  
following below:

In DBLK, all top-level Frames, Dialogs and Panels become RUBY CLASSES.  
The name you type in the class field within DBLK becomes the class name  
in your Ruby program. Likewise, for the controls â€œwithinâ€ a container,  
the DBLK class name becomes the name of a Ruby module in your program  
that will be used to extend the control.

From my understanding of this, it’s saying that whatever I type in the  
class field within dialogblocks for any frame, dialog, or panel, in my  
ruby code, I will use the name as a class. And, likewise, for any  
control within a container, the name I use in the class field becomes a  
ruby module name in my ruby code.

I have quite a few questions about this. First, with GUI driven ruby  
applications does it matter where I place my modules and classes? Can I  
place all of them in one file? Or, should I keep the modules and  
classes in separate files?

Secondly, is there a list of what is actually classified as a frame,  
dialog, panel, or control for dialogblocks? I tend to confuse some of  
these elements.

Summary:

Rather than ask a lot more questions at this moment, I’m just trying to  
get to a comfort level of just setting up my project, feeling out how I  
want to progress, and then get into some further questions. I would  
appreciate any responses to the ones I have outlined already and any  
links to particular in-depth tutorials, if available.

Thank you.

---

<div class="post-metadata">

**Author:** ![elricstorm](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/da6949/32.png) [@elricstorm](https://www.ruby-forum.com/u/elricstorm)\
**Post date:** [January 20, 2010, 5:20pm UTC](https://www.ruby-forum.com/t/wxruby-and-dialogblocks-questions/181951/2 "2010-01-20T17:20:06Z")

</div>

I believe I found a partial answer to one of my questions. In  
DialogBlocks, when you place down an element, underneath the class name  
is a base class name which appears to reference ctrl or frame, or dialog  
stating which class it belongs to.

---

<div class="post-metadata">

**Author:** ![elricstorm](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/da6949/32.png) [@elricstorm](https://www.ruby-forum.com/u/elricstorm)\
**Post date:** [January 20, 2010, 5:46pm UTC](https://www.ruby-forum.com/t/wxruby-and-dialogblocks-questions/181951/3 "2010-01-20T17:46:20Z")

</div>

Adding some more questions:

I see that there is a rake task that can be created using:

file ‘lib/gui\_base\_classes.rb’ =\> ‘xrc/my\_project.xrc’ do | t |  
sh “xrcise -o #{t.name} xrc/project.xrc”  
end

… which is supposed to be able to automatically update your project if  
something changes. However, there’s no example explanation of what this  
does exactly. For instance, what does gui\_base\_classes.rb correspond  
to? What is in that file? Is project.xrc just an overall xrc file for  
the entire project? Or, is it just one xrc file that points to multiple  
xrc files? Again, no explanation or example referenced with the rake  
task.

When I create a new project in dialogblocks, it asks me the projects xrc  
name. Let’s say for example, I make it project.xrc. When I create a  
first frame element called parent\_window and then decide to let the xrc  
be named to parent\_window.rb, when I save my project later on, I see the  
following in the ui folder.

\ui\project.xrc  
\ui\parent\_window.xrc

This leads me to believe that I will have multiple xrc files for each  
frame? Or, am I mistaken… Which file would I be using in the rake  
task above? Again, following the tutorials outlined here:

[http://wxruby.rubyforge.org/wiki/wiki.pl?UsingXRCise](http://wxruby.rubyforge.org/wiki/wiki.pl?UsingXRCise)

What I understand 100% is that xrcise is basically creating ruby file(s)  
that contain all of the information pertaining to the elements of my  
program. And, all I have to create are the listener events for each  
piece of the gui with my modules and classes.

What I don’t understand is the inner-workings of all of this and how it  
ties in together in terms of files, folder structure, requires, and  
includes…

---

<div class="post-metadata">

**Author:** ![elricstorm](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/da6949/32.png) [@elricstorm](https://www.ruby-forum.com/u/elricstorm)\
**Post date:** [January 20, 2010, 9:56pm UTC](https://www.ruby-forum.com/t/wxruby-and-dialogblocks-questions/181951/4 "2010-01-20T21:56:15Z")

</div>

Well, I’ve made some headway and have created a default template that is  
usable with DialogBlocks, Ruby 1.9.1, and Netbeans 6.8. I’m going to go  
ahead and attach the template for anyone else that comes after me that  
may find issues with getting started with WxRuby and DialogBlocks.

Requirements for the Template:

Ruby 1.9.1  
DialogBlocks  
Netbeans 6.8

Un-rar the template into any directory and open the folder with  
netbeans. The entire folder structure will appear as this:

\GuiTemplate  
–\frames (for frame initialization)  
–\icons (for storing icons)  
–\images (for storing images)  
–\lib (for source files)  
---- main.rb (your main source file)  
---- wxhelper.rb (a helper file that loads your rb from xrc source)  
---- wxhelper\_template.rb (the template I found which you can use for  
reference)  
–\nbproject (the netbeans project directory)  
–\spec (rspec test folder)  
–\test (normal test folder)  
–\ui (for your xrc and rb files that contain the GUI elements)  
---- gui\_base\_classes.rb (the rb file that holds all of the xrc  
information)  
---- gui\_base\_classes.xrc (the xml source from dialogblocks)  
---- gui\_base\_project.pjd (the DialogBlocks project file)  
---- main\_gui\_window.xrc (the first frame xrc file)  
LICENSE (lic file)  
Rakefile (contains a lot of rake tasks which I’ll show below)  
README (shows pre-reqs)  
start (the file you run to start your gui)

==============================

After you download and open this up, test it out by going to the  
GuiTemplate folder and running the command : ruby start

A gui window should open. If so, then everything checks out fine.

Commands you can run:

Type rake --description or D to see the description of all the rake  
tasks. The default rake task is set for rake project\_update which you  
can perform just by simply typing the command “rake” all by itself.

Running rake project\_update will automatically rebuild your  
ui/gui\_base\_classes.rb file from ui/gui\_base\_classes.xrc so that as you  
design in DialogBlocks you can just run the rake task from NB and you  
can test your app out after running the task.

Once you open the project in netbeans you can right-click on the project  
when you want to start a new project and go to properties. You can  
rename the project (you’ll receive a warning about hidden files and  
subversion - just ignore this) and you have your new project handy.

To start working on it in DialogBlocks graphic designer, browse to  
YourProject\ui\gui\_base\_project.pjd and you are up and running.

===========================

Hopefully, this will simplify the needs for others that want to design  
graphical programs with this combination of software.

Take care.
