Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 [Tutorial] Reseting GUI.ProcessEvent
Index -> Programming, Turing -> Turing Tutorials
View previous topic Printable versionDownload TopicRate TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Ashkan




PostPosted: Fri Dec 26, 2003 2:48 am   Post subject: [Tutorial] Reseting GUI.ProcessEvent

Hey Everyone,
Well recently i faced a problem with reseting the GUI.ProcessEvent which as you might know, whenever you press the Quit button you can no longer use that GUI.ProcessEvent in your program. Well i came here and read some of the old posts regarding this topic but non of them really suggested the straight forward answer to it. They mostly suggested that you can use an if statement and that might work for some but for some really complicated ones they dont really work.. so i worked on it and finally i figured out a way to get around this that i want to share with you.

Information regarding GUI.ProcessEvent :
GUI.ProcessEvent is a function which is predefined in Turing and the function returns the boolean value Ture or Fals.
Well by calling this inside a loop you basically allow the program to wait for the user to finish using the GUI structure as it is still set to false, however after they pressed the Quit button the GUI.ProcessEvent will be set to True and it will then exit and the user is not longer able to make changes to GUI structure of the program.

Question:
Do you want to use the GUI.ProcessEvent more than one time in your program?
Do you want to allow the user to be able to use the GUI structure as long as he wants?

Solution:

1. Go to your Turing Library of predefined modules and you will find the "%Support/lib/GUIclass".

2. Open the Directory and open the file called "WidgetModule.tu"

3. Simply go the Export list and add the word "quitting" at the end.

Details: inside the WidgetModule.tu there is a function called ProcessEvent as follow:

Quote:
% Process a single event
function ProcessEvent : boolean
const activeWindow : int := Window.GetActive
theEventTime := Time.Elapsed
CheckForDifferentBlinkingTextField

if CheckForEvent (activeWindow) then
result quitting
else
for count : 1 .. WidgetGlobals.numWindows
if WidgetGlobals.window (count).windowID not= activeWindow
then
if CheckForEvent (WidgetGlobals.window (count).windowID)
then
result quitting
end if
end if
end for
end if


As you might notice the result of the function is "quitting" however it is not in the exported list of the module and thats the reason that you have to add it.

ATTENTION:
*Doing this you are changing one of the predefined modules and so i strongly recommend you to make a BACK UP of the WidgetModule.tu file in advance.
*However you are not really making a big change in it, you are just exporting something Extra there.

4. Open your program and import the "WidgetModule.tu"

import GUI in "%oot/lib/GUI", WidgetModule in "C:\\Program Files\\Turing\\Support\\Lib\\GUIClass\\WidgetModule.tu"

*Address Above is just an example. you might have to change yours.

5. Now in order to set it false after it has been set to true because the user have proessed the Quit Button , add the following code after it..

Quote:

WidgetModule.quitting := false


6. Done

7. =) Very Happy SmileRazz

Example:
If you notice there is a program for check box in turing reference that is :


code:

        import GUI in "%oot/lib/GUI"
       
        procedure DoNothing (status : boolean)
        end DoNothing
       
        View.Set ("graphics:500;500,nobuttonbar")
        var cb1 : int := GUI.CreateCheckBox (10, 10, "Check Box 1",
            DoNothing)
        var cb2 : int := GUI.CreateCheckBoxFull (200, 10, "Check Box 2",
            DoNothing, GUI.RIGHT, '2')
        GUI.SetCheckBox (cb2, true)
        var quitBtn : int := GUI.CreateButton (230, 10, 0, "Quit", GUI.Quit)
        loop
            exit when GUI.ProcessEvent
        end loop
        var cb1Status : boolean := GUI.GetCheckBox (cb1)
        var cb2Status : boolean := GUI.GetCheckBox (cb2)
        if cb1Status then
            put "Check box 1: filled"
        else
            put "Check box 1: empty"
        end if
        if cb2Status then
            put "Check box 2: filled"
        else
            put "Check box 2: empty"
        end if


