Jump to content

GUISetOnEvent, force loop to stop?


huldu
 Share

Recommended Posts

Is there any way, in a gui, to force a loop to stop?

#include <GUIConstants.au3>

Opt("GUIOnEventMode",1)

$Form1 = GUICreate("Testing", 100, 100, 100, 100) 
GUISetOnEvent($GUI_EVENT_CLOSE, "ExitNow")

$Button1 = GUICtrlCreateButton("Start", 25, 25, 50, 50)
GUICtrlSetOnEvent($Button1, "Start")

GUISetState(@SW_SHOW)

While 1

WEnd

Func Start()
    GUICtrlSetData($Button1, "Stop")
    GUICtrlSetOnEvent($Button1, "Stop")
    ToolTip("In start function.",0,0)
EndFunc

Func Stop()
    GUICtrlSetData($Button1, "Start")
    GUICtrlSetOnEvent($Button1, "Start")
    ToolTip("In stop function.",0,0)
EndFunc

Func ExitNow()
    Exit
EndFunc

The above works fine, when you click on start the stuff start, if you click on stop it stops. However lets say you have a while loop inside the function... There is no way to exit the loop, it seems to get stuck in it and ignore the GUICtrlSetOnEvent actions. Is there any way to FORCE the GUICtrlSetOnEvent to _always_ be checked, even if in a loop?

"I'm paper, rock is fine, nerf scissors!!!"

Link to comment
Share on other sites

#include <GUIConstants.au3>

Opt("GUIOnEventMode",1)

$Form1 = GUICreate("Testing", 100, 100, 100, 100) 
GUISetOnEvent($GUI_EVENT_CLOSE, "ExitNow")

$Button1 = GUICtrlCreateButton("Start", 25, 25, 50, 50)
GUICtrlSetOnEvent($Button1, "Start")

GUISetState(@SW_SHOW)

While 1

WEnd

Func Start()
    GUICtrlSetData($Button1, "Stop")
    GUICtrlSetOnEvent($Button1, "Stop")
    ToolTip("In start function.",0,0)
EndFunc

Func Stop()
    GUICtrlSetData($Button1, "Start")
    GUICtrlSetOnEvent($Button1, "Start")
    ToolTip("In stop function.",0,0)
EndFunc

Func ExitNow()
    Exit
EndFunc

Something like this ?

-jaenster

Link to comment
Share on other sites

That was a copy of what i already wrote.

I need help to stop this, below. Once the loop has started i cant stop it using the button, which is what im looking for. A way to stop the loop using the button, not a hotkey.

#include <GUIConstants.au3>

Opt("GUIOnEventMode",1)

$Form1 = GUICreate("Testing", 100, 100, 100, 100)
GUISetOnEvent($GUI_EVENT_CLOSE, "ExitNow")

$Button1 = GUICtrlCreateButton("Start", 25, 25, 50, 50)
GUICtrlSetOnEvent($Button1, "Start")

GUISetState(@SW_SHOW)

While 1

WEnd

Func Start()
    While 1
    GUICtrlSetData($Button1, "Stop")
    GUICtrlSetOnEvent($Button1, "Stop")
    ToolTip("In start function.",0,0)
    WEnd
EndFunc

Func Stop()
    GUICtrlSetData($Button1, "Start")
    GUICtrlSetOnEvent($Button1, "Start")
    ToolTip("In stop function.",0,0)
EndFunc

Func ExitNow()
    Exit
EndFunc

"I'm paper, rock is fine, nerf scissors!!!"

Link to comment
Share on other sites

huh wtf i dont add the good thing , sorry ... i copy it from you and edit it ... omg

#include <GUIConstants.au3>

Opt("GUIOnEventMode",1)

$Form1 = GUICreate("Testing", 100, 100, 100, 100) 
GUISetOnEvent($GUI_EVENT_CLOSE, "ExitNow")

$Button1 = GUICtrlCreateButton("Start", 25, 25, 50, 50)
GUICtrlSetOnEvent($Button1, "Start")

GUISetState(@SW_SHOW)

While 1
$msg = GUIGetMsg()
if $msg = $button1 Then
    exitloop
endif
WEnd

Func Start()
    GUICtrlSetData($Button1, "Stop")
    GUICtrlSetOnEvent($Button1, "Stop")
    ToolTip("In start function.",0,0)
EndFunc

Func Stop()
    GUICtrlSetData($Button1, "Start")
    GUICtrlSetOnEvent($Button1, "Start")
    ToolTip("In stop function.",0,0)
EndFunc

Func ExitNow()
    Exit
EndFunc

-jaenster

Link to comment
Share on other sites

The above still doesnt work... And it wont ever work because the loop is after the main loop. So when you are in the second loop, the stuff in the main loop is ignored because its not running.

