Jump to content

How best to implement a scrolling log


deadbug
 Share

Recommended Posts

I want to implement a scrolling log window to let the user know how my autoit script is getting along.

I expect that this log could be several hundred lines long.

It looks like I can achieve what I want using an Edit box, setting it to read only (so the user cannot scribble in it) and then write to it when more data needs to be displayed.

But it looks like the "write to it" part is really: "read what the edit box contents", tag on additional contents, rewrite edit box.

I can possibly optimise slightly by always remembering what was last written to the box.

But either way, it means that each time I update the log, I need to rewrite the entire log.

Is this the correct approach? It feels "inefficient". Is there a better way?

Link to comment
Share on other sites

I want to implement a scrolling log window to let the user know how my autoit script is getting along.

I expect that this log could be several hundred lines long.

It looks like I can achieve what I want using an Edit box, setting it to read only (so the user cannot scribble in it) and then write to it when more data needs to be displayed.

But it looks like the "write to it" part is really: "read what the edit box contents", tag on additional contents, rewrite edit box.

I can possibly optimise slightly by always remembering what was last written to the box.

But either way, it means that each time I update the log, I need to rewrite the entire log.

Is this the correct approach? It feels "inefficient". Is there a better way?

You can add lines to an edit without having to rewrite the whole edit, see the help for GuiCtrlSetData or look up _GUICtrlEdit_AppendText.
Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
Share on other sites

#include <GDIPlus.au3>
#include <GUIEdit.au3>
#include <EditConstants.au3>

$status = GUICtrlCreateEdit("", 8, 104, 609, 169, BitOR($ES_AUTOVSCROLL, $ES_READONLY, $ES_WANTRETURN, $WS_VSCROLL))
GUICtrlSetData(-1, "Status Box" & @CRLF)
GUICtrlSetFont(-1, 8, 400, 0, "Terminal")
GUICtrlSetBkColor(-1, 0xCCCCCC)

... make a gui :)

_s("Add something to the status box function")

Func _s($line)
    local $set_status = GUICtrlRead($status)
    $line = $set_status & $line
    GUICtrlSetData($status, $line & @CRLF)
    _GUICtrlEdit_Scroll($status, $SB_SCROLLCARET)
EndFunc   ;==>_s

I am not sure if you need all those includes. I am just learning au3 myself.

I write sometimes 1000+ lines to it :)

Edited by avery
www.abox.orgAvery HowellVisit My AutoIt Websitehttp://www.abox.org
Link to comment
Share on other sites

I take it this is whag you wanted to do. All you need to do is read what the log already says and set the editbox data to what the new line is, plus your old data. You do not need to write is all in again Here is an example of a small MSN syle chat I made for you.

Run it and type a few things into the first box and press send. Then type something else ect.

#include <GUIConstants.au3>
    
$name = inputbox ( "Name" , "What is your name?" ) 

Guicreate ( "Example" , 200, 200)
$button = guictrlcreatebutton ( "Send" , 1,1,30)
$box = guictrlcreateinput ( "" , 1,30, 170, 30)
$main = GUICtrlCreateedit ( "", 1, 70, 190, 120)

GUISetState ()
While 1
   $msg = GUIGetMsg()
Select

Case $msg = $GUI_EVENT_CLOSE
    exitloop
    
Case $msg = $button
    $boxread = guictrlread ( $box )
    $mainread = guictrlread ( $main )
    GUIctrlsetdata ( $main , $name & ": " & $boxread & @CRLF & $mainread )  
    
EndSelect
Wend

Hope this helps.

Link to comment
Share on other sites

I take it this is whag you wanted to do. All you need to do is read what the log already says and set the editbox data to what the new line is, plus your old data. You do not need to write is all in again Here is an example of a small MSN syle chat I made for you.

Run it and type a few things into the first box and press send. Then type something else ect.

#include <GUIConstants.au3>
     
 $name = inputbox ( "Name" , "What is your name?" ) 
 
 Guicreate ( "Example" , 200, 200)
 $button = guictrlcreatebutton ( "Send" , 1,1,30)
 $box = guictrlcreateinput ( "" , 1,30, 170, 30)
 $main = GUICtrlCreateedit ( "", 1, 70, 190, 120)
 
 GUISetState ()
 While 1
    $msg = GUIGetMsg()
 Select
 
 Case $msg = $GUI_EVENT_CLOSE
     exitloop
     
 Case $msg = $button
     $boxread = guictrlread ( $box )
     $mainread = guictrlread ( $main )
     GUIctrlsetdata ( $main , $name & ": " & $boxread & @CRLF & $mainread ) 
     
 EndSelect
 Wend

Hope this helps.

That does exacyly what deadbug is saying he wants to avoid.

This adds to the edit without rewriting it all.

#include <GUIConstants.au3>
    
Guicreate ( "Example" , 200, 200)
$button = guictrlcreatebutton ( "Send" , 1,1,30)
$box = guictrlcreateinput ( "" , 1,30, 170, 30)
$main = GUICtrlCreateedit ( "", 1, 70, 190, 120)

GUISetState ()
While 1
   $msg = GUIGetMsg()
Select

Case $msg = $GUI_EVENT_CLOSE
    exitloop
    
Case $msg = $button
    $boxread = guictrlread ( $box )
   ;$mainread = guictrlread ( $main )
    GUIctrlsetdata ( $main ,  $boxread & @CRLF,1 )  
    
EndSelect
Wend
Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
Share on other sites

That does exacyly what deadbug is saying he wants to avoid.

Indeed!

This adds to the edit without rewriting it all.

Perfect! Isee now that I had completely misunderstood the "default" argument to GUICtrlSetData.

Many thanks for enlightening me.

-- deadbug

Link to comment
Share on other sites

  • 10 years later...

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