Jump to content

Fail to update label value without flickering


gahhon
 Share

Recommended Posts

Global $iLableID

Func _Metro_SplashTextScreen($Flag, $Title = "", $Text = "", $mWidth = 600, $Fontsize = 11, $ParentGUI = "")
    Local $msgbDPI = _HighDPICheck()
    Local $SplashScreen_Form

    If $Flag = 1 Then
        If $HIGHDPI_SUPPORT Then
            $mWidth = Round($mWidth * $gDPI)
        Else
            $Fontsize = ($Fontsize / $Font_DPI_Ratio)
        EndIf

        Local $LabelSize = _StringSize($Text, $Fontsize, 400, 0, "Arial", $mWidth - (30 * $msgbDPI))
        Local $mHeight = 120 + ($LabelSize[3] / $msgbDPI)
        $SplashScreen_Form = _Metro_CreateGUI($Title, $mWidth / $msgbDPI, $mHeight, -1, -1, False, $ParentGUI)

        GUICtrlCreateLabel(" " & $Title, 2 * $msgbDPI, 2 * $msgbDPI, $mWidth - (4 * $msgbDPI), 30 * $msgbDPI, 0x0200, 0x00100000)
        GUICtrlSetBkColor(-1, _AlterBrightness($GUIThemeColor, 30))
        GUICtrlSetColor(-1, $FontThemeColor)
        _GUICtrlSetFont(-1, 11, 600, 0, "Arial", 5)
        $iLableID = GUICtrlCreateLabel($Text, 15 * $msgbDPI, 50 * $msgbDPI, $LabelSize[2], $LabelSize[3], -1, 0x00100000)
        GUICtrlSetBkColor(-1, $GUIThemeColor)
        GUICtrlSetColor(-1, $FontThemeColor)
        GUICtrlSetFont(-1, $Fontsize, 400, 0, "Arial", 5)

        GUISetState(@SW_SHOW)
        Sleep(500)

        Return 1
    ElseIf $Flag = 0 Then
        GUIDelete($SplashScreen_Form)
        Return 1
    Else
        Return SetError(0, "", "Error: Invalid flag value")
    EndIf
EndFunc   ;==>_Metro_SplashTextScreen

Func _Metro_SetSplashText($newMessage)
    If $newMessage <> "" Then
        GUICtrlSetData($iLableID, $newMessage)
        Sleep(500)
    EndIf
EndFunc   ;==>_Metro_SetSplashText
#include "MetroGUI-UDF\MetroGUI_UDF.au3"

$sMessage = "Copying"
_Metro_SplashTextScreen(1, "", $sMessage)

For $i = 1 To 10
    $sMessage = $sMessage & "."
    _Metro_SetSplashText($sMessage)
Next

_Metro_SplashTextScreen(0)

I don't know why it keep stuck on showing "Copying" without updating. Any idea?

Expected result: update the Copying by adding dots/second, without flickering.

Please kindly advise.

Link to comment
Share on other sites

To prevent flicker, update message only if changed:

#include "MetroGUI-UDF\MetroGUI_UDF.au3"

$sMessage = "Copying"
_Metro_SplashTextScreen(1, "", $sMessage)

Local $sPrev
For $i = 1 To 10
    If $sPrev <> $sMessage Then
        $sMessage &= "."
        _Metro_SetSplashText($sMessage)
        $sPrev = $sMessage
    EndIf
Next

_Metro_SplashTextScreen(0)

 

Link to comment
Share on other sites

1 hour ago, dmob said:

To prevent flicker, update message only if changed:

#include "MetroGUI-UDF\MetroGUI_UDF.au3"

$sMessage = "Copying"
_Metro_SplashTextScreen(1, "", $sMessage)

Local $sPrev
For $i = 1 To 10
    If $sPrev <> $sMessage Then
        $sMessage &= "."
        _Metro_SetSplashText($sMessage)
        $sPrev = $sMessage
    EndIf
