Jump to content

GUI Control Array Grid


storme
 Share

Recommended Posts

G'day all

This is just a first attempt so all improvement suggestions welcome.

If there is a UDF to do this please let me know.

This is a simple concept that is repeated time and again in various programs I've seen. A list of things (programs in this case) with a CheckBox to select or deselect each line and buttons (in my case) to do various things with each of the things.

The example below uses an array for each of the columns that will be displayed.

If no one suggests anything easier I'll be changing it to a 2 dimensional array to hold all of the controls. This will simplify the section that positions the controls as it can use 2 "FOR" statements to position everything. The reason I've left it in this early form is I'm sure someone else has a better way or a a UDF that does it all already. :-)

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

$Form1 = GUICreate("Form1", 500, 200, 192, 124)

Local $numPrograms = 4
;Create controls
Local $Checkbox[$numPrograms]
Local $btnDownload[$numPrograms]
Local $btnInstall[$numPrograms]
Local $btnUpdate[$numPrograms]
Local $btnRun[$numPrograms]
Local $btnUninstall[$numPrograms]
Local $buttonWidth = 80
Local $buttonHeight = 20
Local $CheckboxWidth = 80
Local $CheckboxHeigth = 20

For $i = 0 To $numPrograms - 1
    $Checkbox[$i] = GUICtrlCreateCheckbox("Prog Name " & $i, 0, 0, $CheckboxWidth, $CheckboxHeigth)
    $btnDownload[$i] = GUICtrlCreateButton("Download", 0, 0, $buttonWidth, $buttonHeight, $BS_FLAT)
    $btnInstall[$i] = GUICtrlCreateButton("Install", 0, 0, $buttonWidth, $buttonHeight, $BS_FLAT)
    $btnUpdate[$i] = GUICtrlCreateButton("Update", 0, 0, $buttonWidth, $buttonHeight, $BS_FLAT)
    $btnRun[$i] = GUICtrlCreateButton("Run", 0, 0, $buttonWidth, $buttonHeight, $BS_FLAT)
    $btnUninstall[$i] = GUICtrlCreateButton("Uninstall", 0, 0, $buttonWidth, $buttonHeight, $BS_FLAT)
Next

;MOVE controls
Local $groupLeft = 10
Local $groupTop = 20
Local $groupHeightSpacing = 25
Local $groupWidthSpacing = 10

For $i = 0 To $numPrograms - 1
    GUICtrlSetPos($Checkbox[$i], $groupLeft, $groupTop + ($groupHeightSpacing * $i))
    GUICtrlSetPos($btnDownload[$i], $groupLeft + $CheckboxWidth, $groupTop + ($groupHeightSpacing * $i))
    GUICtrlSetPos($btnInstall[$i], $groupLeft + $CheckboxWidth + $buttonWidth, $groupTop + ($groupHeightSpacing * $i))
    GUICtrlSetPos($btnUpdate[$i], $groupLeft + $CheckboxWidth + $buttonWidth + $buttonWidth, $groupTop + ($groupHeightSpacing * $i))
    GUICtrlSetPos($btnRun[$i], $groupLeft + $CheckboxWidth + $buttonWidth + $buttonWidth + $buttonWidth, $groupTop + ($groupHeightSpacing * $i))
    GUICtrlSetPos($btnUninstall[$i], $groupLeft + $CheckboxWidth + $buttonWidth + $buttonWidth + $buttonWidth + $buttonWidth, $groupTop + ($groupHeightSpacing * $i))
Next

;test states
GUICtrlSetState($btnDownload[0], $GUI_DISABLE); First program already installed
GUICtrlSetState($btnInstall[0], $GUI_DISABLE)

GUICtrlSetState($btnDownload[1], $GUI_HIDE); Second program can only be installed and uninstalled
GUICtrlSetState($btnUpdate[1], $GUI_HIDE); EG regitry fix, device driver, Windows update
GUICtrlSetState($btnRun[1], $GUI_HIDE)

GUISetState(@SW_SHOW)

While 1
    $nMsg = GUIGetMsg()
    If $nMsg Then
        Switch $nMsg
            Case $GUI_EVENT_CLOSE
                Exit
        EndSwitch
        If $nMsg = $btnInstall[0] Then
            MsgBox(0, "Found", "Button0-0")
        EndIf
    EndIf
WEnd

Thanks all

John Morrison

Link to comment
Share on other sites

It's a good idea! I'm so lazy to program gui everytime i need it :)

Is it possible to put all your controls into something scrollable like listbox to make this really universal?

Than maybe it will be exelent universal gui control for installers.

Link to comment
Share on other sites

udgeen

IF I get some motivation I'll extend this to what I was originally aiming for. A Dynamic control capable of resizing to text input, etc. BUT that is a long way off. I don't like GUI programing. Which is why I was hoping someone had already created a UDF to do this...sigh

