Jump to content

How to have tray items run in background


Recommended Posts

  • Moderators

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. :)

M23

Edit: And you can mix and match modes for the GUI and tray - they need not be the same mode. ;)

Edited by Melba23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 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

 

Link to comment
Share on other sites

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
Link to comment
Share on other sites

  • Moderators

Gimerly,

Just as with a GUI, you cannot mix OnEvent and MessageLoop modes for the tray! :(

Does this make it easier to understand? :huh:

Using TrayOnEvent mode:

#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
EndFunc
And 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
WEnd
As you can see, the button and tray are always active - unless the script is paused by a MsgBox. :)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 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

 

Link to comment
Share on other sites

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

while 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 
Link to comment
Share on other sites

  • Moderators

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 by Melba23
Wrong button, too soon!

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 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

 

Link to comment
Share on other sites

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

Link to comment
Share on other sites

  • Moderators

Gimerly,

 

I was hoping that autoIT could do some type of parallel processing

Alas, no - single thread is all you get. Glad I could help. :)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 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

 

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...