Jump to content

Help on GUI to display and validate actions from multiple Folders Content


Go to solution Solved by Nine,

Recommended Posts

Hello Guys 😀

Today request as i get stuck on it.
I wrote last years several AU3 using simple actions to display CheckBox or RadioBox in a unique GUI.
Then validating all that were Checked to create a list of actions to run after.
But all entries were static, and not dynamic as i want to setup today !
My firsts AU3  were made after getting and understanding form this marvelous AutoIt Forums where i found what i needed to become better and better on it !
So today, i'd like to do things better (perhaps using a better method than the one i capitalized on ?)

My problem is quite simple to explain : i try with few words. 
i'd like to create a GUI to display on several columns, options that would be populated from Folders
my today example is related to printers !
I need to show approx 100 printers (one checkbox per printer) + a Validation button
And once clicked on Validation, i need to read all Checkboxes that were checked
and create an answer file, adding one line per checked option !
then i will parse the answer file, and perform an install of each item / each line !

I know how to do so for some 10 or 15 entries (if static)
what i need today is to be able to create and populate Checkbox, by reading Subfolders structure
what i began to do is :
Creating a Main Folder (@scriptdir\Rubriques\) and then up to 10 subfolders categorizing my items

Rubriques\PrintPool1, Rubriques\PrintPool2, etc... up to \PrintPool10

in each PrintPoolx sub folder, i may have 4 to 15 Other Subfolder, containing Printer Name

To start, i'm trying to do it with 2 subfolders only : will extend to more when ready !
So i have @ScriptDir\Rubriques\PrintPool1 and @ScriptDir\Rubriques\PrintPool2

PrintPool1 contains 3 Folders
PrintPool2 contains 2 Folders :
in each final (child) subfolder, only have one TXT file (appstoinstall.txt - same one for all subfolders) containing the name of the script to be run afterwards !

so i just need to handle perfectly how to obtain the final list of all items needed (all that were checked !)
i tried wring a code to:
 collect all items in Rubriques Main Folder : only to be displayed
 For Each Item(Subfolder) in MainFolder, collect all items from the Child Subfolder to be displayed and assigned to a checkbox
This works fine to display ! but still not to collect checkbox choices !  (attached)
Attached a Zip file (to unzip where you want) contains the Subfolders Structure zip file and Mymenu.au3

MyMenu.au3 will show and populate what needed : but i get stuck to verify which CheckBoxes were checked !
thanks for help !

EasyPrinters.zip

Link to post
Share on other sites

The code wasn't runnable for me, a lot of issues with variables, after some modifications I saw the gist of the Gui, but it was quite confusing to understand, recommend you  don't declare variables within functions.  With regards to the checkboxes, I'd personally use an array, or use dummy controls to get the id, below is an example using both:

#include <Array.au3>
#include <File.au3>
#include <GUIConstantsEx.au3>
;~ Root directory name
Global $g_sRootDir = @ScriptDir & "\Rubriques"
;~ $g_aCheckboxes[x][0] = Checkbox Control Id
;~ $g_aCheckboxes[x][1] = Root Path
;~ $g_aCheckboxes[x][2] = Subfolder
    Global $g_aCheckboxes[0][3]
;~ Dummy Control Id
    Global $g_idCheckboxStart

Example()

