GUI Loop beenden

  • HILFE ( muss einfach im ersten post stehen :P )

    hi @ all
    befasse mich erst seit kurzem mit autoit, bin also n kacknoob !
    deshalb bitte ich um etwas gedult ^^


    kurze beschreibung zu meinen autoit prob :

    hab ein gui gebastelt das eine funktion aufruft, diese funktion dauert mehrere minuten in einer do/for schleife,
    wobei ein durchlauf 3-8 sec dauert, soweit so gut...
    nun moechte ich (ueber das gui) diese funktion pausieren, bzw abbrechen
    das problem ist , dass wenn die func laueft, ich keinen einfluss mehr auf das gui hab
    bzw ich dieses nicht ansprechen kann ( pausieren, exit )
    was aber durch das "tray-menu" möglich ist ...also muss es irgendwie gehen :P


    vereinfahcte variante des scripts :

    Spoiler anzeigen
    [autoit]


    #include <GUIConstants.au3>

    [/autoit] [autoit][/autoit] [autoit]

    $wait = 1000 ; wait-time simuliert einen step
    $s = 0 ; progressbar-saveposition

    [/autoit] [autoit][/autoit] [autoit]

    GUICreate("GUI BSP",220,100, 100,200)
    $progressbar = GUICtrlCreateProgress (10,10,200,20, $PBS_SMOOTH)
    $button = GUICtrlCreateButton ("Start",25,70,70,20)
    $def_button = GUICtrlSetState($button, $GUI_DEFBUTTON)
    $button2 = GUICtrlCreateButton ("Cancel",125,70,70,20)
    $howto = GUICtrlCreateButton ("HowTo",25,40,70,20)
    $options = GUICtrlCreateButton ("Options",125,40,70,20)
    ;---------------------------------------------------------------
    GUISetState ()
    do
    $msg = GUIGetMsg()

    If $msg = $howto Then
    MsgBox (64,"HowTo", ".....")
    ElseIf $msg = $options Then
    MsgBox (1,"Options", ".....")
    ElseIf $msg = $button2 Then
    ExitLoop
    ElseIf $msg = $button Then
    GUICtrlSetState($HowTo, $GUI_DISABLE)
    GUICtrlSetState($options, $GUI_DISABLE)
    GUICtrlSetData ($button, "Pause")

    For $i = $s To 10
    $m = GUIGetMsg ()
    If $m = $button2 Then ExitLoop
    If $m = -3 Then ExitLoop
    If $m = $button Then
    GUICtrlSetData ($button, "Next")
    $s = $i ;save the current bar-position to $s
    ExitLoop
    Else
    _count()
    EndIf
    Next

    [/autoit] [autoit][/autoit] [autoit]

    if $i > 10 then
    GUICtrlSetData ($button, "Start")
    GUICtrlSetState($HowTo, $GUI_ENABLE)
    GUICtrlSetState($options, $GUI_ENABLE)
    EndIf
    EndIf

    [/autoit] [autoit][/autoit] [autoit]

    until $msg = $GUI_EVENT_CLOSE
    ;---------------------------------------------------------------

    [/autoit] [autoit][/autoit] [autoit]

    Func _count ()
    $s=0
    GUICtrlSetData ($progressbar,$i*10)
    Sleep($wait)
    EndFunc ; => _count

    [/autoit] [autoit][/autoit] [autoit][/autoit]

    hab dieses bsp mit Opt("GUIOnEventMode", 1) sowie mit der GUIGetMsg() variante versucht
    beide versuche leider ohne erfolg

    hab auch schon im forum gesucht und ein ähnliches thema gefunden
    Loop stoppen
    leider funzt die lösung die dort angeboten wird nicht :/

    bin für jede hilfe/anregung dankbar ,

    b00ny

  • danke fuer den tip :)
    habs nun etwas verändert..


    Spoiler anzeigen
    [autoit][/autoit] [autoit][/autoit] [autoit]

    #include <GUIConstants.au3>

    [/autoit] [autoit][/autoit] [autoit]

    $wait = 1000 ; wait-time simuliert einen step
    $s = 0 ; progressbar-saveposition
    Global $Paused
    HotKeySet("{PAUSE}", "TogglePause")

    [/autoit] [autoit][/autoit] [autoit]

    GUICreate("GUI BSP",220,100, 100,200)
    $progressbar= GUICtrlCreateProgress (10,10,200,20, $PBS_SMOOTH)
    $start = GUICtrlCreateButton ("Start",25,70,70,20)
    $def_button = GUICtrlSetState($start, $GUI_DEFBUTTON)
    $cancel = GUICtrlCreateButton ("Cancel",125,70,70,20)
    $howto = GUICtrlCreateButton ("HowTo",25,40,70,20)
    $options = GUICtrlCreateButton ("Options",125,40,70,20)
    ;---------------------------------------------------------------
    GUISetState ()

    [/autoit] [autoit][/autoit] [autoit]

    While 1
    $msg = GUIGetMsg()
    Select
    Case $msg = $GUI_EVENT_CLOSE
    ExitLoop
    Case $msg = $cancel
    ExitLoop
    Case $msg = $howto
    MsgBox (64,"HowTo", ".....")
    Case $msg = $options
    MsgBox (1,"Options", ".....")
    Case $msg = $start
    _count ()
    _count2 ()
    ; Case
    EndSelect
    WEnd
    ;---------------------------------------------------------------

    [/autoit] [autoit][/autoit] [autoit]

    Func TogglePause()
    $Paused = NOT $Paused
    While $Paused
    sleep(100)
    ToolTip('Script is "Paused"',0,0)
    WEnd
    ToolTip("")
    EndFunc ;=> TogglePause

    [/autoit] [autoit][/autoit] [autoit]

    Func _count ()
    GUICtrlSetState($HowTo, $GUI_DISABLE)
    GUICtrlSetState($options, $GUI_DISABLE)
    GUICtrlSetData ($start, "Pause")

    For $i = $s To 10
    $m = GUIGetMsg ()
    If $m = $cancel Then ExitLoop
    If $m = -3 Then ExitLoop
    If $m = $start Then
    GUICtrlSetData ($start, "Next")
    $s = $i ;save the current bar-position to $s
    ExitLoop
    Else
    $s=0
    GUICtrlSetData ($progressbar,$i*10)
    Sleep($wait)
    EndIf
    Next
    EndFunc ; => _count

    [/autoit] [autoit][/autoit] [autoit]

    Func _count2 ()
    GUICtrlSetData ($start, "Start")
    GUICtrlSetData ($progressbar,0)
    GUICtrlSetState($HowTo, $GUI_ENABLE)
    GUICtrlSetState($options, $GUI_ENABLE)
    EndFunc ; => _count2

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit][/autoit] [autoit][/autoit]

    das mit dem hotkey funzt , allerdings würd ich das gerne über einen button im gui machen , gibts da ne möglichkeit ?

    b00ny

  • tach!

    ich glaube nicht das das geht mit dem button weil dein script ja dann in der funktion ist

    mfg DjBasslord

    3 Mal editiert, zuletzt von DjBasslord (5. März 2007 um 20:36)

  • Wie willst du überprüfen ob der Button gedrückt wurde ohne das die OnEvent FUnktion aufgerufen wird? Weil @GUI_CTRLID ändert sich aj erst wenn nen anderes controll gedrückt wurde, was zu Komplikationen führen kann odeR?

  • so... danke für den tipp mit AdlibEnable ;)

    alleine mit der erklaerung oder dem bsp. in der autoit hilfe wär ich da nie drauf gekommen
    die beschreibung dort ist sehr dürftig und das beispiel och...naja..zumindest fuer n noob...
    habs soweit am laufen , nach 3h kopfzerbrechen o_O

    Spoiler anzeigen
    [autoit][/autoit] [autoit][/autoit] [autoit]

    #include <GUIConstants.au3>
    Global $stop
    Global $pause
    Global $Paused
    $hotkey01 = HotKeySet("{PAUSE}", "TogglePause")
    $dui = GUICreate("GUI BSP",220,100, 100,200)
    $progressbar= GUICtrlCreateProgress (10,10,200,20, $PBS_SMOOTH)
    $start = GUICtrlCreateButton ("Start",25,70,70,20)
    $def_button = GUICtrlSetState($start, $GUI_DEFBUTTON)
    $cancel = GUICtrlCreateButton ("Cancel",125,70,70,20)
    $howto = GUICtrlCreateButton ("HowTo",25,40,70,20)
    $options = GUICtrlCreateButton ("Options",125,40,70,20)
    $wait = 2000
    ;---------------------------------------------------------------

    [/autoit] [autoit][/autoit] [autoit]

    GUISetState ()
    AdlibEnable("_progress_exit", 100)
    While 1
    $msg = GUIGetMsg()
    Select
    Case $msg = $GUI_EVENT_CLOSE
    ExitLoop
    Case $msg = $cancel
    ExitLoop
    Case $msg = $howto
    MsgBox (64,"HowTo", "wärend des prozesses reagieren die button ""pause/next"" und ""cancel"" etwas verzögert...verzögerung: ~$wait")
    Case $msg = $options
    MsgBox (1,"Options", ".....")
    Case $msg = $start
    $pause = 1
    _button_disable()
    _progress ()
    _button_enable()
    EndSelect
    WEnd

    [/autoit] [autoit][/autoit] [autoit]

    ;---------------------------------------------------------------
    Func _progress ()
    GUICtrlSetData ($start, "Pause")
    For $i=0 To 10 Step 1
    Select
    Case $stop = 1
    Exit
    Case $pause = 2
    GUICtrlSetData ($start, "Next")
    _progress_pause()
    GUICtrlSetData ($start, "Pause")
    EndSelect
    GUICtrlSetData ($progressbar,$i*(95/10))
    Sleep($wait)
    Next
    EndFunc ; => _progress ()
    ;------------------------------
    Func _progress_exit ()
    While 2
    $msg = GUIGetMsg()
    Select
    Case $msg = $cancel
    $stop = 1
    ExitLoop
    Case $msg = $start And $pause = 1
    $pause= 2
    Case $msg = $start And $pause = 2
    $pause= 1
    EndSelect
    ExitLoop
    WEnd
    EndFunc ; => _progress_exit
    ;------------------------------
    Func _progress_pause()
    While 3
    if $pause = 2 Then
    sleep(500)
    if $stop = 1 Then
    Exit
    EndIf
    Else
    ExitLoop
    EndIf
    WEnd
    EndFunc ; => _progress_pause
    ;------------------------------
    Func _button_disable()
    GUICtrlSetState($HowTo, $GUI_DISABLE)
    GUICtrlSetState($options, $GUI_DISABLE)
    EndFunc ; =>_button_disable
    ;------------------------------
    Func _button_enable ()
    GUICtrlSetData ($start, "Start")
    GUICtrlSetState($HowTo, $GUI_ENABLE)
    GUICtrlSetState($options, $GUI_ENABLE)
    GUICtrlSetData ($progressbar,0)
    EndFunc ; => _button_enable ()
    ;------------------------------
    Func TogglePause()
    $Paused = NOT $Paused
    While $Paused
    sleep(100)
    ToolTip('Script is "Paused"',0,0)
    WEnd
    ToolTip("")
    EndFunc ;=> TogglePause
    ;------------------------------

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit][/autoit]

    wenn noch wer vorschläge/anregungen zum layout/syntax hat nur her damit...bin da in vielen dingen "unsicher" ...

    noch zwei fragen:

    1.kann ich je script nur einmal "AdlibEnable" anwenden ?
    2.das GUI/script reagiert waerend der func "_progress" nur verzoegert auf die buttons, weil es ja immer nach einem step prüft..
    wenn ich das script aber über "hotkey" pausiere oder beende kommt der eingriff sofort , also ohne verzögerung
    wie schaffe ich es diese verzögerung der buttons zu reduzieren bzw ganz (relativ) abzustellen?
    sicher ich koennte in funktion "_progress" die abfrage mehrmals einbauen und in diesem falle $wait "auf die anzahl der abfragen aufteilen
    suche aber ne andere loesung , jemand ne idee ?



    mfG
    b00ny