Next

_Metro_SplashTextScreen(0)

 

Your code is cannot work, because on the 1st loop you have assigned $sMessage to $sPrev, so then the 2nd loop fail to go into the IF statement (Copying. = Copying.)

I did tried print to console of the value

Func _Metro_SetSplashText($newMessage)
    If $newMessage <> "" Then
        GUICtrlSetData($iLableID, $newMessage)
        ConsoleWrite("$iLableID = " & $iLableID & " $newMessage = " & $newMessage & @CRLF)
    EndIf
EndFunc   ;==>_Metro_SetSplashText

And the result is expected, but it just can't update the label only. Any idea?

image.png.92d86e3416d15d8c921dabd1b8ae090d.png

Edited by gahhon
Link to comment
Share on other sites

Its because you set the width of $iLableId to the width of "Copying", you don't change the size of $iLableId so the "." aren't being displayed.  So you would either have to preset the width or set $newMessage to "Copying              " so that it has enough room for following dots.

Edited by Subz
Link to comment
Share on other sites

13 minutes ago, Subz said:

Its because you set the width of $iLableId to the width of "Copying", you don't change the size of $iLableId so the "." aren't being displayed.  So you would either have to preset the width or set $newMessage to "Copying              " so that it has enough room for following dots.

Oh got it. Because of the _StringSize. So I just set it to default then work fine already.

Then is it possible to display _Metro_SplashTextScreen & _Metro_SetSplashText while copying?

Link to comment
Share on other sites

2 hours ago, Subz said:

Use Adlibregister("SetSplashText") before you start copying and use AdlibUnregister to stop it.

Func _Metro_LoopInProgress()
    $iMsg &= "."
    _Metro_SetSplashText($iMsg)
    ConsoleWrite($iMsg & @CRLF)
EndFunc   ;==>_Metro_SetSplashText
_Metro_SplashTextScreen(1, "", $iMsg)
AdlibRegister("_Metro_LoopInProgress")
DirRemove($DIR_WA_FOLDER, 1)
_WinAPI_ShellFileOperation($CUR_WA_FOLDER, $DIR_WA_FOLDER, $FO_COPY, BitOr($FOF_SIMPLEPROGRESS, $FOF_NOCONFIRMATION))
AdlibUnRegister("_Metro_LoopInProgress")
_Metro_SplashTextScreen(0)
_Metro_MsgBox(0, "", "Whatsapp Extension is up to date!")
_FileWriteLog($LOG_INSTALLATION, "Debug: Application is up to date.")

What I thought is the looping time is every 250ms right?
But how come it is slower than I use Sleep(500)

#include "MetroGUI-UDF\MetroGUI_UDF.au3"

Local $sMessage = "Installation in progress "
_Metro_SplashTextScreen(1, "", $sMessage)

For $i = 1 To 10
    $sMessage &= "."
    _Metro_SetSplashText($sMessage)
    Sleep(500)

    If Mod($i, 3) = 0 Then
        $sMessage = "Installation in progress "
    EndIf
Next

_Metro_SplashTextScreen(0)

 

Link to comment
Share on other sites

Sleep pauses the script for x amount of time, the higher the number the longer it sleeps, so Sleep(250)  = wait 250 ms, Sleep(500) = wait 500ms.  Here is basic example of Adlibregister

#include <MetroGUI_UDF.au3>

Global $iLableID, $sMessage = "Installation in progress ", $g_iEllipsis = 1, $g_bEllipsis = True

_Metro_SplashTextScreen(1, "", $sMessage)

AdlibRegister("_Metro_LoopText", 200) ;~ Change time(ms) to increase/decrease speed of marquee text

For $i = 1 To 10
    Sleep(1000)
Next

AdlibUnRegister("_Metro_LoopText")

_Metro_SplashTextScreen(0)
_Metro_MsgBox(0, "", "Whatsapp Extension is up to date!")

