Advertisement
tidbit

Gui Buildeer Deluxe 1.3

Jan 26th, 2016 (edited)
5,024
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2. Name: GUI Buildeer Deluxe
  3. Version 1.3 (Thursday, February 04, 2016)
  4. Created: Saturday, January 02, 2016
  5. Author: tidbit
  6. Credit:
  7.     Family Dollar, For "providing" the delicious snacks (at discount prices) needed for making this program.
  8.     Bugz000      , A currently unused function that may get added in eventually.
  9.  
  10. Hotkeys:
  11.     esc   --- Quit
  12.     enter --- Generate! but not Generate?
  13.     maybe others
  14.    
  15. Description:
  16.     Generate a gui with the press of a key. No more slaving away at trying to
  17.     build a gui in a "Gui builder" or trying to figure out the code yourself, learning
  18.     is overrated anyways.
  19.     For the visually impaired or those who cannot read, there is also a Speak option.
  20.     If you want some control, there's advanced settings for you to do stuff with.
  21.    
  22. Other info:
  23.     Avalable controls (specify the number in the GUI)
  24.     1=edit, 2=button, 3=checkbox, 4=radio, 5=ddl, 6=combobox
  25.     7=hotkey, 8=datetime, 9=Listview, 10=slider, 11=progress
  26.  
  27. To-do:
  28.     - groupbox, treeview, tabs, possibly activex (ie)
  29.     - new positioning system to reduce the chance of oversized 90% empty guis
  30.    
  31. */
  32. #SingleInstance, force
  33. _name_:="GUI Buildeer Deluxe"
  34. _ver_:="1.3"
  35.  
  36. texts:=["","Settings","Width","Height","Color","Domains","Qualification"
  37. ,"Dock","IPR","ACSC's","Submit","OK","Okay","Send","Forward","Back","button"
  38. ,"add","remove","delete","...",A_DDDD,"Reports","Open","Easy","Size","Brand"
  39. ,"Rank","Polar bear pelts","QTY","Quality","Quantity","Material"
  40. ,"Hotkey","Macro: ","Operation","GHz","MHz","pudding","Select one: "]
  41. lists:=["aaa||bbb|ccc|ddd|eee", "Car|Truck||Suv|Van|Boat", "1||2|3|4|5|6", "LDL||ISPS|QTR|AXTDs", "Goat|Pig|Cow|Crow|Ostrich|Alpaca||Gazelle"]
  42.  
  43.  
  44.  
  45. gui, settings: margin, 6, 6
  46. gui, settings: +resize
  47. ; gui, settings: color, 0x8FBC8F
  48. ; gui, settings: font, s12
  49. gui, settings: add, button, xm ym w200 default vgenbtn1 gdoTheStuff, Generate!
  50. gui, settings: add, checkbox, xm y+m cgreen vspeak, Speak the controls
  51. gui, settings: add, text, xm y+m cblue vtxt1, Controls* to add:
  52. gui, settings: add, edit, x+m yp-3 w100 section number cblue vcCount, 7
  53. gui, settings: add, updown, vud1, 7
  54. gui, settings: add, text, xm y+m vtxt2, Gui name:
  55. gui, settings: add, edit, xs yp-3 w100 vguiName,
  56. gui, settings: add, text, xm y+-1 cgray vtxt3, *(control groups, such as a text+edit`nor three checkboxes)
  57. GroupBox2("Settings", "speak,txt1,cCount,ud1,txt2,txt3,guiName", "settings")
  58.  
  59. gui, settings: add, checkbox, xm y+10 checked cgreen vaddvVars, Add vVariables?
  60. gui, settings: add, checkbox, xm y+m  checked cgreen vaddgLabels, Add gLabels?
  61. gui, settings: add, radio, xm y+m r3 cred section checked vmode1 gmode, Odds mode
  62. gui, settings: add, radio, xp y+m r3 cred  vmode2 gmode, Order mode
  63. gui, settings: add, edit, x+m ys w150 hp -wantreturn vodds, 1 1 1 1 2 2 2 2 3 3 4 5 5 6 6 7 8 9 10 10 11 11
  64. gui, settings: add, edit, xp y+m w150 hp -wantreturn vorder, 1 1 2 10 11 9 5
  65. gui, settings: add, text, xm y+-1 cgray vtxt4, *(1=edit, 2=button, 3=checkbox, 4=radio, 5=ddl,`n6=combobox, 7=hotkey, 8=datetime, 9=Listview,`n10=slider, 11=progress)
  66.  
  67. gui, settings: add, button, xs ys w100 r1 vdefaults gdefaults, Defaults
  68.  
  69. guiControlGet, pos, settings: pos, order
  70. guiControl, settings: move, odds, % "x" posx
  71. guiControlGet, pos2, settings: pos, addvVars
  72. guiControl, settings: move, defaults, % "x" (posx+posw)//2 " y" pos2y+pos2h//2
  73. ; guiControl, settings: move, reset, % "x" pos2x+pos2w+6 " y" pos2y+pos2h//2
  74.  
  75. GroupBox2("Advanced settings", "mode1,mode2,odds,order,txt4,addvVars,addgLabels,defaults", "settings")
  76.  
  77. gui, settings: add, button, xm y+m w200 vgenbtn2 gdoTheStuff, Generate?
  78.  
  79. gui, settings: add, text, ym section, Output:
  80. gui, settings: add, button, x+m ys-3 ghelp, What does this stuff mean?
  81. gui, settings: add, button, x+m yp ghelp2, More help please!
  82.  
  83. gui, settings: font, s10, courier new
  84. gui, settings: add, edit, xs y+m w430 r22 -wrap +hScroll vdisp
  85.  
  86. guiControlGet, pos, settings: pos, disp
  87. guiControlGet, pos2, settings: pos, genbtn2
  88. guiControl, settings: move, disp, % "h" pos2y+pos2h-posy
  89.  
  90. ; Since your memory is poor, save some default values.
  91. gui, settings: submit, nohide
  92. dOdds:=odds
  93. dOrder:=order
  94. dVars:=addvVars
  95. dLabels:=addgLabels
  96.  
  97. gosub, mode
  98. gui, settings: show, x100 autoSize, % _name_ " - v" _ver_
  99. return
  100.  
  101.  
  102. ; esc:: ; we don't need you either.
  103. ;   critical
  104. ;   exitapp
  105. ; return
  106.  
  107.  
  108. settingsGuiClose: ; you don't like me
  109. settingsGuiEscape: ; you don't like me and you're too lazy to move the mouse
  110. gennedGuiEscape:
  111.     exitapp
  112. return
  113.  
  114.  
  115. settingsGuiSize: ; big, small, big, small
  116.     guiControlGet, pos, settings: pos, disp
  117.     guiControl, settings: move, disp, % "w" A_GuiWidth-posx-6 " h" A_GuiHeight-posy-6
  118. return
  119.  
  120.  
  121. mode: ; you pressed a radio button, probably
  122.     gui, settings: default
  123.     gui, settings: submit, nohide
  124.     if (mode1=1)
  125.         guiControl, settings: enable, cCount
  126.     else if (mode2=1)
  127.         guiControl, settings: disable, cCount
  128. return
  129.  
  130.  
  131. defaults:
  132.     gui, settings: default
  133.     guiControl, settings:, odds, %dOdds%
  134.     guiControl, settings:, order, %dOrder%
  135.     guiControl, settings:, addvVars, %dVars%
  136.     guiControl, settings:, addgLabels, %dLabels%
  137. return
  138.  
  139.  
  140. help2:
  141.     splitPath, A_AhkPath,, dur
  142.     if (fileExist(dur "\AutoHotkey.chm"))
  143.         run, hh mk:@MSITStore:%dur%\AutoHotkey.chm::/docs/commands/Gui.htm
  144.     else
  145.         msgBox, 48, Dang, You seem to be lacking something here... probably the help file.
  146. return
  147.  
  148.  
  149. help: ; because you need it
  150.     help=
  151.     (ltrim join`n
  152.     OPTIONS:`tInformation for: gui, add, control, OPTIONS, text
  153.     ---
  154.     x30`tx coordinates (coords) for the control, in pixels
  155.     xm`tPosition the control to the GUIs "margin" (the default spacing)
  156.     x+3`tPosition the control 3 pixels to the right of the previously added control
  157.     xs`tPosition the control at the last controls x-coord that used the keyword "section"
  158.     xp`tPosition the control at the previous added controls x-coord
  159.     xp+3`tPosition the control at the previous added controls x-coord and indent 3 pixels
  160.     y...`tHas all the same options as X, but for Y, obviously
  161.     ---
  162.     w100`tWidth of the control, in pixels
  163.     wp`tUse the previous controls width
  164.     h100`tHeight of the control, in pixels
  165.     hp`tUse the previous controls height
  166.     r1`tSet the control to this many "text rows" tall. 1=1 line, 2=2 lines, etc.
  167.     ---
  168.     vBanana`tControls output variable. This usually contains its value.
  169.     `tYou DO NOT use the "v". Only use "Banana". "Banana" is the variable name.
  170.     `t"v" only tells AHK that "banana is the variable for this control".
  171.     gLabel`tThe label (section of code) to go to when the control is triggered.
  172.     )
  173.     help:=st_columnize(help, "`t")
  174.     msgBox2(help, _name_ " - help", "r20 -wrap +hscroll readonly")
  175. return
  176.  
  177.  
  178. doTheStuff: ; did I stutter?
  179.     critical ; prevent button spamming, because why not.
  180.     gui, genned: destroy ; we don't need that old crap in our gui.
  181.     gui, genned: default
  182.     gui, settings: submit, nohide
  183.    
  184.     ; !!! do not touch !!!
  185.     codeArr:=[] ; raw code and settings
  186.     cArr:=[]    ; the final control strings.
  187.     vList:={}   ; used to generate variable names like banana1, banana2, ...
  188.     gList:={}   ; is this label already in existence?
  189.     odds:=strReplace(odds, ",", " ")   ; repace commas with spaces. lets users use , or space
  190.     order:=strReplace(order, ",", " ") ; repace commas with spaces. lets users use , or space
  191.     odds:=regExReplace(odds, "(\h){2,}", "$1")   ; remove excessive blanks
  192.     order:=regExReplace(order, "(\h){2,}", "$1") ; remove excessive blanks
  193.  
  194.     guiName:=(guiName="") ? "" : guiName ": "
  195.  
  196.     if (speak=1) ; creative variable names at their finest.
  197.     {
  198.         guiControl, settings: disable, genbtn1
  199.         guiControl, settings: disable, genbtn2
  200.         lemons:=ComObjCreate("SAPI.SpVoice")
  201.         lemons.rate:=3
  202.     }
  203.    
  204.     if (mode1=1)
  205.     {
  206.         list:=strSplit(odds, " ")
  207.         count:=cCount
  208.     }
  209.     else if (mode2=1)
  210.     {
  211.         list:=strSplit(order, " ")
  212.         count:=list.maxIndex()
  213.     }
  214.    
  215.     if (count<=0)
  216.     {
  217.         msgBox, Pretty sure you cannot do that.
  218.         return
  219.     }
  220.     ; generate the controls and their settings.
  221.     ; c... = control...
  222.     loop, %count%
  223.     {
  224.         ctext:=texts[rand(texts.maxIndex())]
  225.         clist:=lists[rand(lists.maxIndex())]
  226.         cont:=list[(mode2=1) ? A_Index : rand(list.maxIndex())]
  227.        
  228.         cVar:=genLabelN(ctext)
  229.         cVar:=(cVar="") ? "dummy" : cVar
  230.         cPos:=genPos()
  231.         cwidth:=rand(200,40)
  232.         ; cwidth:=(cwidth<30) ? "" : cwidth
  233.         cRange1:=rand(30)       ; min for sliders/progress
  234.         cRange2:=rand(300, 100) ; max for sliders/progress
  235.        
  236.         guiOptions:=cPos " w" cwidth " v" cVar
  237.         guiOptions2:=guiOptions " g" cVar
  238.        
  239.         if (cont=1)
  240.             codeArr.push(addEdit(ctext, 1, guiOptions))
  241.         else if (cont=2)
  242.             codeArr.push(addButton(ctext, 1, guiOptions2))
  243.         else if (cont=3)
  244.             codeArr.push(addCheckbox(ctext, 1, guiOptions2, rand(4,2)))
  245.         else if (cont=4)
  246.             codeArr.push(addCheckbox(ctext, 2, guiOptions2, rand(4,2)))
  247.         else if (cont=5)
  248.             codeArr.push(addEdit(clist, 2, guiOptions2))
  249.         else if (cont=6)
  250.             codeArr.push(addEdit(clist, 3, guiOptions2))
  251.         else if (cont=7)
  252.             codeArr.push(addEdit(ctext, 4, guiOptions))
  253.         else if (cont=8)
  254.             codeArr.push(addEdit(ctext, 5, guiOptions2))
  255.         else if (cont=9)
  256.             codeArr.push(addListview(clist, cPos " w" rand(400,100)
  257.             . " r" rand(15, 5) " vLV" cVar " g" cVar))
  258.         else if (cont=10)
  259.             codeArr.push(addButton(rand(cRange2, cRange1), 2, cPos " w" cwidth
  260.             . " tooltip range" cRange1 "-" cRange2 " v" cVar " g" cVar))
  261.         else if (cont=11)
  262.             codeArr.push(addButton(rand(cRange2, cRange1), 3, cPos " w" cwidth
  263.             . " range" cRange1 "-" cRange2
  264.             . " c0x" format("{:x}{:x}{:x}", rand(255), rand(255), rand(255))
  265.             . " background0xdeb887 v" cVar))
  266.     }
  267.     ; msgBox % st_printArr(codeArr)
  268.     ; do some re-formatting to build the gui a bit easier.
  269.     ; probably not needed, but w/e.
  270.     for key, arr in codeArr ; 'split' by the total number of items
  271.     {
  272.         loop, % arr["opts"].maxIndex()
  273.         {
  274.             options:="" ; never forget.
  275.             ctype:=arr["sets", A_Index, "t"] ; control type
  276.             clabel:=arr["sets", A_Index, "l"] ; control label (text)
  277.             for bbb, arr2 in arr["opts", A_Index] ; I really hate doing this 2-for thingy
  278.                 for k, v in arr2
  279.                     if (k="v")
  280.                     {
  281.                         vvar:=trim(v)
  282.                         break, 2
  283.                     }
  284.             if (vList.hasKey(vvar) && vvar!="") ; if this variable aready exists, add 1
  285.                 vList[vvar]+=1
  286.             else if (vvar!="") ; otherwise it's new, set to 1
  287.                 vList[vvar]:=1
  288.             arr["opts", A_Index, bbb, "v"].=vList[vvar] ; because
  289.            
  290.             ; fileAppend, % st_printArr(arr["opts", A_Index]) "`n", *
  291.             for k, arr2 in arr["opts", A_Index] ; I really hate doing this 2-for thingy
  292.                 for k, v in arr2
  293.                     options.=" " k "" v
  294.             cArr.push({"t":ctype, "l": clabel, "opts":options})
  295.         }
  296.     }
  297.  
  298.     ; build the gui and generate the code
  299.     codeOut:=""
  300.     ; msgBox, % st_printArr(codeArr)
  301.     for k, v in cArr
  302.     {
  303.         t1:=trim(v.t), t2:=trim(v.opts), t3:=trim(v.l) ; the main gui sections.
  304.         ; msgBox % t2
  305.         if (addvVars=0)
  306.             t2:=regExReplace(t2, "i)\s?\b[v]\S+")
  307.         if (addgLabels=0)
  308.             t2:=regExReplace(t2, "i)\s?\b[g]\S+")
  309.            
  310.         t22:=regExReplace(t2, "i)\b[vg]\S+") ; don't create it with a glabel. it'll toss an error. v also isn't needed.
  311.         gui, genned: add, %t1%, %t22%, %t3%
  312.         if (speak=1) ; you figure this out yourself
  313.         {
  314.             gui, genned: show, center autoSize
  315.             lemons.speak((rand(5)=1) ? texts[rand(texts.maxIndex())] : t1)
  316.         }
  317.        
  318.         if (t1="Listview") ; listviews need things inside them.
  319.         {
  320.             loop, % rand(10, 3) ; random amount of things.
  321.             {
  322.                 temp:=A_Index ; the row of the listview
  323.                 LV_Add() ; probably adds a row?
  324.                 loop, % LV_GetCount("column") ; that many.
  325.                     LV_Modify(temp, "col" A_Index, texts[rand(texts.maxIndex())])
  326.             }
  327.             LV_ModifyCol() ; make the columns not tiny.
  328.         }
  329.         codeOut.="gui, " guiName "add, " t1 ", " t2 ", " t3 "`n"
  330.     }
  331.  
  332.     ; sloppy stuff below.
  333.     codeOut:=st_columnize(codeOut, ",", [1,3][rand(2)], " ", ",")
  334.     codeOut.="`n`ngui, " guiName "show,, " _name_ " - v" rand(200) ".0`nreturn"
  335.     guiName2:=strReplace(guiName, ": ")
  336.     temp=
  337.     (ltrim join`n
  338.     `n`n
  339.     `; When you press escape or the [x] button, exit the program
  340.     %guiName2%GuiEscape:
  341.     %guiName2%GuiClose:
  342.     `texitApp
  343.     return
  344.     )
  345.     codeOut.=temp
  346.  
  347.     ; add in the g-labels:
  348.     ; msgBox % "...ggg`n" st_printArr(vList)
  349.     if (addgLabels=1)
  350.     {
  351.         for key, val in cArr
  352.         {
  353.             regExMatch(val["opts"], "i)\b[g](\S+)", o) ; o1 contains the glabel
  354.             if (o1="" || gList.hasKey(o1))
  355.                 continue
  356.                    
  357.             codeSample:=""
  358.             if (val["t"]="button")
  359.             {
  360.                 temp:=rand(vList.GetCapacity()-1)
  361.                 temp2:=texts[rand(texts.maxIndex())]
  362.                 for k, v in vList
  363.                     if (A_Index=temp)
  364.                         temp:=k rand(v)
  365.                 if (SubStr(temp, 1, 2)="LV") ; listviews. they suck.
  366.                     codeSample:="`n`tLV_Add("""", """ temp2 """, """ texts[rand(texts.maxIndex())] """)"
  367.                 else
  368.                 {
  369.                     codeSample:="`n`tguiControl, " guiName ", " temp ", " temp2
  370.                     if (rand(2)=1) ; move the control.
  371.                     {
  372.                         codeSample:="`n`tguiControlGet, moveIt, " guiName "pos, " temp
  373.                         codeSample.="`n`tguiControl, " guiName "movedraw, " temp
  374.                         . ", `% ""x"" moveItX+5 "" y"" moveItY+2"
  375.                         codeSample.="`n`t; guiControl, " guiName "movedraw, " temp ", x5 y2"
  376.                     }
  377.                 }
  378.             }
  379.             gList[o1]:=1 ; this label has now been used. do not add another.
  380.             temp=
  381.             (ltrim join`n
  382.             `n`n
  383.             %o1%:
  384.             `tgui, %guiName%submit, noHide
  385.             `t`; Your code here%codeSample%
  386.             return
  387.             )
  388.             codeOut.=temp
  389.         }
  390.     }
  391.  
  392.     if (speak=1) ; I hope you understand what this means by now...
  393.         lemons.rate:=0, lemons.speak("Your ""G. u. i."" is complete")
  394.    
  395.     guiControl, settings:, disp, %codeOut%
  396.     ; gui, genned: +ownersettings
  397.     gui, genned: show, autoSize NA, % _name_ " - v" rand(200) ".0"
  398.    
  399.     if (speak=1) ; I give up.
  400.     {
  401.         lemons.speak("Copy the code, and study it well, " texts[rand(texts.maxIndex())])
  402.         soundBeep, 750, 345
  403.         if (rand(3)=1)
  404.             lemons.speak("don't forget to thank tidbit!")
  405.         guiControl, settings: enable, genbtn1
  406.         guiControl, settings: enable, genbtn2
  407.     }
  408.     ; msgBox % st_printArr(vList) "`n---`n" st_printArr(codeArr)
  409.     ; msgBox % st_printArr(cArr)
  410. return
  411.  
  412.  
  413. ; 3 1 1 5 3 16 135 1 5 5 8 2 53
  414. rand(max=100, min=1)
  415. {
  416.     random, r, %min%, %max%
  417.     return r
  418. }
  419.  
  420. ; supid position stuff
  421. genPos()
  422. {
  423.     aaa:=rand(100, 1)
  424.     return (aaa<=60) ? "xm"
  425.          : (aaa<=70) ? "x+3 yp"
  426.          : (aaa<=95) ? "xp y+3"
  427.          :             "ym"
  428. }
  429. ; old supid position stuff
  430. ; genPos()
  431. ; {
  432. ;   aaa:=rand(100, 1)
  433. ;   return (aaa<=60) ? {"x":"m" , "y":" "}
  434. ;        : (aaa<=70) ? {"x":"+3", "y":"p"}
  435. ;        : (aaa<=95) ? {"x":"p" , "y":"+3"}
  436. ;        :             {"x":" " , "y":"m"}
  437. ; }
  438.  
  439. ; generate a name for vVar or whatever. remove anything not in the ABCs. Poor ampersand.
  440. genLabelN(N)
  441. {
  442.     if (N="")
  443.         return "Banana"
  444.     return regExReplace(N, "[\W- ]", "")
  445. }
  446.  
  447. ; very sloppy stuff below. I won't bother explaining.
  448. addEdit(labelT="", ctype=1, options="x14 y13 w200 r1")
  449. {
  450.     opts:={}
  451.     opts["opts"]:={}  ; gui options, x, y, w, h, etc
  452.     opts["sets"]:={}  ; gui settings, such as type and display text
  453.     ctype:=(ctype=1) ? "edit"
  454.     : (ctype=2) ? "ddl"
  455.     : (ctype=3) ? "comboBox"
  456.     : (ctype=4) ? "hotkey"
  457.     : "dateTime"
  458.    
  459.     if (ctype="hotkey")
  460.         modifiers:=["!","+","^","!+","^!","!^+","^+"]
  461.         , special:=modifiers[rand(modifiers.maxIndex())] chr(rand(90, 65))
  462.     if (ctype="dateTime")
  463.         modifiers:=["","LongDate","Time","yyyy-MMM-dd","yyyy-dd-MMM"]
  464.         , special:=modifiers[rand(modifiers.maxIndex())]
  465.     ; control 1. the label/text control.
  466.     if (labelT!=""        ; if the label is blank don't create it.
  467.     && ctype!="ddl"       ; ddls don't need a label.
  468.     && ctype!="datetime") ; datetime don't need a label.
  469.     {
  470.         temp:=opts["opts"].push({})
  471.         options2:=RegExReplace(options, "i)\b[wrhg]\S+")
  472.         options2:=RegExReplace(options2, "i)(v\S+)", "vtext")
  473.         for k,v in strSplit(trim(RegExReplace(options2, "(\h)+", "$1")), " ")
  474.             regExMatch(v, "i)\b(hwnd|[xywhrcvg])(\S+)", o) ; these are the GUI options
  475.             , opts["opts", temp].push({"" o1:o2})
  476.            
  477.         opts["sets"].push({"l":(ctype="combobox") ? "List" : labelT, "t":"text"})
  478.  
  479.         ; control 2. the input control to the right
  480.         temp:=opts["opts"].push({})
  481.         options:="x+3 yp-3 " RegExReplace(options, "i)\b[xy]\S+")
  482.         for k,v in strSplit(trim(RegExReplace(options, "(\h)+", "$1")), " ")
  483.             regExMatch(v, "i)\b(hwnd|[xywhrcvg])(\S+)", o) ; these are the GUI options
  484.             , opts["opts", temp].push({"" o1:o2})
  485.        
  486.         opts["sets"].push({"l":(ctype="Edit") ? ""
  487.         : (ctype="Hotkey") ? special
  488.         : labelT
  489.         , "t":ctype})
  490.     }
  491.     else
  492.     {
  493.         temp:=opts["opts"].push({})
  494.         for k,v in strSplit(trim(RegExReplace(options, "(\h)+", "$1")), " ")
  495.             regExMatch(v, "i)\b(hwnd|[xywhrcvg])(\S+)", o) ; these are the GUI options
  496.             , opts["opts", temp].push({"" o1:o2})
  497.    
  498.         opts["sets"].push({"l":(ctype="edit") ? "List"
  499.         : (ctype="dateTime") ? special
  500.         : labelT
  501.         , "t":ctype})
  502.     }
  503.     ; msgBox % st_printArr(opts)
  504.     return opts
  505. }
  506.  
  507. ; use your imagination. Also supports sliders and progresses. big boring rectangles.
  508. addButton(labelT="Button", ctype=1, options="x14 y13 w200 r1")
  509. {
  510.     opts:={}
  511.     opts["opts"]:={}  ; gui options, x, y, w, h, etc
  512.     opts["sets"]:={}  ; gui settings, such as type and display text
  513.     ctype:=(ctype=3) ? "progress"
  514.     : (ctype=2) ? "slider"
  515.     : "button"
  516.  
  517.     temp:=opts["opts"].push({})
  518.     for k,v in strSplit(trim(RegExReplace(options, "(\h)+", "$1")), " ")
  519.         regExMatch(v, "i)\b(hwnd|background|tooltip|range|[xywhrcvg])(\S*)", o) ; these are the GUI options
  520.         , opts["opts", temp].push({"" o1:o2})
  521.     opts["sets"].push({"l":labelT, "t":ctype})
  522.  
  523.     ; msgBox, % st_printArr(opts)
  524.     return opts
  525. }
  526.  
  527. ; checkbox, radio
  528. addCheckbox(labelT="aaa", ctype=1, options="x14 y13 w200 r1", count=3)
  529. {
  530.     opts:={}
  531.     opts["opts"]:={}  ; gui options, x, y, w, h, etc
  532.     opts["sets"]:={}  ; gui settings, such as type and display text
  533.     labelT:=(trim(labelT)="") ? "dummy" : labelT
  534.     ctype:=(ctype=1) ? "checkbox" : "radio"
  535.     aaa:=rand(3,1)=1
  536.    
  537.     loop, %count%
  538.     {
  539.         bbb:=A_Index ; super usful variable name. atleast it's easy to identify
  540.         options:=RegExReplace(options, "i)\b[wrh]\S+") ; just let them auto-size themselves.
  541.        
  542.          ; first control of the group dictates the starting position
  543.          ; which is the initial Options. we don't need to modify them.
  544.         temp:=opts["opts"].push({}) ; this var name isn't so helpful. deal with it
  545.         if (bbb!=1)
  546.         {
  547.             if  (aaa=1) ; horizontal list, less chance
  548.                 options:=" x+3 yp " RegExReplace(options, "i)\b[xy]\S+")
  549.             else ; vertical list
  550.                 options:=" xp y+3 " RegExReplace(options, "i)\b[xy]\S+")
  551.         }
  552.         options:=trim(RegExReplace(options, "(\h)+", "$1"))
  553.         for k,v in strSplit(options, " ")
  554.             regExMatch(v, "i)\b(hwnd|[xywhrcvg])(\S+)", o)
  555.             , opts["opts", temp].push({"" o1:o2})
  556.         opts["sets"].push({"l":labelT " " bbb, "t":ctype})
  557.     }  
  558.     ; msgBox % st_printArr(opts)
  559.     return opts
  560. }
  561.  
  562. ; Listview. pretty much identical code to Button. should have just combined them. boohoo.
  563. addListview(labelT="Header1|Header2|Header3", options="x14 y13 w200 r15")
  564. {
  565.     opts:={}
  566.     opts["opts"]:={}  ; gui options, x, y, w, h, etc
  567.     opts["sets"]:={}  ; gui settings, such as type and display text
  568.  
  569.     temp:=opts["opts"].push({})
  570.     for k,v in strSplit(trim(RegExReplace(options, "(\h)+", "$1")), " ")
  571.         regExMatch(v, "i)\b(hwnd|[xywhrcvg])(\S+)", o) ; these are the GUI options
  572.         , opts["opts", temp].push({"" o1:o2})
  573.    
  574.     opts["sets"].push({"l":labelT, "t":"listView"})
  575.     return opts
  576. }
  577.  
  578. ; really old function made by tidbit.
  579. msgbox2(text="", title="Msgbox", options="readonly -wrap w300 r12", ctrl="edit")
  580. {
  581.     static
  582.     Gui, msgbox: New
  583.     Gui, font,, Courier New
  584.     Gui, +OwnDialogs +hwndMBHWND
  585.     Gui, add, %ctrl%, %options% -wantReturn, %text%
  586.     GuiControlGet, x, Pos, %ctrl%1
  587.     xw:=xw-70+xx
  588.     Gui, add, button, x%xw% y+10 w70 Default vbtn gMB2OK, OK
  589.     GuiControl, focus, btn
  590.     Gui, show,, %title%
  591.     WinWaitClose, ahk_id %MBHWND%
  592.  
  593.     msgboxGUIEscape:
  594.     msgboxGUIClose:
  595.     MB2OK:
  596.         gui,  Destroy
  597.     Return
  598. }
  599.  
  600. ; really really old function made by tidbit.
  601. GroupBox2(Text, Controls, GuiName=1, Offset="0,0", Padding="3,3,3,3", TitleHeight=15)
  602. {
  603.    static
  604.    xx:=yy:=ww:=hh:=PosX:=PosY:=PosW:=PosH:=0
  605.    StringSplit, Padding, Padding, `,
  606.    StringSplit, Offset, Offset, `,
  607.    loop, parse, Controls, `,
  608.    {
  609.       LoopField:=trim(A_LoopField)
  610.       guiControlGet, Pos, %GuiName%: Pos, %LoopField%
  611.       if (A_Index=1)
  612.          xx:=PosX, yy:=PosY, ww:=PosX+PosW, hh:=PosY+PosH
  613.       xx:=((xx<PosX) ? xx : PosX)
  614.       yy:=((yy<PosY) ? yy : PosY)
  615.       ww:=((ww>PosX+PosW) ? ww : PosX+PosW)
  616.       hh:=((hh>PosY+PosH) ? hh : PosY+PosH)
  617.       guiControl, %GuiName%: Move, %LoopField%, % "x" PosX+Padding1+Offset1 " y" PosY+Padding3+Offset2+titleHeight
  618.    }
  619.    xx+=Offset1
  620.    yy+=Offset2
  621.    ww+=Padding1+Padding2+Offset1-xx
  622.    hh+=Padding3+Padding4+titleHeight+Offset2-yy
  623.    counter+=1
  624.    UID:="GB" GUIName counter xx yy ww hh
  625.    status := GroupBox2_Add(guiname, xx, yy, ww, hh, uid, text)
  626.    Return (status == true ? [uid,xx,yy,ww,hh] : false)
  627. }
  628. GroupBox2_Add(guiname, xx, yy, ww, hh, uid, text) {
  629.     Global
  630.     Gui, %GuiName%: add, GroupBox, x%xx% y%yy% w%ww% h%hh% v%UID%, %Text%
  631.     return (errorlevel == 0 ? true : false)
  632. }
  633.  
  634. ; used for debugging. it's a major life-saver
  635. ; Lexikos or someone needs to add something like this built-in to ahk :P
  636. st_printArr(array, depth=5, indentLevel="")
  637. {
  638.    for k,v in Array
  639.    {
  640.       list.= indentLevel "[" k "]"
  641.       if (IsObject(v) && depth>1)
  642.          list.="`n" st_printArr(v, depth-1, indentLevel . "    ")
  643.       Else
  644.          list.=" => " v
  645.       list.="`n"
  646.    }
  647.    return rtrim(list, "`r`n `t")
  648. }
  649.  
  650. ; ; old function made by tidbit. pretty helpful. quite long. probably not the best.
  651. st_columnize(data, delim="csv", justify=1, pad=" ", colsep=" | ")
  652. {      
  653.     widths:=[]
  654.     dataArr:=[]
  655.    
  656.     if (instr(justify, "|"))
  657.         colMode:=strsplit(justify, "|")
  658.     else
  659.         colMode:=justify
  660.     ; make the arrays and get the total rows and columns
  661.     loop, parse, data, `n, `r
  662.     {
  663.         if (A_LoopField="")
  664.             continue
  665.         row:=A_Index
  666.        
  667.         if (delim="csv")
  668.         {
  669.             loop, parse, A_LoopField, csv
  670.             {
  671.                 dataArr[row, A_Index]:=A_LoopField
  672.                 if (dataArr.maxindex()>maxr)
  673.                     maxr:=dataArr.maxindex()
  674.                 if (dataArr[A_Index].maxindex()>maxc)
  675.                     maxc:=dataArr[A_Index].maxindex()
  676.             }
  677.         }
  678.         else
  679.         {
  680.             dataArr[A_Index]:=strsplit(A_LoopField, delim)
  681.             if (dataArr.maxindex()>maxr)
  682.                 maxr:=dataArr.maxindex()
  683.             if (dataArr[A_Index].maxindex()>maxc)
  684.                 maxc:=dataArr[A_Index].maxindex()
  685.         }
  686.     }
  687.     ; get the longest item in each column and store its length
  688.     loop, %maxc%
  689.     {
  690.         col:=A_Index
  691.         loop, %maxr%
  692.             if (strLen(dataArr[A_Index, col])>widths[col])
  693.                 widths[col]:=strLen(dataArr[A_Index, col])
  694.     }
  695.     ; the main goodies.
  696.     loop, %maxr%
  697.     {
  698.         row:=A_Index
  699.         loop, %maxc%
  700.         {
  701.             col:=A_Index
  702.             stuff:=dataArr[row,col]
  703.             len:=strlen(stuff)
  704.             difference:=abs(strlen(stuff)-widths[col])
  705.  
  706.             ; generate a repeating string about the length of the longest item
  707.             ; in the column.
  708.             loop, % ceil(widths[col]/((strlen(pad)<1) ? 1 : strlen(pad)))
  709.                 padSymbol.=pad
  710.  
  711.             if (isObject(colMode))
  712.                 justify:=colMode[col]
  713.             ; justify everything correctly.
  714.             ; 3 = center, 2= right, 1=left.
  715.             if (strlen(stuff)<widths[col])
  716.             {
  717.                 if (justify=3)
  718.                     stuff:=SubStr(padSymbol, 1, floor(difference/2)) . stuff
  719.                     . SubStr(padSymbol, 1, ceil(difference/2))
  720.                 else
  721.                 {
  722.                     if (justify=2)
  723.                         stuff:=SubStr(padSymbol, 1, difference) stuff
  724.                     else ; left justify by default.
  725.                         stuff:= stuff SubStr(padSymbol, 1, difference)
  726.                 }
  727.             }
  728.             out.=stuff ((col!=maxc) ? colsep : "")
  729.         }
  730.         out:=trim(out) "`r`n"
  731.         ; out.="`r`n"
  732.     }
  733.     stringTrimRight, out, out, 2 ; remove the last blank newline
  734.     return out
  735. }
  736.  
  737.  
  738. ; hope you enjoyed the random babbling.
  739. ; enjoy.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement