Jump to content

GOLGRILL a lot of tasty BUTTONS on a GRILL

Recommended Posts

Often I need to create a panel to monitor a lot of things (users, files, items etc) so I use this piece of code to create a dynamic grid of buttons.

The number of buttons is variable, and it's related to the size of the gui, the size of the buttons and the distance between buttons.

Every "button" is a set of three with a real button stacked on the top of two labels, imagine reading a .CSV file or an array or a database and displaying all the things using the labels (Text and COLOR too) and clickin' on the relative button you can call further info on the item or call a particular function.

So you can decide the number of the buttons, the width of the buttons, and also the distance  between buttons.

It's quick and dirty, simple  and very improvable (I know..) so fell free to play with the code.

;Grill test/template
; (c) 2019 NSC
; V.0.6

#Region    ;************ Includes ************
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <StaticConstants.au3>
#include <EditConstants.au3>
#include <ProgressConstants.au3>
#include <_GOLLOG.au3>; NSC first UDF
#EndRegion ;************ Includes ************

Dim $agButton[1]
Global $ButtonU, $rProgress, $form1, $labeltot, $ntotButtonS
; the number of buttons is variable based on the guisize, the button size and button distance, three examples....
;Global $guiwidth = 850, $guiheight = 500, $buttonW = 150, $buttonHDistance = 10, $buttonVDistance = 20 ; SMALL GUI / BIG BUTTONS <- try it !
Global $guiwidth = 1500, $guiheight = 700, $buttonW = 90 , $buttonHDistance = 29, $buttonVDistance = 3; BIG GUI / SMALL BUTTONS 
;Global $guiwidth = 1200, $guiheight = 800, $buttonW = 300, $buttonHDistance = 30, $buttonVDistance = 7; last two variables are horizontal and vertical distance between buttons
Global $ver = "V.0.6"

Gollog(">>>>> START")

Dim $aResult[11] = [10, "a", "b", "c", "d", "e", "f", "g", "h", "i", "j"]
; this is an example, it can be an array, a DB, a .text file read in real time.


Gollog("start analyzing...")

While 1

    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
        Case $ButtonU
        Case Else
            For $i = 1 To $ntotButtonS
                If $nMsg = $agButton[$i] Then
                    $Bhit = GUICtrlRead($agButton[$i])


Func Gui()

    $form1 = GUICreate("Buttons on a grill   " & $ver & "      (c) NSC 2019", $guiwidth, $guiheight, 90, 10)

    $ButtonU = GUICtrlCreateButton("Update", 2, 2, 170, 50)

    $labeltot = GUICtrlCreateLabel("Total found", 5, 55)

    $Gollogedit = GUICtrlCreateEdit("", 2, $guiheight - 255, 180, 250, BitOR($ES_AUTOVSCROLL, $ES_AUTOHSCROLL, $ES_WANTRETURN, $WS_BORDER))
    $rProgress = GUICtrlCreateProgress($guiwidth - 18, 5, 16, $guiheight - 7, BitOR($PBS_SMOOTH, $PBS_VERTICAL, $WS_BORDER))
    GUICtrlSetColor(-1, 0x00FF00)
    GUICtrlSetBkColor(-1, 0x000000)


EndFunc   ;==>Gui

