Jump to content

after disable a button, the script not exit on press ESC button


 Share

Recommended Posts

Greetings!

 

If you open the script and press ESC (to exit), the script exit fine.

If you click in the button, to disable it, whe you press ESC (to exit), for me, the windows play a sound and not exit.

This is happens to you?

Why?

How solve it?

Obs: I preffer use events in script.

 

Best regards.

#include-once
#include <Array.au3>
#include <GUIConstantsEx.au3>

OnAutoItExitRegister("OnExit")

Opt("GUIOnEventMode", 1)
Opt("GUIEventOptions", 1)
Opt("MustDeclareVars", 1)

Global $aGuiSize[2] = [320, 240]
Global $sGuiTitle = "GuiTitle"
Global $hGui
Global $hButton

$hGui = GUICreate($sGuiTitle, $aGuiSize[0], $aGuiSize[1])
GUISetOnEvent($GUI_EVENT_CLOSE, "Quit")

$hButton = GUICtrlCreateButton("Click here!", 10, 10, 80, 25)
GUICtrlSetOnEvent($hButton, "ButtonClick")

GUISetState(@SW_SHOW, $hGui)

While Sleep(25)
WEnd

Func ButtonClick()
    GUICtrlSetState($hButton, $GUI_DISABLE)
EndFunc

Func OnExit()
    GUISetState($hGui, @SW_HIDE)
    GUIDelete($hGui)
EndFunc   ;==>OnExit

Func Quit()
    Exit
EndFunc   ;==>Quit

 

Edited by Luigi

Visit my repository

Link to comment
Share on other sites

@Subz, its work, but, have a problem.

I you click ESC out of script, it will be finished.

This is not wanted.

 

WIth HotKeySet, you need write more code to verify each loop, if this script is on focus or not, and enable HotKeySet(ESC) or not in focus, disable HotKeySet(ESC).

Try it.

Edited by Luigi

Visit my repository

Link to comment
Share on other sites

Sorry my english...

If you do not click on button, the run of script is normal. If you press ESC, they exit, this is good way.

If you click a button, when you use GUICtrlSetState($hButton, $GUI_DISABLE) for this or any GUICtrlCreateButton, the ESC key does not work anymore.

For me, the Windows play a error sound and script not exit with ESC key, I need click on "X" to exit.

Why the script lost the function of ESC?

Visit my repository

Link to comment
Share on other sites

@KickStarter15, this issue is old for me.
With one or many button (or other elements: GuiCtrlCreateInput, GuiCtrlCreateCombo, GuiCtrlCreateEdit)...

When you use only one  GUICtrlSetState($HandleOfAnyElement, $GUI_DISABLE) the ESC not work any more.

Of course...

If you GUICtrlSetState($HandleOfAnyElement, $GUI_ENABLE), the ESC recover the function, and Exit fine.

 

$GUI_DISABLE disable only element or disable the GUI?
In the AutoIt's HELP say: "Control will be greyed out."

 

Edited by Luigi

Visit my repository

Link to comment
Share on other sites

Not 100% sure maybe someone else can answer, but when you press escape it sends a notification of -3 or $GUI_EVENT_CLOSE to the button control, when the button is disabled it no longer accepts any notifications.  So if you were to add another dummy control and after disabling the first button you clicked on the dummy control you can send notifications again to that non disabled control.

Hope that makes sense.

 

Link to comment
Share on other sites

A "virtual way" to DISABLE the button, is unsign the function from button, and re-paint it like a disable button.

When ENABLE it again, assing the function to the button and re-paint like a enabled button.

 

I do not find this elegant solution, but it works.

I still do not know if the error is mine or I'm not using the code the right way.

The button was never DISABLED, I remove the function's link.

You can click, but, does not work.

#include-once
#include <Array.au3>
#include <GUIConstantsEx.au3>

OnAutoItExitRegister("OnExit")

Opt("GUIOnEventMode", 1)
Opt("GUIEventOptions", 1)
Opt("MustDeclareVars", 1)

Global $aGuiSize[2] = [320, 240]
Global $sGuiTitle = "GuiTitle"
Global $hGui
Global $hLock, $hUnLock

$hGui = GUICreate($sGuiTitle, $aGuiSize[0], $aGuiSize[1])
GUISetOnEvent($GUI_EVENT_CLOSE, "SpecialEvents", $hGui)

$hLock = GUICtrlCreateButton("Lock me!", 10, 10, 80, 25)
GUICtrlSetOnEvent($hLock, "ButtonDisable")

$hUnLock = GUICtrlCreateButton("Unlock!", 10, 40, 80, 25)
GUICtrlSetOnEvent($hUnLock, "ButtonEnable")

GUISetState(@SW_SHOW, $hGui)

While Sleep(25)
WEnd

