Sign in to follow this  
Followers 0
kicker10bog

Minimize GUI to tray then open GUI from tray ... Buttons don't respond after opening from tray.

3 posts in this topic

So, I wrote a basic alarm script with a simple GUI ... My next step was to be able to minimize the GUI to the tray. I can do that now too. I can even reopen the GUI from the tray, but the buttons won't respond when I reopen.

...

I think it's because it gets stuck in a while loop in another function.

Here's the script:

#NoTrayIcon
#include <GuiConstants.au3>
#include <Constants.au3>
#include <ButtonConstants.au3>
#include <ComboConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <SliderConstants.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
Opt("TrayOnEventMode",1)
Opt("TrayMenuMode",1)
TraySetOnEvent($TRAY_EVENT_PRIMARYUP,"ShowGUI")


#Region ; Global variables not used in current version, but will be used in later versions
Global $SunAlarmActive, $SunAlarmHour, $SunAlarmMinute, $SunAlarmAMPM, $SunAlarmTarget, $SunAlarmTargetName
Global $MonAlarmActive, $MonAlarmHour, $MonAlarmMinute, $MonAlarmAMPM, $MonAlarmTarget, $MonAlarmTargetName
Global $TueAlarmActive, $TueAlarmHour, $TueAlarmMinute, $TueAlarmAMPM, $TueAlarmTarget, $TueAlarmTargetName
Global $WedAlarmActive, $WedAlarmHour, $WedAlarmMinute, $WedAlarmAMPM, $WedAlarmTarget, $WedAlarmTargetName
Global $ThurAlarmActive, $ThurAlarmHour, $ThurAlarmMinute, $ThurAlarmAMPM, $ThurAlarmTarget, $ThurAlarmTargetName
Global $FriAlarmActive, $FriAlarmHour, $FriAlarmMinute, $FriAlarmAMPM, $FriAlarmTarget, $FriAlarmTargetName
Global $SatAlarmActive, $SatAlarmHour, $SatAlarmMinute, $SatAlarmAMPM, $SatAlarmTarget, $SatAlarmTargetName
#EndRegion

Global $alarm24Hour, $alarm24HrTime, $alarm12Hour, $alarm12HrTime, $alarmHour, $alarmMinute, $time, $desiredVolume, $alarmCheck
Global $browserHomeTitle, $target, $targetName, $AM_PM, $closeCheck, $closeHour, $closeMinute, $closeAM_PM, $close24Hour, $closeTime



TraySettings()
OpenGUI()

#Region ### Functions ###
; Executes the Alarm
Func AlarmExecute()
    While $time <> $alarm24HrTime
        $time = @HOUR & ":" & @MIN
    WEnd
        If ($time == $alarm24HrTime And $alarmCheck = True) Then
            ControlVolume()
            OpenTargetAndExecute()
            CloseBrowserTabIfActive()
            $time = @HOUR & ":" & @MIN
        EndIf
EndFunc


; Gets the settings for the alarm
Func AlarmSettings()
    If ($AM_PM == "PM" And $alarmHour <> 12) Then
        $alarm24Hour = $alarmHour + 12
    ElseIf ($AM_PM == "AM" And $alarmHour == 12) Then
        $alarm24Hour = 00
    Else
        $alarm24Hour = $alarmHour
    EndIf
    If $alarm24Hour < 10 Then
        $alarm24Hour = 0 & $alarm24Hour
    EndIf

    If ($closeAM_PM == "PM" And $closeHour <> 12) Then
        $close24Hour = $closeHour + 12
    ElseIf ($closeAM_PM == "AM" And $closeHour == 12) Then
        $close24Hour = 00
    Else
        $close24Hour = $alarmHour
    EndIf
    If $close24Hour < 10 Then
        $close24Hour = 0 & $close24Hour
    EndIf

    $alarm24HrTime = $alarm24Hour & ":" & $alarmMinute
    $alarmTime = $alarmHour & ":" & $alarmMinute & " " & $AM_PM
    $closeTime = $close24Hour & ":" & $closeMinute
    $time = @HOUR & ":" & @MIN
EndFunc

; Contols the speaker volume
Func ControlVolume()
    Send("{VOLUME_DOWN 100}")
    $volumeUp = $desiredVolume / 2
    $volumeCount = 0
    While $volumeCount < $volumeUp
        Send("{VOLUME_UP}")
        $volumeCount += 1
    WEnd
EndFunc

