Sign in to follow this  
Followers 0
Bilan

Simple problem with Loop and GUI

4 posts in this topic

I'm just a beginner when it comes to programming. I have this problem:

I have a GUI with several buttons, one of these buttons calls on a loop function that doesnt stop. Another button should let it stop though, how do I do that? I don't understand how to let the GUI still function when some other processes in the same program are running.

Thanks.

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

A number of ways to do it. I made this for someone else, but maybe it'll help (or confuse) you.

#include <GUIConstants.au3>

Opt('GUIOnEventMode', 1)

$paused = True
$new = True

GUICreate('Toggle', 160, 206)
GUISetOnEvent($GUI_EVENT_CLOSE, 'quit')

GUICtrlCreateButton('Toggle', 30, 30, 100, 26)
GUICtrlSetOnEvent(-1, 'toggle')

GUICtrlCreateButton('Other Btn', 30, 86, 100, 26)
GUICtrlSetOnEvent(-1, 'otherfunc')

$label = GUICtrlCreateLabel('Weeeeee', 30, 147, 100, 26)

GUISetState()

While 1
    Sleep(50)
    If Not $paused Then runloop()
WEnd

Func runloop()
    ToolTip('running')
EndFunc

Func otherfunc()
    $new = Not $new
    If $new Then
        GUICtrlSetData($label, 'Some new text')
    Else
        GUICtrlSetData($label, 'Lalalala')
    EndIf
EndFunc

Func toggle()
    $paused = Not $paused
    ToolTip('')
EndFunc

Func quit()
    Exit
EndFunc
Edited by xcal

Share this post


Link to post
Share on other sites

@xcal

I assume that Bilan cannot produce a code like the one you submit as your is not really looping inside the called function.

just change your runloop function to

Func runloop()
While 1
Sleep(10)
Wend
EndFunc

As AutoIT is not a multithreaded program your solution is the only way to interrupt the execution. Just because you don't loop in the function ...

@Bilan

No solution unless you transform your program to work a @xcal one :P

Share this post


Link to post
Share on other sites

Ah I found some other way, changed the plan :P. Thanks anyway.

Share this post


Link to post
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
Sign in to follow this  
Followers 0