Kip

NO a GUI designer creates a static interface. The basic script I posted can be dynamic, change the "Local $numPrograms = 4" to 3 or 5 (or anything that will fit in the window). In a real program you could search for programs and present the list of programs found with the actions possible on those programs.

Thanks for the feedback

John Morrison

Link to comment
Share on other sites

UPDATE!

Here is a slightly more usable version and closer to what I originaly envisioned.

I've also included some dummy data to give a better idea of what could be done.

Spybot is installed, it can be updated, run and uninstalled.

Nortons & AVG arn't downloaded yet so can't do anything except be downloaded

and

Defrag can only be run

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

$Form1 = GUICreate("Form1", 550, 200, 192, 124)

Local $numPrograms = 4
Local $numControls = 6; Number of buttons + Checkbox

Global $programNames[$numPrograms] = ["Spybot", "Norton", "AVG", "Defrag"]
Global $buttonNames[$numControls - 1] = ["Download", "Install", "Update", "Run", "Uninstall"]



Global $guiControlArray[$numPrograms][$numControls]

;Create controls
Local $buttonWidth = 80
Local $buttonHeight = 20
Local $CheckboxWidth = 80
Local $CheckboxHeigth = 20

For $p = 0 To $numPrograms - 1
    $guiControlArray[$p][0] = GUICtrlCreateCheckbox($programNames[$p], 0, 0, $CheckboxWidth, $CheckboxHeigth)
    For $c = 0 To $numControls - 2
        $guiControlArray[$p][$c+1] = GUICtrlCreateButton($buttonNames[$c], 0, 0, $buttonWidth, $buttonHeight, $BS_FLAT)
    Next
Next

;MOVE controls
Local $groupLeft = 10
Local $groupTop = 20
Local $groupHeightSpacing = 25
Local $groupWidthSpacing = 10


For $p = 0 To $numPrograms - 1
    GUICtrlSetPos($guiControlArray[$p][0], $groupLeft, $groupTop + ($groupHeightSpacing * $p))
    For $C = 1 To $numControls - 1
        GUICtrlSetPos($guiControlArray[$p][$c], $groupLeft + $CheckboxWidth + (($buttonWidth + $groupWidthSpacing) * ($c-1)), $groupTop + ($groupHeightSpacing * $p))
    Next
    ConsoleWriteError(@CRLF)
Next

;test states
;Spybot
GUICtrlSetState($guiControlArray[0][1], $GUI_DISABLE)
GUICtrlSetState($guiControlArray[0][2], $GUI_DISABLE)
;UICtrlSetState($guiControlArray[0][3], $GUI_DISABLE)
;UICtrlSetState($guiControlArray[0][4], $GUI_DISABLE)
;UICtrlSetState($guiControlArray[0][5], $GUI_DISABLE)
;Nortons
GUICtrlSetState($guiControlArray[1][2], $GUI_DISABLE)
GUICtrlSetState($guiControlArray[1][3], $GUI_DISABLE)
GUICtrlSetState($guiControlArray[1][4], $GUI_DISABLE)
GUICtrlSetState($guiControlArray[1][5], $GUI_DISABLE)
;AVG
GUICtrlSetState($guiControlArray[2][2], $GUI_DISABLE)
GUICtrlSetState($guiControlArray[2][3], $GUI_DISABLE)
GUICtrlSetState($guiControlArray[2][4], $GUI_DISABLE)
GUICtrlSetState($guiControlArray[2][5], $GUI_DISABLE)
;Defrag
GUICtrlSetState($guiControlArray[3][1], $GUI_HIDE)
GUICtrlSetState($guiControlArray[3][2], $GUI_HIDE)
GUICtrlSetState($guiControlArray[3][3], $GUI_HIDE)
;UICtrlSetState($guiControlArray[3][4], $GUI_DISABLE)
GUICtrlSetState($guiControlArray[3][5], $GUI_HIDE)

GUISetState(@SW_SHOW)

While 1
    $nMsg = GUIGetMsg()
    If $nMsg Then
        Switch $nMsg
            Case $GUI_EVENT_CLOSE
                Exit
        EndSwitch
        If $nMsg = $guiControlArray[0][1] Then
            MsgBox(0, "Found", "Button0-1")
        EndIf
    EndIf
WEnd

John Morrison

Link to comment
Share on other sites

UPDATE!

G'day all

I've had a bit more fun and made the creation and display of the GUI array more streamlined.

Let me know if there is anything that can be improoved.

If you don't want the scrolling just comment out

