GUI kontrollieren, trotz Schleife etc. (Adlib)

  • Seid gegrüßt!

    Ich bin ja nun schon relativ lange mit AutoIt 'unterwegs', aber habe gerade was die Kontrolle von GUIs angeht, während das Script normal weiterlaufen soll noch immer meine Probleme.
    Bisher habe ich das Problem immer umgangen und das Script entsprechend angepasst, aber nun eben nicht mehr.

    Das Script ist ein Updater für meine zahlreichen Tools hier in der Firma. Es ist eine UDF die in das jeweilige Script mit eingebunden wird und dann nur mit wenigen Funktionsaufrufen gesteuert wird (den Rest macht die UDF selbst, da die Tools & Server jeweils die selbe Struktur haben).

    Problem: Kontrolle des Updater-GUIs (Buttons, Labels etc. klicken), während der Updater im Hintergrund seine Arbeit verrichtet.
    Das GUI wird von der UDF gestellt und gesteuert, nicht von dem Mainscript.

    Ich hatte mich damals schon damit beschäftigt und mit Adlib rumgespielt und auch damals etwas funktionstüchtiges, einfaches zusammenbekommen (klickbare Buttons, obwohl das Script in einer Schleife irgendwas anderes gemacht hat).
    Keine Ahnung wie ich es damals gemacht habe, aber ich probiere hier schon eine Weile rum und hab schon gut gegoogelt, aber naja... vielleicht kann mir einer von euch das fehlende Bauteil verraten. ;)

    Was ich im Script mache ist, zunächst das GUI per Funktion zu erstellen (klappt) und im Anschluss per Adlib die "master function" (_lib_update_master) aufzurufen, welche den Update Prozess steuert.
    Während diese Funktion arbeitet, soll das GUI jedoch weiterhin ansprechbar sein... was es nicht ist.

    Genauer gesagt, möchte ich das $GUI_B_Patchnotes (Label) anklickbar ist und dann als Event (_lib_changelog()) eine Datei öffnet.

    Wo liegt der (Denk-)Fehler?

    Zum Testen des Scripts:
    Ordnerstrktur erstellen: %userprofile%\DublinTools\CTI\download
    In \download die Datei "CTI.notes" mit min 1 Zeile erstellen, sowie die Datei "changelog.txt".

    Source vom Updater (bei weitem noch nicht vollständig):

    Spoiler anzeigen
    [autoit]

    #include <GUIConstantsEx.au3>
    #include <ProgressConstants.au3>
    #include <StaticConstants.au3>
    #include <WindowsConstants.au3>
    #include <File.au3>
    ;~ Opt("GUIOnEventMode", 1)

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

    Global $GUI_W_Splash, $GUI_W_Image, $GUI_Progress_Main, $GUI_Progress_Sub, $GUI_L_Headline, $GUI_L_Patchnotes, $GUI_B_Patchnotes, $GUI_Box_Patchnotes, $GUI_L_Progress_Main, $GUI_L_Progress_Sub
    Global $int_BetaUpdate = 0, $int_ProjectName, $int_Logfile
    Global $upd_PathServer, $upd_PathClient, $upd_PathRestart, $upd_VersServer, $upd_VersClient, $upd_FileInformation, $upd_FileNotes, $upd_FileRads, $upd_ArrayInformation, $upd_ArrayNotes, $upd_DataNotes

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

    $upd_PathServer = "\\riot3\File Transfer\DublinTools\"
    $upd_PathClient = @UserProfileDir & "\DublinTools\"
    $upd_VersClient = FileGetVersion(@ScriptFullPath)

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

    Func _lib_update_GuiCreate()
    $GUI_W_Splash = GUICreate("Updater", 650, 391, -1, -1, BitOR($WS_MINIMIZEBOX,$WS_POPUP,$WS_GROUP))
    GUISetFont(9, 400, 0, "Cambria")
    $GUI_W_Image = GUICtrlCreatePic("C:\Users\dbusch\Desktop\Tools\CTI\assets\splash.jpg", 0, 0, 668, 404, BitOR($SS_NOTIFY,$WS_GROUP))
    $GUI_Progress_Sub = GUICtrlCreateProgress(24, 315, 270, 11, BitOR($PBS_SMOOTH,$WS_BORDER))
    $GUI_Progress_Main = GUICtrlCreateProgress(24, 350, 270, 11, BitOR($PBS_SMOOTH,$WS_BORDER))
    $GUI_L_Headline = GUICtrlCreateLabel("", 24, 24, 271, 18)
    $GUI_L_Patchnotes = GUICtrlCreateLabel("Changelog Preview", 24, 65, 175, 15)
    $GUI_B_Patchnotes = GUICtrlCreateLabel("full changelog", 220, 65, 75, 15, $WS_BORDER)
    $GUI_Box_Patchnotes = GUICtrlCreateLabel("", 24, 80, 271, 202, $WS_BORDER)
    $GUI_L_Progress_Sub = GUICtrlCreateLabel("", 24, 300, 270, 15)
    $GUI_L_Progress_Main = GUICtrlCreateLabel("", 24, 335, 270, 15)

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

    GUICtrlSetBkColor($GUI_L_Headline, $GUI_BKCOLOR_TRANSPARENT)
    GUICtrlSetBkColor($GUI_L_Patchnotes, $GUI_BKCOLOR_TRANSPARENT)
    GUICtrlSetBkColor($GUI_Box_Patchnotes, $GUI_BKCOLOR_TRANSPARENT)
    GUICtrlSetBkColor($GUI_B_Patchnotes, $GUI_BKCOLOR_TRANSPARENT)
    GUICtrlSetBkColor($GUI_L_Progress_Main, $GUI_BKCOLOR_TRANSPARENT)
    GUICtrlSetBkColor($GUI_L_Progress_Sub, $GUI_BKCOLOR_TRANSPARENT)
    GUICtrlSetState($GUI_Box_Patchnotes, $GUI_HIDE)
    GUICtrlSetState($GUI_L_Patchnotes, $GUI_HIDE)
    GUICtrlSetState($GUI_B_Patchnotes, $GUI_HIDE)
    GUICtrlSetColor($GUI_L_Headline, 0xBF9B3B) ; gold
    GUICtrlSetColor($GUI_L_Patchnotes, 0xBF9B3B) ; gold
    GUICtrlSetColor($GUI_Box_Patchnotes, 0x3061BE) ; blue
    GUICtrlSetColor($GUI_B_Patchnotes, 0x3061BE) ; blue
    GUICtrlSetColor($GUI_L_Progress_Main, 0xBF9B3B) ; gold
    GUICtrlSetColor($GUI_L_Progress_Sub, 0xBF9B3B) ; gold
    GUICtrlSetFont($GUI_L_Headline, 12, 800, 0, "Cambria")
    GUICtrlSetFont($GUI_L_Patchnotes, 10, 800, 0, "Cambria")
    ;~ GUICtrlSetFont($GUI_Box_Patchnotes, 9, 400, 0, "Cambria")
    ;~ GUICtrlSetOnEvent($GUI_B_Patchnotes, "_lib_changelog")

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

    GUISetState(@SW_SHOW)
    EndFunc

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

    _lib_update_GuiCreate()
    AdlibRegister('_adlib')

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

    While 1
    $msg = GUIGetMsg()
    If $msg = $GUI_B_Patchnotes Then _lib_changelog()

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

    Sleep(100)
    WEnd

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

    Func _adlib()
    _lib_update_Master("CTI", 1)
    ;~ AdlibUnRegister("_adlib")
    EndFunc

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

    Func _lib_changelog()
    ShellExecute($upd_PathClient & "\download\changelog.txt")
    EndFunc

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

    Func _lib_update_Master($pProjectName, $pUpdateStep, $pBetaUpdate = 0)
    Local $tUpdate = 0
    $int_ProjectName = $pProjectName
    $int_BetaUpdate = $pBetaUpdate
    $int_Logfile = $pProjectName & ".log"
    $upd_PathClient &= $int_ProjectName
    $upd_PathServer &= $int_ProjectName
    $upd_FileInformation = $int_ProjectName & ".update" ; update information
    $upd_FileNotes = $int_ProjectName & ".notes" ; patchpreview
    $upd_FileRads = $int_ProjectName & ".rads" ; tool structure information (for RADS check)
    If $int_BetaUpdate = 1 Then $upd_PathServer &= "\Beta"

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

    GUICtrlSetData($GUI_L_Headline, "Launching " & $int_ProjectName)

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

    Select
    Case $pUpdateStep = 1
    If Not FileExists($upd_PathClient & "\download") Then DirCreate($upd_PathClient & "\download")

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

    _lib_update_GuiSetState(11)
    _lib_update_getInformation()

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

    _lib_update_GuiSetState(12)
    $tUpdate = _lib_update_checkVersion()
    If $tUpdate = 1 Then
    _lib_update_GuiSetState(13)
    _lib_update_getNotes()
    _lib_update_GuiSetState(14)
    ;~ _lib_update_getRads()
    Else
    _lib_update_GuiSetState(50) ; no update / launch tool
    Return
    EndIf
    EndSelect
    EndFunc

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

    Func _lib_update_getInformation()
    Local $answer

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

    If FileExists($upd_PathClient & "\" & $upd_FileInformation) Then
    _FileReadToArray($upd_PathClient & "\" & $upd_FileInformation, $upd_ArrayInformation)
    Else
    FileCopy($upd_PathServer & "\" & $upd_FileInformation, $upd_PathClient & "\" & $upd_FileInformation, 1)
    _FileReadToArray($upd_PathClient & "\" & $upd_FileInformation, $upd_ArrayInformation)
    EndIf

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

    If Not IsArray($upd_ArrayInformation) Then MsgBox(48, "ERROR", "ERROR - No Information Array!")
    EndFunc

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

    Func _lib_update_getNotes()
    Local $answer, $i

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

    If FileExists($upd_PathClient & "\download\" & $upd_FileNotes) Then
    _FileReadToArray($upd_PathClient & "\download\" & $upd_FileNotes, $upd_ArrayNotes)
    Else
    FileCopy($upd_PathServer & "\" & $upd_FileNotes, $upd_PathClient & "\download\" & $upd_FileNotes, 1)
    _FileReadToArray($upd_PathClient & "\download\" & $upd_FileNotes, $upd_ArrayNotes)
    EndIf

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

    If Not IsArray($upd_ArrayNotes) Then
    MsgBox(48, "ERROR", "ERROR - No Patchnotes Array!")
    Else
    For $i=1 To $upd_ArrayNotes[0] Step 1
    $upd_DataNotes &= $upd_ArrayNotes[$i] & @CRLF
    Next
    GUICtrlSetData($GUI_Box_Patchnotes, $upd_DataNotes)
    GUICtrlSetState($GUI_Box_Patchnotes, $GUI_SHOW)
    GUICtrlSetState($GUI_L_Patchnotes, $GUI_SHOW)
    GUICtrlSetState($GUI_B_Patchnotes, $GUI_SHOW)
    EndIf
    EndFunc

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

    Func _lib_update_GuiSetState($pState)
    Select
    Case $pState = 11
    GUICtrlSetData($GUI_Progress_Sub, 5)
    GUICtrlSetData($GUI_Progress_Main, 2)
    GUICtrlSetData($GUI_L_Progress_Sub, "retrieving information")
    GUICtrlSetData($GUI_L_Progress_Main, "checking for updates")

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

    Case $pState = 12
    GUICtrlSetData($GUI_Progress_Sub, 40)
    GUICtrlSetData($GUI_Progress_Main, 10)
    GUICtrlSetData($GUI_L_Progress_Sub, "comparing versions")

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

    Case $pState = 13
    GUICtrlSetData($GUI_Progress_Sub, 60)
    GUICtrlSetData($GUI_Progress_Main, 15)
    GUICtrlSetData($GUI_L_Progress_Sub, "retrieving changelogs")

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

    Case $pState = 14
    GUICtrlSetData($GUI_Progress_Sub, 80)
    GUICtrlSetData($GUI_Progress_Main, 20)
    GUICtrlSetData($GUI_L_Progress_Sub, "retrieving update details")

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

    Case $pState = 50
    GUICtrlSetData($GUI_Progress_Sub, 100)
    GUICtrlSetData($GUI_Progress_Main, 100)
    GUICtrlSetData($GUI_L_Progress_Sub, "Done")
    GUICtrlSetData($GUI_L_Progress_Main, "Launching " & $int_ProjectName)
    Sleep(2500)
    EndSelect
    EndFunc

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

    Func _lib_update_checkVersion()
    Local $answer
    ;~ $upd_VersServer = $upd_ArrayInformation[1]
    $upd_VersServer = 1

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

    If $upd_VersServer > $upd_VersClient Then
    $answer = MsgBox(64+4, "Updater", "Update available!" & @CRLF & @CRLF & _
    "Targeted Tool: " & $int_ProjectName & @CRLF & _
    "Your Version: " & $upd_VersClient & @CRLF & _
    "Server Version: " & $upd_VersServer & @CRLF & @CRLF & _
    "Proceed and update to latest version?")

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

    If $answer = 6 Then
    Return 1
    Else
    Return 0
    EndIf
    EndIf
    EndFunc

    [/autoit]

    Einmal editiert, zuletzt von Matricus (28. Oktober 2011 um 15:52)

  • Moin Moin,

    wie läuft denn deine "Hauptschleife" - sprich läuft dein programm in einer Endloschleife wie Sie z.B. der Koda-Form Designer vorschlägt:

    [autoit]


    While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
    Case $GUI_EVENT_CLOSE
    Exit
    Case $InputKennwort
    Case $ButtonKennwort
    Case $LabelBenutzernamen
    EndSwitch
    WEnd

    [/autoit]

    Wenn ja - schau dir mal die Hilfe von GUICtrlSetOnEvent an. ( http://www.autoitscript.com/autoit3/docs/f…lSetOnEvent.htm ) - Damit habe ich zwar auch noch nicht gerbeitet aber das müsste der Weg sein (sehe ich in vielen Beispielen.

    Das hier von Oscar macht genau das was du willst - es arbeite im Hintergund weiter (Uhr hochzählen) und trotzdem kannst du die Buttons anklicken:
    Stadion-Uhr

    BLinz(ler) :pinch:

  • Das Problem dabei ist, dass das Script eine UDF ist, sprich in das Hauptscript hinzugefügt wird.
    Das Hauptscript macht währenddessen nichts (akzeptiert auch keine GUI-Anfragen, da es noch kein GUI zeigt), es wartet bis die UDF einen Wert zurückgibt.

    Das von dir verlinkte Script verwendet interne Zählfunktionen (Differenz seit Start), weswegen das GUI permanent angesprochen werden kann.
    Anders als mein Script läuft der Counter permanent in der GUI-Schleife und wartet auf GUI-Events (OnClick) um dann Funktion X auszuführen.
    Mein Script soll jedoch in der GUI-Schleife laufen (ob nun GetMsg oder OnEvent ist egal), aber nebenbei automatisch einen bestimmten Ablauf durchlaufen und dennoch bei GuiEvent X, Funktion Y aufrufen.

    Ich werde die UDF einfach mal standalone als executable machen und per cmdline aufrufen, sollte niemand eine zündende Idee haben.

    ps: Ich habe mal ein Bild vom Updater angehangen.
    Dass Control das angesteuert werden können soll ist "full changelog" ($GUI_B_Patchnotes), welches dann bei Klick eine .txt Datei öffnet.

  • Okay, die Lösung war einfacher als gedacht.

    Das Script hat, so wie es gedacht war, schon funktioniert, nur seltsamerweise hat das "Hintergrundbild", die Splash Art, die Controls beim klicken überlagert, sodass keine Events empfangen wurden.
    Als ich nun das Image Control als letztes deklariert habe, funktionierten die Events wie gewünscht, nur mit dem Fehler, dass die Controls nun tatsächlich hinter dem Bild waren (nicht sicht- aber anklickbar).

    Als Lösung dafür: 2 GUIs erstellt (parent & child), eines für den Hintergrund, das andere als overlay für die controls.
    Etwas umständlicher, wird aber funktionieren...

  • Schön das du dir zu helfen weist, geht aber viel einfacher ;)

    [autoit]

    $cBG = GUICtrlCreatePic($path, 0, 0, 253, 149)
    GUICtrlSetState(-1, $GUI_DISABLE)

    [/autoit]

    Durch das $GUI_DISABLE sollten die Events ganz normal empfangen werden :)

    MfG hellboy

    [autoit]

    Do
    _help($user)
    Until $questions = 0

    [/autoit]

    Meine Werke:
    Ste`s Web-Radio

  • Schön das du dir zu helfen weist, geht aber viel einfacher ;)

    [autoit]

    $cBG = GUICtrlCreatePic($path, 0, 0, 253, 149)
    GUICtrlSetState(-1, $GUI_DISABLE)

    [/autoit]

    Durch das $GUI_DISABLE sollten die Events ganz normal empfangen werden :)

    *-*
    Das ich auf solch eine einfache Lösung nicht komme... Ist aber immer so, ich denke zu kompliziert. ;)

    Vielen Dank dafür, funktioniert!