Jump to content

GUI Buttons not working correctly


NoelG
 Share

Recommended Posts

Hi all. I'm running into a problem with my script where the OK button on "form1" will not do anyting. I can remove main menu region, then the password prompt works just fine. I'm not a skilled script writer so any help would greatly be appreciated. I'm not sure what is the root cause of this issue and have spend hours looking at it and trying other things.

Thanks for any help you give.

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <EditConstants.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>

Dim $PasswordEdit, $username_input, $Form2  

_main_menu()
#Region ### Start Main Menu with required functions ###
Func _main_menu()
Opt("GUIOnEventMode", 1)
#Region ### START Koda GUI section ### Form=C:\Program Files\AutoIt3\SciTE\Koda\Forms\updatedvd.kxf
$Form2 = GUICreate("Update DVD Fall 2009", 364, 365, 453, 187)
GUISetOnEvent($GUI_EVENT_CLOSE, "Form2Close")
GUISetOnEvent($GUI_EVENT_MINIMIZE, "Form2Minimize")
GUISetOnEvent($GUI_EVENT_MAXIMIZE, "Form2Maximize")
GUISetOnEvent($GUI_EVENT_RESTORE, "Form2Restore")
$Button1 = GUICtrlCreateButton("Install All", 24, 80, 137, 121, 0)
GUICtrlSetFont(-1, 14, 800, 2, "MS Sans Serif")
GUICtrlSetColor(-1, 0x0000FF)
GUICtrlSetOnEvent(-1, "Button1Click")
$Button2 = GUICtrlCreateButton("Windows Updates", 192, 80, 137, 121, 0)
GUICtrlSetFont(-1, 11, 800, 2, "MS Sans Serif")
GUICtrlSetColor(-1, 0x0000FF)
GUICtrlSetOnEvent(-1, "Button2Click")
$Button3 = GUICtrlCreateButton("Browse DVD", 112, 224, 137, 121, 0)
GUICtrlSetFont(-1, 14, 800, 2, "MS Sans Serif")
GUICtrlSetColor(-1, 0x0000FF)
GUICtrlSetOnEvent(-1, "Button3Click")
$Label1 = GUICtrlCreateLabel("Welcome to the Update DVD.", 32, 16, 307, 28)
GUICtrlSetFont(-1, 15, 400, 0, "MS Sans Serif")
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
    Sleep(100)
WEnd
EndFunc

Func Button1Click() ;Install All Function
    GUIDelete($Form2)
    #Region --- CodeWizard generated code Start ---
    ;MsgBox features: Title=Yes, Text=Yes, Buttons=OK and Cancel, Icon=Info
    If Not IsDeclared("iMsgBoxAnswer") Then Local $iMsgBoxAnswer
    $iMsgBoxAnswer = MsgBox(65, "Update DVD Fall 2009", "!!!!!READ CAREFULLY BEFORE CONTNUING!!!!!" & @CRLF & "This update DVD is provided by the me to all laptop users as a collection of security and functionality upgrades. This DVD is not to be used on any equipment that is not owned by me without express authorization from the me " & @CRLF & @CRLF & "Please note that this disk will update and/or install the following programs: " & @CRLF & "Adobe Reader" & @CRLF & "iFolder" & @CRLF & "Flash Player" & @CRLF & "Shockwave" & @CRLF & "Novell Client" & @CRLF & "GroupWise" & @CRLF & "Windows" & @CRLF & "ZoneAlarm" & @CRLF & @CRLF & "These updates will take several hours to complete and your computer will reboot several times during the process. No interaction is required on your part after the process begins. We recommend starting this disk just prior to going to sleep. " & @CRLF & @CRLF & "Click OK to move on to the next step, inputting your user name and password. " & @CRLF)
    Select
        Case $iMsgBoxAnswer = 1 ;OK
            _get_password()
        Case $iMsgBoxAnswer = 2 ;Cancel

    EndSelect
    #EndRegion --- CodeWizard generated code Start ---

EndFunc   ;==>Button1Click
Func Button2Click() ;Install Windows Update Function

EndFunc   ;==>Button2Click
Func Button3Click() ;Browse File Structure.

EndFunc   ;==>Button3Click

Func Form2Close()
Exit
EndFunc

Func Form2Maximize()

EndFunc

Func Form2Minimize()

EndFunc

Func Form2Restore()

EndFunc
#EndRegion ### End of Main Menu with Functions ###


