Jump to content
t0nZ

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.

;TEST
;GOL-Grill
;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.

Gui()

Gollog("start analyzing...")
Monitor()

While 1

    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            CLOSEClicked()
            Exit
        Case $ButtonU
            Monitor()
        Case Else
            For $i = 1 To $ntotButtonS
                If $nMsg = $agButton[$i] Then
                    $Bhit = GUICtrlRead($agButton[$i])
                    infoB($Bhit)
                EndIf
            Next
    EndSwitch

WEnd

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)

    GUISetState(@SW_SHOW)

EndFunc   ;==>Gui

Func Monitor()

    GUIDelete($form1)

    Gui()

    $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

        Gollog($itemFound)

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

        ;______first-----------------------------_______line___________________UNO________11111_____\\\\\\\\\\------------
        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
        GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT)
        GUICtrlSetFont(-1, 7, -1, -1, 'verdana')
        GUICtrlSetColor(-1, 0x000000)

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

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


    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
        Else
            $leftSTEP = $leftSTART
            $topSTEP += $lineDOWN
            If $topSTEP >= $guiheight - 50 Then
                $nomorebuttons = 1
                Gollog("displayed " & $ntotButtonS & " buttons")
                Gollog("NO more buttons !")
            EndIf
        EndIf
    WEnd

    GUISetState(@SW_SHOW)

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)
    Gollog("<---STOP")
    Exit
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.

