Jump to content
Sign in to follow this  
XabiK

Problem with GUI Button (hint: it's not working)

Recommended Posts

XabiK
Hi all,
 
This is my first post in the AutoIt forum... I'm a newbie, but I used AutoIt to develop an internal tool in my company; long to explain, but we need to convert some CAD files (3D models and drawings) into a new format, and instead of click, click, select, etc. thousands of times, I tried to use AutoIt.
 
I managed to do all the conversion, but I wanted to put some 'icing on the cake', creating a form to let the user select what type of conversion he/she wants to do.
 
Actually, it's my first form, and it's driving me nuts!
 
It's very easy: one combo box with 3 different options. When the user selects one option from the combo box, an explanation appears, and he/she can click 'OK'.
 
The thing is... I can't click on the button (it's not working)
 
I suppose it's just a silly mistake of mine, but I can't find it, and I've read a lot of tutorials, forum posts, etc... Can someone help me?
 
Code follows:
 
#region Include
#include-once
#include <ButtonConstants.au3>
#include <ComboConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#endregion Include

#region AutoItSetOption
Opt("GUIOnEventMode", 1)
#endregion AutoItSetOption

#region Input Form definition
Local $frmInput = GUICreate("Conversion tool", 300, 200, -1, -1)
Local $lblTitle = GUICtrlCreateLabel("Please, select elements to convert:", 65, 15, 170, 17, $SS_CENTER)
Local $acmbMode[3]
$acmbMode[0] = "Convert drawings and parts"
$acmbMode[1] = "Only convert parts"
$acmbMode[2] = "Convert drawings and assemblies"
Local $cmbMode = GUICtrlCreateCombo("", 45, 45, 210, 25, BitOR($CBS_DROPDOWN, $CBS_AUTOHSCROLL))
GUICtrlSetOnEvent(-1, "_cmbModeFunction") ;Set the combo box's function
GUICtrlSetData(-1, $acmbMode[0] & "|" & $acmbMode[1] & "|" & $acmbMode[2])
Local $alblExplanation[3]
$alblExplanation[0] = "Parts and drawings" & @LF & "will be converted and linked"
$alblExplanation[1] = "Only parts will be converted"
$alblExplanation[2] = "Assemblies and drawings" & @LF & "will be converted and linked" & @LF & @LF & "Assemblies must exist on input folder!"
Local $lblExplanation = GUICtrlCreateLabel("", 45, 90, 210, 100, $SS_CENTER)
Local $btnOK = GUICtrlCreateButton("&OK", 125, 160, 50, 25)
GUICtrlSetOnEvent(-1, "_btnOKFunction") ;Set the button's function
GUICtrlSetState(-1, $GUI_DISABLE)
GUISetOnEvent($GUI_EVENT_CLOSE, "_frmExitGUIFunction") ;What function to call when we try close the GUI
#endregion Input Form definition

GUISetState(@SW_SHOW)

Local $astrMode[3]
$astrMode[0] = "3D+2D"
$astrMode[1] = "3D"
$astrMode[2] = "ASSY+2D"
Global $strMode = $astrMode[0]

;Endless While loop to keep the GUI Open
While 1
    Sleep(10); So we don't use heaps of CPU
WEnd

#region Event functions
Func _cmbModeFunction()
    For $i = 0 To 2
        If GUICtrlRead($cmbMode) = $acmbMode[$i] Then
            $strMode = $astrMode[$i]
            GUICtrlSetData($lblExplanation, $alblExplanation[$i])
            GUICtrlSetState($btnOK, $GUI_ENABLE)
            ExitLoop
        EndIf
    Next
EndFunc   ;==>_cmbModeFunction

Func _btnOKFunction()
    MsgBox(64, "Mode...", $strMode) ;Check!
    GUIDelete() ;It closes the window
EndFunc   ;==>_btnOKFunction

Func _frmExitGUIFunction()
    Exit ;Exit the program
EndFunc   ;==>_frmExitGUIFunction
#endregion Event functions

MsgBox(65, "Return value...", $strMode) ;Final check ($strMode is used after)

Thanks in advance!

Share this post


Link to post
Share on other sites
JLogan3o13

Look at these three lines. You are disabling the button:

Local $btnOK = GUICtrlCreateButton("&OK", 125, 160, 50, 25)
GUICtrlSetOnEvent(-1, "_btnOKFunction") ;Set the button's function
GUICtrlSetState(-1, $GUI_DISABLE) <-------------

√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites
Melba23

XabiK,

Welcome to the AutoIt forum. :)

 

I suppose it's just a silly mistake of mine

Indeed it is - but a very easy one to make. Your $lblExplanation label is very large and overlaps with the button - as AutoIt now cannot tell which should be actioned (because labels can be clicked too) it reacts to neither. :)

Two solutions: either shorten your label so the 2 controls do not overlap or remove the $SS_NOTIFY style from the label when you create it. I think the first is the way to go. ;)

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
XabiK

XabiK,

Welcome to the AutoIt forum. :)

 

Indeed it is - but a very easy one to make. Your $lblExplanation label is very large and overlaps with the button - as AutoIt now cannot tell which should be actioned (because labels can be clicked too) it reacts to neither. :)

Two solutions: either shorten your label so the 2 controls do not overlap or remove the $SS_NOTIFY style from the label when you create it. I think the first is the way to go. ;)

M23

Thanks a lot!!!

I didn't notice the size of the label control because I didn't use Koda (BTW, it's a wonderful tool)

Yeah: I did modify the label size and button position... it works!!!

BR

Share this post


Link to post
Share on other sites
XabiK

 

Look at these three lines. You are disabling the button:

Local $btnOK = GUICtrlCreateButton("&OK", 125, 160, 50, 25)
GUICtrlSetOnEvent(-1, "_btnOKFunction") ;Set the button's function
GUICtrlSetState(-1, $GUI_DISABLE) <-------------

Hi! Thanks for your interest... but the '$GUI_DISABLE' thing it's a feature, not a bug :)

Actually, I enable the button a bit later, when the user selects an actual option from the combo box:

...        If GUICtrlRead($cmbMode) = $acmbMode[$i] Then
               $strMode = $astrMode[$i]
               GUICtrlSetData($lblExplanation, $alblExplanation[$i])
               GUICtrlSetState($btnOK, $GUI_ENABLE) <-------------
               ExitLoop
...        EndIf
Edited by XabiK

Share this post


Link to post
Share on other sites
Melba23

XabiK,

Top tip: Colour your labels when you create a GUI - then you can see exactly where they are. Remove the colouring when you have it all ready to run. ;)

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
JLogan3o13

Serves me right for reading through too fast, I missed your enabling of the button completely :>  Glad you were able to get it worked out.


√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites
Melba23

JLogan3o13,

I felt the same when I read your post - until I went back and checked. :D

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
Normonator

I personally like to add $SS_SUNKEN as a style to my labels to see the borders while testing.


[member='That Guy']~~Normonator~~

Share this post


Link to post
Share on other sites
meisandy

XabiK,

Top tip: Colour your labels when you create a GUI - then you can see exactly where they are. Remove the colouring when you have it all ready to run. ;)

M23

Nice tip! I shall have to remember that for the next time I'm creating a GUI. Presumably this is also handy for any control that allows you to set a background colour and might get confused with the main window.

By the way OP, nice hint. Very... helpful :P

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  

×