In order to be able to use the program without allowing it to end i made the following changes:

Quote:

import GUI in "%oot/lib/GUI", WidgetModule in "C:\\Program Files\\Turing\\Support\\Lib\\GUIClass\\WidgetModule.tu"

procedure DoNothing (status : boolean)
end DoNothing

View.Set ("graphics:600;500,nobuttonbar")
var cb1 : int := GUI.CreateCheckBox (10, 10, "Check Box 1",
DoNothing)
var cb2 : int := GUI.CreateCheckBoxFull (200, 10, "Check Box 2",
DoNothing, GUI.RIGHT, '2')

loop
var quitBtn : int := GUI.CreateButton (230, 10, 0, "Quit", GUI.Quit)
loop
exit when GUI.ProcessEvent
end loop
var cb1Status : boolean := GUI.GetCheckBox (cb1)
var cb2Status : boolean := GUI.GetCheckBox (cb2)
if cb1Status then
put "Check box 1: filled"
else
put "Check box 1: empty"
end if
if cb2Status then
put "Check box 2: filled"
else
put "Check box 2: empty"
end if
WidgetModule.quitting := false
end loop


*Change the address accordingly.

Works for me.
I hope it helps you all.
Sponsor
Sponsor
Sponsor
sponsor
Ashkan




PostPosted: Fri Dec 26, 2003 2:52 am   Post subject: Edit

hey any moderator wants to edit my post cuz althoughh i used the code tag but it didnt work in some parts .. so you might wanna fix that to make it look better ..
Tony




PostPosted: Fri Dec 26, 2003 3:06 am   Post subject: (No subject)

wow, this looks messed... I notices weird stuff is happening when code tag is used more then once Confused I'll talk to dan
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
Homer_simpson




PostPosted: Sun Dec 28, 2003 2:08 am   Post subject: (No subject)

ashkan man.... by any chance are u persian?
Tony




PostPosted: Sun Dec 28, 2003 1:27 pm   Post subject: (No subject)

score! replacing extra code tags with quote, solves the alignment problems Very Happy Though it's still messed... Confused I donno whats wrong, but it looks like dan is back in town, so we'll see.

Also - its a very nice tutorial, have some+Bits
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
Ashkan




PostPosted: Mon Dec 29, 2003 3:39 pm   Post subject: hey y'all

Hey Homer Simpson, ya am persian and i speak persian fluently cuz i lived in iran for 10 years...
hey tony and Dan thanx for editing the interface of the tutorial and thanx for the bits...
however whats this whole thing about bits? llllllollll Razz Smile =)
Mazer




PostPosted: Mon Dec 29, 2003 3:45 pm   Post subject: (No subject)

"what are bits"? "what are bits"?!!!?!?! only the single most important thing known to man! (seriously, who needs water anyways?)

here's a link to show you just how important bits are:
http://www.compsci.ca/v2/viewtopic.php?t=2478
Homer_simpson




PostPosted: Mon Dec 29, 2003 8:43 pm   Post subject: (No subject)

nice man...
u'd be the first persian to join after me...
+chandta bit =Þ
Ashkan




PostPosted: Mon Dec 29, 2003 11:00 pm   Post subject: Halo

hey homer, nice to meet ya man, merci for bits

Am gonna post some of my programs for ya guys, am not into makin games really, mostly dealin with databases and programs..
=P
shorthair




PostPosted: Sat Jan 17, 2004 6:34 pm   Post subject: (No subject)

THIS IS NOW OBSELITE ( cant spell) there is a new command in turing to reset it , no need for extra code

just get hte turing 4.0.5 update and your set , raed the help for the 30 + new commands
Display posts from previous:   
   Index -> Programming, Turing -> Turing Tutorials
View previous topic Tell A FriendPrintable versionDownload TopicRate TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 10 Posts ]
Jump to:   


Style:  
Search: