Sign in to follow this  
Followers 0
Raoh

Control parenting and compiling questions

11 posts in this topic

#1 ·  Posted (edited)

Hi.

I have started just yesterday with AutoIt. It looks like a great general-purpose scripting language, and just what I was looking for a certain app I need to build.

So far, everything is Ok and pretty easy to code, but I'm not sure if I'm missing something or it's a feature missing.

Lets say I have a Group control (the frame with the tittle).

Now, once this control is declared, I declare some other new controls, so they are under Group's parenting.

Lets say:

$myGroup = GUICtrlCreateGroup(.....)
    $myLabel = GUICtrlCreateLabel(....)
    $mytextBox = GUICtrlCreateInput(....)

Now, the behavior that I expect is that when I change the visibility status of the parent control, in this example $myGroup, everything under its parenting becomes also invisible, but the thing is, only $myGroup becomes invisible, while the child controls remain visible.

 

So, the question is: is there anything I'm missing, or do I have to manually hide every control?

 

 

Now, a second question about compiling the script.

What is an "a3x" file?

 

Thanks in advance.

Edited by Raoh

Share this post


Link to post
Share on other sites



hello Raoh, welcome to AutoIt and to the forum!

there is no "control parenting" (except with specific cases, like tabs and graphics). you need to handle all the so-called "children" controls yourself. there is a very simple way to do it, using a "Dummy" control (a control without any visibility or operational features), and using the concept that control ID's are allocated sequentially.

$idFirstDummy=GUICtrlCreateDummy()

$myGroup = GUICtrlCreateGroup(.....)
$myLabel = GUICtrlCreateLabel(....)
$mytextBox = GUICtrlCreateInput(....)

$idLastDummy=GUICtrlCreateDummy()

; to hide all control between first and last dummy controls:
For $id=$idFirstDummy To $idLastDummy
    GUICtrlSetState($id,$GUI_HIDE)
Next

as for a3x files - search the help file, it's quite clearly explained.

Share this post


Link to post
Share on other sites

hello Raoh, welcome to AutoIt and to the forum!

there is no "control parenting" (except with specific cases, like tabs and graphics). you need to handle all the so-called "children" controls yourself. there is a very simple way to do it, using a "Dummy" control (a control without any visibility or operational features), and using the concept that control ID's are allocated sequentially.

$idFirstDummy=GUICtrlCreateDummy()

$myGroup = GUICtrlCreateGroup(.....)
$myLabel = GUICtrlCreateLabel(....)
$mytextBox = GUICtrlCreateInput(....)

$idLastDummy=GUICtrlCreateDummy()

; to hide all control between first and last dummy controls:
For $id=$idFirstDummy To $idLastDummy
    GUICtrlSetState($id,$GUI_HIDE)
Next

as for a3x files - search the help file, it's quite clearly explained.

 

Thanks for your help.

So basically, is a Dummy Control like a container that will contain every control defined between two Dummy Controls?

If that is true, then the $idLastDummy in your example, could be the "start" of another container. I hope you understand my weird question ^_^

But everything is clear now.

BTW, is it possible to have the Parenting feature in the (near) future?

 

Thanks also for the a3x file tip.

Share this post


Link to post
Share on other sites

Raoh,

 

is a Dummy Control like a container that will contain every control defined between two Dummy Controls?

No. The ControlIDs returned by the native AutoIt functions that create controls (GUICtrlCreate*) are actually indices to an internal array within AutoiIt that holds the details of the actual controls. These indices are allocated initially in ascending numerical order - although AutoIt first tries to fill any blanks left by previously deleted controls, so this cannot be guaranteed. What orbs was showing was that creating a dummy before and after creating a series of controls gives you the maximum and minimum ControlID values of those controls - these values can then be used as the limits for a loop to alter them. Clearer? :)

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

#5 ·  Posted (edited)

So basically, is a Dummy Control like a container that will contain every control defined between two Dummy Controls?

If that is true, then the $idLastDummy in your example, could be the "start" of another container. I hope you understand my weird question ^_^

 

a dummy control is more like a checkpoint. yes, you can consider the last checkpoint of a batch of controls as the first checkpoint of another batch of controls. however, for naming conventions and script readability, i believe it is better to enclose any batch of controls with its own dedicated pair of dummy controls. EDIT: Melba23 beat me to it, and his explanation is better.

 

BTW, is it possible to have the Parenting feature in the (near) future?

 

don't hold your breath.

Edited by orbs

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

Raoh,

 

No. The ControlIDs returned by the native AutoIt functions that create controls (GUICtrlCreate*) are actually indices to an internal array within AutoiIt that holds the details of the actual controls. These indices are allocated initially in ascending numerical order - although AutoIt first tries to fill any blanks left by previously deleted controls, so this cannot be guaranteed. What orbs was showing was that creating a dummy before and after creating a series of controls gives you the maximum and minimum ControlID values of those controls - these values can then be used as the limits for a loop to alter them. Clearer? :)

M23

 

Then I don't understand the use of the dummies anyway.

Using two dummies to "open" and "close" your series, doesn't ensure that all those controls in the series will be consecutive in the controls array.

Lets say, I have 5 controls already declared.

Now I remove the control with ID = 1, having now control IDs of 0, 2, 3 and 4.

If I create a dummy control $startDummy, it will lie in the second array position, since as you said, AutoIt wants to fill gaps.

Now I declare 5 controls, which will have an ID of 5, 6, 7, 8 and 9.

Finally I create a "ending" dummy $endDummy, which will have an index of 10.

If now I run a for...next with the dummy controls IDs the program will run from ID = 1 to ID = 10, but IDs of 2, 3 and 4 are outside the planned IDs.

 

So basically, I'm saying this:

