gui- loop-problem

  • hi!

    hab da wieder ein kleines problem mit meinem script..

    Spoiler anzeigen
    [autoit]

    #include <GuiConstants.au3>

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

    #region start-gui
    $gui_start = GuiCreate("Quotenlisten-TOOL",166,73,-1,-1,$WS_POPUPWINDOW)
    WinSetOnTop("Quotenlisten-TOOL","",1)

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

    GuiCtrlCreateLabel("Quotenlisten-Tool starten?", 18, 11, 130, 20)
    $b_ja = GuiCtrlCreateButton("Ja", 14, 40, 60, 20)
    $b_nein = GuiCtrlCreateButton("Nein", 91, 40, 60, 20)
    GuiSetState()
    #endregion end start-gui

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

    #region haupt-gui
    $gui_haupt = GUICreate("Quotenlisten-TOOL", 297, 230, -1, -1,-1,$WS_EX_APPWINDOW,$gui_start)
    GUICtrlCreateLabel("Quotenlisten alle", 5, 14, 80, 20)
    $i_mins = GUICtrlCreateInput("10", 90, 11, 50, 20, $ES_NUMBER)
    GUICtrlCreateUpdown(-1)
    GUICtrlSetLimit(-1,9999,10)
    GUICtrlCreateLabel("Minuten drucken und uploaden", 143, 16, 161, 17)

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

    $b_start = GUICtrlCreateButton("START", 110, 40, 70, 20)

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

    $infotext = GUICtrlCreateLabel(" (im stop-modus)", 50, 70, 220, 20)

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

    $pr_print = GuiCtrlCreateProgress(75, 90, 190, 10, $PBS_SMOOTH)
    $pr_up = GuiCtrlCreateProgress(75, 103, 190, 10, $PBS_SMOOTH)
    GuiCtrlCreateLabel("print-status", 20, 88, 52, 15)
    GuiCtrlCreateLabel("upload-status", 9, 101, 64, 15)
    $printprozent = GuiCtrlCreateLabel("0%", 266, 88, 40, 15)
    $upprozent = GuiCtrlCreateLabel("0%", 266, 101, 40, 15)

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

    $ed_status = GUICtrlCreateEdit("", 10, 120, 277, 100,$ES_READONLY)
    #endregion haupt-gui ende

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

    #region stop?-gui
    $gui_stop = GuiCreate("ERROR #1337",120,80,-1, -1,$WS_DLGFRAME,-1,$gui_haupt)
    WinSetOnTop("ERROR #1337","",1)
    GuiCtrlCreateLabel("Bitte zuerst stoppen!", 15, 9, 130, 20)
    $b_ok1 = GuiCtrlCreateButton("ok", 30, 33, 60, 20)
    #endregion end stop?-gui

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

    #region mindestwert-gui
    $gui_mindest = GuiCreate("ERROR #123",120,80,-1, -1,$WS_DLGFRAME,-1,$gui_haupt)
    WinSetOnTop("ERROR #123","",1)
    GuiCtrlCreateLabel("Mindestwert: 10", 15, 9, 130, 20)
    $b_ok2 = GuiCtrlCreateButton("ok", 30, 33, 60, 20)
    #endregion end mindestwert-gui

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

    While 1
    $msg = GuiGetMsg(1)
    Switch $msg[0]
    Case $b_nein
    Exit
    Case $b_ja
    GuiSetState()
    GUISetState(@SW_HIDE,$gui_start)
    GUISetState(@SW_HIDE,$gui_stop)
    GUISetState(@SW_HIDE,$gui_mindest)
    GUISetState(@SW_SHOW,$gui_haupt)
    Case $b_start
    If GUICtrlRead($b_start) = "START" Then
    startmodus()
    Else
    stopmodus()
    EndIf
    Case $b_ok1
    GUISetState(@SW_HIDE,$gui_stop)
    GUISetState(@SW_RESTORE,$gui_haupt)
    GUISetState(@SW_ENABLE,$gui_haupt)
    Case $b_ok2
    GUISetState(@SW_HIDE,$gui_mindest)
    GUISetState(@SW_RESTORE,$gui_haupt)
    GUISetState(@SW_ENABLE,$gui_haupt)
    Case $GUi_EVENT_CLOSE
    If GUICtrlRead($b_start) = "stop" Then
    GUISetState(@SW_SHOW,$gui_stop)
    GUISetState(@SW_RESTORE,$gui_stop)
    GUISetState(@SW_DISABLE,$gui_haupt)
    Else
    undtschuess()
    EndIf
    EndSwitch
    WEnd
    Exit

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

    Func stopmodus()
    GUICtrlSetState($i_mins, $GUI_ENABLE)
    GUICtrlSetData($b_start, "START")
    GUICtrlSetData($infotext, " (im stop-modus)")
    GUICtrlSetData($printprozent, "0%")
    GUICtrlSetData($pr_print, "0")
    GUICtrlSetData($upprozent, "0%")
    GUICtrlSetData($pr_up, "0")
    EndFunc

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

    Func startmodus()
    $mintimer = GUICtrlRead($i_mins)
    If $mintimer <= 9 Then
    GUICtrlSetData($i_mins, 10)
    $mintimer = 10

    GUISetState(@SW_DISABLE,$gui_haupt)
    GUISetState(@SW_RESTORE,$gui_mindest)
    GUISetState(@SW_SHOW,$gui_mindest)
    Else
    GUICtrlSetData($b_start, "stop")
    GUICtrlSetData($printprozent, "0%")
    GUICtrlSetData($pr_print, "0")
    GUICtrlSetData($upprozent, "0%")
    GUICtrlSetData($pr_up, "0")
    GUISetState(@SW_DISABLE, $gui_haupt)
    GUICtrlSetState($i_mins, $GUI_DISABLE)
    printupdate()

    EndIf
    EndFunc

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

    Func printupdate()
    $printprogresstimer = GUICtrlRead($pr_print)
    GUICtrlSetData($infotext, " printing")
    GUISetState(@SW_DISABLE, $b_start)
    While $printprogresstimer < 100
    Sleep(1)
    $printprogresstimer += 1
    GUICtrlSetData($b_start, "printing")
    GUICtrlSetData($pr_print, $printprogresstimer)
    GUICtrlSetData($printprozent, $printprogresstimer & "%")
    WEnd
    If $printprogresstimer = 100 Then uploadupdate()
    EndFunc

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

    Func uploadupdate()
    $upprogresstimer = GUICtrlRead($pr_up)
    GUICtrlSetData($infotext, " uploading")
    While $upprogresstimer < 100
    Sleep(1)
    $upprogresstimer += 1
    GUICtrlSetData($b_start, "uploading")
    GUICtrlSetData($pr_up, $upprogresstimer)
    GUICtrlSetData($upprozent, $upprogresstimer & "%")
    WEnd
    if $upprogresstimer = 100 Then
    GUICtrlSetData($b_start, "stop")
    GUICtrlSetState($b_start, $GUI_ENABLE)
    GUISetState(@SW_ENABLE, $gui_haupt)
    GUISetState(@SW_ENABLE, $b_start)
    timer($i_mins)
    EndIf
    EndFunc

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

    Func timer($label)
    $label = GUICtrlRead($i_mins)
    Local $time = TimerInit()
    While 1
    $nMsg = GUIGetMsg(1)
    Switch $nMsg[0]
    Case $GUi_EVENT_CLOSE
    GUISetState(@SW_SHOW,$gui_stop)
    GUISetState(@SW_RESTORE,$gui_stop)
    GUISetState(@SW_DISABLE,$gui_haupt)
    Case $b_ok1
    GUISetState(@SW_HIDE,$gui_stop)
    GUISetState(@SW_RESTORE,$gui_haupt)
    GUISetState(@SW_ENABLE,$gui_haupt)
    EndSwitch
    $new = ($label * 1000) - TimerDiff($time)
    $seconds = Round($new / 1000)
    $newMin = Floor($seconds / 60)
    $newSec = Mod($seconds, 60)
    If $newSec < 10 Then $newSec = "0" & $newSec
    If $newMin < 10 Then $newMin = "0" & $newMin
    If ($newMin > 0 Or Number($newSec) > 0) Then
    Sleep(30)
    GUICtrlSetData($infotext, "nächster druck/upload in " & $newMin & " Min " & $newSec & " Sek")
    If GUIGetMsg() = $b_start Then
    stopmodus()
    ExitLoop
    EndIf
    ElseIf $newSec = 0 Then
    GUICtrlSetData($printprozent, "0%")
    GUICtrlSetData($pr_print, "0")
    GUICtrlSetData($upprozent, "0%")
    GUICtrlSetData($pr_up, "0")
    printupdate()
    Sleep(30)
    EndIf
    WEnd
    EndFunc

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

    Func undtschuess()
    WinSetOnTop("Quotenlisten-TOOL","",2)
    MsgBox(64, "thx for using blub-products", "©2007 - xxx", 2)
    WinSetOnTop("thx for using blub-products","",1)
    Exit
    EndFunc

    [/autoit]

    also der 1. durchlauf funktioniert problemlos - aber sobald ich mal gestartet hab, und der 1. durchlauf fertig ist, "funktioniert" der stop/start button nichtmehr richtig, und während dem upload und print prozess ist der button seltsamer weise auch nichtmehr deaktiviert..
    statt zu stoppen, startet es dann immer neu..

    komm einfach nicht auf meinen fehler.. sieht wer was?
    bin dankbar für alles!

    (ps.: eingabe is absichtlich in sekunden :p )

    • Offizieller Beitrag

    Was mir zumindest sofort auffällt:
    In deiner Func "startmodus()" fehlt die Umbenennung des Buttons ( GUICtrlSetData($b_start, "STOP") ). Denn du willst ja eine Switchfunktion für den Button erreichen.
    Ich finde es aber etwas kompliziert per Auslesen der Beschriftung des Buttons den Status zu erfragen. Hier würde ich mit Boolscher Variable arbeiten.

    [autoit]

    Dim $statusStart = True
    ;..
    ;..
    Case $b_start
    If $statusStart Then
    ; Code für Startmodus
    Else
    ; Code für Stopmodus
    EndIf
    $statusStart = Not $statusStart ; aus True wird False u. umgekehrt
    ;..

    [/autoit]
  • hmm.. stimmt eigentlich - weiss nicht wieso ich nicht gleich draufgekommen bin - thx auf jedenfall mal :) werds gleich probiern

    edit: grad gesehn das der button eh umbenannt wird im "startmodus" - also vondaher stimmts ja von der logik theoretisch - aber trotzdem is da noch wo der hund drinnen :(

    Einmal editiert, zuletzt von derblub (2. Oktober 2007 um 13:43)