#Region ### Start of Password Prompt with Functions ###
Func _get_password()
Opt("GUIOnEventMode", 1)
#Region ### START Koda GUI section ### Form=C:\Program Files\AutoIt3\SciTE\Koda\Forms\username_password.kxf
$Form1 = GUICreate("Password Dialog", 257, 188, -1, -1)
GUISetIcon("D:\008.ico")
GUISetOnEvent($GUI_EVENT_CLOSE, "Form1Close")
GUISetOnEvent($GUI_EVENT_MINIMIZE, "Form1Minimize")
GUISetOnEvent($GUI_EVENT_MAXIMIZE, "Form1Maximize")
GUISetOnEvent($GUI_EVENT_RESTORE, "Form1Restore")
$PasswordEdit = GUICtrlCreateInput("password", 8, 88, 233, 21, BitOR($ES_PASSWORD,$ES_AUTOHSCROLL))
$ButtonOk = GUICtrlCreateButton("&OK", 86, 152, 75, 25, 0)
GUICtrlSetOnEvent(-1, "ButtonOkClick")
$ButtonCancel = GUICtrlCreateButton("&Cancel", 167, 152, 75, 25, 0)
GUICtrlSetOnEvent(-1, "ButtonCancelClick")
$EnterPassLabel = GUICtrlCreateLabel("Enter password", 8, 68, 77, 17)
$username = GUICtrlCreateLabel("Enter Username", 8, 8, 80, 17)
$username_input = GUICtrlCreateInput("username", 8, 32, 233, 21)
$okcontinue = GUICtrlCreateLabel("Click Ok to continue.", 8, 120, 103, 17)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
 Sleep(100)
WEnd

EndFunc   ;==>_get_password

Func ButtonCancelClick()
    Exit
EndFunc   ;==>ButtonCancelClick

Func ButtonOkClick() ;Move on to next step after input of password and username.
    MsgBox(1, "test", "ok button test")
EndFunc   ;==>ButtonOkClick

Func Form1Close()
Exit
EndFunc

Func Form1Maximize()

EndFunc

Func Form1Minimize()

EndFunc

Func Form1Restore()

EndFunc
#EndRegion ### Password Prompt with functions ###
Link to comment
Share on other sites

KK, I don't know where the problem was, but I fixed it. (and redid half your code at the same time!). I think it was me moving the loop outside of any functions... This means that all the GUI's are running in the same loop, and being controlled togethor, rather than as individuals. I assume you wish to remain using OnEventMode, so I left it there, but I prefer using a loop for small dialogs with one or two buttons. If you need any help explaining what I did, just ask :D

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <EditConstants.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>

Global $PasswordEdit, $username_input, $Form2, $Form1

   Opt("GUIOnEventMode", 1)

_main_menu()

While 1
   Sleep (100)
WEnd

Func _main_menu()
   $Form2 = GUICreate("Update DVD Fall 2009", 364, 365, 453, 187)
      GUISetOnEvent($GUI_EVENT_CLOSE, "Form2Close")

      $Button1 = GUICtrlCreateButton("Install All", 24, 80, 137, 121, 0)
         GUICtrlSetFont(-1, 14, 800, 2, "MS Sans Serif")
         GUICtrlSetColor(-1, 0x0000FF)
         GUICtrlSetOnEvent(-1, "Button1Click")

      $Button2 = GUICtrlCreateButton("Windows Updates", 192, 80, 137, 121, 0)
         GUICtrlSetFont(-1, 11, 800, 2, "MS Sans Serif")
         GUICtrlSetColor(-1, 0x0000FF)
         GUICtrlSetOnEvent(-1, "Button2Click")

      $Button3 = GUICtrlCreateButton("Browse DVD", 112, 224, 137, 121, 0)
         GUICtrlSetFont(-1, 14, 800, 2, "MS Sans Serif")
         GUICtrlSetColor(-1, 0x0000FF)
         GUICtrlSetOnEvent(-1, "Button3Click")

      $Label1 = GUICtrlCreateLabel("Welcome to the Update DVD.", 32, 16, 307, 28)
         GUICtrlSetFont(-1, 15, 400, 0, "MS Sans Serif")

      GUISetState(@SW_SHOW)
EndFunc

