Forum: wxRuby Need Help with understanding Threads, Timers, and Yield

Posted by Alpha Blue (elricstorm)
on 2010-01-22 16:40
(Received via mailing list)
Hi Everyone,



I'm posting this to the correct list now.



I'm a new GUI developer that is having some difficulty understanding 
some of
the nuances of GUI development with Ruby and want to hopefully get some 
of
my questions answered.  First, let me provide my setup:



.         I'm using Ruby 1.9.1 patch 243 installed from
mingw32-ruby-1.9.1-wxruby-2.0.1-setup.exe
<http://rubyforge.org/frs/download.php/63415/mingw32-ruby-1.9.1-wxruby-2.0.1
-setup.exe>  .

.         I'm using DialogBlocks as my GUI designer.

.         I'm using wg_sugar/xrcise for compiling my xrc source files.

.         I'm using Windows Vista and Netbeans 6.8 IDE for my 
development
environment.

.         I've created a full project template to make it easier to 
develop
my GUIs going forward using all of this setup.



My design template is segmented as follows:



.         \icons

.         \images

.         \lib

.         \nbproject

.         \psd

.         \tasks

.         \ui

.         Rakefile

.         Start



My xrc source and the ruby files that handle that source are stored in 
my UI
directory.  My lib folder contains my main program ruby files and the 
tasks
folder contains my rake tasks.  The rest of the folders are pretty
self-explanatory.  The start file houses the following in the first file
listed here:



http://gist.github.com/283794



Notes:



I'm first requiring any files I need and then loading my globals and a
wxhelper file.  The wxhelper file is fairly simple in that it's loading 
all
of the ruby files that are listed in my UI directory for handling the 
GUi
frames.  In addition, any pre-init type of events that need to take 
place
(building directories, reading configuration files, etc. are done with
WxHelper.  Then I'm loading my main.rb file which houses all of the meat 
of
my code, including the listener events.  As you can see on lines 16-18 
of
the start file, I'm starting a timer to pass threads.  I believe this is 
the
proper place to put this code, but I may be mistaken.  I'll ask 
questions
about this in a moment.



Lastly, my main.rb file handles something similar in the second file 
listed
here:



http://gist.github.com/283794



When I'm ready to work on my GUI development, I simply design in
DialogBlocks, save my xrc, run a rake task that automatically builds my 
ruby
files from xrc using xrcise, and then type ruby start to execute my GUI. 
I
prefer this type of setup because it feels right.  However, it may not 
be
the most efficient way to design and therefore, if there is a better way 
to
implement a design template, please let me know.



So, now that I have all of my pre-requisite mish-mosh out of the way (my
apologies for the length), you at least understand how I'm operating and 
can
possibly answer my questions a little more easily now.



Here are my questions:



Question 1:  Did I place the timer event in the right spot?  I placed it 
in
the init section of my start script.  Second-guessing myself, the only 
other
place I felt I could place it would be within the initialize section of 
my
main.rb script but this didn't feel right.  Because my program is 
starting
with the init, I felt it should go here.  If I'm mistaken, please 
correct me
and explain why it shouldn't go here.



Question 2:  My program is going to be using several open socket 
connections
simultaneously and CPU processing will occur as well.  Therefore, I'm 
trying
to simplify my template by incorporating threads to handle CPU/IO 
blocking.
I believe I understand the processes, but my biggest issue may be WHEN 
and
HOW to implement threads in my programs.  Coming from other languages 
where
simple gui designs didn't incorporate threading, I can understand and
appreciate the concept behind threading.  I had first thought about
implementing fibers but I don't believe this is the best thing for me to 
do
since I'm going to be handling cpu blocking.  In addition, some java 
users
mention that even if you use a fiber, you have to have a thread to 
manage
it.  So, threading is the way I want to go.  I'm a newbie and novice
programmer in terms of threading and even looking over the examples, I 
just
can't wrap my head around it at the moment.  Any help would be 
appreciated
with reference to my code listed above and when to use threads and also 
how
to use them.



Question 3:  I really do love DialogBlocks because it does simplify GUI
design.  I read and parsed my own set of notes which I'll outline below 
and
post the follow-up question:



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.



How am I supposed to properly include the classes and modules within my
program template structure?  Should I be placing multiple modules and
classes in the same main.rb file or should I place them in separate 
files
and (require?/load?) them from my main.rb file?  For instance, the first
class that I had which is listed in main.rb is GuiMain which is 
referenced
from the main gui frame that acts as the parent container for my
application.  I haven't added any other elements yet that will become
modules or classes, so I'm just uncertain where these code bits will be
placed, or how to properly include them in my GUI.  Any help concerning 
this
would be appreciated.



Question 4:  This is more of a dialogblocks question but I'm certain 
someone
who may use dialogblocks can answer it for me.  The question I have 
relates
to sizers and my application as a whole.  I understand the concept of 
sizers
but what I don't understand is how to properly size my Gui App depending 
on
resolution sizes of other users' desktops.  For instance, right now I 
have a
simple 700 x 550 starting gui app.  I know that if I place a vertical 
sizer
into my app and a main panel into that sizer, that whenever someone 
resizes
the app, it will stretch out the main panel as well.  However, this 
appears
frustrating to me mainly because I'm heavily into CSS designing and I'm
always trying to optimize for different browser sizes.  What is a good
starting application size (and the absolute maximum size you should 
place as
a minimum starting point, before resizing?) Or, is there a way to test 
for
desktop resolution across all OS platforms, and determine an initial gui 
app
starting size based on that resolution type?



These four question outlines are my biggest concerns at the moment.  I'm 
a
very fast learner, have a lot of free time to read/learn and browse api,
etc.  I soak up information like a sponge which is a good thing.  So, 
please
feel free to inundate me with as much information possible about these
questions and/or other novice items that I may not know about.  I like 
the
feel of WxRuby and I'm really excited to get down into porting some of 
my
older GUI app code over to WxRuby.



Many thanks in advance.



Sincerely,



Joel Dezenzio
Please log in before posting. Registration is free and takes only a minute.
Existing account (Switch to SSL-encrypted connection)
NEW: Do you have a Google/GoogleMail or Yahoo account? No registration required!
Log in with Google account | Log in with Yahoo account
No account? Register here.