; Opens the target site and exeutes commands
Func OpenTargetAndExecute()
    Send("{BROWSER_HOME}")
    WinWaitActive($browserHomeTitle)
    SendKeepActive($browserHomeTitle)
    Send($target & "{ENTER}")
    MsgBox(0, "Alarm", "The Alarm was triggered at " & $alarm12HrTime & " and " & $targetName & " was succesfully reached.", 3300)
    ;Sleep(3600000)
    ;Sleep(60000);         For Testing
EndFunc

; Closes the target if active
Func CloseBrowserTabIfActive()
    $time = @HOUR & ":" & @MIN
    If (WinActive($targetName) And $closeCheck = True) Then
        While $time <> $closeTime
            $time = @HOUR & ":" & @MIN
        WEnd
        Send("^w")
    EndIf
EndFunc

; Tray operations
Func TraySettings()
    $openUserInterface = TrayCreateItem("Open Web Alarm User Interface")
    TrayItemSetOnEvent(-1, "ShowGUI")
    TrayCreateItem("")
    $exititem = TrayCreateItem("Exit")
    TrayItemSetOnEvent(-1, "ExitApp")
EndFunc

; Builds the GUI and executes the code
Func OpenGUI()
    Opt("GUIOnEventMode", 1)
    #Region ### START Koda GUI section ### Form=C:\Users\Jason\Documents\AutoIt\tuts\practiceFiles\AlarmClock.kxf
    $AlarmClock = GUICreate("Alarm Clock", 541, 412, 216, 182, BitOR($WS_MINIMIZEBOX,$WS_SIZEBOX,$WS_THICKFRAME,$WS_SYSMENU,$WS_CAPTION,$WS_POPUP,$WS_POPUPWINDOW,$WS_GROUP,$WS_BORDER,$WS_CLIPSIBLINGS))
    GUISetIcon("D:\003.ico")
    $GroupBox1 = GUICtrlCreateGroup("", 8, 1, 521, 367)
    $desiredVolume = GUICtrlCreateSlider(9, 263, 517, 45)
    GUICtrlSetLimit($desiredVolume, 100, 0)
    $Vol = GUICtrlCreateLabel("Volume", 14, 237, 70, 28)
    GUICtrlSetFont($Vol, 16, 400, 0, "MS Sans Serif")
    $alarmHour = GUICtrlCreateCombo("", 135, 40, 41, 25)
    GUICtrlSetData($alarmHour, "1|2|3|4|5|6|7|8|9|10|11|12")
    $alarmMinute = GUICtrlCreateCombo("", 193, 40, 43, 25)
    GUICtrlSetData($alarmMinute, "00|01|02|03|04|05|06|07|08|09|10|11|12|13|14|15|16|17|18|19|20|21|22|23|24|25|26|27|28|29|30|31|32|33|34|35|36|37|38|39|40|41|42|43|44|45|46|47|48|49|50|51|52|53|54|55|56|57|58|59")
    $colon = GUICtrlCreateLabel(":", 181, 34, 9, 28)
    GUICtrlSetFont($colon, 14, 400, 0, "MS Sans Serif")
    $target = GUICtrlCreateInput("Pandora.com", 12, 155, 513, 21)
    $targetName = GUICtrlCreateInput("Pandora Radio", 12, 212, 512, 21)
    $browserHomeTitle = GUICtrlCreateInput("New Tab", 11, 99, 514, 21)
    $Browser = GUICtrlCreateLabel("Your Browser Homepage Title", 13, 65, 258, 28)
    GUICtrlSetFont($Browser, 16, 400, 0, "MS Sans Serif")
    $TargetUR = GUICtrlCreateLabel("Desired Target URL", 10, 125, 169, 28)
    GUICtrlSetFont($TargetUR, 16, 400, 0, "MS Sans Serif")
    $TargetNameInpu = GUICtrlCreateLabel("Desired Target Name", 13, 183, 184, 28)
    GUICtrlSetFont($TargetNameInpu, 16, 400, 0, "MS Sans Serif")
    $timeLabel = GUICtrlCreateLabel("Alarm Time - Hour : Minute AM/PM", 12, 10, 298, 28)
    GUICtrlSetFont($timeLabel, 16, 400, 0, "MS Sans Serif")
    $AM_PM = GUICtrlCreateCombo("", 248, 40, 55, 25)
    GUICtrlSetData($AM_PM, "AM|PM")
    $Label1 = GUICtrlCreateLabel("Close Tab Time - Hour : Minute AM/PM", 189, 306, 335, 28)
    GUICtrlSetFont($Label1, 16, 400, 0, "MS Sans Serif")
    $closeHour = GUICtrlCreateCombo("", 339, 338, 41, 25)
    GUICtrlSetData($closeHour, "1|2|3|4|5|6|7|8|9|10|11|12")
    $Label2 = GUICtrlCreateLabel(":", 385, 332, 9, 28)
    GUICtrlSetFont($Label2, 14, 400, 0, "MS Sans Serif")
    $closeMinute = GUICtrlCreateCombo("", 397, 338, 43, 25)
    GUICtrlSetData($closeMinute, "00|01|02|03|04|05|06|07|08|09|10|11|12|13|14|15|16|17|18|19|20|21|22|23|24|25|26|27|28|29|30|31|32|33|34|35|36|37|38|39|40|41|42|43|44|45|46|47|48|49|50|51|52|53|54|55|56|57|58|59")
    $closeAM_PM = GUICtrlCreateCombo("", 452, 338, 55, 25)
    GUICtrlSetData($closeAM_PM, "AM|PM")
    $closeCheck = GUICtrlCreateCheckbox("Close The Tab at the Specified Time", 132, 339, 196, 17)
    $alarmCheck = GUICtrlCreateCheckbox("Make Alarm Active", 313, 43, 114, 17)
    GUICtrlCreateGroup("", -99, -99, 1, 1)
    $Okay = GUICtrlCreateButton("&OK", 354, 375, 75, 25, $WS_GROUP)
    GUICtrlSetOnEvent($Okay, "OkayClick")
    $Exit = GUICtrlCreateButton("&Exit the Alarm", 451, 375, 75, 25, $WS_GROUP)
    GUICtrlSetOnEvent($Exit, "ExitApp")
    GUISetOnEvent($GUI_EVENT_CLOSE, "ExitApp")
    GUISetOnEvent($GUI_EVENT_MINIMIZE, "MinimizeGUItoTray")
    GUISetState(@SW_SHOW)
    #EndRegion ### END Koda GUI section ###

    While 1
     Sleep(100)
    WEnd

EndFunc

Func OkayClick()
    MinimizeGUItoTray()
    $browserHomeTitle = GUICtrlRead($browserHomeTitle)
    $desiredVolume = GUICtrlRead($desiredVolume)
    $target = GUICtrlRead($target)
    $targetName = GUICtrlRead($targetName)
    $alarmHour = GUICtrlRead($alarmHour)
    $alarmMinute = GUICtrlRead($alarmMinute)
    $AM_PM = GUICtrlRead($AM_PM)
    $alarmCheck = GUICtrlRead($alarmCheck)
    $closeCheck = GUICtrlRead($closeCheck)
    $closeHour = GUICtrlRead($closeHour)
    $closeMinute = GUICtrlRead($closeMinute)
    $closeAM_PM = GUICtrlRead($closeAM_PM)
    AlarmSettings()
    AlarmExecute()
EndFunc

Func ExitApp()
    Exit
EndFunc

Func ShowGUI()
    GuiSetState(@SW_Show)
    TraySetState(2) ; hide
EndFunc

Func MinimizeGUItoTray()
    GUISetState(@SW_HIDE)
    TraySetState(1)
    TraySetToolTip ("Web Alarm App - click here to see user interface")
EndFunc
#EndRegion ### End Functions ###

Share this post


Link to post
Share on other sites



kicker10bog,

A good tip - if you think you are getting stuck in a loop, add this line:

Opt("TrayIconDebug", 1)

and you get the current line displayed in the traytip. :D

Anyway, all that did was confirm my suspicion that you were getting stuck in your AlarmExecute() function:

While $time <> $alarm24HrTime
    $time = @HOUR & ":" & @MIN
WEnd

You need to find a way to check the time within your main loop. Perhaps create the GUI once and then show/hide it as necessary. I will have another look after dinner - but do try and solve it yourself in the meantime, it is much more satisfying that way! :huggles:

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

#3 ·  Posted (edited)

Thanks Melba23!

I noticed that loop might be causing the problem after I posted it. ... Changed that function

If ($time == $alarm24HrTime And $alarmCheck = True) Then
        While $time <> $alarm24HrTime
            $time = @HOUR & ":" & @MIN
        WEnd
        ControlVolume()
        OpenTargetAndExecute()
        CloseBrowserTabIfActive()
        $time = @HOUR & ":" & @MIN
    EndIf

I'm wondering if there's a way to check the GUI for changes while the script is executing another loop... But yes, I'll keep trying things.

Thanks again. :D

Edit:

I figured it out. :huggles:

The app still has a couple minor bugs though, and I haven't put all the features I was hoping to put in yet, but I will eventually. :

Edited by kicker10bog

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