Suggestion for form studio 2 (long)

Area for english topics
Antworten
philpw99
Beiträge: 12
Registriert: Mi 6. Okt 2021, 02:19
Kontaktdaten:

Suggestion for form studio 2 (long)

Beitrag von philpw99 »

ISN AutoIt studio is an awesome piece of software. I learned it and loved it. It helps a lot in designing larger Autoit programs.
Yet there is always a little thing that bugs me. That is how to use the forms generated by Form Studio 2. For now, there are a few ways:
For example, suppose the form name is test.isf
  1. Use #include "test.isf" in the beginning.
    We will get the following code:

    Code: Alles auswählen

    #include <StaticConstants.au3>
    #include <GUIConstantsEx.au3>
    #include <WindowsConstants.au3>
    #Include <GuiButton.au3>
    $Test_Form = GUICreate("Test Form",350,350,-1,-1,-1,-1)
    $MyButton = GUICtrlCreateButton("My Text",120,120,100,30,-1,-1)
    
    Pro:
    • Good for small programs which use one GUI
    • Good for designing the Main GUI.
    Con:
    • Not good for Functions that dynamically create GUIs.
    • This code cannot be enclosed within a function because of the multiple #include
    • If we put it between functions, the control handle names might have duplication problems. Like the OK and Cancel buttons might have the same name.
    • All GUIs and controls are declared and created when the program loads. It's very inefficient if some GUIs and controls are rarely used.
  2. Put GUI in a function, and return the handle to the GUI.

    Code: Alles auswählen

    #include <StaticConstants.au3>
    #include <GUIConstantsEx.au3>
    #include <WindowsConstants.au3>
    #Include <GuiButton.au3>
    Func _Test_Form()
        $Test_Form = GUICreate("Test Form",350,350,-1,-1,-1,-1)
        $MyButton = GUICtrlCreateButton("My Text",120,120,100,30,-1,-1)
        return $Test_Form
    EndFunc
    
    Pro:
    • Good to put the GUI creation along with other functions.
    • The controls handles are enclosed, so they are safe to use inside that function.
    • Good for event driven GUIs and controls.
    Con:
    • Exactly because control handles are enclosed in a function, it's not easy to use their handles in other functions.
    • Need to put extra code in GUI or controls if something is not event-driven. Easy to forget those codes existence.
  3. Only put the control creation code in the .isf
    We will get the following code:

    Code: Alles auswählen

    $MyButton = GUICtrlCreateButton("My Text",120,120,100,30,-1,-1)
    This is currently the way I do with all the forms. I just copy the GUI creation code before the form include, like below:

    Code: Alles auswählen

    $Test_Form = GUICreate("Test Form",350,350,-1,-1,-1,-1)
    #include "test.isf"
    
    Pro:
    • Good for putting into functions that needs to create a GUI by its own.
    • Good for change of design of control layouts later on.
    Con:
    • Always need to copy the GUI creation line before the #include.
    • If GUI setting/size is changed, it will not automatically reflect in the program. Need to remember to copy the GUI creation code.
    • The main au3 file might not have the necessary #include
So what's my suggestion? Maybe we can have a perfect form generated code that will:
1. Generate GUI and control creation code that can be placed inside a function.
2. Put the necessary #include in the main au3 file.
3. Other functions should be able to get the handles of the controls easily.
  • Proposal 1: Put all the GUI control creation code in a function. Add all the handles to a dictionary object, then return the dictionary object.

    Code: Alles auswählen

    #include <StaticConstants.au3>
    #include <GUIConstantsEx.au3>
    #include <WindowsConstants.au3>
    #Include <GuiButton.au3>
    
    Func _Test_Form()
        $oFunc = ObjCreate("Scripting.Dictionary")
        $Test_Form = GUICreate("Test Form",350,350,-1,-1,-1,-1)
        $oFunc.Add("GUI",$Test_Form)
        $MyButton = GUICtrlCreateButton("My Text",120,120,100,30,-1,-1)
        $oFunc.Add("MyButton", $MyButton )
        return $oFunc
    EndFunc
    
    So after calling _Test_Form(), I will get an object that contains all the control handles, along with the GUI handle. I can use it easily in other functions:

    Code: Alles auswählen

    $oTestForm = _TestForm()
    GUISetState( @SW_SHOW, $oTestForm.Item("GUI") )
    GUICtrlSetData( $oTestForm.Item("MyButton"), "Other Text" )
    
    Or even more directly:

    Code: Alles auswählen

    $oTestForm = _TestForm()
    GUISetState( @SW_SHOW, $oTestForm("GUI") )
    GUICtrlSetData( $oTestForm("MyButton"), "Other Text" )
    
    This way all the GUI and controls are enclosed, and functions can still easily change them by using the dictionary object.
    I prefer this way because it solves most of the problems.
    I can put the #include "test.isf" in the beginning of an AU3 file, and let functions dynamically create the GUI on the fly, do something to the controls, wait for user interaction, then delete it.
  • Proposal 2: Generate the GUI and control code directly, but put the #include in the main au3 file.
    This is easy for all the beginners, and easy for more advanced users too, but Form Studio must know which file is the main AU3 and be able to change it.
Benutzeravatar
ISI360
Administrator
Beiträge: 309
Registriert: Fr 11. Okt 2013, 13:06
Kontaktdaten:

Re: Suggestion for form studio 2 (long)

Beitrag von ISI360 »

Hi philpw99!

Thanks for your detailed feedback!

I would also say that this is something for advanced AutoIt users, as you already mentioned.
I find your optimization idea for the Code-generation with use of the "Scripting.Dictionary" a really great idea!! (Proposal 1)
And this would be the easiest option to include in the formstudio. As you have already discovered, there are already multiple "AutoIt Code generation options" in the formstudio, so it would be a good idea to add it here.

I will check that and send you a PM, when i have a testversion ready, ok?

Thanks for your great idea!

PS: I hope i have a litte bit more time for the ISN in 2023. We build a house for our family this year...so not much time for coding so far.
philpw99
Beiträge: 12
Registriert: Mi 6. Okt 2021, 02:19
Kontaktdaten:

Re: Suggestion for form studio 2 (long)

Beitrag von philpw99 »

Thank you for your consideration ! Wish you and your family have a great 2023 !
Looking forward to the new beta version.
philpw99
Beiträge: 12
Registriert: Mi 6. Okt 2021, 02:19
Kontaktdaten:

Re: Suggestion for form studio 2 (long)

Beitrag von philpw99 »

By the way, the new AutoIt 3.3.16 finally made the "Map" feature official !
Here is some description about maps, which is almost the same like Dictionary:
https://www.autoitscript.com/forum/topi ... about-them

The only difference between dictionary and map is this:

To set the object $o, you can do:
$o["a"] = 1234
$o["b"] = 4321
but you cannot do:
$o.a = 1234
$o.b = 4321

but for a map $m, you can do both:
$m["a"] = 1234
$m.a = 1234

Getting the value is the same, a dict can only do:
$v = $o["a"]
but a map can do both:
$v = $m["a"] or $v = $m.a

So probably map is a better feature to use than a dictionary object.
Benutzeravatar
ISI360
Administrator
Beiträge: 309
Registriert: Fr 11. Okt 2013, 13:06
Kontaktdaten:

Re: Suggestion for form studio 2 (long)

Beitrag von ISI360 »

That's right, maps would be an ever better solution.
An we can "push" the maps feature even further.
Antworten