#include <GUIScroll.au3>; http://www.autoitscript.com/forum/index.php?showtopic=79684
Scrollbar_Step(20, $Form1, $SB_VERT); Scrolls per 20 pixels. If not set the default is 1 (smooth scrolling)
Scrollbar_Create($Form1, $SB_VERT, $groupTop + (($groupHeightSpacing + $controlHeight) * $numPrograms))

#Region;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Compression=4
#AutoIt3Wrapper_Res_Fileversion=0.0.3.0
#AutoIt3Wrapper_Res_FileVersion_AutoIncrement=p
#AutoIt3Wrapper_Run_Tidy=y
#AutoIt3Wrapper_Run_Obfuscator=y
#Obfuscator_Parameters=/Striponly
#EndRegion;**** Directives created by AutoIt3Wrapper_GUI ****

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GUIScroll.au3>; http://www.autoitscript.com/forum/index.php?showtopic=79684
#include <Array.au3>

Global $numPrograms = 10
Global $numControls = 6; Number of buttons + Checkbox

; declare variables
Local $programNames[$numPrograms] = ["Spybot", "Norton", "AVG", "Defrag", "prog1", "prog2", "prog3", "prog4", "prog5", "prog6"]
Local $controlText[$numControls] = ["", "Download", "Install", "Update", "Run", "Uninstall"]; First element will be replaced by program name
Local $controlTypes[$numControls] = ["Checkbox", "Button", "Button", "Button", "Button", "Button"]
Local $controlWidth[$numControls] = [60, 80, 80, 80, 80, 80]
Local $controlHeight = 20
Local $guiControlArray[$numPrograms][$numControls]

Local $groupLeft = 10; left most position for group
Local $groupTop = 20; Top most position for group
Local $groupHeightSpacing = 5; space between rows
Local $groupWidthSpacing = 10; Space between collumns

; actually create and display the GUIarray
Local $Form1 = GUICreate("Form1", 560, 200, 192, 124)
_controlArrayCreate($programNames, $controlText, $controlTypes, $controlWidth, $controlHeight, $guiControlArray)
_controlArrayDisplay($groupLeft, $groupTop, $groupHeightSpacing, $groupWidthSpacing, $guiControlArray)
GUISetState(@SW_SHOW)

;add scroll bars (Need GUIScroll.au3 UDF)
Scrollbar_Step(20, $Form1, $SB_VERT); Scrolls per 20 pixels. If not set the default is 1 (smooth scrolling)
Scrollbar_Create($Form1, $SB_VERT, $groupTop + (($groupHeightSpacing + $controlHeight) * $numPrograms))

;Change button states
_controlArraySetState("Spybot", $programNames, "Download", $controlText, $guiControlArray, $GUI_DISABLE)
_controlArraySetState("Spybot", $programNames, "Install", $controlText, $guiControlArray, $GUI_DISABLE)
_controlArraySetState("Norton", $programNames, "Install", $controlText, $guiControlArray, $GUI_DISABLE)
_controlArraySetState("Norton", $programNames, "Update", $controlText, $guiControlArray, $GUI_DISABLE)
_controlArraySetState("Norton", $programNames, "Run", $controlText, $guiControlArray, $GUI_DISABLE)
_controlArraySetState("Norton", $programNames, "Uninstall", $controlText, $guiControlArray, $GUI_DISABLE)
_controlArraySetState("AVG", $programNames, "Install", $controlText, $guiControlArray, $GUI_DISABLE)
_controlArraySetState("AVG", $programNames, "Update", $controlText, $guiControlArray, $GUI_DISABLE)
_controlArraySetState("AVG", $programNames, "Run", $controlText, $guiControlArray, $GUI_DISABLE)
_controlArraySetState("AVG", $programNames, "Uninstall", $controlText, $guiControlArray, $GUI_DISABLE)
_controlArraySetState("Defrag", $programNames, "Download", $controlText, $guiControlArray, $GUI_HIDE)
_controlArraySetState("Defrag", $programNames, "Install", $controlText, $guiControlArray, $GUI_HIDE)
_controlArraySetState("Defrag", $programNames, "Update", $controlText, $guiControlArray, $GUI_HIDE)
_controlArraySetState("Defrag", $programNames, "Uninstall", $controlText, $guiControlArray, $GUI_HIDE)


main()

Exit

;--------------------------------------------------------------------------------------------------

Func main()
    While 1
        Local $nMsg = GUIGetMsg()
        If $nMsg Then
            Switch $nMsg
                Case $GUI_EVENT_CLOSE
                    Exit
            EndSwitch
            If $nMsg = $guiControlArray[0][1] Then
                MsgBox(0, "Found", "Button0-1")
            EndIf
        EndIf
    WEnd
EndFunc  ;==>main

;--------------------------------------------------------------------------------------------------
;--------------------------------------------------------------------------------------------------