$myLabel1 = GUICtrlCreateLabel(...)
$myLabel2 = GUICtrlCreateLabel(...)
$myLabel3 = GUICtrlCreateLabel(...)
$myLabel4 = GUICtrlCreateLabel(...)
$myLabel5 = GUICtrlCreateLabel(...)

; Program does things, and NULL's one label:

$myLabel2 = NULL


; Now dummy controls

$idFirstDummy=GUICtrlCreateDummy() ; This will have ID of 2
    $myGroup = GUICtrlCreateGroup(.....) ; ID of 6
    $myLabel = GUICtrlCreateLabel(....) ; ID of 7
    $mytextBox = GUICtrlCreateInput(....) ; ID of 8
$idLastDummy=GUICtrlCreateDummy() ; ID of 9

; to hide all control between first and last dummy controls:
For $id=$idFirstDummy To $idLastDummy ; This will go from ID = 2 to ID = 9
    GUICtrlSetState($id,$GUI_HIDE)
Next 
; I have hidden 3 objects that were not planned: ID

So if I'm correct, I'm not sure how good would be this solution for a program where controls are created and removed dinamically.

But for my program right now is not a problem, and I will do this solution.

Edited by Raoh

Share this post


Link to post
Share on other sites

Raoh,

 

I'm not sure how good would be this solution for a program where controls are created and removed dinamically

It is not a good solution at all in that case (which is why I always refer to this technique as a "trick"). Admittedly you will still have the "bounds" of the ControlID values, but you may have other controls also included within those bounds - ones which you do not wish to effect when using the Dummy's ControlIDs as limits in a loop. ;)

To be correct you should use arrays to hold the returned ControlIDs. That way you can loop through the array elements and check the ControlIDs held in those elements without worrying about them being consecutive. :)

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

Raoh,

 

It is not a good solution at all in that case (which is why I always refer to this technique as a "trick"). Admittedly you will still have the "bounds" of the ControlID values, but you may have other controls also included within those bounds - ones which you do not wish to effect when using the Dummy's ControlIDs as limits in a loop. ;)

To be correct you should use arrays to hold the returned ControlIDs. That way you can loop through the array elements and check the ControlIDs held in those elements without worrying about them being consecutive. :)

M23

 

Yes, arrays is a good solution.

But it's a bit annoying anyway have to run a for...next loop whenever I want to just hide a couple of controls.

IMO, parenting would be the best solution.

 

Now talking about this forum, how do you set a "[ code] [ /code]" block with syntax highlight?

Share this post


Link to post
Share on other sites

[ autoit ] code here [ /autoit ] (remove the spaces) :)


Snips & Scripts


My Snips: graphCPUTemp ~ getENVvars
My Scripts: Short-Order Encrypter - message and file encryption V1.6.1 ~ AuPad - Notepad written entirely in AutoIt V1.9.4

Feel free to use any of my code for your own use.                                                                                                                                                           Forum FAQ

 

Share this post


Link to post
Share on other sites

Yes, arrays is a good solution.

But it's a bit annoying anyway have to run a for...next loop whenever I want to just hide a couple of controls.

 

write your own function to encapsulate the for...next loop. calling the function is a one-liner in your main script.

Now talking about this forum, how do you set a "[ code] [ /code]" block with syntax highlight?

 

click the small blue A-like button in the toolbar

Share this post


Link to post
Share on other sites

Raoh,

When you post code please use Code tags - see here how to do it. And when you reply, please use the "Reply to this topic" button at the top of the thread or the "Reply to this topic" editor at the bottom rather than the "Quote" button - we know what we wrote and it just pads the thread unnecessarily. :)

As to parenting controls, I do not agree with your suggestion - if a loop is too much bother to code then there is a simple workaround by creating all the group controls within a child GUI and then hiding/showing that as required: ;)

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

$hGUI = GUICreate("Test", 500, 500)

$cButton_1 = GUICtrlCreateButton("Hide Group 1", 10, 300, 180, 30)
$cButton_2 = GUICtrlCreateButton("Hide Group 2", 260, 300, 180, 30)

GUISetState()

$hChild_1 = GUICreate("", 200, 200, 0, 0, $WS_POPUP, $WS_EX_MDICHILD, $hGUI)

GUICtrlCreateGroup(" Group 1 ", 10, 10, 180, 180)
For $i = 1 To 5
    GUICtrlCreateButton("Button 1-" & $i, 20, 30 * $i, 80, 30)
Next

GUISetState()

$hChild_2 = GUICreate("", 200, 200, 250, 0, $WS_POPUP, $WS_EX_MDICHILD, $hGUI)

GUICtrlCreateGroup(" Group 2 ", 10, 10, 180, 180)
For $i = 1 To 5
    GUICtrlCreateButton("Button 2-" & $i, 20, 30 * $i, 80, 30)
Next

GUISetState()

While 1

    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $cButton_1
            Switch GUICtrlRead($cButton_1)
                Case "Hide Group 1"
                    GUISetState(@SW_HIDE, $hChild_1)
                    GUICtrlSetData($cButton_1, "Show Group 1")
                Case Else
                    GUISetState(@SW_SHOW, $hChild_1)
                    GUICtrlSetData($cButton_1, "Hide Group 1")
            EndSwitch
        Case $cButton_2
            Switch GUICtrlRead($cButton_2)
                Case "Hide Group 2"
                    GUISetState(@SW_HIDE, $hChild_2)
                    GUICtrlSetData($cButton_2, "Show Group 2")
                Case Else
                    GUISetState(@SW_SHOW, $hChild_2)
                    GUICtrlSetData($cButton_2, "Hide Group 2")
            EndSwitch
    EndSwitch

WEnd
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

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