Sign in to follow this  
Followers 0
akorx

Update label without blinking/sparking

8 posts in this topic

#1 ·  Posted (edited)

Hi Guys,

I'm french and i don't how we say that something is blinking very fast : sparking ? flashing ?

Try this :

GUICreate("",520,305)

$Pic1=GUICtrlCreatePic("C:\Program Files\AutoIt3\Examples\GUI\msoobe.jpg", 0, 0, 520,305)

GUISetState()

$lbl=GUICtrlCreateLabel("",20,40,200,200)

For $i=1 to 1000000000 step 1

GUICtrlSetData($lbl,$i)

Next

How can i do if i want to refresh my label called $lbl without sparking ? is there a way to do this?

It's possible that GUICtrlSetData is not the best way... waht do you think about it ?

Don't answer me to display the value by 100 !!! it's just a exemple, i want to see ALL values !

Edited by akorx

AkorxMail akorx@yahoo.fr

Share this post


Link to post
Share on other sites



Hi Guys,

I'm french and i don't how we say that something is blinking very fast : sparking ? flashing ?

Try this :

GUICreate("",520,305)

$Pic1=GUICtrlCreatePic("C:\Program Files\AutoIt3\Examples\GUI\msoobe.jpg", 0, 0, 520,305)

GUISetState()

$lbl=GUICtrlCreateLabel("",20,40,200,200)

For $i=1 to 1000000000 step 1

GUICtrlSetData($lbl,$i)

Next

How can i do if i want to refresh my label called $lbl without sparking ? is there a way to do this?

It's possible that GUICtrlSetData is not the best way... waht do you think about it ?

use contolsettext

Share this post


Link to post
Share on other sites

The way to do it is to only change the label if the information has changed from the last time you go through the loop. In your example, there really isn't any way to fix that because you're changing it so fast it's going to blink.


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

use contolsettext

Wuuhhhaa :D, that's a really nice work-around I've never tried! Looping without a sleep() is still too fast, but at least this does not repaint the whole control!

Edited by KaFu

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

OK ok... it was just a exemple. Now imagine you've got a script that will be automatically close after 60 seconds... you want to display the countdown in a label. So the label will be refreshed each seconde. If you add a font on your GUI and the font of your label with transparent parameter you will see sometimes a bug during the refresh : it's sparking...

EXEMPLE :

#NoTrayIcon

#include <SendMessage.au3>

#include <GUIConstants.au3>

#include <GUIConstantsEx.au3>

#include <ProgressConstants.au3>

#include <Timers.au3>

$gui=GUICreate("Title",520,305)

$Pic1=GUICtrlCreatePic("C:\Program Files\AutoIt3\Examples\GUI\msoobe.jpg", 0, 0, 520,305)

GUICtrlSetState(-1, $GUI_DISABLE)

GUISetBkColor(0x99FF66)

$label1 = GUICtrlCreateLabel("Try :" & chr(10) ,55,30,380,30,"0x01")

GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT)

$label2 = GUICtrlCreateLabel("- " & chr(34) & "1 grhrttrhh" & chr(34) & chr(10) & chr(10) & "- " & chr(34) & "2 trhgtrtrth" & chr(34) & chr(10) & chr(10) & "- " & chr(34) & "3 ttrrttr" & chr(34) & chr(10),150,70,400,70,"0x0000")

GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT)

$label3 = GUICtrlCreateLabel("Please Enter your name",60,150,400,20,0x01)

GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT)

GUICtrlSetFont (-1,9, 800)

$label5 = GUICtrlCreateLabel("Shutdown in : ",307,280,150,30,0x50020102)

GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT)

$label6 = GUICtrlCreateLabel("120 s.",460,280,50,30,0x50020100)

GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT)

$input1 = GUICtrlCreateInput("",160,180,200,20,0x01)

GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT)

$Button1 = GUICtrlCreateButton(" go! ",210,215,100,20,0x01)

GUISetState()

Local $starttime = _Timer_Init()

While 1

$dif1 = _Timer_Diff($starttime)

$dif2 = int($dif1/1000)

$tps = 120-$dif2

if GUICtrlRead($label6)<>$dif2 then

GUICtrlSetData($label6, $tps & " s.")

Sleep(100)

EndIf

if $tps<=0 then Exit

$msg = GUIGetMsg()

Select

