Live-Log

  • Hey Leute,

    gibt es eine coole UDF oder Snippet zu einem Live-Log :)?
    Ich habe mir das mit nem List-Element umgesetzt

    Spoiler anzeigen
    [autoit]

    $sSpace = " "
    $listLog = GUICtrlCreateList($sSpace & "Log <- Hier halte ich dich up2date! ->", 50, 480, 520, 100, BitOR($WS_BORDER, $WS_VSCROLL, $LBS_NOTIFY, $LBS_DISABLENOSCROLL, $LBS_NOSEL), $WS_EX_WINDOWEDGE)
    GUICtrlSetFont(-1, 7)
    GUICtrlSetBkColor(-1, 0x000000)
    GUICtrlSetColor(-1, 0xFFFFFF)

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

    Func _log($text)
    FileWrite($file, _NowTime() & " -> " & $text & @CRLF)
    $aResult = StringRegExp($text, ".{85,105} (.)", 3)
    If Not @error Then
    GUICtrlSetData($listLog, _NowTime() & " -> " & StringReplace($text, $aResult[0], "|" & $aResult, 1) & "|")
    Else
    GUICtrlSetData($listLog, _NowTime() & " -> " & $text & "|")
    EndIf
    _GUICtrlListBox_SetTopIndex($listLog, _GUICtrlListBox_GetCount($listLog) - 1)
    EndFunc ;==>_log

    [/autoit]

    Das sieht auch ganz nett aus, allerdings wird der String ja, wenn er zu lang ist, getrennt und in die nächste Zeile geschrieben. Allerdings sieht das dann ja so aus:

    Zitat

    ___________________________________Log <- Hier halte ich dich up2date! ->
    11:35:51 -> Blablablablablablab
    BlablablablablablabBlablablablablablabBlablablablablablabBlablablablablablabBlablablablablablabBlablablablablablab!

    Und das nervt micht :D... Aber mit Leerzeichen ausrichten klappt auch nicht "ordentlich" ausgerichtet... Und meine Trenn-Funktion scheint auch nicht immer sauber zu arbeiten...^^ Jemand ne Idee :)?

    LG
    Aca

    Einmal editiert, zuletzt von Acanis (18. Juli 2013 um 13:40)

  • Hey,

    das ist schon netter, hier mal als lauffähiges Beispiel... Aber wie kriegt man nen "sauberen" Zeilenumbruch hin?

    Spoiler anzeigen
    [autoit]

    #include <GUIConstantsEx.au3>
    #include <WindowsConstants.au3>
    #include <ListboxConstants.au3>
    #include <Date.au3>
    #include <GuiListBox.au3>

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

    Example1()

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

    Func Example1()
    Local $msg

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

    GUICreate("My GUI", 600, 600) ; will create a dialog box that when displayed is centered

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

    $sSpace = " "
    Global $listLog = GUICtrlCreateList(StringFormat("%91s", "Log <- Hier halte ich dich up2date! ->"), 50, 480, 520, 100, BitOR($WS_BORDER, $WS_VSCROLL, $LBS_NOTIFY, $LBS_DISABLENOSCROLL, $LBS_NOSEL), $WS_EX_WINDOWEDGE)
    GUICtrlSetFont(-1, 7)
    GUICtrlSetBkColor(-1, 0x000000)
    GUICtrlSetColor(-1, 0xFFFFFF)

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

    $Button_1 = GUICtrlCreateButton("Test", 10, 30, 100)

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

    GUISetState(@SW_SHOW)

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

    ; Run the GUI until the dialog is closed
    While 1
    $msg = GUIGetMsg()
    Select
    Case $msg = $GUI_EVENT_CLOSE
    Exit
    Case $msg = $Button_1
    _log("Testsasasasasasasasasasasasasa sasasasasasasasasasasasasa dsddddddddddddddddddddd asssssssssssss feeeeeeeeeeeeeeeeee fasssssssssss fass")
    EndSelect
    WEnd
    EndFunc ;==>Example1

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

    Func _log($text)
    $aResult = StringRegExp($text, ".{85,105} (.)", 3)
    If Not @error Then
    GUICtrlSetData($listLog, _NowTime() & " -> " & StringReplace($text, $aResult[0], "|" & $aResult, 1) & "|")
    Else
    GUICtrlSetData($listLog, _NowTime() & " -> " & $text & "|")
    EndIf
    _GUICtrlListBox_SetTopIndex($listLog, _GUICtrlListBox_GetCount($listLog) - 1)
    EndFunc ;==>_log

    [/autoit]

    LG
    Aca

  • Warum nimmst du nicht StringFormat mit in GUICtrlSetData rein?
    Ist ja nur für die Überschrift ^^

  • Ich brauche nur n richtiges Pattern, glaube ich... Mit: (?:(.{60,75})\s){1}(.+) kriege ich z.B. ein Array mit dem 1. Teilstring zwischen 60 und 75 und dann dem Rest... Aber es kann ja sein, dass mal etwas über 3 Zeilen geht... Und will nicht für jeden Fall n eigenes Pattern machen^^...


    LG
    Aca

    *edit*
    Also Ziel: Pattern, dass mir einen String in Teilstrings zerlegt, wo es eine Leerstelle zwischen Stelle X und Y findet!

  • Hey,

    das ist schon netter, hier mal als lauffähiges Beispiel... Aber wie kriegt man nen "sauberen" Zeilenumbruch hin?

    [...]


    Sucht du eventuell

    [autoit]

    @CRLF

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

    ;Beispiel:
    ConsoleWrite("Text")
    ConsoleWrite("Text mit Zeilenumbruch (@CRLF)" & @CRLF)

    [/autoit]


    MfG

    There's a joke that C has the speed and efficieny of assembly language combined with readability of....assembly language. In other words, it's just a glorified assembly language. - Teh Interwebz

    C makes it easy to shoot yourself in the foot; C++ makes it harder, but when you do, you blow off your whole leg. - Bjarne Stroustrup
    Genie zu sein, bedeutet für mich, alles zu tun, was ich will. - Klaus Kinski

  • Hey Pain,

    nein...^^ Wie ich einen Zeilenumbruch mache, weiß ich (ist im Beispiel ja drin), nur wie ich einen String an einer sauberen Stelle zwischen Zeichen X und Zeichen Y breche, also die Teilstrings bekomme, das klappt nicht so 100%ig :D.


    LG
    Aca

    *edit*

    Spoiler anzeigen
    [autoit]

    #include <GUIConstantsEx.au3>
    #include <WindowsConstants.au3>
    #include <ListboxConstants.au3>
    #include <Date.au3>
    #include <GuiListBox.au3>
    #include <Array.au3>

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

    Example1()

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

    Func Example1()
    Local $msg

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

    GUICreate("My GUI", 600, 600) ; will create a dialog box that when displayed is centered

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

    Global $listLog = GUICtrlCreateList(StringFormat("%91s", "Log <- Hier halte ich dich up2date! ->"), 50, 480, 520, 100, BitOR($WS_BORDER, $WS_VSCROLL, $LBS_NOTIFY, $LBS_DISABLENOSCROLL, $LBS_NOSEL), $WS_EX_WINDOWEDGE)
    GUICtrlSetFont(-1, 7)
    GUICtrlSetBkColor(-1, 0x000000)
    GUICtrlSetColor(-1, 0xFFFFFF)

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

    $Button_1 = GUICtrlCreateButton("Test", 10, 30, 100)

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

    GUISetState(@SW_SHOW)

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

    ; Run the GUI until the dialog is closed
    While 1
    $msg = GUIGetMsg()
    Select
    Case $msg = $GUI_EVENT_CLOSE
    Exit
    Case $msg = $Button_1
    _log("Testsasasasasasasasasasasasasa sasasasasasasasa sasassssssssss dasdsasasasasasasasa dassda dassd sdassdsasasasasasa dsdddddddddddd ddddddddd asssssssssssss feeeeeeeeeeeeeeeeee fasssssssssss f23233223ass")
    EndSelect
    WEnd
    EndFunc ;==>Example1

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

    Func _log($text)
    Local $sResult, $iMaxChars = 75, $bFirstLine = True

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

    If StringLen($text) >= $iMaxChars Then
    $aResult = StringSplit($text, " ", 2)

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

    For $i = 0 To UBound($aResult) - 1
    If (StringLen($sResult) + StringLen($aResult[$i])) < $iMaxChars Then
    ConsoleWrite(StringLen($sResult) & @CRLF)
    $sResult &= $aResult[$i] & " "
    Else
    If $bFirstLine Then
    GUICtrlSetData($listLog, "[" & _NowTime() & "]: " & $sResult & "|")
    $bFirstLine = False
    $iMaxChars = 60
    Else
    GUICtrlSetData($listLog, " " & $sResult & "|")
    EndIf

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

    $sResult = ""
    EndIf
    Next

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

    If StringLen($sResult) > 0 Then GUICtrlSetData($listLog, " " & $sResult & "|")
    Else
    GUICtrlSetData($listLog, "[" & _NowTime() & "]: " & $text & "|")
    EndIf

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

    _GUICtrlListBox_SetTopIndex($listLog, _GUICtrlListBox_GetCount($listLog) - 1)
    EndFunc ;==>_log

    [/autoit]

    So habe ichs nu gelöst... StringFormat hat irgendwie nicht richtig geklappt, zum Einrücken in den Zeilen... Aber die Lösung scheint mir ganz praktabel^^...

    5 Mal editiert, zuletzt von Acanis (18. Juli 2013 um 13:39)