Ran into this problem several times tho. Still havent found a solution. The only bandaid i could get work was to run a second application, but this isnt leading anywhere because im forced to run a third and fourth and so on until i can figure out how to fix this.

Btw, just add a while loop in the Start() function and you see what i mean.'

I think alot of this is because of a Sleep() inside the loop, but i still dont understand why GUISetOnEvent isnt responding when it should be doing it(?).

Edited by huldu

"I'm paper, rock is fine, nerf scissors!!!"

Link to comment
Share on other sites

#include <GUIConstants.au3>

Opt("GUIOnEventMode",1)

$Form1 = GUICreate("Testing", 100, 100, 100, 100)
GUISetOnEvent($GUI_EVENT_CLOSE, "ExitNow")

$Button1 = GUICtrlCreateButton("Start", 25, 25, 50, 50)
GUICtrlSetOnEvent($Button1, "Start")

GUISetState(@SW_SHOW)

While 1

WEnd

Func Start()
    While 1
    GUICtrlSetData($Button1, "Stop")
    GUICtrlSetOnEvent($Button1, "Stop")
    ToolTip("In start function.",0,0)
    Exitloop
    WEnd
EndFunc

Func Stop()
    GUICtrlSetData($Button1, "Start")
    GUICtrlSetOnEvent($Button1, "Start")
    ToolTip("In stop function.",0,0)
EndFunc

Func ExitNow()
    Exit
EndFunc

Does this work?

Edited by Liope
Link to comment
Share on other sites

Hehe, the problem above is that if i use exitloop in the end of the loop, whats the point of the loop in the first place :lmao:

The loop is there to repeat events, until stop button is being pressed.

"I'm paper, rock is fine, nerf scissors!!!"

Link to comment
Share on other sites

havent read all of this thread but what about something like

$blah = GuiCreate("")
$button = GuiCtrlCreateButon("moo",-1,-1)
GuiSetState()
While 1
$msg = GuiGetMsg()
select
case $msg= $button
exitloop
endselect
WEnd

--dont know if thsi will help or not

~cdkid

Edited by cdkid
AutoIt Console written in C#. Write au3 code right at the console :D_FileWriteToLineWrite to a specific line in a file.My UDF Libraries: MySQL UDF Library version 1.6 MySQL Database UDF's for AutoItI have stopped updating the MySQL thread above, all future updates will be on my SVN. The svn location is:kan2.sytes.net/publicsvn/mysqlnote: This will still be available, but due to my new job, and school hours, am no longer developing this udf.My business: www.hirethebrain.com Hire The Brain HireTheBrain.com Computer Consulting, Design, Assembly and RepairOh no! I've commited Scriptocide!
Link to comment
Share on other sites

The problem is while in a loop (after the main program loop), events for some reason get ignored. If the events still worked i would be out of the loop in no-time.

The above doesnt help with the problem however.

"I'm paper, rock is fine, nerf scissors!!!"

Link to comment
Share on other sites

#include <GUIConstants.au3>

Opt("GUIOnEventMode",1)

$Form1 = GUICreate("Testing", 100, 100, 100, 100)
GUISetOnEvent($GUI_EVENT_CLOSE, "ExitNow")

$Button1 = GUICtrlCreateButton("Start", 25, 25, 50, 50)
GUICtrlSetOnEvent($Button1, "Start")

GUISetState(@SW_SHOW)

While 1

WEnd

Func Start()
 ;While 1
    GUICtrlSetData($Button1, "Stop")
    GUICtrlSetOnEvent($Button1, "Stop")
    ToolTip("In start function.",0,0)
 ;WEnd
EndFunc

Func Stop()
    GUICtrlSetData($Button1, "Start")
    GUICtrlSetOnEvent($Button1, "Start")
    ToolTip("In stop function.",0,0)
EndFunc

Func ExitNow()
    Exit
EndFunc

not sure what the second while loop is for

edit: should have read tho whole post, woops. let me try again!

now this is going to bug me ! i cannot exit out of that second loop ! there's got to be a way.

Edited by pecloe
Link to comment
Share on other sites

The only way i know of so far is that if HotKeySet() is used you can exit the loop. However using the HotKeySet of course requires the use of the keyboard. There must be a way to use a "button" for this function aswell (in the GUI).

If someone knows how, please let me know.

"I'm paper, rock is fine, nerf scissors!!!"

Link to comment
Share on other sites

According to the helpfile:

In the OnEvent mode instead of constantly polling the GUI to find out if anything has happened you make the GUI temporarily pause your script and call a pre-defined function to handle the event. For example, if the user clicks Button1 the GUI pauses your main script and calls a previously defined user function that deals with Button1. When the function call is completed the main script is resumed. This mode is similar to the Visual Basic forms method.

This line specifically: When the function call is completed the main script is resumed.

So, if you're in a while loop inside a function, the OnEvent mode is not receiving any events (or you could say it is temporarily turned off).

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...