Case $msg = $GUI_EVENT_CLOSE

GUIDelete($gui)

Exit

Case $msg = $Button1 or $msg = $input1

GUICtrlSetData($label5, "")

GUICtrlSetData($label6, "")

$progressbar1 = GUICtrlCreateProgress (60, 250, 400)

For $i = 0 to 100 step 1

sleep(50)

GUICtrlSetData($progressbar1, $i)

Next

Sleep(1000)

Exit

EndSelect

WEnd

Do you see a solution ?

Edited by akorx

AkorxMail akorx@yahoo.fr

Share this post


Link to post
Share on other sites

akorx,

I have just run your script 3 times and I got no "sparking" from the countdown label. :D

M23

P.S. When you post code please use Code tags. Put [autoit] before and [/autoit] after your posted code. :oops:


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

I can see a flashing from the background color behind the label occasionally when I run it. That's because there's a picture that the label is being drawn over that is causing the problem. One thing you might consider is, instead of creating a label on the GUI, use the title of the GUI and put your countdown message in that, then you won't get any redraw issues regardless of how slow the computer is.

#include <SendMessage.au3>
#include <GUIConstants.au3>
#include <GUIConstantsEx.au3>
#include <ProgressConstants.au3>
#include <Timers.au3>

$gui = GUICreate("deblocage utilisateur convergence ou sillage", 520, 305) ; I used lower case because the title is so long the timer isn't seen otherwise.
$Pic1 = GUICtrlCreatePic("C:\Program Files\AutoIt3\Examples\GUI\msoobe.jpg", 0, 0, 520, 305)
GUICtrlSetState(-1, $GUI_DISABLE)
GUISetBkColor(0x99FF66)
$label1 = GUICtrlCreateLabel("Try :" & Chr(10), 55, 30, 380, 30, "0x01")
GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT)
$label2 = GUICtrlCreateLabel("- " & Chr(34) & "1 grhrttrhh" & Chr(34) & Chr(10) & Chr(10) & "- " & Chr(34) & "2 trhgtrtrth" & Chr(34) & Chr(10) & Chr(10) & "- " & Chr(34) & "3 ttrrttr" & Chr(34) & Chr(10), 150, 70, 400, 70, "0x0000")
GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT)
$label3 = GUICtrlCreateLabel("Please Enter your name", 60, 150, 400, 20, 0x01)
GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT)
GUICtrlSetFont(-1, 9, 800)
$label5 = GUICtrlCreateLabel("Shutdown in : ", 307, 280, 150, 30, 0x50020102)
GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT)
$label6 = GUICtrlCreateLabel("120 s.", 460, 280, 50, 30, 0x50020100)
GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT)
$input1 = GUICtrlCreateInput("", 160, 180, 200, 20, 0x01)
GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT)
$Button1 = GUICtrlCreateButton(" go! ", 210, 215, 100, 20, 0x01)

GUISetState()

Local $starttime = _Timer_Init()

While 1
;~  $dif1 = _Timer_Diff($starttime)
;~  $dif2 = Int($dif1 / 1000)
    $tps = 120 - Int(_Timer_Diff($starttime) / 1000) ; changed to make the code shorter, no functional difference.
    If GUICtrlRead($label6) <> $tps Then
        WinSetTitle("deblocage utilisateur convergence ou sillage", "", "deblocage utilisateur convergence ou sillage" & "   Shutdown in: " & $tps & " s.")
;~      Sleep(100) ; not needed
    EndIf
    If $tps <= 0 Then Exit
    $msg = GUIGetMsg()
    Select
        Case $msg = $GUI_EVENT_CLOSE
            GUIDelete($gui)
            Exit
        Case $msg = $Button1 Or $msg = $input1
            GUICtrlSetData($label5, "")
            GUICtrlSetData($label6, "")
            $progressbar1 = GUICtrlCreateProgress(60, 250, 400)
            For $i = 0 To 100 Step 1
                Sleep(50)
                GUICtrlSetData($progressbar1, $i)
            Next
            Sleep(1000)
            Exit
    EndSelect
WEnd

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

You may also want to check the contents of the label before setting a new value. Here is a simple example.

For $i = 0 To 10
    If GuiCtrlRead($hLabel) <> $i Then GuiCtrlSetData($hLabel, $i)
    Sleep(1000)
Next

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

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  
Followers 0