golgrill.PNG

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

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By TXTechie
      Hello Everyone,
      I've developed my own GUI using AutoIt and I'm allowing users to minimize the GUI, but I also want to include some kind of timer so that it will automatically restore the GUI after something like 30 minutes or an hour. However, I also want them to be able to manually restore the GUI by clicking the application's icon in the taskbar.
      I've searched through the forums, but I'm not sure how to get started.
      Any ideas or functions to research are appreciated!
      Regards,
      TX Techie
    • By Rskm
      Hi, recently i created a GUI for some calculations in AutoIT.  The GUI has 2 tabs and on the first tab, it has few inputboxes where i use to click with mouse and start entering the inputs. i recently made some changes in the position of these textboxes. I made this by changing the autoit code file instead of making changes in KODA. Now i cannot click inside these textboxes with mouse. However, i can use TAB key to cycle through/enter input in these input boxes. what could have made the inputboxes not responding to mouseclicks. thanks
    • By TheDcoder
      Hi everyone,
      I am bit stumped as to why I am not able to set the time in the Date control
      #include <DateTimeConstants.au3> #include <GUIConstantsEx.au3> #include <MsgBoxConstants.au3> Example() Func Example() GUICreate("My GUI get date", 200, 200, 800, 200) Local $idDate = GUICtrlCreateDate("1953/04/25", 10, 10, 185, 20, $DTS_TIMEFORMAT) ; to select a specific default format Local $sStyle = "HH:mm:ss" GUICtrlSendMsg($idDate, $DTM_SETFORMATW, 0, $sStyle) ; Set time Local $iRet = GUICtrlSetData($idDate, '13:33:37') ConsoleWrite('GUICtrlSetData returned ' & ($iRet = 1 ? 'success' : 'failure') & @CRLF) GUISetState(@SW_SHOW) ; Loop until the user exits. While GUIGetMsg() <> $GUI_EVENT_CLOSE WEnd MsgBox($MB_SYSTEMMODAL, "Time", GUICtrlRead($idDate)) EndFunc ;==>Example The documentation for GUICtrlSetData clearly mentions that it uses the same format as GUICtrlRead:
      But I get failure
      What gives?
      Thanks for the help in advance!
    • By thedemons
      Introduction
      ImGui is a popular library written by ocornut, it can make awesome user interface based on directx. It is being used by many big apps/games.  The UI is nice and flexible, easy to use because of frame-by-frame drawing. So I decided to convert the entire ImGui library to AutoIt
      At first it's just an experiment, i converted some basic draw functions of imgui, compile to a dll, then using DllCall in autoit to call the functions. I was testing to see how much FPS i can get in autoit, and i was expected a low FPS, since autoit is slow. Suprisingly, the FPS turned out to be so high, it works really fast, even when drawing 1000 buttons at the same time. Features
      More than +270 functions converted from ImGui (compiled dll). Has 90% of the capability of what you can do in C++; Usable ImGuiIO and ImGuiStyle, so you can set whatever configurations you like. Preview
          
      Usage
      #include <WinAPI.au3> #include "ImGui.au3" ; Create a window Local $hwnd = _ImGui_GUICreate("AutoIt ImGui", 1024, 768) _WinAPI_ShowWindow($hwnd) ; Set style color _ImGui_StyleColorsLight() ;~ _ImGui_StyleColorsDark() Local $f_value = 5 While 1 ; when the user click close button on the window, this will return false if Not _ImGui_PeekMsg() Then Exit ; must call _ImGui_BeginFrame() _ImGui_Begin("Another window") _ImGui_Text("Hello there..") If _ImGui_Button("click me") Then $f_value = 5 _ImGui_SliderFloat("slider", $f_value, 2, 20) If _ImGui_IsItemHovered() Then _ImGui_ToolTip("what r u doing?") _ImGui_End() ; must call _ImGui_EndFrame() Wend  
      Remark
      Most of the functions were converted automatically. I haven't tested all of them yet, if some function doesn't work for you, please tell me. Still missing some features of ImGui, please tell me if you needed any. Run \tools\imgui-au3-setup.au3 to add _ImGui functions to SciTE auto-complete. Source Code
      Require: DirectX GitHub: imgui-autoit
    • By MesterPerfect
      good morning
      this is the first post here in the autoit forums
      i hope that you can help me in my problem
      i have a JSON encoded
      it a map of my forums
      where i want to make a treeview that have the same type of map
      e.g
      a system (as category)
      windows (as sub category)
      software (as an child item in the windows category)
      .....
      i don't know how to do that
      so, i know that i can do that using the json functions
      but i need your help about how we can do it as the type that i told you
      by the way i need to put the sub info for each item in an array that give me the ability to manage my items
      e.g
      can post thread
      can reply
      message cound ...
      you just give me a small example and i can continue.
      am sorry if this against the rules of the forum.
      but i realy searched a lot but i couldn't
      i hope some one give me the way.
      thank you very much in advance
       
      here is the link of json forum
      https://www.autoitscript.com/forum/topic/148114-a-non-strict-json-udf-jsmn/
      and here is my encoded json file
       
      { "tree_map": { "0": [ 1, 5, 6, 7 ], "1": [ 2 ], "2": [ 4 ], "5": [ 3 ], "6": [ 8 ], "8": [ 9, 10 ] }, "nodes": [ { "breadcrumbs": [], "description": "", "display_in_list": true, "display_order": 1, "node_id": 1, "node_name": null, "node_type_id": "Category", "parent_node_id": 0, "title": "Main category", "type_data": {} }, { "breadcrumbs": [ { "node_id": 1, "title": "Main category", "node_type_id": "Category" } ], "description": "", "display_in_list": true, "display_order": 1, "node_id": 2, "node_name": null, "node_type_id": "Forum", "parent_node_id": 1, "title": "Main forum", "type_data": { "allow_poll": true, "allow_posting": true, "can_create_thread": true, "can_upload_attachment": true, "discussion_count": 0, "last_post_date": 0, "last_post_id": 0, "last_post_username": "", "last_thread_id": 0, "last_thread_prefix_id": 0, "last_thread_title": "", "message_count": 0, "min_tags": 0, "require_prefix": false } }, { "breadcrumbs": [ { "node_id": 1, "title": "Main category", "node_type_id": "Category" }, { "node_id": 2, "title": "Main forum", "node_type_id": "Forum" } ], "description": "", "display_in_list": true, "display_order": 1, "node_id": 4, "node_name": null, "node_type_id": "Forum", "parent_node_id": 2, "title": "my forums1", "type_data": { "allow_poll": true, "allow_posting": true, "can_create_thread": true, "can_upload_attachment": true, "discussion_count": 0, "last_post_date": 0, "last_post_id": 0, "last_post_username": "", "last_thread_id": 0, "last_thread_prefix_id": 0, "last_thread_title": "", "message_count": 0, "min_tags": 0, "require_prefix": false } }, { "breadcrumbs": [], "description": "", "display_in_list": true, "display_order": 2, "node_id": 5, "node_name": null, "node_type_id": "Category", "parent_node_id": 0, "title": "Perfect", "type_data": {} }, { "breadcrumbs": [ { "node_id": 5, "title": "Perfect", "node_type_id": "Category" } ], "description": "", "display_in_list": true, "display_order": 2, "node_id": 3, "node_name": null, "node_type_id": "Forum", "parent_node_id": 5, "title": "ahmed", "type_data": { "allow_poll": true, "allow_posting": true, "can_create_thread": true, "can_upload_attachment": true, "discussion_count": 0, "last_post_date": 0, "last_post_id": 0, "last_post_username": "", "last_thread_id": 0, "last_thread_prefix_id": 0, "last_thread_title": "", "message_count": 0, "min_tags": 0, "require_prefix": false } }, { "breadcrumbs": [], "description": "", "display_in_list": true, "display_order": 3, "node_id": 6, "node_name": null, "node_type_id": "Forum", "parent_node_id": 0, "title": "autoit", "type_data": { "allow_poll": true, "allow_posting": true, "can_create_thread": true, "can_upload_attachment": true, "discussion_count": 0, "last_post_date": 0, "last_post_id": 0, "last_post_username": "", "last_thread_id": 0, "last_thread_prefix_id": 0, "last_thread_title": "", "message_count": 0, "min_tags": 0, "require_prefix": false } }, { "breadcrumbs": [ { "node_id": 6, "title": "autoit", "node_type_id": "Forum" } ], "description": "", "display_in_list": true, "display_order": 3, "node_id": 8, "node_name": null, "node_type_id": "Forum", "parent_node_id": 6, "title": "examples", "type_data": { "allow_poll": true, "allow_posting": true, "can_create_thread": true, "can_upload_attachment": true, "discussion_count": 0, "last_post_date": 0, "last_post_id": 0, "last_post_username": "", "last_thread_id": 0, "last_thread_prefix_id": 0, "last_thread_title": "", "message_count": 0, "min_tags": 0, "require_prefix": false } }, { "breadcrumbs": [ { "node_id": 6, "title": "autoit", "node_type_id": "Forum" }, { "node_id": 8, "title": "examples", "node_type_id": "Forum" } ], "description": "", "display_in_list": true, "display_order": 3, "node_id": 9, "node_name": null, "node_type_id": "Forum", "parent_node_id": 8, "title": "GUI", "type_data": { "allow_poll": true, "allow_posting": true, "can_create_thread": true, "can_upload_attachment": true, "discussion_count": 0, "last_post_date": 0, "last_post_id": 0, "last_post_username": "", "last_thread_id": 0, "last_thread_prefix_id": 0, "last_thread_title": "", "message_count": 0, "min_tags": 0, "require_prefix": false } }, { "breadcrumbs": [ { "node_id": 6, "title": "autoit", "node_type_id": "Forum" }, { "node_id": 8, "title": "examples", "node_type_id": "Forum" } ], "description": "", "display_in_list": true, "display_order": 31, "node_id": 10, "node_name": null, "node_type_id": "Forum", "parent_node_id": 8, "title": "windowEX", "type_data": { "allow_poll": true, "allow_posting": true, "can_create_thread": true, "can_upload_attachment": true, "discussion_count": 0, "last_post_date": 0, "last_post_id": 0, "last_post_username": "", "last_thread_id": 0, "last_thread_prefix_id": 0, "last_thread_title": "", "message_count": 0, "min_tags": 0, "require_prefix": false } }, { "breadcrumbs": [], "description": "", "display_in_list": true, "display_order": 4, "node_id": 7, "node_name": null, "node_type_id": "Category", "parent_node_id": 0, "title": "vbs", "type_data": {} } ] }  
×
×
  • Create New...