Sign in to follow this  
Followers 0
MattX

Constantly changing GUI Output

26 posts in this topic

I have a msg box output but want to change it to a GUI in which the result always changes without the flickering - can someone provide a snippit of code which shows this ?

Share this post


Link to post
Share on other sites



There are tons of examples throughout the forum.

Search "flicker" and you will easily find them.

Or post your flickering code here so someone who can help will be able to see a problem

There are many reasons why your gui control might flicker.


AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Share this post


Link to post
Share on other sites

Here's a demo showing one way to do it in a loop. The first label shouldn't flicker much at all, the second one will flicker a lot.

Global $I = 1, $lastI = 1

$GUI = GUICreate("test")

$label = GUICtrlCreateLabel("Number = 1", 10, 10, 300, 40)
GUICtrlSetFont(-1, 30, 400)
$label2 = GUICtrlCreateLabel("Minimal flicker", 10, 60)
$label3 = GUICtrlCreateLabel("Number = 1", 10, 80, 300, 40)
GUICtrlSetFont(-1, 30, 400)
$label4 = GUICtrlCreateLabel("Lots of flicker", 10, 130)

GUISetState()

Global $Timer = TimerInit()

While GUIGetMsg() <> -3
    If $I <> $lastI Then
        GUICtrlSetData($label, "Number = " & $I)
        $lastI = $I
    EndIf
    If TimerDiff($Timer) >= 1000 Then
        $I += 1
        $Timer = TimerInit()
    EndIf
    GUICtrlSetData($label3, "Number = " & $I)
    If $I = 20 Then ExitLoop
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

#4 ·  Posted (edited)

Also got the problem of a new GUI being re-created everytime - what have I missed that's so obvious why this is happening ?

$filefolder = 'd:temp'
$fileextension = '*.eml'

    While 1
    sleep(2000)
    $FileList = _FileListToArray($filefolder, $fileextension);only list files with given extension
    ;If @error Then ContinueLoop
    ;MsgBox(0, "number of files:", $FileList[0])
    $Gui = GUICreate("Job Count", 260, 250)
    $Label = GUICtrlCreateLabel("Jobs: " & $FileList[0], 20, 20)
    GUISetState()
    WEnd
Edited by MattX

Share this post


Link to post
Share on other sites

You should look at the code I posted as to how to update your label.


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

I take it out the loop, the GUI no longer gets made:

#include <File.au3>
#include <Array.au3>
#include <GUIConstants.au3>


$filefolder = 'd:temp'
$fileextension = '*.eml'

$Gui = GUICreate("Job Count", 260, 250)
$Label = GUICtrlCreateLabel("Jobs: " & $FileList[0], 20, 20)
GUISetState()

While 1
    sleep(2000)
    $FileList = _FileListToArray($filefolder, $fileextension);only list files with given extension
WEnd

Share this post


Link to post
Share on other sites

Your label is crashing the script because the array $FileList doesn't exist/hasn't been declared yet.


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

#9 ·  Posted (edited)

Oooppps.... ;)

Now to try and get rid of the flicker.....

#include <File.au3>
#include <Array.au3>
#include <GUIConstants.au3>


$filefolder = 'd:temp'
$fileextension = '*.eml'

$Gui = GUICreate("Job Count", 260, 250)
;$Label = GUICtrlCreateLabel("Jobs: " & $FileList[0], 20, 20)
GUISetState()

While 1
    sleep(2000)
    $FileList = _FileListToArray($filefolder, $fileextension);only list files with given extension
    $Label = GUICtrlCreateLabel("Jobs: " & $FileList[0], 20, 20)
WEnd
Edited by MattX

Share this post


Link to post
Share on other sites

Run this in the full version of Scite4AutoIt3 before posting it again, you have no error checking in this, so if $FileList is empty, the label again crashes the script because it's not an array. You need to explain more what the problems you're getting are when you post, just throwing a defective script up with no explanation doesn't help much once they start getting longer. This one was pretty obvious without even running it.


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

I think has sorted that:

$filefolder = 'd:temp'
$fileextension = '*.eml'

$Gui = GUICreate("Job Count", 260, 250)
GUISetState()

While 1
    Sleep(2000)
    $FileList = _FileListToArray($filefolder, $fileextension);only list files with given extension
    If $FileList = 0 Then
        $Label = GUICtrlCreateLabel("Jobs: Null", 20, 20)
        ContinueLoop
    EndIf

    $Label = GUICtrlCreateLabel("Jobs: " & $FileList[0], 20, 20)
WEnd

Share this post


Link to post
Share on other sites

Here's a demo showing one way to do it in a loop. The first label shouldn't flicker much at all, the second one will flicker a lot.

Global $I = 1, $lastI = 1

$GUI = GUICreate("test")

$label = GUICtrlCreateLabel("Number = 1", 10, 10, 300, 40)
GUICtrlSetFont(-1, 30, 400)
$label2 = GUICtrlCreateLabel("Minimal flicker", 10, 60)
$label3 = GUICtrlCreateLabel("Number = 1", 10, 80, 300, 40)
GUICtrlSetFont(-1, 30, 400)
$label4 = GUICtrlCreateLabel("Lots of flicker", 10, 130)

GUISetState()

Global $Timer = TimerInit()

While GUIGetMsg() <> -3
    If $I <> $lastI Then
        GUICtrlSetData($label, "Number = " & $I)
        $lastI = $I
    EndIf
    If TimerDiff($Timer) >= 1000 Then
        $I += 1
        $Timer = TimerInit()
    EndIf
    GUICtrlSetData($label3, "Number = " & $I)
    If $I = 20 Then ExitLoop
WEnd

This is great and works a treat but I can't work out how this is achieved.

Share this post


Link to post
Share on other sites

#14 ·  Posted (edited)

That works, because the label is only updated if it has changed (I think)

On looking I would take a shot as it's the:

While GUIGetMsg() <> -3
    If $I <> $lastI Then
        GUICtrlSetData($label, "Number = " & $I)
        $lastI = $I
    EndIf

That's the trick - question is - how to get that into my script and if someone could explain to me what's actually happening, I may be able to incorperate this into my script.Thanks.

Edited by MattX

Share this post


Link to post
Share on other sites

Mattx,

Do NOT create the label inside of a loop, create it where you create the gui and update it in the loop if it changes (exactly like BremanNH's code).

kylomas


Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Share this post


Link to post
Share on other sites

The code in my script inside the While loop does a few things.

First, it checks to see if the value of the $I variable has changed since the last time through the loop. If it has changed, change the label's contents with an update.

If $I <> $lastI Then
        GUICtrlSetData($label, "Number = " & $I)
        $lastI = $I
    EndIf

Second, the variable $I is only updated once a second by using the TimerDiff function to see if 1000 ms have passed, if it has, add 1 to $I.

If TimerDiff($Timer) >= 1000 Then
        $I += 1
        $Timer = TimerInit()
    EndIf

Third, if variable $I = 20, then exit the loop, this keeps it from running forever, that can be changed or eliminated if needed.

If $I = 20 Then ExitLoop

The GUIGetMsg is checking to see if you've clicked the X on the GUI to shut it down before $I gets to 20.

While GUIGetMsg() <> -3

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

#17 ·  Posted (edited)

I have it flickering worse than ever now - someone want to give me a clue as to why ?

Plus it now quits when the $label returns 0 which I don't want it to do.

$filefolder = 'd:temp'
$fileextension = '*.eml'

Global $Label = 0, $lastlabel =0

$Gui = GUICreate("Web-DMZ Count", 200, 50)
GUISetBkColor(0xFFFF00)
GUISetState()
$Label = GUICtrlCreateLabel("Jobs:  ", 20, 20)

While 1
    If $Label <> $lastlabel Then
    $FileList = _FileListToArray($filefolder, $fileextension);only list files with given extension
    GUICtrlSetData($label,"Jobs:    " & $FileList[0])
    $lastlabel = $FileList
    If $FileList = 0 Then
        $Label = GUICtrlCreateLabel("Jobs: Null", 20, 20)
        ContinueLoop
    EndIf
EndIf
    
WEnd
Edited by MattX

Share this post


Link to post
Share on other sites

#18 ·  Posted (edited)

Looks like your logic has a flaw. You are comparing the Control handle with a result and My guess is you always want to do the _FileListToArray .

Something like this maybe:

While 1
    $FileList = _FileListToArray($filefolder, $fileextension);only list files with given extension
    If $FileList <> $lastlabel Then
        GUICtrlSetData($Label, "Jobs:   " & $FileList[0])
        $lastlabel = $FileList
        If $FileList = 0 Then
            GUICtrlSetData($Label, "Jobs: Null")
            ContinueLoop
        EndIf
    EndIf
WEnd
Edited by Jos

Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

I'm not getting any output now - this is driving me nuts. This should be so fricking simple.

$filefolder = 'd:temp'
$fileextension = '*.eml'

Global $I = 1, $lastI = 1

$Gui = GUICreate("Web-DMZ Count", 200, 50)
GUISetBkColor(0xFFFF00)
GUISetState()
$Label = GUICtrlCreateLabel("Jobs:    ", 20, 20)

Global $Timer = TimerInit()

While 1
    If $I <> $lastI Then
    $FileList = _FileListToArray($filefolder, $fileextension);only list files with given extension
    GUICtrlSetData($label,"Jobs:    " & $FileList[0])
    $lastI = $I

       If TimerDiff($Timer) >= 1000 Then
        $I += 1
        $Timer = TimerInit()
    EndIf

    If $FileList = 0 Then
        $Label = GUICtrlCreateLabel("Jobs: Null", 20, 20)
        ContinueLoop
    EndIf
EndIf

WEnd

Share this post


Link to post
Share on other sites

You still have the _FileListToArray inside the IF which means it will never be executed after $I equals $LastI.

Check the modifications I made.


Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

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