Func _Metro_LoopText()
    Switch $g_bEllipsis
        Case 0
            $sMessage = "Installation in progress "
            $g_iEllipsis = 0
            $g_bEllipsis = True
        Case 1
            $sMessage &= "."
            $g_iEllipsis += 1
            If $g_iEllipsis >= 5 Then $g_bEllipsis = False ;~ Change $g_iEllipsis >= n to increase/decrease number of ellipsis
    EndSwitch
    GUICtrlSetData($iLableID, $sMessage)
EndFunc

Func _Metro_SplashTextScreen($Flag, $Title = "", $Text = "", $mWidth = 600, $Fontsize = 11, $ParentGUI = "")
    Local $msgbDPI = _HighDPICheck()
    Local $SplashScreen_Form
    $g_iEllipsis = 1    ;~ Reset $g_iEllipsis to default
    $g_bEllipsis = True ;~ Reset $g_bEllipsis to default
    If $Flag = 1 Then
        If $HIGHDPI_SUPPORT Then
            $mWidth = Round($mWidth * $gDPI)
        Else
            $Fontsize = ($Fontsize / $Font_DPI_Ratio)
        EndIf

        Local $LabelSize = _StringSize($Text & "xxxxxxxxxx", $Fontsize, 400, 0, "Arial", $mWidth - (30 * $msgbDPI)) ;~ Add more x(s) to change the width of $iLableID
        Local $mHeight = 120 + ($LabelSize[3] / $msgbDPI)
        $SplashScreen_Form = _Metro_CreateGUI($Title, $mWidth / $msgbDPI, $mHeight, -1, -1, False, $ParentGUI)

        GUICtrlCreateLabel(" " & $Title, 2 * $msgbDPI, 2 * $msgbDPI, $mWidth - (4 * $msgbDPI), 30 * $msgbDPI, 0x0200, 0x00100000)
        GUICtrlSetBkColor(-1, _AlterBrightness($GUIThemeColor, 30))
        GUICtrlSetColor(-1, $FontThemeColor)
        _GUICtrlSetFont(-1, 11, 600, 0, "Arial", 5)
        $iLableID = GUICtrlCreateLabel($Text, 15 * $msgbDPI, 50 * $msgbDPI, $LabelSize[2], $LabelSize[3], -1, 0x00100000)
        GUICtrlSetBkColor(-1, $GUIThemeColor)
        GUICtrlSetColor(-1, $FontThemeColor)
        GUICtrlSetFont(-1, $Fontsize, 400, 0, "Arial", 5)

        GUISetState(@SW_SHOW)
        Sleep(500)

        Return 1
    ElseIf $Flag = 0 Then
        GUIDelete($SplashScreen_Form)
        Return 1
    Else
        Return SetError(0, "", "Error: Invalid flag value")
    EndIf
EndFunc   ;==>_Metro_SplashTextScreen

 

Link to comment
Share on other sites

8 hours ago, Subz said:

Sleep pauses the script for x amount of time, the higher the number the longer it sleeps, so Sleep(250)  = wait 250 ms, Sleep(500) = wait 500ms.  Here is basic example of Adlibregister

#include <MetroGUI_UDF.au3>

Global $iLableID, $sMessage = "Installation in progress ", $g_iEllipsis = 1, $g_bEllipsis = True

_Metro_SplashTextScreen(1, "", $sMessage)

AdlibRegister("_Metro_LoopText", 200) ;~ Change time(ms) to increase/decrease speed of marquee text

For $i = 1 To 10
    Sleep(1000)
Next

AdlibUnRegister("_Metro_LoopText")

_Metro_SplashTextScreen(0)
_Metro_MsgBox(0, "", "Whatsapp Extension is up to date!")