Func ButtonDisable()
    GUICtrlSetBkColor($hLock, 0xCCCCCC)
    GUICtrlSetColor($hLock, 0x9090A8)
    GUICtrlSetOnEvent($hLock, "")
EndFunc   ;==>ButtonDisable

Func ButtonEnable()
    GUICtrlSetBkColor($hLock, 0xE1E1E1)
    GUICtrlSetColor($hLock, 0x5A005A)
    GUICtrlSetOnEvent($hLock, "ButtonDisable")
EndFunc   ;==>ButtonEnable

Func OnExit()
    GUIDelete($hGui)
EndFunc   ;==>OnExit

Func SpecialEvents()
    ConsoleWrite("@GUI_CtrlId[ " & @GUI_CtrlId & " ]" & @LF)
    Switch @GUI_CtrlId
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
EndFunc   ;==>SpecialEvents

 

Edited by Luigi

Visit my repository

Link to comment
Share on other sites

  • Moderators

Luigi,

I have been playing with this all morning. In both OnEvent and MessageLoop mode, disabling a control programmatically after the GUI has been displayed prevents the ESCAPE key from exiting the GUI. Setting the control to disabled before the GUI is displayed does not have this effect.

Unless someone can come up with a logical explanation it looks like a bug to me - I suggest opening a Trac ticket and linking to this thread.

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

In Post#11 remove the  GUICtrlSetOnEvent($hUnLock, "ButtonEnable") function so it now does nothing, click "Lock me!" its now disabled and escape doesn't work, now click the "Unlock" button (it does nothing) but if you press escape it will now close.  As mentioned above when you click "Lock me!" the focus is still on that disabled button which no longer accepts notifications, you have to change the focus to a non disabled control which will accept notifications.

Link to comment
Share on other sites

@Melba23, WOW! This is not my error?

@Subz, you are right!

Just write on line of code and redirect the focus for another ENABLED GuiCtrlElement!

GUICtrlSetState($hUnLock, $GUI_FOCUS)

Thank you! ^^

#include-once
#include <Array.au3>
#include <GUIConstantsEx.au3>

OnAutoItExitRegister("OnExit")

Opt("GUIOnEventMode", 1)
Opt("GUIEventOptions", 1)
Opt("MustDeclareVars", 1)

Global $aGuiSize[2] = [320, 240]
Global $sGuiTitle = "GuiTitle"
Global $hGui
Global $hLock, $hUnLock

$hGui = GUICreate($sGuiTitle, $aGuiSize[0], $aGuiSize[1])
GUISetOnEvent($GUI_EVENT_CLOSE, "SpecialEvents", $hGui)

$hLock = GUICtrlCreateButton("Lock me!", 10, 10, 80, 25)
GUICtrlSetOnEvent($hLock, "ButtonDisable")

$hUnLock = GUICtrlCreateButton("Unlock!", 10, 40, 80, 25)
GUICtrlSetOnEvent($hUnLock, "ButtonEnable")

GUISetState(@SW_SHOW, $hGui)

While Sleep(25)
WEnd

Func ButtonDisable()
    GUICtrlSetState($hLock, $GUI_DISABLE)
    GUICtrlSetState($hUnLock, $GUI_FOCUS)
;~  GUICtrlSetBkColor($hLock, 0xCCCCCC)
;~  GUICtrlSetColor($hLock, 0x9090A8)
;~  GUICtrlSetOnEvent($hLock, "")
EndFunc   ;==>ButtonDisable

Func ButtonEnable()
    GUICtrlSetState($hLock, $GUI_ENABLE)
;~  GUICtrlSetBkColor($hLock, 0xE1E1E1)
;~  GUICtrlSetColor($hLock, 0x5A005A)
;~  GUICtrlSetOnEvent($hLock, "ButtonDisable")
EndFunc   ;==>ButtonEnable

Func OnExit()
    GUIDelete($hGui)
EndFunc   ;==>OnExit

Func SpecialEvents()
    ConsoleWrite("@GUI_CtrlId[ " & @GUI_CtrlId & " ]" & @LF)
    Switch @GUI_CtrlId
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
EndFunc   ;==>SpecialEvents

 

Edited by Luigi

Visit my repository

Link to comment
Share on other sites

  • Moderators

Subz,

Even though your workaround solves the problem, I am not sure your explanation is logical. $GUI_EVENT_CLOSE is, as its name suggests, a GUI event, not a control one. So I would expect it to be sent even if the currently focused control is disabled - but I freely admit have no knowledge of how AutoIt deals with this internally.

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

Melba23

In the beginning I expected the same behavior you described as well, it wasn't until I created a dummy button and couldn't tab between controls either, when the focus was on the disabled button, that I gathered that the keys were being sent to the control not to the Gui, so my explanation is really around observational behavior, but have no idea if this is correct or not.

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