Func Button1Click() ;Install All Function
    GUISetState (@SW_HIDE, $Form2)
    ;MsgBox features: Title=Yes, Text=Yes, Buttons=OK and Cancel, Icon=Info
    If Not IsDeclared("iMsgBoxAnswer") Then Local $iMsgBoxAnswer
    $iMsgBoxAnswer = MsgBox(65, "Update DVD Fall 2009", _
      "!!!!!READ CAREFULLY BEFORE CONTNUING!!!!!" & @CRLF & _
      "This update DVD is provided by the me to all laptop users as a collection of security and functionality upgrades." & _
      " This DVD is not to be used on any equipment that is not owned by me without express authorization from the me " & _
      @CRLF & @CRLF & "Please note that this disk will update and/or install the following programs: " & @CRLF & _
      "Adobe Reader" & @CRLF & "iFolder" & @CRLF & "Flash Player" & @CRLF & "Shockwave" & @CRLF & "Novell Client" & @CRLF & _
      "GroupWise" & @CRLF & "Windows" & @CRLF & "ZoneAlarm" & @CRLF & @CRLF & _
      "These updates will take several hours to complete and your computer will reboot several times during the process. " & _
      "No interaction is required on your part after the process begins. We recommend starting this disk just prior " & _
      "to going to sleep. " & @CRLF & @CRLF & "Click OK to move on to the next step, inputting your user name and password. ")
    Select
        Case $iMsgBoxAnswer = 1 ;OK
            _get_password()
        Case $iMsgBoxAnswer = 2 ;Cancel
    EndSelect
EndFunc   ;==>Button1Click

Func Button2Click() ;Install Windows Update Function
EndFunc   ;==>Button2Click

Func Button3Click() ;Browse File Structure.
EndFunc   ;==>Button3Click

Func Form2Close()
   Exit
EndFunc   ;==>Form2Close

Func _get_password()
   $Form1 = GUICreate("Password Dialog", 257, 188, -1, -1)
      GUISetIcon("D:\008.ico")

      GUISetOnEvent($GUI_EVENT_CLOSE, "Form1Close")

      GUICtrlCreateButton("&OK", 86, 152, 75, 25, 0)
         GUICtrlSetOnEvent(-1, "ButtonOkClick")
      GUICtrlCreateButton("&Cancel", 167, 152, 75, 25, 0)
         GUICtrlSetOnEvent(-1, "ButtonCancelClick")

      GUICtrlCreateLabel("Enter password", 8, 68, 77, 17)
         $PasswordEdit = GUICtrlCreateInput("password", 8, 88, 233, 21, BitOR($ES_PASSWORD,$ES_AUTOHSCROLL))

      GUICtrlCreateLabel("Enter Username", 8, 8, 80, 17)
         $username_input = GUICtrlCreateInput("username", 8, 32, 233, 21)

      GUICtrlCreateLabel("Click Ok to continue.", 8, 120, 103, 17)

   GUISetState(@SW_SHOW)
EndFunc   ;==>_get_password

Func ButtonCancelClick()
   GUISetState (@SW_SHOW, $Form2)
   GUISetState (@SW_HIDE, $Form1)
EndFunc   ;==>ButtonCancelClick

Func ButtonOkClick() ;Move on to next step after input of password and username.
    MsgBox(1, "test", "ok button test" & @CRLF & "Username: " & @TAB & GUICtrlRead ($username_input) & @CRLF & _
      "Password: " & @TAB & GUICtrlRead ($PasswordEdit))
EndFunc   ;==>ButtonOkClick

Func Form1Close()
   Exit
EndFunc

Mat

Edit: The loop it was then! Thanks spiff.

Edited by Mat
Link to comment
Share on other sites

Thanks Mat and Spiff! That really helped. I didn't know that you could use one loop for all GUI's. How exactly does that work? I use OnEventMode cause that's what Koda gave me. I'll have to go back into the help file to read up on the differences.

Thanks again for the help!

Link to comment
Share on other sites

The GUI bit only creates the controls and window line by line. The loop is what keeps the script running. What you were doing was having 2 seperate loops, so it probably got stuck in one... I don't know exactly what it was, but its always best to know exactly where your script should be at any time. use Opt("TrayIconDebug", 1) to help.

On to onevent vs GUI loop. Using a loop allows you to create a dialog and remove it in one function, without interfering with whats outside. Thats why its probably the better option for dialogs.

Mat

Link to comment
Share on other sites

I don't tend to use the OnEventMode option, but I can make an educated guess as to what was going on.

My guess is that when an event is triggered, program execution is interrupted, the event is serviced (via your user-defined function), and when that function completes, execution is then resumed at the same point at which it was interrupted (your first while loop), only after that can the next event be captured and processed.

Your (second) endless loop within the first event call prevented the function from ever returning and being considered completed, so further events were ignored (or possibly queued).

Edited by Spiff59
Link to comment
Share on other sites

Thanks for the information. Sounds like it makes sense. I never thought about it that way. I was able to successfully integrate the above code, with some slight variable name changes, into the rest of the script. And everything is working :D

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