Func _controlArrayCreate($programNames, $controlText, $controlTypes, $controlWidth, $controlHeight, ByRef $guiControlArray)
    Local $tempText = ""
;Create controls
    For $p = 0 To $numPrograms - 1
        For $c = 0 To $numControls - 1
        ; First element is always program name
            If $c = 0 Then
                $tempText = $programNames[$p]
            Else
                $tempText = $controlText[$c]
            EndIf
            
            Select
                Case $controlTypes[$c] = "Checkbox"
                    $guiControlArray[$p][$c] = GUICtrlCreateCheckbox($tempText, 0, 0, $controlWidth[$c], $controlHeight)
                Case $controlTypes[$c] = "Button"
                    $guiControlArray[$p][$c] = GUICtrlCreateButton($tempText, 0, 0, $controlWidth[$c], $controlHeight, $BS_FLAT)
                Case $controlTypes[$c] = "Label"
                    $guiControlArray[$p][$c] = GUICtrlCreateLabel($tempText, 0, 0, $controlWidth[$c], $controlHeight, $BS_FLAT)
            EndSelect
        Next
    Next
EndFunc  ;==>_controlArrayCreate

Func _controlArrayDisplay($groupLeft, $groupTop, $groupHeightSpacing, $groupWidthSpacing, $guiControlArray)
    
; calc left position of each control
    Local $tempLeft = $groupLeft
    Local $controlLeft[$numControls]
    For $c = 0 To $numControls - 1
        $controlLeft[$c] = $tempLeft
        $tempLeft += $controlWidth[$c] + $groupWidthSpacing
    Next

;Move controls
    For $p = 0 To $numPrograms - 1
        For $c = 0 To $numControls - 1
            GUICtrlSetPos($guiControlArray[$p][$c], $controlLeft[$c], $groupTop + (($controlHeight + $groupHeightSpacing) * $p))
        Next
    Next
EndFunc  ;==>_controlArrayDisplay

Func _controlArraySetState($program, $programNames, $control, $controlText, $guiControlArray, $state)
    Local $programIndex = _ArraySearch($programNames, $program, 0, 0, 0, 1)
    Local $controlIndex = _ArraySearch($controlText, $control, 0, 0, 0, 1)
    
    If ($programIndex <> -1) And ($controlIndex <> -1) Then
        GUICtrlSetState($guiControlArray[$programIndex][$controlIndex], $state)
    Else
    ; Can't find program and/or control
        Return -1
    EndIf
EndFunc  ;==>_controlArraySetState

Have fun

John Morrison

Link to comment
Share on other sites

  • 3 months later...

G'day all

I've already posted a question about this in the "General Help and Support" LINK section but I though I'd better update the original thread on it here.

To scroll the "array" I've crated a seperate window and used "GUIScroll.au3" but I'm not sure how or if this can be used within a window, which is what I originaly wanted to do. Any help would be apreciated.

Interaction (button clicking) is handled by a great little script "onEventFunc.au3" which made life a lot easier for this script.

To run the script you'll have to get

GUIScroll.au3

and

onEventFunc.au3

; ================================================================
; Name...........: GUI_Control_Grid
; Description ...: Creates an interactive array of controls
; Syntax.........: Only "proof of concept" look in code
; Parameters ....: N/A
; Return values .: N/A
; Author ........: John Morrison
; Modified.......: 01Jan09
; Remarks .......:
; Related .......:
; Link ..........: http://www.autoitscript.com/forum/index.php?showtopic=87870
; Example .......: Yes this file "proof of concept"
; ================================================================
Opt("GUIOnEventMode", 1)

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Compression=4
#AutoIt3Wrapper_Res_Fileversion=0.0.3.0
#AutoIt3Wrapper_Res_FileVersion_AutoIncrement=p
#AutoIt3Wrapper_Run_Tidy=y
#AutoIt3Wrapper_Run_Obfuscator=y
#Obfuscator_Parameters=/Striponly
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include "GUIScroll.au3"    ; http://www.autoitscript.com/forum/index.php?showtopic=79684
#include "onEventFunc.au3" ;http://www.autoitscript.com/forum/index.php?showtopic=71811
#include <Array.au3>

Global $numPrograms = 10
Global $numControls = 6 ; Number of buttons + Checkbox

; declare variables
Local $programNames[$numPrograms] = ["Spybot", "Norton", "AVG", "Defrag", "prog1", "prog2", "prog3", "prog4", "prog5", "prog6"]
Local $controlText[$numControls] = ["", "Download", "Install", "Update", "Run", "Uninstall"] ; First element will be replaced by program name
Local $controlTypes[$numControls] = ["Checkbox", "Button", "Button", "Button", "Button", "Button"]
Local $functionNames[$numControls] = ["", "FuncDownload", "FuncInstall", "FuncUpdate", "FuncRun", "FuncUninstall"] ; blank "" entries mean no function to call
Local $controlWidth[$numControls] = [60, 80, 80, 80, 80, 80]
Local $controlHeight = 20
Local $guiControlArray[$numPrograms][$numControls]

Local $groupLeft = 10 ; left most position for group
Local $groupTop = 20 ; Top most position for group
Local $groupHeightSpacing = 5 ; space between rows
Local $groupWidthSpacing = 10 ; Space between collumns

; actually create and display the GUIarray
Local $Form1 = GUICreate("Select function to perform", 560, 200, 192, 124)
_controlArrayCreate($programNames, $controlText, $controlTypes, $controlWidth, $controlHeight, $guiControlArray)
_controlArrayDisplay($groupLeft, $groupTop, $groupHeightSpacing, $groupWidthSpacing, $guiControlArray)

SetOnEventA($GUI_EVENT_CLOSE, "ExitProgram")
GUISetState(@SW_SHOW)

;add scroll bars (Needs GUIScroll.au3 UDF)
Scrollbar_Step(20, $Form1, $SB_VERT); Scrolls per 20 pixels. If not set the default is 1 (smooth scrolling)
Scrollbar_Create($Form1, $SB_VERT, $groupTop + (($groupHeightSpacing + $controlHeight) * $numPrograms))

;Change button states
_controlArraySetState("Spybot", $programNames, "Download", $controlText, $guiControlArray, $GUI_DISABLE)
_controlArraySetState("Spybot", $programNames, "Install", $controlText, $guiControlArray, $GUI_DISABLE)
_controlArraySetState("Norton", $programNames, "Install", $controlText, $guiControlArray, $GUI_DISABLE)
_controlArraySetState("Norton", $programNames, "Update", $controlText, $guiControlArray, $GUI_DISABLE)
_controlArraySetState("Norton", $programNames, "Run", $controlText, $guiControlArray, $GUI_DISABLE)
_controlArraySetState("Norton", $programNames, "Uninstall", $controlText, $guiControlArray, $GUI_DISABLE)
_controlArraySetState("AVG", $programNames, "Install", $controlText, $guiControlArray, $GUI_DISABLE)
_controlArraySetState("AVG", $programNames, "Update", $controlText, $guiControlArray, $GUI_DISABLE)
_controlArraySetState("AVG", $programNames, "Run", $controlText, $guiControlArray, $GUI_DISABLE)
_controlArraySetState("AVG", $programNames, "Uninstall", $controlText, $guiControlArray, $GUI_DISABLE)
_controlArraySetState("Defrag", $programNames, "Download", $controlText, $guiControlArray, $GUI_HIDE)
_controlArraySetState("Defrag", $programNames, "Install", $controlText, $guiControlArray, $GUI_HIDE)
_controlArraySetState("Defrag", $programNames, "Update", $controlText, $guiControlArray, $GUI_HIDE)
_controlArraySetState("Defrag", $programNames, "Uninstall", $controlText, $guiControlArray, $GUI_HIDE)


main()

Exit

;--------------------------------------------------------------------------------------------------

Func main()
    ;Just wait around for the events to do something
    While 1
        Sleep(60000)
        #cs
            Local $nMsg = GUIGetMsg()
            If $nMsg Then
            Switch $nMsg
            Case $GUI_EVENT_CLOSE
            Exit
            EndSwitch
            ;If $nMsg = $guiControlArray[0][1] Then
            ;   MsgBox(0, "Found", "Button0-1")
            ;EndIf
            EndIf
        #ce
    WEnd
EndFunc   ;==>main

;--------------------------------------------------------------------------------------------------
Func ExitProgram()
    Exit
EndFunc   ;==>ExitProgram

Func FuncDownload($program, $Control)
    ConsoleWrite("Pressed " & $Control & " button for program " & $program & @CR)
EndFunc   ;==>FuncDownload

Func FuncInstall($program, $Control)
    ConsoleWrite("Pressed " & $Control & " button for program " & $program & @CR)
EndFunc   ;==>FuncInstall

Func FuncUpdate($program, $Control)
    ConsoleWrite("Pressed " & $Control & " button for program " & $program & @CR)
EndFunc   ;==>FuncUpdate

Func FuncRun($program, $Control)
    ConsoleWrite("Pressed " & $Control & " button for program " & $program & @CR)
EndFunc   ;==>FuncRun

Func FuncUninstall($program, $Control)
    ConsoleWrite("Pressed " & $Control & " button for program " & $program & @CR)
EndFunc   ;==>FuncUninstall