Func Monitor()



    $leftSTART = 186 ;left align
    $topSTART = 5 ;start from top
    $lineDOWN = 45 + $buttonVDistance ; vertical line distance 45 is buttons very near
    $extraHSTEP = 3 ; extra line distance
    $buttonSEMIH = 15 ; height of one of the 3 vertical impiled semibuttons
    $separatorSEMIH = 2 ;vertical distance between 3 semibuttons
    $separatorW = 2 ;aux horizontal distance
    ;---------- derived measures
    $rightLIMIT = $guiwidth - 123     ; right limit befor Carriage Return
    $leftINCREMENT = $buttonHDistance + $buttonW ; horizontal increment button after button
    $leftSTEP = $leftSTART ;incremental horizontal
    $topSTEP = $topSTART ;incremental vertical

    $foundB = $aResult[0]
    GUICtrlSetData($labeltot, "Found n°" & $foundB)

    $ntotButtonS = 0
    $nomorebuttons = 0

    For $i = 1 To $foundB

        Local $itemFound = $aResult[$i] ;\TA1000


        GUICtrlCreateGroup('', $leftSTEP, $topSTEP - 3, $buttonW + 3, 50)

        Local $textbutton = "button n°" & $i
        _ArrayAdd($agButton, GUICtrlCreateButton($textbutton, $leftSTEP + $separatorSEMIH, $topSTEP + $extraHSTEP, $buttonW, $buttonSEMIH, $BS_flat))
        GUICtrlSetBkColor(-1, 0xccffcc)         ;green, sort of
        GUICtrlSetFont(-1, 7, -1, -1, 'verdana')
        GUICtrlSetColor(-1, 0x000000)

        ;___second__________line___________________DUE ________222222--------------------------------------------------------------------

        Local $textLINE2 = $itemFound
        GUICtrlCreateLabel($textLINE2, $leftSTEP + $separatorW, $topSTEP + $buttonSEMIH + $separatorSEMIH, $buttonW, $buttonSEMIH, BitOR($SS_CENTER, $SS_CENTERIMAGE))
        GUICtrlSetBkColor(-1, 0xD2D7A8)
        GUICtrlSetFont(-1, 7, -1, -1, 'verdana')
        GUICtrlSetColor(-1, 0x000000)

        ; __third______line________tre___________________________________________________________333333-3333333-333333333-333333-33333-33333-3333--------------------------------

        Local $textLINE3 = "line3"
        GUICtrlCreateLabel($textLINE3, $leftSTEP + $separatorW, $topSTEP + $buttonSEMIH + $buttonSEMIH + $separatorSEMIH, $buttonW, $buttonSEMIH, BitOR($SS_CENTER, $SS_CENTERIMAGE))          ; NSC modify
        GUICtrlSetFont(-1, 7, -1, -1, 'verdana')
        GUICtrlSetColor(-1, 0x000000)

        $ntotButtonS += 1
        GUICtrlSetData($rProgress, (100 * $ntotButtonS / $foundB))

        If $leftSTEP + $buttonW < $rightLIMIT Then ;
            $leftSTEP += $leftINCREMENT ;53
            $leftSTEP = $leftSTART
            $topSTEP += $lineDOWN
            If $topSTEP >= $guiheight - 50 Then
                $nomorebuttons = 1
                Gollog("displayed " & $ntotButtonS & " buttons")
                Gollog("NO more buttons !")
        Sleep(100) ; REMOVE is only for demo

    While $nomorebuttons = 0 ; draw empty buttons (nice to do)
        $ntotButtonS += 1
        _ArrayAdd($agButton, GUICtrlCreateButton("B-" & $ntotButtonS, $leftSTEP + $separatorSEMIH, $topSTEP + $extraHSTEP, $buttonW, $buttonSEMIH, $BS_flat))
        If $leftSTEP + $buttonW < $rightLIMIT Then ;
            $leftSTEP += $leftINCREMENT
            $leftSTEP = $leftSTART
            $topSTEP += $lineDOWN
            If $topSTEP >= $guiheight - 50 Then
                $nomorebuttons = 1
                Gollog("displayed " & $ntotButtonS & " buttons")
                Gollog("NO more buttons !")


EndFunc   ;==>Monitor

Func infoB($Bhit) ; this function act on the pressed button, it's an example so assign the task you need.
    gollog("infoB -> " & $Bhit)
EndFunc   ;==>infoB

Func CLOSEClicked()
    MsgBox(64, "exit", "program exiting", 1)
EndFunc   ;==>CLOSEClicked

You will need also the Include from this post for the LOG (Gollog) instructions, but you can also just remove the gollog and the EDIT box.

Look at the screenshot, It's from an APP made using this code.


21/11/2019 V.0.6