Func Example()
    Local $iCheckbox = 0, $iLeft = 10, $iTop = 10
    Local $hGUI = GUICreate("Example", 300, 200)
    _SetCheckBoxes()
    Local $iColdButton_Close = GUICtrlCreateButton("Close", 210, 170, 85, 25)
    GUISetState()
    While 1
        $iMsg = GUIGetMsg()
        Switch $iMsg
            Case $GUI_EVENT_CLOSE, $iColdButton_Close
                ExitLoop
            Case $g_idCheckboxStart To $g_aCheckboxes[UBound($g_aCheckboxes)-1][0]
                If _IsChecked($iMsg) Then MsgBox(4096, "", "Selected : " & $g_aCheckboxes[$iMsg][2] & @CRLF & "Root Path : " & $g_aCheckboxes[$iMsg][1] & @CRLF & "Full Path : " & $g_aCheckboxes[$iMsg][1] & "\" & $g_aCheckboxes[$iMsg][2])
        EndSwitch
    WEnd
    GUIDelete($hGUI)
EndFunc

Func _IsChecked($iColdControlID)
    Return BitAND(GUICtrlRead($iColdControlID), $GUI_CHECKED) = $GUI_CHECKED
EndFunc   ;==>_IsChecked

Func _SetCheckBoxes()
    ;~ Create Checkbox Start id
        $g_idCheckboxStart = GUICtrlCreateDummy()
    ;~ Resize $g_aCheckboxes array
        ReDim $g_aCheckboxes[$g_idCheckboxStart + 1][3]
    ;~ Set $g_aCheckboxes[last row][0] to Checkbox Start id
        $g_aCheckboxes[UBound($g_aCheckboxes) - 1][0] = $g_idCheckboxStart
        $g_aCheckboxes[UBound($g_aCheckboxes) - 1][1] = "Checkbox Start Id"
    ;~ Set $iCheckbox to $g_aCheckboxes Row Count
        Local $iCheckbox = UBound($g_aCheckboxes)
    ;~ Checkbox Start Left Position
        $iLeft = 10
    ;~ Checkbox Start Top Position
        $iTop = 10
    ;~ Get Root Folder List
    Local $aRootDir = _FileListToArray($g_sRootDir, "*", 2)
        If @error Then Exit MsgBox(16, "Error", 'No folders found in "' & $g_sRootDir & '".')
    Local $aSubFolders, $sSubtitle = ""
    For $i = 1 To $aRootDir[0]
        ;~ Get SubFolder List
        $aSubFolders = _FileListToArray($g_sRootDir & "\" & $aRootDir[$i], "*", 2)
            If @error Then ContinueLoop
        ;~ Set Root Folder + Subfolder Count
        $sSubtitle = $aRootDir[$i] & " : " & $aSubFolders[0]
        ;~ Add Subtitle to Gui
        _ArrayAdd($g_aCheckboxes, GUICtrlCreateLabel($sSubtitle, $iLeft, $iTop, 100, 20) & "|" & $sSubtitle & "|")
        ;~ Set $iCheckbox to $g_aCheckboxes Row Count
        $iCheckbox = UBound($g_aCheckboxes)
        ;~ Resize $g_aCheckboxes array ($g_aCheckboxes Row Count + Subfolder Count)
        If $iCheckbox < $iCheckbox + $aSubFolders[0] Then ReDim $g_aCheckboxes[$iCheckbox + $aSubFolders[0]][3]
        ;~ Loop through SubFolders
        For $j = 1 To $aSubFolders[0]
            $iTop += 25
            ;~ Set Checkbox Id for each SubFolder item
            $g_aCheckboxes[$iCheckbox][0] = GUICtrlCreateCheckbox($aSubFolders[$j], $iLeft, $iTop, 100, 20)
            ;~ Set Root Folder Path
            $g_aCheckboxes[$iCheckbox][1] = $g_sRootDir & "\" & $aRootDir[$i]
            ;~ Set SubFolder Name
            $g_aCheckboxes[$iCheckbox][2] = $aSubFolders[$j]
            $iCheckbox += 1
        Next
        ;~ Set left position to 110
            $iLeft += 110
        ;~ Reset top position to 10
            $iTop = 10
    Next
EndFunc

 

Link to post
Share on other sites
  • Solution
Posted (edited)

Another way with no global variables.

#include <File.au3>
#include <GUIConstants.au3>

Opt("MustDeclareVars", True)

Example()

Func Example()
  Local $hGUI = GUICreate("", @DesktopWidth, @DesktopHeight - 30, -1, -1, $WS_POPUP)
  Local $iXPos = 30, $iYPos
  GUICtrlCreateLabel("Easy Printers Installer", $iXPos, 50, 600,80)
  GUICtrlSetFont(-1, 25 )
  Local $idBtn_Valid = GuiCtrlCreateButton("OK to Install", 800 + $iXPos, 50, 200, 50)
  GUICtrlSetFont(-1, 15 )
  Local $idBtn_Cancel = GuiCtrlCreateButton("CANCEL", 1000 + $iXPos, 50, 200, 50)
  GUICtrlSetFont(-1, 15 )
  Local $aMenu = _FileListToArray(@ScriptDir & "\Rubriques", "*", $FLTA_FOLDERS), $aTemp
  _ArrayColInsert($aMenu, 1)
  For $i = 1 To $aMenu[0][0]
    $aTemp = _FileListToArray(@ScriptDir & "\Rubriques" & "\" & $aMenu[$i][0], "*", $FLTA_FOLDERS)
    _ArrayColInsert($aTemp, 1)
    GUICtrlCreateLabel($aMenu[$i][0] & ":" & $aTemp[0][0], $iXPos, 110, 200, 30)
    GUICtrlSetFont(-1, 13)
    $iYPos = 140
    For $j = 1 To $aTemp[0][0]
      $aTemp[$j][1] = GUICtrlCreateCheckbox($aTemp[$j][0], $iXPos, $iYPos, 100, 20)
      $iYPos += 25
    Next
    $iXPos += 100
    $aMenu[$i][1] = $aTemp
  Next

  GUISetState()
  While True
    Switch GUIGetMsg()
      Case $GUI_EVENT_CLOSE, $idBtn_Cancel
        ExitLoop
      Case $idBtn_Valid
        Validate($aMenu)
    EndSwitch
  WEnd
EndFunc

Func Validate(ByRef $aMenu)
  Local $sPath
  For $i = 1 To $aMenu[0][0]
    For $j = 1 To ($aMenu[$i][1])[0][0]
      If GUICtrlRead(($aMenu[$i][1])[$j][1]) = $GUI_CHECKED Then
        $sPath = @ScriptDir & "\Rubriques\" & $aMenu[$i][0] & "\" & ($aMenu[$i][1])[$j][0]
        ConsoleWrite($sPath & @CRLF)
        ; do the install here
      EndIf
    Next
  Next
EndFunc

 

Edited by Nine
Link to post
Share on other sites

And Many thanks also to Nine for your solution!

amazing how you could reduce my script with so few lines ! 

and working like a charm !

i'll adopt this one and engage to optimize installs, etc...

many many thanks !

have a nice week end all :)

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
  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...