;--------------------------------------------------------------------------------------------------
; GUI Control Routines
Func _controlArrayCreate($programNames, $controlText, $controlTypes, $controlWidth, $controlHeight, ByRef $guiControlArray)
    Local $tempText = ""
    ;Create controls
    For $p = 0 To $numPrograms - 1
        For $c = 0 To $numControls - 1
            ; First element is always program name
            If $c = 0 Then
                $tempText = $programNames[$p]
            Else
                $tempText = $controlText[$c]
            EndIf
            
            Select
                Case $controlTypes[$c] = "Checkbox"
                    $guiControlArray[$p][$c] = GUICtrlCreateCheckbox($tempText, 0, 0, $controlWidth[$c], $controlHeight)
                    If $functionNames[$c] Then
                        SetOnEventA(-1, $functionNames[$c], $paramByVal, $programNames[$p], $paramByVal, $controlText[$c])
                        ConsoleWrite("SetOnEventA(-1, " & $functionNames[$c] & ", $paramByVal, " & $programNames[$p] & " " & $controlText[$c] & @CR)
                    EndIf
                Case $controlTypes[$c] = "Button"
                    $guiControlArray[$p][$c] = GUICtrlCreateButton($tempText, 0, 0, $controlWidth[$c], $controlHeight, $BS_FLAT)
                    If $functionNames[$c] Then
                        SetOnEventA(-1, $functionNames[$c], $paramByVal, $programNames[$p], $paramByVal, $controlText[$c])
                        ConsoleWrite("SetOnEventA(-1, " & $functionNames[$c] & ", $paramByVal, " & $programNames[$p] & " " & $controlText[$c] & @CR)
                    EndIf
                Case $controlTypes[$c] = "Label"
                    $guiControlArray[$p][$c] = GUICtrlCreateLabel($tempText, 0, 0, $controlWidth[$c], $controlHeight, $BS_FLAT)
            EndSelect
        Next
    Next
EndFunc   ;==>_controlArrayCreate

Func _controlArrayDisplay($groupLeft, $groupTop, $groupHeightSpacing, $groupWidthSpacing, $guiControlArray)
    
    ; calc left position of each control
    Local $tempLeft = $groupLeft
    Local $controlLeft[$numControls]
    For $c = 0 To $numControls - 1
        $controlLeft[$c] = $tempLeft
        $tempLeft += $controlWidth[$c] + $groupWidthSpacing
    Next

    ;Move controls
    For $p = 0 To $numPrograms - 1
        For $c = 0 To $numControls - 1
            GUICtrlSetPos($guiControlArray[$p][$c], $controlLeft[$c], $groupTop + (($controlHeight + $groupHeightSpacing) * $p))
        Next
    Next
EndFunc   ;==>_controlArrayDisplay

Func _controlArraySetState($program, $programNames, $Control, $controlText, $guiControlArray, $state)
    Local $programIndex = _ArraySearch($programNames, $program, 0, 0, 0, 1)
    Local $controlIndex = _ArraySearch($controlText, $Control, 0, 0, 0, 1)
    
    If ($programIndex <> -1) And ($controlIndex <> -1) Then
        GUICtrlSetState($guiControlArray[$programIndex][$controlIndex], $state)
    Else
        ; Can't find program and/or control
        Return -1
    EndIf
EndFunc   ;==>_controlArraySetState

Thanks for any/all feedback

John Morrison

Link to comment
Share on other sites

UPDATE

New features

RUNALL example

Click the checkbox in front of RUNALL and all programs will echo the RUNALL check box

Press one of the buttons behind RUNALL and that function will be run for all programs that are "ticked" and have that function available.

; ================================================================
; Name...........: GUI_Control_Grid
; Description ...: Creates an interactive array of controls
; Syntax.........: Only "proof of concept" look in code
; Parameters ....: N/A
; Return values .: N/A
; Author ........: John Morrison
; Modified.......: 05May09
; Remarks .......:
; Related .......:
; Link ..........: http://www.autoitscript.com/forum/index.php?showtopic=87870
; Example .......: Yes this file "proof of concept"
; ================================================================
Opt("GUIOnEventMode", 1)

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Compression=4
#AutoIt3Wrapper_Res_Fileversion=0.0.3.0
#AutoIt3Wrapper_Res_FileVersion_AutoIncrement=p
#AutoIt3Wrapper_Run_Tidy=y
#AutoIt3Wrapper_Run_Obfuscator=y
#Obfuscator_Parameters=/Striponly
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include "GUIScroll.au3"    ; http://www.autoitscript.com/forum/index.php?showtopic=79684
#include "onEventFunc.au3" ;http://www.autoitscript.com/forum/index.php?showtopic=71811
#include <Array.au3>

Global $numPrograms = 8
Global $numControls = 6 ; Number of buttons + Checkbox

