Jump to content

Simple problem with Loop and GUI


Bilan
 Share

Recommended Posts

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.

Link to comment
Share on other sites

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
Link to comment
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

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...