Func _Metro_LoopText()
    Switch $g_bEllipsis
        Case 0
            $sMessage = "Installation in progress "
            $g_iEllipsis = 0
            $g_bEllipsis = True
        Case 1
            $sMessage &= "."
            $g_iEllipsis += 1
            If $g_iEllipsis >= 5 Then $g_bEllipsis = False ;~ Change $g_iEllipsis >= n to increase/decrease number of ellipsis
    EndSwitch
    GUICtrlSetData($iLableID, $sMessage)
EndFunc

Func _Metro_SplashTextScreen($Flag, $Title = "", $Text = "", $mWidth = 600, $Fontsize = 11, $ParentGUI = "")
    Local $msgbDPI = _HighDPICheck()
    Local $SplashScreen_Form
    $g_iEllipsis = 1    ;~ Reset $g_iEllipsis to default
    $g_bEllipsis = True ;~ Reset $g_bEllipsis to default
    If $Flag = 1 Then
        If $HIGHDPI_SUPPORT Then
            $mWidth = Round($mWidth * $gDPI)
        Else
            $Fontsize = ($Fontsize / $Font_DPI_Ratio)
        EndIf

        Local $LabelSize = _StringSize($Text & "xxxxxxxxxx", $Fontsize, 400, 0, "Arial", $mWidth - (30 * $msgbDPI)) ;~ Add more x(s) to change the width of $iLableID
        Local $mHeight = 120 + ($LabelSize[3] / $msgbDPI)
        $SplashScreen_Form = _Metro_CreateGUI($Title, $mWidth / $msgbDPI, $mHeight, -1, -1, False, $ParentGUI)

        GUICtrlCreateLabel(" " & $Title, 2 * $msgbDPI, 2 * $msgbDPI, $mWidth - (4 * $msgbDPI), 30 * $msgbDPI, 0x0200, 0x00100000)
        GUICtrlSetBkColor(-1, _AlterBrightness($GUIThemeColor, 30))
        GUICtrlSetColor(-1, $FontThemeColor)
        _GUICtrlSetFont(-1, 11, 600, 0, "Arial", 5)
        $iLableID = GUICtrlCreateLabel($Text, 15 * $msgbDPI, 50 * $msgbDPI, $LabelSize[2], $LabelSize[3], -1, 0x00100000)
        GUICtrlSetBkColor(-1, $GUIThemeColor)
        GUICtrlSetColor(-1, $FontThemeColor)
        GUICtrlSetFont(-1, $Fontsize, 400, 0, "Arial", 5)

        GUISetState(@SW_SHOW)
        Sleep(500)

        Return 1
    ElseIf $Flag = 0 Then
        GUIDelete($SplashScreen_Form)
        Return 1
    Else
        Return SetError(0, "", "Error: Invalid flag value")
    EndIf
EndFunc   ;==>_Metro_SplashTextScreen

 

I have tried to put AdlibRegister with ms value like 100~200, but it will still hang in a bit while copying. After it complete the copying, it will show extra 3-4 dots.
Let's say,
While copying, display: Installation in progress .
0-99% copy progress, display: Installation in progress .
When done copying, display: Installation in progress .... (It immediately pop 3 extra dots) Then display "Whatsapp Extension is up to date!"

Link to comment
Share on other sites

Unfortunately any functions that cause the script to pause, like FileCopy, FileMove (mostly with large files).  To get around this in the past pass these commands to cmd using Run, not RunWait as that will pause the script, example:

AdlibRegister("_Metro_LoopText", 200) ;~ Change time(ms) to increase/decrease speed of marquee text
Local $iCmd, $aFileList = _FileListToArrayRec(@ScriptDir, "*.csv", 1, 0, 0, 2)
For $i = 1 To $aFileList[0]
    $iCmd = Run(@ComSpec & ' /c copy "' & $aFileList[$i] & '" "' & @ScriptDir & '\New Folder" /Y', "", @SW_HIDE)
    While ProcessExists($iCmd)
        Sleep(100)
    WEnd
Next
AdlibUnRegister("_Metro_LoopText")

 

Link to comment
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
 Share

×
×
  • Create New...