Jump to content
Sign in to follow this  
TheCrimsonCrusader

Preventing Flickering Text on GuiCtrlLabel when Reading from File

Recommended Posts

TheCrimsonCrusader

The short story of this script is I have a loop that is reading a text file (x:\result.txt). Line #5 in this text file constantly gets updated from the output results of the "pgp.bat and the pgp1.bat" files, so I have the loop reading the file constantly and updating the label with what is read. The change of what is read is constant, but I am trying to eliminate the expected "flickering" problem with the label that gets updated.

I've dabbled with the ControlSetText and GUICtrlSetData commands from prior examples, but I haven't been having any luck in having it work in this sample code. Yes, calling the batch files is cheesy, but I am only doing that temporary as I will have to convert some characters over to the ASCII codes before moving them into AutoIt. The $totalblocks label only gets ran one time, since that is static label, but the $blocksremaining label in the loop is the label that would be constantly updated.

Any help/suggestions would be greatly appreciated! Thanks.

CODE
#include <File.au3>

$main = GUICreate("PGP WDE", 310, 150)

RunWait("x:\pgp.bat","",@SW_HIDE)

RunWait("x:\pgp1.bat","",@SW_HIDE)

_ReplaceStringInFile ("x:\result.txt"," Total sectors: ",@CRLF)

_ReplaceStringInFile ("x:\result.txt"," lowwatermark: ",@CRLF)

_ReplaceStringInFile ("x:\result.txt"," highwatermark: ",@CRLF)

$totalblocks=FileReadLine("x:\result.txt",4)

GUICtrlCreateLabel($totalblocks, 150, 90, 180, 16)

GUICtrlSetFont (-1,10, 800)

GUICtrlSetFont (-1,10, 800)

GUICtrlCreateLabel("Decrypting drive. Please wait...", 20, 10, 280, 16)

GUICtrlSetFont (-1,10, 800)

GUICtrlSetColor(-1,0x0000cd)

GUICtrlCreateLabel("Please do not shut down the workstation", 20, 40, 280, 16)

GUICtrlSetFont (-1,10, 800)

GUICtrlSetColor(-1,0xff0000)

GUICtrlCreateLabel("because this could cause data corruption.", 20, 60, 280, 16)

GUICtrlSetFont (-1,10, 800)

GUICtrlSetColor(-1,0xff0000)

GUICtrlCreateLabel("Total blocks: ", 20, 90, 120, 16)

GUICtrlSetFont (-1,10, 800)

GUICtrlCreateLabel("Blocks decrypted: ", 20, 120, 180, 16)

GUICtrlSetFont (-1,10, 800)

GUISetState()

While 1

RunWait("x:\pgp.bat","",@SW_HIDE)

RunWait("x:\pgp1.bat","",@SW_HIDE)

_ReplaceStringInFile ("x:\result.txt"," Total sectors: ",@CRLF)

_ReplaceStringInFile ("x:\result.txt"," lowwatermark: ",@CRLF)

_ReplaceStringInFile ("x:\result.txt"," highwatermark: ",@CRLF)

$blocksremaining=FileReadLine("x:\result.txt",5)

GUICtrlCreateLabel($blocksremaining, 150, 120, 180, 16)

GUICtrlSetFont (-1,10, 800)

WEnd

Share this post


Link to post
Share on other sites
Marlo

just add a small interval in your While Wend loop.

Example:

While 1
RunWait("x:\pgp.bat","",@SW_HIDE)
RunWait("x:\pgp1.bat","",@SW_HIDE)
_ReplaceStringInFile ("x:\result.txt"," Total sectors: ",@CRLF)
_ReplaceStringInFile ("x:\result.txt"," lowwatermark: ",@CRLF)
_ReplaceStringInFile ("x:\result.txt"," highwatermark: ",@CRLF)
$blocksremaining=FileReadLine("x:\result.txt",5)
GUICtrlCreateLabel($blocksremaining, 150, 120, 180, 16)
GUICtrlSetFont (-1,10, 800)

Sleep(50)

WEnd

Click here for the best AutoIt help possible.Currently Working on: Autoit RAT

Share this post


Link to post
Share on other sites
TheCrimsonCrusader

Sorry, I guess I should have mentioned that. I've tried various sleep intervals and while it does help some, it doesn't eliminate the problem of flickering entirely, it just spaces them out more in terms of their frequency and I would like for the "blocks remaining" count to be updated somewhat frequently.

Share this post


Link to post
Share on other sites
martin

Sorry, I guess I should have mentioned that. I've tried various sleep intervals and while it does help some, it doesn't eliminate the problem of flickering entirely, it just spaces them out more in terms of their frequency and I would like for the "blocks remaining" count to be updated somewhat frequently.

DOn't create thousands of labels!

Create a label once at a150, 120 and give it the required font. Don't do that in your while loop.

In your while loop just change the text in the label with GuiCtrlSetData.


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.

Share this post


Link to post
Share on other sites
Zedna

#include <File.au3>

Global $blocksremaining, $blocksremaining_prev

$main = GUICreate("PGP WDE", 310, 150)
RunWait("x:\pgp.bat", "", @SW_HIDE)
RunWait("x:\pgp1.bat", "", @SW_HIDE)
_ReplaceStringInFile("x:\result.txt", " Total sectors: ", @CRLF)
_ReplaceStringInFile("x:\result.txt", " lowwatermark: ", @CRLF)
_ReplaceStringInFile("x:\result.txt", " highwatermark: ", @CRLF)
$totalblocks = FileReadLine("x:\result.txt", 4)
GUICtrlCreateLabel($totalblocks, 150, 90, 180, 16)
GUICtrlSetFont(-1, 10, 800)
GUICtrlSetFont(-1, 10, 800)
GUICtrlCreateLabel("Decrypting drive. Please wait...", 20, 10, 280, 16)
GUICtrlSetFont(-1, 10, 800)
GUICtrlSetColor(-1, 0x0000cd)
GUICtrlCreateLabel("Please do not shut down the workstation", 20, 40, 280, 16)
GUICtrlSetFont(-1, 10, 800)
GUICtrlSetColor(-1, 0xff0000)
GUICtrlCreateLabel("because this could cause data corruption.", 20, 60, 280, 16)
GUICtrlSetFont(-1, 10, 800)
GUICtrlSetColor(-1, 0xff0000)
GUICtrlCreateLabel("Total blocks: ", 20, 90, 120, 16)
GUICtrlSetFont(-1, 10, 800)
GUICtrlCreateLabel("Blocks decrypted: ", 20, 120, 180, 16)
GUICtrlSetFont(-1, 10, 800)
$label_remain = GUICtrlCreateLabel('', 150, 120, 180, 16)
GUICtrlSetFont(-1, 10, 800)
GUISetState()

While 1
    RunWait("x:\pgp.bat", "", @SW_HIDE)
    RunWait("x:\pgp1.bat", "", @SW_HIDE)
    _ReplaceStringInFile("x:\result.txt", " Total sectors: ", @CRLF)
    _ReplaceStringInFile("x:\result.txt", " lowwatermark: ", @CRLF)
    _ReplaceStringInFile("x:\result.txt", " highwatermark: ", @CRLF)
    $blocksremaining = FileReadLine("x:\result.txt", 5)
    If $blocksremaining <> $blocksremaining_prev Then
        GUICtrlSetData($label_remain, $blocksremaining)
        $blocksremaining_prev = $blocksremaining
    EndIf
WEnd

Share this post


Link to post
Share on other sites

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
Sign in to follow this  

×