czardas Posted October 6, 2010 Share Posted October 6, 2010 (edited) This is a scaled down reproducer. The label on my GUI can be updated manually or automatically. I can switch between these two modes using the Mode menu. However, when in Auto mode, if I click on the menu and ponder a while before deciding which mode to select, the automated actions become queued. As soon as I make a decision the GUI updates several steps in one hit. I would like to be able to freeze all action until either a mode has been selected or the menu display has disappeared. How can I tell if the user clicked on 'Mode' main menu? Any suggestions would be appreciated. expandcollapse popup#include <GUIConstantsEx.au3> #include <StaticConstants.au3> Local $hGUI, $h_Mode, $h_Manual, $h_Auto, $h_Label $hGUI = GUICreate("", 100, 120) $h_Mode = GUICtrlCreateMenu("Mode") $h_Manual = GUICtrlCreateMenuItem("Manual", $h_Mode) $h_Auto = GUICtrlCreateMenuItem("Auto", $h_Mode) $h_Label = GUICtrlCreateLabel("0", 5, 5, 90, 90, $SS_CENTER) GUICtrlSetFont(-1, 46, 400, -1, "Comic Sans MS") GUISetState() Local $ai_Colors[3] = [0x58A200, 0x7FBDE9, 0xE9E87F], $i_Mode = 0, $i_Count = 1 While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop Case $h_Manual $i_Mode = 0 Case $h_Auto $i_Mode = 1 Local $i_TmStrt = TimerInit(), $i_TmIntval = 2000 Case $h_Label If $i_Mode = 0 Then _UpdateLabel($i_Count) ; Update the label manually. EndSwitch If $i_Mode = 1 Then ; Update the label automatically at regular intervals. If TimerDiff($i_TmStrt) > $i_TmIntval Then _UpdateLabel($i_Count) $i_TmIntval += 2000 EndIf EndIf WEnd Func _UpdateLabel(ByRef $iCount) ; Changes the display. If $iCount = 10 Then $iCount = 1 GUICtrlSetData($h_Label, $iCount) $iCount += 1 GUICtrlSetBkColor($h_Label, $ai_Colors[Mod($iCount, 3)]) EndFunc Edited October 6, 2010 by czardas operator64 ArrayWorkshop Link to comment Share on other sites More sharing options...
AlmarM Posted October 6, 2010 Share Posted October 6, 2010 Why are you added 2000ms each time the timer has reached it's limit?Why not reset the TimerInit() ?If $i_Mode = 1 Then ; Update the label automatically at regular intervals. If TimerDiff($i_TmStrt) > 2000 Then _UpdateLabel($i_Count) $i_TmStrt = TimerInit() EndIf EndIf*! I could be missing something, didn't read the whole post yet. This is just a small notice. !* Minesweeper A minesweeper game created in autoit, source available. _Mouse_UDF An UDF for registering functions to mouse events, made in pure autoit. 2D Hitbox Editor A 2D hitbox editor for quick creation of 2D sphere and rectangle hitboxes. Link to comment Share on other sites More sharing options...
czardas Posted October 6, 2010 Author Share Posted October 6, 2010 (edited) Why are you added 2000ms each time the timer has reached it's limit? Why not reset the TimerInit() ? If $i_Mode = 1 Then ; Update the label automatically at regular intervals. If TimerDiff($i_TmStrt) > 2000 Then _UpdateLabel($i_Count) $i_TmStrt = TimerInit() EndIf EndIf *! I could be missing something, didn't read the whole post yet. This is just a small notice. !* Yes that helps, thanks! It's an improvement. Now it only leaps forward one step. haha! That is something I think I can probably just about live with. Although it would still be better if I could pause it completely. Edited October 6, 2010 by czardas operator64 ArrayWorkshop Link to comment Share on other sites More sharing options...
jaberwacky Posted October 6, 2010 Share Posted October 6, 2010 Is this what you want? expandcollapse popup#include <GUIConstantsEx.au3> #include <StaticConstants.au3> Global Const $hGUI = GUICreate("", 100, 120) Global Const $h_Mode = GUICtrlCreateMenu("Mode") Global Const $h_Manual = GUICtrlCreateMenuItem("Manual", $h_Mode) Global Const $h_Auto = GUICtrlCreateMenuItem("Auto", $h_Mode) Global Const $h_Label = GUICtrlCreateLabel("0", 5, 5, 90, 90, $SS_CENTER) GUICtrlSetFont(-1, 46, 400, -1, "Comic Sans MS") GUISetState() Global Const $ai_Colors[3] = [0x58A200, 0x7FBDE9, 0xE9E87F] Global $i_Mode = 0 While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop Case $h_Manual $i_Mode = 0 Case $h_Auto $i_Mode = 1 Case $h_Label If $i_Mode = 0 Then _UpdateLabel() ; Update the label manually. EndSwitch If $i_Mode = 1 Then ; Update the label automatically at regular intervals. _UpdateLabel() Sleep(2000) EndIf WEnd Func _UpdateLabel() ; Changes the display. Local Static $i_Count = 1 If $i_Count = 10 Then $i_Count = 1 GUICtrlSetData($h_Label, $i_Count) GUICtrlSetBkColor($h_Label, $ai_Colors[Mod($i_Count - 1, 3)]) $i_Count += 1 EndFunc ;==>_UpdateLabel Helpful Posts and Websites: AutoIt3 Variables and Function Parameters MHz | AutoIt Wiki | Using the GUIToolTip UDF BrewManNH | Can't find what you're looking for on the Forum? Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted October 6, 2010 Moderators Share Posted October 6, 2010 czardas, When you open the menu bar, you enter a modal loop which freezes the script until you exit the loop by choosing something. If you look for this exit, you can reset the timer and so not jump ahead. It is coded like this: expandcollapse popup#include <GUIConstantsEx.au3> #include <StaticConstants.au3> Global $hGUI, $h_Mode, $h_Manual, $h_Auto, $h_Label, $i_TmStrt, $i_TmIntval = 2000 $hGUI = GUICreate("", 100, 120) $h_Mode = GUICtrlCreateMenu("Mode") $h_Manual = GUICtrlCreateMenuItem("Manual", $h_Mode) $h_Auto = GUICtrlCreateMenuItem("Auto", $h_Mode) $h_Label = GUICtrlCreateLabel("0", 5, 5, 90, 90, $SS_CENTER) GUICtrlSetFont(-1, 46, 400, -1, "Comic Sans MS") GUISetState() GUIRegisterMsg(0x0212,"_WM_EXITMENULOOP") ; look for the WM_EXITMENULOOP message Local $ai_Colors[3] = [0x58A200, 0x7FBDE9, 0xE9E87F], $i_Mode = 0, $i_Count = 1 While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop Case $h_Manual $i_Mode = 0 Case $h_Auto $i_Mode = 1 $i_TmStrt = TimerInit() Case $h_Label If $i_Mode = 0 Then _UpdateLabel($i_Count) ; Update the label manually. EndSwitch If $i_Mode = 1 Then ; Update the label automatically at regular intervals. If TimerDiff($i_TmStrt) > $i_TmIntval Then _UpdateLabel($i_Count) $i_TmStrt = TimerInit() EndIf EndIf WEnd Func _UpdateLabel(ByRef $iCount) ; Changes the display. If $iCount = 10 Then $iCount = 1 GUICtrlSetData($h_Label, $iCount) $iCount += 1 GUICtrlSetBkColor($h_Label, $ai_Colors[Mod($iCount, 3)]) EndFunc Func _WM_EXITMENULOOP($hWnd, $iMsg, $wParam, $lParam) $i_TmStrt = TimerInit() ; Now reset the timer so we stay on the same menu number EndFunc I hope that is what you wanted. 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...
czardas Posted October 6, 2010 Author Share Posted October 6, 2010 Is this what you want?I don't know what you did, but I can't switch backwards and forwards between modes anymore. operator64 ArrayWorkshop Link to comment Share on other sites More sharing options...
AlmarM Posted October 6, 2010 Share Posted October 6, 2010 I don't know what you did, but I can't switch backwards and forwards between modes anymore.He did a Sleep(2000) instead of a TimerInit, TimerDiff. Minesweeper A minesweeper game created in autoit, source available. _Mouse_UDF An UDF for registering functions to mouse events, made in pure autoit. 2D Hitbox Editor A 2D hitbox editor for quick creation of 2D sphere and rectangle hitboxes. Link to comment Share on other sites More sharing options...
czardas Posted October 6, 2010 Author Share Posted October 6, 2010 Melba, that is exactly what I was looking for. Thanks to everybody! operator64 ArrayWorkshop Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted October 6, 2010 Moderators Share Posted October 6, 2010 czardas,I only learnt about those particular MENULOOP messages last week - glad I was able to put it to good use so soon afterwards. 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...
czardas Posted October 6, 2010 Author Share Posted October 6, 2010 (edited) Both you, M23, and AlmarM set me on the right path. I much appreciate it. It's for a tic-tac-toe engine I made (I know it's old hat!), which has 5 playing modes and two levels of skill. When the computer plays against itself, the grid also displays an analysis by highlighting different fields using a colour scheme. A bit like a disco. Edited October 6, 2010 by czardas operator64 ArrayWorkshop Link to comment Share on other sites More sharing options...
AlmarM Posted October 6, 2010 Share Posted October 6, 2010 (edited) I only learnt about those particular MENULOOP messages last week - glad I was able to put it to good use so soon afterwards. I learned somethnig today! It's for a tic-tac-toe engine I made (I know it's old hat!), which has 5 playing modes and two levels of skill. When the computer plays against itself, the grid also displays an analysis by highlighting different fields using a colour scheme. A bit like a disco. Ah, yes... That made sence! Also, glad I could help. Edited October 6, 2010 by AlmarM Minesweeper A minesweeper game created in autoit, source available. _Mouse_UDF An UDF for registering functions to mouse events, made in pure autoit. 2D Hitbox Editor A 2D hitbox editor for quick creation of 2D sphere and rectangle hitboxes. Link to comment Share on other sites More sharing options...
jaberwacky Posted October 6, 2010 Share Posted October 6, 2010 Sheesh, I was way off the mark! I learned something new too, thanks M23! Helpful Posts and Websites: AutoIt3 Variables and Function Parameters MHz | AutoIt Wiki | Using the GUIToolTip UDF BrewManNH | Can't find what you're looking for on the Forum? Link to comment Share on other sites More sharing options...
czardas Posted October 6, 2010 Author Share Posted October 6, 2010 Sheesh, I was way off the mark! I learned something new too, thanks M23!Your input is still appreciated. The reason for not using sleep, in this situation, is so I can still interact with the controls whilst the display changes in automatic mode. The script needed to be slowed down in order to be able to observe the changes. M23's solution opens a lot of new possiblities I didn't know about. operator64 ArrayWorkshop 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