Script lightly updated with better management of buttons size and distance.


Edited by t0nZ
Script updated with better management of buttons

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

  • Similar Content

    • By secman
      I have an issue with a script being used for a Toddler group register. 
      I list the kids, with their carer and additional carer in ComboLists so a number of carers can be registered per kid. 
      When page down to a second page of kids, the carers are correctly displayed but when I roll the mouse over the combo boxes it reverts to those on the first page.
      I am using the following style codes with the combo boxes - BitOR($CBS_DROPDOWN, $CBS_SIMPLE) and they are only holding 2 or 3 entries.
      Here is the code for the pagedisplay function which is called for each line of the registration page (10 lines, currently 55 kid records)) 
      Func PageDisp($L)
      ;Clears display once all records displayed
          If $L > $KidsFound Then
              $Label2[$L] = GUICtrlCreateLabel(" ", 75, $v, 280, 29)
              $Label352[$L] = GUICtrlCreateLabel("", 1040, $v, 100, 29)
              $Label152[$L] = GUICtrlCreateLabel("", 380, $v, 220, 29)
              $Label252[$L] = GUICtrlCreateLabel("",  650, $v, 220, 29);
          $Kid2d = $Kid1d[$L] ; sets value to find additional carers
      If $Kid1a[$L] <> "" then
          $Label2[$L] = GUICtrlCreateLabel("(" & $L & ")" & $Kid1a[$L] & " " & $Kid1b[$L] , 75, $v, 280, 29)
          GUICtrlSetFont(-1, 14, 400, 0, "Segoe UI")
              If $Kid1e[$L] <> "" then
                  $Combo[$L] = GUICtrlCreateCombo("(" & $L & ")"  & $Kid1e[$L], 380, $v, 220, 29, BitOR($CBS_DROPDOWN, $CBS_SIMPLE ))
                  GUICtrlSetData(-1, $Kid1e[$L] & "|" & $Kid1f[$L], $Kid1e[$L])
                  GUICtrlSetFont(-1, 12, 400, 0, "Segoe UI")
                  GUICtrlSetBkColor(-1, 0xFFFFFF)
                  $Label352[$L] = GUICtrlCreateLabel($Kid1c[$L], 1040, $v, 100, 29)
                  if $Kid1f[$L] <> "" then
                      FindCarer($Kid2d) ;finds additional carers 
                      $Combo2[$L] = GUICtrlCreateCombo("(" & $L & ")" & "",  650, $v, 220, 29, BitOR($CBS_DROPDOWN,$CBS_SIMPLE ))
                      GUICtrlSetData(-1, $Combo2List[$L], "")
                      GUICtrlSetFont(-1, 12, 400, 0, "Segoe UI")
                      GUICtrlSetBkColor(-1, 0xFFFFFF)
                      If StringRight($Kid1e[$L],3) = "[L]" Then
                          $Label152[$L] = GUICtrlCreateLabel("", 380, $v, 220, 29)
                          $Label252[$L] = GUICtrlCreateLabel("Leader",  650, $v, 220, 29);
                          GUICtrlSetColor(-1, 0x0000FF)
                      $Label252[$L] = GUICtrlCreateLabel("(" & $L & ")" & " No Additional Carers",  650, $v, 220, 29);
              GUICtrlSetFont(-1, 12, 400, 0, "Segoe UI")
              GUICtrlSetBkColor(-1, 0xFFFFFF)
              If $Kid1c[$L] = "Registered" Then
                  $Label52[$L] = GUICtrlCreateLabel($Kid1c[$L], 1040, $v, 100, 29)
                  $Label152[$L] =GUICtrlCreateLabel ($Kid1f[$L],  650, $v, 220, 29);
                  GUICtrlSetFont(-1, 14, 400, 0, "Segoe UI")
                  GUICtrlSetBkColor(-1, 0xFFFFFF)
                  If StringRight($Kid1e[$L],3) = "[L]" Then
                      $Label252[$L] = GUICtrlCreateLabel("", 380, $v, 220, 29)
                      $Label152[$L] = GUICtrlCreateLabel("Leader",  650, $v, 220, 29);
                      GUICtrlSetColor(-1, 0x0000FF)
      I hope someone can point me in the right direction as I can't see how this is happening
      Many thanks 
    • By Fenzik
      i searched the forum for something near, but with no success...
      I have Combobox control with $CBS_DROPDOWNLIST style with some items (for example (one, two, nine).
      When i want to select the item, using keyboard, the items are selected only on First letter base (for example when i type "on", Nine is selected).
      Is there some trick to force the combobox with $CBS_DROPDOWNLIST style to accept more than the First letter during selecting the items from the list?
      Mi wanted result is the same as for example - when you type "fir" on the desktop, Firefox is automatically selected.
      Thank you so much.
    • By therks
      I'm trying to implement a scrolling list of controls. I have it sort of working using the GUIScrollBars_Ex UDF by @Melba23 found here. I also want to be able to tab through the controls, which I have accomplished by adding $WS_EX_CONTROLPARENT to the child GUI. The problem is that with that style applied, the scrollbar doesn't act like a scrollbar, instead it acts as a title bar to the child GUI letting you drag the it around (and you can even "maximize" it by double clicking).
      Any ideas?
      #include <GUIConstants.au3> #include "GUIScrollbars_Ex.au3" $iButtonCount = 30 $hParent = GUICreate('Example', 300, 230) $hChild = GUICreate('', 300, 200, 0, 0, BitOR($WS_CHILD, $WS_TABSTOP), $WS_EX_CONTROLPARENT, $hParent) For $i = 0 To $iButtonCount GUICtrlCreateButton('Button in list', 0, $i*30, 300, 30) Next GUISwitch($hParent) GUICtrlCreateButton('More Buttons', 0, 200, 150, 30) GUICtrlCreateButton('More Buttons', 150, 200, 150, 30) GUISetState(@SW_SHOW, $hParent) GUISetState(@SW_SHOW, $hChild) _GUIScrollbars_Generate($hChild, 100, $iButtonCount * 30+20) While GUIGetMsg() <> $GUI_EVENT_CLOSE WEnd  
    • By Saravanan2213
      Hi everyone,
      i just need your help. i have script for cleaning browsing history and other unwanted file but the problem is i don't want to see the GUI i have attached below. It should not show anything on the screen. is it possible to do it in autoit. thanks in advance.
      So for i have tried flag
      Run("rundll32.exe InetCpl.cpl,ClearMyTracksByProcess 255", "", @SW_HIDE)
      Looking forward your help.........

    • By Pickpocketz88
      First I would just like to say HELLO! to anyone reading. It has been a while since I've posted to the Forums but I'm always crawling around.
      Now to the matter at hand. I have been looking high and low for a simplistic answer my burned out brain can find but to no avail. I've only recently upped my AutoIt skill and only by a little bit such as ordering my script neatly with my own UDFs and using Global/Dim more often to make my GUI creation understandable and easy to keep things orderly. My current problem however is figuring out how to make my newest endeavor work which is my own "Debugger". I've made a GUI with an Edit Control to display what my Variables are holding and other information from a concurrently running Script. I have access to all of the scripts I'm attempting to connect but I'm dumbfounded on how I would separately read variable information from one running script into another. I'll provide my "Debugger" script that I want to read variables into and a "Meta Script" I'd want to pass info from.
      #Region Include Files #include <AutoItConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <ColorConstantS.au3> #EndRegion #Region AutoIt Options ;Opt("TrayAutoPause", 0) ;Opt("TrayMenuMode", 3) #EndRegion #Region Hotkeys HotKeySet("{ESC}", "ExitProgram") HotKeySet("{PGDN}", "PauseProgram") HotKeySet("!1", "Snippet_1") HotKeySet("!2", "Snippet_2") HotKeySet("!3", "Snippet_3") HotKeySet("!4", "Snippet_4") HotKeySet("!5", "Snippet_5") HotKeySet("!6", "Snippet_6") HotKeySet("!7", "Snippet_7") HotKeySet("!8", "Snippet_8") HotKeySet("!9", "Snippet_9") #EndRegion #Region Global Variables #Region Globals Global $gMain, $ctrlEdit ;, $gParent #EndRegion #Region $gMain Params Dim $gMainW = @DesktopWidth / 2 Dim $gMainH = @DesktopHeight / 2 Dim $gMainX = (@DesktopWidth / 2) - ($gMainW / 2) Dim $gMainY = (@DesktopHeight / 2) - ($gMainH / 2) Dim $gMainStyle = $WS_POPUP Dim $gMainStyleEx = -1 ;Dim $gMainParent = $gParent #EndRegion #Region $ctrlEdit Params Dim $ctrlEditW = Round($gMainW * 0.98) Dim $ctrlEditH = Round($gMainH * 0.98) Dim $ctrlEditX = ($gMainW - $ctrlEditW) / 2 Dim $ctrlEditY = ($gMainH - $ctrlEditH) / 2 Dim $ctrlEditStyle = -1 Dim $ctrlEditStyleEx = -1 #EndRegion #EndRegion #Region GUI Initialization ;$gParent = GUICreate("", -1, -1, -1, -1, -1, $WS_EX_TOOLWINDOW) $gMain = GUICreate("", $gMainW, $gMainH, $gMainX, $gMainY, $gMainStyle, $gMainStyleEx) GUISetBkColor($COLOR_BLACK, $gMain) $ctrlEdit = GUICtrlCreateEdit("MainW: " & $gMainW & @CRLF & "MainH: " & $gMainH & @CRLF & "EditW: " & $ctrlEditW & @CRLF & "EditH: " & $ctrlEditH, $ctrlEditX, $ctrlEditY, $ctrlEditW, $ctrlEditH, $ctrlEditStyle, $ctrlEditStyleEx) GUISetState(@SW_SHOW, $gMain) #EndRegion MainFunction() #Region Main Function (GUI) Func MainFunction() While 1 $msg = GUIGetMsg() If $msg = $GUI_EVENT_CLOSE Then Exit EndIf WEnd EndFunc #EndRegion #Region Functions Func Functions() EndFunc #EndRegion #Region Program 1 Func Snippet_1() EndFunc #EndRegion #Region Program 2 Func Snippet_2() EndFunc #EndRegion #Region Program 3 Func Snippet_3() EndFunc #EndRegion #Region Program 4 Func Snippet_4() EndFunc #EndRegion #Region Program 5 Func Snippet_5() EndFunc #EndRegion #Region Program 6 Func Snippet_6() EndFunc #EndRegion #Region Program 7 Func Snippet_7() EndFunc #EndRegion #Region Program 8 Func Snippet_8() EndFunc #EndRegion #Region Program 9 Func Snippet_9() EndFunc #EndRegion #Region Pause/Exit Functions Func PauseProgram() While 1 Sleep(1000) WEnd EndFunc Func ExitProgram() Exit EndFunc #EndRegion Pause/Exit Functions #Region Snippets #CS #CE #EndRegion #Region Other Information #CS #CE #EndRegion That's the Debugger script. Please forgive anything ignorant but point it out if you will, I'll take any pointers to get better! (I usually use a Select to get $GUI_EVENT_CLOSE but this is early on)
      Now if I made another script with a basic GUI similar to this and wanted to read say the GUI Width ($gMainW) into the Debugger Edit Control could I do it? If so, could I do it for every variable I have in a script? I read something about the Run function and adding the variables as an option parameter I believe which I think I could do with an array to keep it from being super long and ugly but would that be the only way to do this? Any information is going to be appreciated and thank you in advance for your time!
      Edit: Sadly it just dawned on me that I could make a UDF that will create a child window that will do this instead of having a separate script trying to invade another... I'll still be keeping an eye on this for any comments but I apologize if I wasted your time!
  • Create New...