; declare variables
Global $programNames[$numPrograms] = ["RUNALL", "Spybot", "Norton", "AVG", "Defrag", "prog1", "prog2", "prog3"]
Global $controlText[$numControls] = ["", "Download", "Install", "Update", "Run", "Uninstall"] ; First element will be replaced by program name
Global $controlTypes[$numControls] = ["Checkbox", "Button", "Button", "Button", "Button", "Button"]
;Local $functionNames[$numControls] = ["", "FuncDownload", "FuncInstall", "FuncUpdate", "FuncRun", "FuncUninstall"] ; blank "" entries mean no function to call
Global $functionNames[$numControls] = ["GUIDOIT", "GUIDOIT", "GUIDOIT", "GUIDOIT", "GUIDOIT", "GUIDOIT"] ; blank "" entries mean no function to call
Local $controlWidth[$numControls] = [60, 80, 80, 80, 80, 80]
Local $controlHeight = 20
Global $guiControlArray[$numPrograms][$numControls]

Local $groupLeft = 10 ; left most position for group
Local $groupTop = 20 ; Top most position for group
Local $groupHeightSpacing = 5 ; space between rows
Local $groupWidthSpacing = 10 ; Space between collumns

; actually create and display the GUIarray
;Local $Form1 = GUICreate("Select function to perform", 560, 200, 192, 124)
Local $Form1 = GUICreate("Select function to perform", 560, 200, 192, 124, BitOR($GUI_SS_DEFAULT_GUI, $WS_SIZEBOX))
Opt("GUIResizeMode", BitOR($GUI_DOCKTOP, $GUI_DOCKLEFT, $GUI_DOCKWIDTH, $GUI_DOCKHEIGHT))
_controlArrayCreate($programNames, $controlText, $controlTypes, $controlWidth, $controlHeight, $guiControlArray)
_controlArrayDisplay($groupLeft, $groupTop, $groupHeightSpacing, $groupWidthSpacing, $guiControlArray)

SetOnEventA($GUI_EVENT_CLOSE, "ExitProgram")
GUISetState(@SW_SHOW)

;add scroll bars (Needs GUIScroll.au3 UDF)
Scrollbar_Step(20, $Form1, $SB_VERT); Scrolls per 20 pixels. If not set the default is 1 (smooth scrolling)
Scrollbar_Create($Form1, $SB_VERT, $groupTop + (($groupHeightSpacing + $controlHeight) * $numPrograms))

;Change button states
_controlArraySetState("Spybot", $programNames, "Download", $controlText, $guiControlArray, $GUI_DISABLE)
_controlArraySetState("Spybot", $programNames, "Install", $controlText, $guiControlArray, $GUI_DISABLE)
_controlArraySetState("Norton", $programNames, "Install", $controlText, $guiControlArray, $GUI_DISABLE)
_controlArraySetState("Norton", $programNames, "Update", $controlText, $guiControlArray, $GUI_DISABLE)
_controlArraySetState("Norton", $programNames, "Run", $controlText, $guiControlArray, $GUI_DISABLE)
_controlArraySetState("Norton", $programNames, "Uninstall", $controlText, $guiControlArray, $GUI_DISABLE)
_controlArraySetState("AVG", $programNames, "Install", $controlText, $guiControlArray, $GUI_DISABLE)
_controlArraySetState("AVG", $programNames, "Update", $controlText, $guiControlArray, $GUI_DISABLE)
_controlArraySetState("AVG", $programNames, "Run", $controlText, $guiControlArray, $GUI_DISABLE)
_controlArraySetState("AVG", $programNames, "Uninstall", $controlText, $guiControlArray, $GUI_DISABLE)
_controlArraySetState("Defrag", $programNames, "Download", $controlText, $guiControlArray, $GUI_HIDE)
_controlArraySetState("Defrag", $programNames, "Install", $controlText, $guiControlArray, $GUI_HIDE)
_controlArraySetState("Defrag", $programNames, "Update", $controlText, $guiControlArray, $GUI_HIDE)
_controlArraySetState("Defrag", $programNames, "Uninstall", $controlText, $guiControlArray, $GUI_HIDE)


main()

Exit

;--------------------------------------------------------------------------------------------------

Func main()
    ;Just wait around for the events to do something
    While 1
        Sleep(60000)
        #cs
            Local $nMsg = GUIGetMsg()
            If $nMsg Then
            Switch $nMsg
            Case $GUI_EVENT_CLOSE
            Exit
            EndSwitch
            ;If $nMsg = $guiControlArray[0][1] Then
            ;   MsgBox(0, "Found", "Button0-1")
            ;EndIf
            EndIf
        #ce
    WEnd
EndFunc   ;==>main

;--------------------------------------------------------------------------------------------------
Func ExitProgram()
    Exit
EndFunc   ;==>ExitProgram

