Gimerly Posted May 19, 2014 Posted May 19, 2014 Hello all, I need to create tray items and I am unsure on how to allow the program to consistently loop to check for any button clicks on my tray items and have the rest of my code run as well.
Moderators Melba23 Posted May 19, 2014 Moderators Posted May 19, 2014 (edited) Gimerly,If you are in MessageLoop mode than add a TrayGetMsg structure to your idle loop in the same way as GUIGetMsg. If in OnEvent mode, then set event functions to your items using TraySetOnEvent in the same manner as GUICtrlSetOnEvent. M23Edit: And you can mix and match modes for the GUI and tray - they need not be the same mode. Edited May 19, 2014 by Melba23 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
Gimerly Posted May 19, 2014 Author Posted May 19, 2014 Hey thanks for the reply. I still have my script paused. could you have a look at the code. I really need to be able to use the rest of script while to having this mode. Opt("TrayMenuMode", 3) Func TrayItems() $ABout = TrayCreateItem("About") TrayCreateItem("") ; Create a separator line. $Exit = TrayCreateItem("Exit") TrayItemSetOnEvent(-1, "ExitScript") TraySetOnEvent($TRAY_EVENT_PRIMARYDOUBLE, "TrayEvent") TraySetOnEvent($TRAY_EVENT_SECONDARYUP, "TrayEvent") TraySetState(1) ; Show the tray menu. While 1 switch TrayGetMsg() Case $About msgbox(0, "A message", "this is some text") case $Exit exitloop endswitch WEnd EndFunc
Moderators Melba23 Posted May 19, 2014 Moderators Posted May 19, 2014 Gimerly,Just as with a GUI, you cannot mix OnEvent and MessageLoop modes for the tray! Does this make it easier to understand? Using TrayOnEvent mode:expandcollapse popup#include <GUIConstantsEx.au3> #include <MsgBoxConstants.au3> #include <TrayConstants.au3> Opt("TrayMenuMode", 3) Opt("TrayOnEventMode", 1) ; Use TrayOnEvent mode TrayCreateItem("About") TrayItemSetOnEvent(-1, "_About") TrayCreateItem("") ; Create a separator line. $Exit = TrayCreateItem("Exit") TrayItemSetOnEvent(-1, "_ExitScript") TraySetOnEvent($TRAY_EVENT_PRIMARYDOUBLE, "_TrayEvent") TraySetOnEvent($TRAY_EVENT_SECONDARYUP, "_TrayEvent") $hGUI = GUICreate("Test", 500, 500) $cButton = GUICtrlCreateButton("Test", 10, 10, 80, 30) GUISetState() While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit Case $cButton MsgBox($MB_SYSTEMMODAL, "Hi", "Button pressed") EndSwitch WEnd Func _TrayEvent() MsgBox($MB_SYSTEMMODAL, "Hi", "Tray Event detected") EndFunc Func _About() MsgBox($MB_SYSTEMMODAL, "About", "Text") EndFunc Func _ExitScript() Exit EndFuncAnd now TrayMessageLoop mode:#include <GUIConstantsEx.au3> #include <MsgBoxConstants.au3> #include <TrayConstants.au3> Opt("TrayMenuMode", 3) $tmAbout = TrayCreateItem("About") TrayCreateItem("") ; Create a separator line. $tmExit = TrayCreateItem("Exit") $hGUI = GUICreate("Test", 500, 500) $cButton = GUICtrlCreateButton("Test", 10, 10, 80, 30) GUISetState() While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit Case $cButton MsgBox($MB_SYSTEMMODAL, "Hi", "Button pressed") EndSwitch Switch TrayGetMsg() Case $tmAbout MsgBox($MB_SYSTEMMODAL, "About", "Text") Case $tmExit Exit Case $TRAY_EVENT_PRIMARYDOUBLE, $TRAY_EVENT_SECONDARYUP MsgBox($MB_SYSTEMMODAL, "Hi", "Tray Event detected") EndSwitch WEndAs you can see, the button and tray are always active - unless the script is paused by a MsgBox. 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
Gimerly Posted May 19, 2014 Author Posted May 19, 2014 I can see what you are doing here. But I dont know how to integrate it into my script. Can you take a look at my script and give me some ideas on how to implement the tray elements with my main script expandcollapse popupwhile 1 ; something to loop the application endlessly while _Wlan_QueryInterface() = "Connected" ; loops only if connected to wifi, if not then the code below is useless and is pointless to run $Backoff = 0 ; Backoff is set a value later on if dropbox requests a backoff. so obvioulsly however long dropbox wants me to wait I will set that value to $Backoff $Response = HttpGetLongDelta($Cursor) ; check to see if a change has occured. wait for a max of 6 miniutes if @Error then ;message("Error with wait, Wait 10sec "&$Response) ; something has happened to the cursor and instead of investigating I will just get a new cursor -_- message("Cursor corrupt - getting new one") ; get the new cursor $Response = postdelta() if @error then ; if there is an error then dont write it to the configuration. message("Error getting latest instructions") pause(10) Else ;if no error than write the latest changes to the configuration iniwrite($puffy &"\puff.ini","full responce","Last",$Response) $Cursor = GetCursor($Response) ; find the cursor in the latest changes and write it to the last variable in the cursor section iniwrite($puffy &"\puff.ini","Cursor","Last",$Cursor) EndIf Else $Backoff = GetBackoff($Response) if $Backoff<> 0 then message("Have been requested to wait "&$Backoff&" seconds until next check") pause($Backoff) endif ; Stringinstr(string, 8) removes all the white space between text. I need to use this as dropbox is inconsistence with the spacing between "changes": and true if stringinstr(StringStripWS($Response,8),'{"changes":true}') Then ; check to see if the return is true. if true then a change has occured and action must be taken message("Change has been detected in puffy servers") $Response = postdelta($Cursor) ; because no error has occured it would still write to my puff.ini file so I need to make sure that if $Response if 0 it doesnt delete all my information -_- if @error then message("error with retrieving changes") ; couldnt retrieve the latest changes -_- pause(10) Else ; iniwrite writes to a configuration file with the parameters being "file to open", "section", "key", "value" iniwrite($puffy &"\puff.ini","full responce","Last",$Response) $Cursor = GetCursor($Response) iniwrite($puffy &"\puff.ini","Cursor","Last",$Cursor) traytip("downloading", "Cursor", 2) traytip("downloaded", "Done", 1) message("updated cursor") $sFile = iniread(@scriptdir & "/puff.ini", "full responce", "Last", "") ;get the latest changes download($sFile) EndIf Else if stringinstr(StringStripWS($Response,8),'{"changes":false}') Then ; if change is false then no change has occured message("Puffy servers didnt detect a chnage") Else message("Unknown Response: "&$Response) EndIf EndIf EndIf sleep($Backoff) WEnd message("unable to establish an internet connection") pause(5) WEnd
Moderators Melba23 Posted May 20, 2014 Moderators Posted May 20, 2014 (edited) Gimerly,Two options - for both you will need to create the tray items before you enter the loop and add the required functions outside the loop: - 1. Set TrayOnEvent mode and assign the functions to the tray items before the loop starts.- 2. Use TrayMessageLoop mode and poll TrayGetMsg inside the loop using a Switch / Select structure.All clear? M23 Edited May 20, 2014 by Melba23 Wrong button, too soon! 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
Gimerly Posted May 20, 2014 Author Posted May 20, 2014 Thanks very much. I have set my main loop as a function and changed it to an if statement so that it only loops once. I created a trayitem called sync and whenever the button is pressed I use the call function to the call upon the function. I also remembered that when using my httpostdelta it pauses the rest of my script as it waits 6 minutes to detect changes to my dropbox account. So now I need to make another script which polls for changes in dropbox account in the background and in main function I will keep checking to see if any changes have occured. I was hoping that autoIT could do some type of parallel processing but it doesn't appear to. Thanks very much for your help Melba23
Moderators Melba23 Posted May 20, 2014 Moderators Posted May 20, 2014 Gimerly, I was hoping that autoIT could do some type of parallel processingAlas, no - single thread is all you get. Glad I could help. 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
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