Computer Science Canada

GUI Problem?

Author:  threatbinder [ Tue Dec 29, 2009 1:01 am ]
Post subject:  GUI Problem?

Example of my problem:
Turing:

import GUI
var ch : char
proc SayHi
    GUI.Quit
end SayHi
loop
    ch := getchar
    if ch = "a" then
        var winID := Window.Open ("graphics:200;200")
        var something := GUI.CreateButton (0, 0, 0, "Hi", SayHi)
        loop
            exit when GUI.ProcessEvent
        end loop
        Window.Close (winID)
    end if
end loop


Okay, so the problem with this is, it works the first time, but the second time the window will open and close so fast that it won't even show. This is because after doing GUI.Quit once, it will always return true in the
Turing:

loop
    exit when GUI.ProcessEvent
end loop

so it will go to Window.Close (winID) without even waiting for the click on the GUI button... is there any solution to this problem? (if I didn't clearly explain my problem, it would help if you try copy and pasting this code onto turing --> press a every time, and see how the first time it opens a window, and after that it doesn't (it does but we can't see it open because it closes so fast).

Any solutions please?

I'm using 4.1.1 btw.

Author:  Euphoracle [ Tue Dec 29, 2009 2:12 am ]
Post subject:  RE:GUI Problem?

GUI.ResetQuit or something. Check the docs.

Author:  TheGuardian001 [ Tue Dec 29, 2009 2:14 am ]
Post subject:  Re: GUI Problem?

You could try not calling GUI.Quit, and having a different exit when with the GUI.Quit

GUI.Quit should only ever be called if you are completely done with GUI. If you've called GUI.Quit, it doesn't bother to continue to check for events, since there's no GUI to check for events from.

If you only want to get rid of specific widgets, you can either hide them with GUI.Hide(widget), which is temporary, or GUI.Dispose(widget) which is permanent.

Edit: ninja'd by Euphoracle's better solution.

Author:  Euphoracle [ Tue Dec 29, 2009 2:47 am ]
Post subject:  RE:GUI Problem?

Actually, GUI.Dispose would be better in the context with which he is using this. Didn't think of that.

Author:  threatbinder [ Tue Dec 29, 2009 4:04 pm ]
Post subject:  Re: RE:GUI Problem?

Euphoracle @ Tue Dec 29, 2009 2:47 am wrote:
Actually, GUI.Dispose would be better in the context with which he is using this. Didn't think of that.


thanks for the gui.resetquit, didn't see that in the turing docs when i looked over the gui unit.


: