Sign in to follow this  
Followers 0
ok123jump

[HELP!] GUI Clock that Constantly Updates

12 posts in this topic

#1 ·  Posted (edited)

Hi guys,

I have a program that is controlled through a GUI. The bottom of my GUI has a clock which is updated every 50ms during the While 1 loop. Some of the GUI buttons call functions which contain algorithms that take on the order of 10's of minutes to run. During the running of these functions, the clock does not update. I am looking for a way to force the clock to update every 20ms - regardless of whether or not there is another loop running within the program. In essence, it would run in the background all the time.

Here's a bit of my code to show you how I'm currently animating the clock.

;----------------GUI Functionality Code-------------------
While 1
    ;20ms Delay to Reduce CPU Usage
    Sleep(20)
    ;Get and Read Time
    UpdateTime()
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $Button_ExportData
            AutoItSetOption("MouseCoordMode", 0)
            ExportData()
            $regionFlag1 = False
            $regionFlag2 = False
        Case .
                     .
                     .
                     .
                     .
                     .

        Case $Menu_Tools_CoordTool
            Local $scrDir = @ScriptDir
            Run("Coordinate Tool.exe", $scrDir & "\Tools")
    EndSwitch
WEnd
.
.
.
.
.
.
Func UpdateTime()
    $tCur = _Date_Time_GetLocalTime()
    GUICtrlSetData($Label_Clock, _Date_Time_SystemTimeToTimeStr($tCur))
EndFunc

I guess this fits into my more general question about how I would have a separate monitoring layer that would allow the program to be terminated by simply clicking the "x" button during algorithm execution, but I fear the flames. =/

Thanks for the help!

Edited by ok123jump

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

One way to do this would be to have your app invoke it's self with a command line parameter that updates the parent process's GUI. Example

If $CmdLine[0] Then
    If $CmdLine[1] = "/time" Then
        $hTimeControl = ControlGetHandle("Your app's title", "", 999) ; Replace 999 with whatever the Time Update's ControlID is
        While 1
            ControlSetText("Your app's title", "", $hTimeControl, @HOUR & ":" & @MIN & ":" & @SEC & "." & @MSEC)
            Sleep(20)
        WEnd
    EndIf
EndIf
Edited by Zef

Share this post


Link to post
Share on other sites

ok123jump,

For the clock update, try using AdlibRegister. It runs a function at a predetermined interval regardless of what else is happening in your script. :mellow:

As for the exit problem, if you use the search feature this has been answered many times before. A lot depends on whether you are using OnEvent or MessageLoop mode. :P

M23


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

You can use timers also.

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

ok123jump,

For the clock update, try using AdlibRegister. It runs a function at a predetermined interval regardless of what else is happening in your script. :P

As for the exit problem, if you use the search feature this has been answered many times before. A lot depends on whether you are using OnEvent or MessageLoop mode. :party:

M23

Thanks! The AdlibRegister function worked! I have been so bothered by fixing this problem that I have spent so much time trying to structure my code so that the GUI functions operated independently of the main calculation loop - I thought I would need to run the Clock in the GUI functions segment.

This simplifies the problem very much so!

Oh yeah... thnx for the flames! I searched under the parameters "run simultaneously", "execute simultaneously", "in parllel", "calculate parallel", "run at the same time"... and about two dozen other terms. You can complain about the quality of my choice for search terms, but not of my non-use of the search function. :mellow:

I am using a MessageLoop, I believe.

Edited by ok123jump

Share this post


Link to post
Share on other sites

Thanks! The AdlibRegister function worked! I have been so bothered by fixing this problem that I have spent so much time trying to structure my code so that the GUI functions operated independently of the main calculation loop - I thought I would need to run the Clock in the GUI functions segment.

This simplifies the problem very much so!

Oh yeah... thnx for the flames! I searched under the parameters "run simultaneously", "execute simultaneously", "in parllel", "calculate parallel", "run at the same time"... and about two dozen other terms. You can complain about the quality of my choice for search terms, but not of my non-use of the search function. :mellow:

I am using a MessageLoop, I believe.

I don't see where Melba23 flamed you at all in this thread and this is the second time in the thread you have refered to being flamed. Perhaps you would like to provide a link to a post where you were flamed.

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

Mmmm... perhaps "flamed" was not the right word. How about "accosted"? I was accosted by Melba23 for failing to use the search functionality - when in fact, I had.

That just doesn't roll off your tongue like "flamed".

Share this post


Link to post
Share on other sites

I can only see where he suggested the use of the Search feature and I can't see that as accosting you. We are well aware that Search can be tricky and the search terms can be very critical. He suggested that as a way for you to find an answer and that should not be misconstrued into meaning anything else.

Perhaps you think that he should have done the search for you? That does happen on occasion but only if the person making the reply has the time to do it for you and generally you only get one chance in that direction. The next time you want help searching, it just won't happen so don't waste your one shot. We all had to get used to the search at one point and it still annoys me but the more you use it the better you become at it.


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

ok123jump,

Please try not to be so sensitive - if you think that was "flaming" you must have a really difficult time using any forum! :P

George is quite correct - I was merely suggesting that you search to find how to use the [X] in a function. And I am well aware that Search is tricky - my top tip is to use "+" in front of each multiple term. :party:

Just to prove what nice people we are, here is the content of a post I wrote a few days ago answering the same question:

[previous post]

If you use OnEvent mode, you can break into the running function:

#include <GUIConstantsEx.au3>

Opt("GUIOnEventMode", 1)

$hGUI = GUICreate("Test", 500, 500)
GUISetOnEvent($GUI_EVENT_CLOSE, "CLOSEClicked")
GUISetState()

_Long_Function()

; Enter an infinite loop
While 1
    Sleep(10)
WEnd

Func _Long_Function()
    $iBegin = TimerInit()
    While TimerDiff($iBegin) < 10000
        ConsoleWrite(@SEC & @CRLF)
        Sleep(1000)
    WEnd
EndFunc

Func CLOSEClicked()
    Exit
EndFunc

If you use MessageLoop mode, you have a big problem. AutoIt will NOT interrupt a running function unless you use a HotKey. So if you have long function without a periodic check of some kind, you cannot break out. The best you can do is run a HotKey and set a flag which you check now and again with an Adlib function.

[/previous post]

I also notice that I neglected to welcome you to the forum as I normally do with newcomers - my apologies: Welcome to the AutoIt forum. :mellow:

Are we all friends again now? :party:

M23


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 also notice that I neglected to welcome you to the forum as I normally do with newcomers - my apologies: Welcome to the AutoIt forum. :mellow:

Are we all friends again now? :P

M23

Of course we're all friends. I posted the "flaming" comment mostly joking, but I see that's a serious accusation here. =/

I do appreciate your help. I am going to study your code and attempt to integrate the strategy into my program.

A further question on the AdlibRegister functionality.

I implemented it, it works great until one of my routines gets in to some pixel checksum subroutines. When this occurs, AutoIt seems to crash. Have you heard of this, or might it be some other problem?

When I disable the pixel checksum routines, my script seems to behave just fine.

Share this post


Link to post
Share on other sites

Note that AdlibRegister will not always interrupt a script and update the clock or whatever. For example, dragging the window might make the clock freeze using AdlibRegister.

Using timers is more reliable I think.


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

#12 ·  Posted (edited)

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