« Return to Thread: Beginner question

Re: Beginner question

by Benjamin Sebastian Kolz :: Rate this Message:

Reply to Author | View in Thread

Some parts of this message have been removed. Learn more about Nabble's security policy.

Thank you for your response!

Do you know if there is any FXRuby turorial which starts at the beginning and explains the commands with details?
I bought the book "FX Ruby: Create Lean and Mean GUIs with Ruby", but its quite difficult for me to follow the commands.
I would need a tutorial that explains step by step the command with examples... is there any?

Thanks for your answers...

ps: if somebody would like to talk from time to time about ruby questions or about FXRuby codes/problems, feel free to add me to the
MSN messenger.



Date: Sat, 20 Jun 2009 21:46:12 +0200
From: meinrad.recheis@...
To: fxruby-users@...
Subject: Re: [fxruby-users] Beginner question

On Sat, Jun 20, 2009 at 5:54 PM, Benjamin Sebastian Kolz <benjaminrub-upf@...> wrote:

Hi everybody,

I just started working with FXRuby and I maybe somebody can help me with a problem.

Just for fun, I wrote a quiz game in Ruby, but up to now it is only running in a DOS window.

To get it a little bit more attractive, I wanted FXRuby to present the questions in a window
and open a field for the user to type in the answer. The answer should then be sent to the main program
as a string variable "response".

I've tried it like this, following the "hello"-example that comes with FX Ruby...

application = FXApp.new("Hello", "FoxTest")
main = FXMainWindow.new(application, "Hello", nil, nil, DECOR_ALL)
FXButton.new(main, frage, nil, application, FXApp::ID_QUIT)
FXButton.new(main, p1, nil, application, FXApp::ID_QUIT)
FXButton.new(main, p2, nil, application, FXApp::ID_QUIT)
FXButton.new(main, p3, nil, application, FXApp::ID_QUIT)
FXButton.new(main, p4, nil, application, FXApp::ID_QUIT)
application.create()
main.show(PLACEMENT_SCREEN)
application.run()

from here on FXApp takes over program control. you need to call your code via event handlers. Check out the connect function. 



# p1,p2,p3 and p4 are the variables that contain the answer possibilties
# frage is the question


Now, everything is displayed but I don't know how to give the user the chance to type the answer into a text field
and then this should be sent to the main program... any idea?

Add a FXTextField for entering the answer. Then bind your code that evaluates the answer to a button event handler like this:

button.connect(SEL_COMMAND) { 
// do something here
}


Ah, and the program works with a while-loop and after the first run I get an error:
"attempted to create more than one FXApp instance (RunTimeError)"
Does anyone know what s the problem here?

You can only have one FXApp instance. When you start FXApp it starts the "GUI-Thread" or others might call it the message loop and calls your code from there. So if you want to have something executed in a FXRuby application you either register event handlers to your buttons and textfield events or start a separate thread for non GUI related things.

you don't need the while loop, the FXApp has its own main loop.

hth,
-- Henon 

-------
Git# --> Git for .NET




Surfen - optimiert für MSN. Hol Dir die neue Version des Internet Explorers - kostenlos!
_______________________________________________
fxruby-users mailing list
fxruby-users@...
http://rubyforge.org/mailman/listinfo/fxruby-users

 « Return to Thread: Beginner question