« Return to Thread: Beginner question

Re: Beginner question

by Meinrad Recheis :: Rate this Message:

Reply to Author | View in Thread

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



_______________________________________________
fxruby-users mailing list
fxruby-users@...
http://rubyforge.org/mailman/listinfo/fxruby-users

 « Return to Thread: Beginner question