Func GUIDOIT($program, $Control)
    Local $tempState
    If $program <> "RUNALL" Then
        ; Single Control
        If $Control <> "" Then
            ConsoleWrite($Control & " STARTED for " & $program & @CR)
        EndIf
    Else
        ; RUNALL Control Pressed - Run selected function for all 'checked' programs
        
        ;Check if it's the check box that has been clicked
        If $Control = "" Then
            ;Echo RUNALL checkbox to all checkboxes
            $tempState = GUICtrlRead($guiControlArray[0][0])
            For $p = 1 To $numPrograms - 1
                GUICtrlSetState($guiControlArray[$p][0], $tempState)
            Next
        Else
            Local $controlIndex = _ArraySearch($controlText, $Control, 0, 0, 0, 1)
            For $p = 1 To $numPrograms - 1
                ;Check Checkbox
                If GUICtrlRead($guiControlArray[$p][0]) = $GUI_CHECKED Then
                    ;Check Button Enabled and not hidden
                    $tempState = GUICtrlGetState($guiControlArray[$p][$controlIndex])
                    If BitAND($tempState, $GUI_ENABLE) And (Not (BitAND($tempState, $GUI_HIDE))) Then
                        ConsoleWrite($Control & " STARTED for " & $programNames[$p] & @CR)
                    EndIf
                EndIf
            Next
        EndIf
    EndIf
    ConsoleWrite(@CR)
EndFunc   ;==>GUIDOIT

;--------------------------------------------------------------------------------------------------
; GUI Control Routines
Func _controlArrayCreate($programNames, $controlText, $controlTypes, $controlWidth, $controlHeight, ByRef $guiControlArray)
    Local $tempText = ""
    ;Create controls
    For $p = 0 To $numPrograms - 1
        For $c = 0 To $numControls - 1
            ; First element is always program name
            If $c = 0 Then
                $tempText = $programNames[$p]
            Else
                $tempText = $controlText[$c]
            EndIf
            
            Select
                Case $controlTypes[$c] = "Checkbox"
                    $guiControlArray[$p][$c] = GUICtrlCreateCheckbox($tempText, 0, 0, $controlWidth[$c], $controlHeight)
                    If $functionNames[$c] Then
                        SetOnEventA(-1, $functionNames[$c], $paramByVal, $programNames[$p], $paramByVal, $controlText[$c])
                        ;ConsoleWrite("SetOnEventA(-1, " & $functionNames[$c] & ", $paramByVal, " & $programNames[$p] & " " & $controlText[$c] & @CR)
                    EndIf
                Case $controlTypes[$c] = "Button"
                    $guiControlArray[$p][$c] = GUICtrlCreateButton($tempText, 0, 0, $controlWidth[$c], $controlHeight, $BS_FLAT)
                    If $functionNames[$c] Then
                        SetOnEventA(-1, $functionNames[$c], $paramByVal, $programNames[$p], $paramByVal, $controlText[$c])
                        ;ConsoleWrite("SetOnEventA(-1, " & $functionNames[$c] & ", $paramByVal, " & $programNames[$p] & " " & $controlText[$c] & @CR)
                    EndIf
                Case $controlTypes[$c] = "Label"
                    $guiControlArray[$p][$c] = GUICtrlCreateLabel($tempText, 0, 0, $controlWidth[$c], $controlHeight, $BS_FLAT)
            EndSelect
        Next
    Next
EndFunc   ;==>_controlArrayCreate

Func _controlArrayDisplay($groupLeft, $groupTop, $groupHeightSpacing, $groupWidthSpacing, $guiControlArray)
    
    ; calc left position of each control
    Local $tempLeft = $groupLeft
    Local $controlLeft[$numControls]
    For $c = 0 To $numControls - 1
        $controlLeft[$c] = $tempLeft
        $tempLeft += $controlWidth[$c] + $groupWidthSpacing
    Next

    ;Move controls
    For $p = 0 To $numPrograms - 1
        For $c = 0 To $numControls - 1
            GUICtrlSetPos($guiControlArray[$p][$c], $controlLeft[$c], $groupTop + (($controlHeight + $groupHeightSpacing) * $p))
        Next
    Next
EndFunc   ;==>_controlArrayDisplay

Func _controlArraySetState($program, $programNames, $Control, $controlText, $guiControlArray, $state)
    Local $programIndex = _ArraySearch($programNames, $program, 0, 0, 0, 1)
    Local $controlIndex = _ArraySearch($controlText, $Control, 0, 0, 0, 1)
    
    If ($programIndex <> -1) And ($controlIndex <> -1) Then
        GUICtrlSetState($guiControlArray[$programIndex][$controlIndex], $state)
    Else
        ; Can't find program and/or control
        Return -1
    EndIf
EndFunc   ;==>_controlArraySetState

Good Luck

John Morrison

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