goss34 Posted October 5, 2015 Share Posted October 5, 2015 Hi Guys,I am sure 99% of the members here will know the answer to this but I am having a problem figuring it out, iv searched the forums but cant find what i am after.Essentially I am trying to write a little monitor that refreshes a gui every minute, currently the gui reads an ini and displays it on the gui as desired, it also updates the gui constantly but if i extend the sleep timer in my while loop then i cannot exit the gui ... i know this isnt the right way to do it but i am unsure how to do it correctly.Heres my current code:expandcollapse popup#include <GUIConstantsEx.au3> Global $iL = 10 , $iT = 10 DetectDate() Func DetectDate() Global $Datestamp = @MDAY & "/" & @MON & "/" & @YEAR EndFunc ;==>DetectDate CreateGui() Func CreateGui() Global $GUI = GUICreate("BACS Monitor", 600, 600) EndFunc ;==>CreateGui Func ShowGui() Global $INI = ".\Test.ini" Global $aArray = IniReadSection($INI, $Datestamp) Local $DateLabel = GUICtrlCreateLabel($datestamp, 10,10) For $i = 1 To $aArray[0][0] Global $Status = IniRead($INI, $aArray[$i][0], "Status", "") If $Status = "Red" Then $Icon = "C:\Red.ico" ElseIf $Status = "Green" Then $Icon = "C:\Green.ico" EndIf GUICtrlCreateLabel($aArray[$i][0], $iL + 10 , $iT + 20) GUICtrlCreateIcon($Icon, -1, $iL + 100, $iT + 20,15,15) $iT = $iT + 20 Next GUISetState(@SW_SHOW, $GUI) Global $iL = 10 , $iT = 10 EndFunc ;==>ShowGui While 1 ; Loop until the user exits. Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit Case Else ShowGui() EndSwitch Sleep(50) WEndAt the moment the ShowGui function just runs and runs which is fine but its too fast, how do i slow it down to run that function every 60 seconds without making the GUI hang?By hang i mean the red cross (top right) is unresponsive which i assume is because the function is running so the GuiGetMsg is no longer monitoring for the click of the red cross.ThanksDan Link to comment Share on other sites More sharing options...
computergroove Posted October 6, 2015 Share Posted October 6, 2015 Take a look at timerinit and timerdiff functions and incorporate them into your for loop. Get Scite to add a popup when you use a 3rd party UDF -> http://www.autoitscript.com/autoit3/scite/docs/SciTE4AutoIt3/user-calltip-manager.html Link to comment Share on other sites More sharing options...
goss34 Posted October 6, 2015 Author Share Posted October 6, 2015 Hi Computergroove,The help file for timerinit just appears to use a sleep, would that not just give me the same problem whereby while the sleep is active the gui would be unresponsive?TaDan Link to comment Share on other sites More sharing options...
Teks Posted October 6, 2015 Share Posted October 6, 2015 Hi,I think you need to use event mode Gui, not message mode. (you should not put Sleep in main loop with message mode anyway) Link to comment Share on other sites More sharing options...
goss34 Posted October 6, 2015 Author Share Posted October 6, 2015 Hi Teks,Is that possible when i want the gui to constantly refresh every 60 seconds without the user clicking any buttons on the gui? From what i have just read i cant see an example of how to do that.I only have the sleep in to stop the CPU maxing out.CheersDan Link to comment Share on other sites More sharing options...
Teks Posted October 6, 2015 Share Posted October 6, 2015 goss34, yes possible, use event mode gui, and timerinit+timerdiff as computergroove suggested. I can post a simple example if you want Link to comment Share on other sites More sharing options...
goss34 Posted October 6, 2015 Author Share Posted October 6, 2015 Hi Teks,If you could post an example that would be great. Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted October 6, 2015 Moderators Share Posted October 6, 2015 goss34,Does this help?#include <GUIConstantsEx.au3> $hGUI = GUICreate("Test", 500, 500) $cLabel = GUICtrlCreateLabel("0", 10, 10, 20, 20) GUISetState() ; Get a timestamp $nBegin = TimerInit() While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit EndSwitch ; See if the timer delay has expired - here it is 5 secs If TimerDiff($nBegin) > 5 * 1000 Then ; Read the value displayed $sValue = GUICtrlRead($cLabel) ; Increase it by 1 and reset GUICtrlSetData($cLabel, $sValue + 1) ; Reset the timestamp for the next delay $nBegin = TimerInit() EndIf WEndTeks,Using Event mode will not help here - as you can see from the above you can very easily do this in either mode.M23 Teks 1 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
Teks Posted October 6, 2015 Share Posted October 6, 2015 (edited) Melba23,thanks for the example. What makes GUIGetMsg() return there since there's no user interaction? Am I missing something about how message mode works?edit: wow, it immediately returns with 0 when there's no event. I didn't know that. That's effectively a busy loop but somehow does not hog the CPU. now I'm curious why event mode was invented. Edited October 6, 2015 by Teks add reason Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted October 6, 2015 Moderators Share Posted October 6, 2015 Teks,In fact GUIGetMsg sleeps for about 12-15ms at every call. A clever little wrinkle from Jon which means you do not have to add a Sleep in the idle loop when in MessageLoop mode - but you certainly do need one if you are in OnEvent mode.Both modes have their pros and cons. I nearly always use MessageLoop mode as it means fewer functions to write for simple scripts - but there have been reports (from people I trust) that having a HUGE MessageLoop loop (with perhaps 100+ controls) can cause problems, although I have never come across it myself.M23 Teks 1 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
goss34 Posted October 6, 2015 Author Share Posted October 6, 2015 goss34,Does this help?#include <GUIConstantsEx.au3> $hGUI = GUICreate("Test", 500, 500) $cLabel = GUICtrlCreateLabel("0", 10, 10, 20, 20) GUISetState() ; Get a timestamp $nBegin = TimerInit() While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit EndSwitch ; See if the timer delay has expired - here it is 5 secs If TimerDiff($nBegin) > 5 * 1000 Then ; Read the value displayed $sValue = GUICtrlRead($cLabel) ; Increase it by 1 and reset GUICtrlSetData($cLabel, $sValue + 1) ; Reset the timestamp for the next delay $nBegin = TimerInit() EndIf WEndTeks,Using Event mode will not help here - as you can see from the above you can very easily do this in either mode.M23It certainly does Melba, thank you very much, i have managed to get what i want going now and can continue with the script.CheersDan Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted October 6, 2015 Moderators Share Posted October 6, 2015 goss34,Delighted I could help, but when you reply, please use the "Reply to this topic" button at the top of the thread or the "Reply to this topic" editor at the bottom rather than the "Quote" button - I know what I wrote and it just pads the thread unnecessarily.M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
goss34 Posted October 6, 2015 Author Share Posted October 6, 2015 Not a problem, noted. Thanks again Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now