Lable buttons via Ini File

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
just me
Posts: 9423
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: Lable buttons via Ini File

01 Jul 2019, 04:19

OK, one suggestion to start with. I didn't change GUI 5 as yet:

Code: Select all

; ------------------------------------------------------------------------------
; Read  the INI file into an array
Menus := []
Loop, %BtnCount%
{
   IniRead, Menu, %IniFile%, %A_Index%, Menu, %A_Index%
   IniRead, Price, %IniFile%, %A_Index%, Price, %A_Space%
   IniRead, Options, %IniFile%, %A_Index%, Options, %A_Space%
   Menus[A_Index] := {Name: Menu, Price: Price, Options: Options}
}

Code: Select all

; ##############################################################################
Gui, 7:Margin, 10, 10
Gui, 7:Add, Text, h20 0x0200 Section, Enter new name:
Gui, 7:Add, Text, xs hp 0x0200, Enter new price:
W := BtnW - 10
Gui, 7:Add, Edit, ys w%W% h20 Limit vNewName
Gui, 7:Add, Edit, xp y+m wp h20 Limit vNewPrice
GuiControlGet, P, 7:Pos, NewPrice
Gui, 7:Add, Text, xm, Options:
W := PW + PX - 10
Gui, 7:Add, Edit, xm y+2 w%W% r5 vNewOptions
Gui, 7:Add, Button, xm w80 gWriteIni, Apply
X := PX + PW - 80
Gui, 7:Add, Button, x%X% yp wp g7GuiClose, Cancel
; ##############################################################################

Code: Select all

; ##############################################################################
WriteIni:
   Gui, Submit, NoHide
   ; MsgBox, 0, New Values, Name:`t%NewName%`n`nPrice:`t%NewPrice
   GuiControl, 6:, Btn%BtnNumber%, %NewName%
   Iniwrite, %NewName%, %IniFile%, %BtnNumber%, Menu
   Iniwrite, %NewPrice%, %IniFile%, %BtnNumber%, Price
   Options := StrReplace(Trim(RTrim(NewOptions, "`n")), "`n", "|")
   Iniwrite, %Options%, %IniFile%, %BtnNumber%, Options
   Menus[BtnNumber, "Name"] := NewName
   Menus[BtnNumber, "Price"] := NewPrice
   Menus[BtnNumber, "Options"] := Options
   Gosub, 7GuiClose
Return
; ##############################################################################
Set:
   BtnNumber := SubStr(A_GuiControl, 4)
   GuiControl, 7:, NewName, % Menus[BtnNumber, "Name"]
   GuiControl, 7:, NewPrice, % Menus[BtnNumber, "Price"]
   GuiControl, 7:, NewOptions, % StrReplace(Menus[BtnNumber, "Options"], "|", "`n")
   Gui, +Disabled
   Gui, 7:Show, , Button %BtnNumber%
Return
; ##############################################################################
Dyson
Posts: 46
Joined: 03 Jun 2019, 14:09

Re: Lable buttons via Ini File

02 Jul 2019, 04:58

This works brilliantly, hopefully we can make it reflect in gui5 :)
just me
Posts: 9423
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: Lable buttons via Ini File

03 Jul 2019, 04:55

Hi Dyson,

this might give you an idea, how it could be implemented. But I believe it's not the best kind of GUI for your application:

Code: Select all

; ##############################################################################
AddToOrder:
   BtnNumber := SubStr(A_GuiControl, 4)
   Menu := Menus[BtnNumber, "Name"]
   If (Menu = BtnNumber) {
      MsgBox, 16, Error!, No menu stored for button %BtnNumber%!
      Return
   }
   Price := Menus[BtnNumber, "Price"]
   Options := Menus[BtnNumber, "Options"]
   OptNumber := 0
   If (Options <> "") {
      GetCursorPos(GX, GY)
      Gui, Opts:New, +hwndHOPTS
      Options := StrSplit(Options, "|")
      For Index, Option in Options
         Gui, Add, Radio, % (Index = 1 ? "vOptNumber" : ""), %Option%
      Gui, 5:+Disabled
      Gui, Show, x%GX% y%GY%, Options
      While WinExist("ahk_id " . HOPTS)
         Sleep 100
   }
   GuiControlGet, Total
   Total += Price
   GuiControl, , Total, % Format("{:0.2f}", Total)
   DllCall("SendMessage", "Ptr", HMENU, "UInt", 0x00B1, "Ptr", -1, "Ptr", -2) ; EM_SETSEL
   Order := Menu . " - " . Price . "`r`n" . (OptNumber ? "(" . Options[OptNumber] . ")`r`n" : "")
   DllCall("SendMessage", "Ptr", HMENU, "UInt", 0x00C2, "Ptr", True, "Str", Order) ; EM_REPLACESEL
Return
OptsGuiClose:
Gui, 5:-Disabled
Gui, Submit
Gui, Destroy
Return
; ##############################################################################
BTW: I forgot that you need both characters `r`n to create a line break in an edit control when the text is changed via DllCall("SendMessage", ...).
Dyson
Posts: 46
Joined: 03 Jun 2019, 14:09

Re: Lable buttons via Ini File

03 Jul 2019, 11:32

says there is an error with this line:

Code: Select all

      GetCursorPos(GX, GY)
just me
Posts: 9423
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: Lable buttons via Ini File

04 Jul 2019, 02:55

My bad, I forgot to add the function:

Code: Select all

; ##############################################################################
GetCursorPos(ByRef X, ByRef Y) {
   VarSetCapacity(XY, 8, 0)
   RetVal := DllCall("GetCursorPos", "Ptr", &XY, "UInt")
   X := NumGet(XY, 0, "Int")
   Y := NumGet(XY, 4, "Int")
   Return RetVal
}
Dyson
Posts: 46
Joined: 03 Jun 2019, 14:09

Re: Lable buttons via Ini File

04 Jul 2019, 03:34

Ok this works, :dance:

but any chance we can make it appear in middle of screen? I have a Drinks button near the bottom and it doesn't show all options :s

is it also possible to make it so you can tick more than one? like on a burger for example what toppings do you want in? cheese lettuce and ketchup or same with mayo instead? etc

Edit: I also realised it doesn't add to the total on the buttons with options
just me
Posts: 9423
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: Lable buttons via Ini File

04 Jul 2019, 03:48

but any chance we can make it appear in middle of screen?
No problem.
cheese lettuce and ketchup or same with mayo instead? etc
Wouldn't that affect the price?
Edit: I also realised it doesn't add to the total on the buttons with options
I'll look at that.
just me
Posts: 9423
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: Lable buttons via Ini File

04 Jul 2019, 03:58

but any chance we can make it appear in middle of screen?
Edit: I also realised it doesn't add to the total on the buttons with options

Code: Select all

; ##############################################################################
AddToOrder:
   BtnNumber := SubStr(A_GuiControl, 4)
   Menu := Menus[BtnNumber, "Name"]
   If (Menu = BtnNumber) {
      MsgBox, 16, Error!, No menu stored for button %BtnNumber%!
      Return
   }
   Price := Menus[BtnNumber, "Price"]
   Options := Menus[BtnNumber, "Options"]
   OptNumber := 0
   If (Options <> "") {
      Gui, Opts:New, +hwndHOPTS
      Options := StrSplit(Options, "|")
      For Index, Option in Options
         Gui, Add, Radio, % (Index = 1 ? "vOptNumber" : ""), %Option%
      Gui, 5:+Disabled
      Gui, Show, , Options
      While WinExist("ahk_id " . HOPTS)
         Sleep 100
   }
   Gui, 5:Default
   GuiControlGet, Total
   Total += Price
   GuiControl, , Total, % Format("{:0.2f}", Total)
   DllCall("SendMessage", "Ptr", HMENU, "UInt", 0x00B1, "Ptr", -1, "Ptr", -2) ; EM_SETSEL
   Order := Menu . " - " . Price . "`r`n" . (OptNumber ? "(" . Options[OptNumber] . ")`r`n" : "")
   DllCall("SendMessage", "Ptr", HMENU, "UInt", 0x00C2, "Ptr", True, "Str", Order) ; EM_REPLACESEL
Return
OptsGuiClose:
Gui, 5:-Disabled
Gui, Submit
Gui, Destroy
Return
; ##############################################################################
Removed call of GetCursorPos() and x/y-positions in Gui, ... Show.
Added Gui, 5:Default.
Dyson
Posts: 46
Joined: 03 Jun 2019, 14:09

Re: Lable buttons via Ini File

04 Jul 2019, 04:05

cheese lettuce and ketchup or same with mayo instead? etc
Wouldn't that affect the price.[/quote]

no as they are free add ons, but I like the way u think lol,
Maybe being able to set a price on the options isn't such a bad idea, if no price is set then its a free add on, I would be able to merge all drinks into one button instead of having to separate bottles and cans,

Going back to the button setting page, is there any way I can set colours on buttons? so like all chip relating buttons can be yellow, fish can be red, burgers blue etc, worked it out I need around 11 diff colours
Dyson
Posts: 46
Joined: 03 Jun 2019, 14:09

Re: Lable buttons via Ini File

04 Jul 2019, 04:08

just me wrote:
04 Jul 2019, 03:58
but any chance we can make it appear in middle of screen?
Edit: I also realised it doesn't add to the total on the buttons with options

Code: Select all

; ##############################################################################
AddToOrder:
   BtnNumber := SubStr(A_GuiControl, 4)
   Menu := Menus[BtnNumber, "Name"]
   If (Menu = BtnNumber) {
      MsgBox, 16, Error!, No menu stored for button %BtnNumber%!
      Return
   }
   Price := Menus[BtnNumber, "Price"]
   Options := Menus[BtnNumber, "Options"]
   OptNumber := 0
   If (Options <> "") {
      Gui, Opts:New, +hwndHOPTS
      Options := StrSplit(Options, "|")
      For Index, Option in Options
         Gui, Add, Radio, % (Index = 1 ? "vOptNumber" : ""), %Option%
      Gui, 5:+Disabled
      Gui, Show, , Options
      While WinExist("ahk_id " . HOPTS)
         Sleep 100
   }
   Gui, 5:Default
   GuiControlGet, Total
   Total += Price
   GuiControl, , Total, % Format("{:0.2f}", Total)
   DllCall("SendMessage", "Ptr", HMENU, "UInt", 0x00B1, "Ptr", -1, "Ptr", -2) ; EM_SETSEL
   Order := Menu . " - " . Price . "`r`n" . (OptNumber ? "(" . Options[OptNumber] . ")`r`n" : "")
   DllCall("SendMessage", "Ptr", HMENU, "UInt", 0x00C2, "Ptr", True, "Str", Order) ; EM_REPLACESEL
Return
OptsGuiClose:
Gui, 5:-Disabled
Gui, Submit
Gui, Destroy
Return
; ##############################################################################
Removed call of GetCursorPos() and x/y-positions in Gui, ... Show.
Added Gui, 5:Default.
Amazing :) its coming together really well
just me
Posts: 9423
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: Lable buttons via Ini File

04 Jul 2019, 05:06

Going back to the button setting page, is there any way I can set colours on buttons?
That's no real challenge. But before going back to the GUI we should complete the layout of the underlying INI file as far as possible.
Multiple selections for options could be managed as CheckBoxes. But you need a way to distinguish between multiple (CheckBoxes) and exclusive (Radios) options, i.e. you need to store a flag in the INI. How should it look like?

Code: Select all

[1] 						; button number
Color=0x0000FF				; red as BGR, we might need different keys for background and text colors
Menu=Burger
Price=4.50
MOptions=Lettuce|Cheese 	; muptiple selection
XOptions=Ketchup|Mayo 		; exclusive selection
[2]
...
Dyson
Posts: 46
Joined: 03 Jun 2019, 14:09

Re: Lable buttons via Ini File

04 Jul 2019, 09:55

yes that looks fine, so we can add cheese and lettuce and ketchup (or) mayo

the colours needed are just the background of the buttons the text is fine as black will just need to make sure I use light colours lol, is there a list of colour numbers I can use as a refrence? I cant find one :(
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: Lable buttons via Ini File

04 Jul 2019, 15:52

Some RGB values. Cheers.
Progress / SplashImage - Syntax & Usage | AutoHotkey
https://www.autohotkey.com/docs/commands/Progress.htm#Object_Colors
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
Dyson
Posts: 46
Joined: 03 Jun 2019, 14:09

Re: Lable buttons via Ini File

08 Jul 2019, 04:05

moving forward with the script I will be adding functionality to the Payment Button, but for now I need a way of voiding items? so maybr thinking is it possible that once a button is pressed (chips for example) I can press chips in the editbox and press void and it can remove it? and decuct the price from the total? may have to change the set up but idk if that's possible? any insights?

Thanks in advance
Dyson
Posts: 46
Joined: 03 Jun 2019, 14:09

Re: Lable buttons via Ini File

08 Jul 2019, 08:28

Code: Select all

AddToOrder:
   BtnNumber := SubStr(A_GuiControl, 4)
   Menu := Menus[BtnNumber, "Name"]
   If (Menu = BtnNumber) {
      MsgBox, 16, Error!, No menu stored for button %BtnNumber%!
      Return
   }
   Price := Menus[BtnNumber, "Price"]
   Options := Menus[BtnNumber, "Options"]
   OptNumber := 0
   If (Options <> "") {
      Gui, Opts:New, +hwndHOPTS
      Options := StrSplit(Options, "|")
      For Index, Option in Options
         Gui, Add, Radio, % (Index = 1 ? "vOptNumber" : ""), %Option%
      Gui, 5:+Disabled
      Gui, Show, , Options
      While WinExist("ahk_id " . HOPTS)
         Sleep 100
   }
   Gui, 5:Default
   GuiControlGet, Total
   Total += Price
   GuiControl, , Total, % Format("{:0.2f}", Total)
   DllCall("SendMessage", "Ptr", HMENU, "UInt", 0x00B1, "Ptr", -1, "Ptr", -2) ; EM_SETSEL
   Order := Menu . "		" . Price . "`r`n" . (OptNumber ? "(" . Options[OptNumber] . ")`r`n" : "")
   DllCall("SendMessage", "Ptr", HMENU, "UInt", 0x00C2, "Ptr", True, "Str", Order) ; EM_REPLACESEL
Gui, 8:Default
   GuiControlGet, Total2
   Total += Price
   GuiControl, , Total2, % Format("{:0.2f}", Total)
   DllCall("SendMessage", "Ptr", HMENU2, "UInt", 0x00B1, "Ptr", -1, "Ptr", -2) ; EM_SETSEL
   Order := Menu . "		" . Price . "`r`n" . (OptNumber ? "(" . Options[OptNumber] . ")`r`n" : "")
   DllCall("SendMessage", "Ptr", HMENU2, "UInt", 0x00C2, "Ptr", True, "Str", Order) ; EM_REPLACESEL
Return

ok so this is basically doing the trick but the total is not calculating correctly for the gui8 page, its calculating it all then twice the proce for the last button selected
Last edited by Dyson on 08 Jul 2019, 11:25, edited 3 times in total.
just me
Posts: 9423
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: Lable buttons via Ini File

09 Jul 2019, 02:13

Code: Select all

   Gui, 8:Default
   GuiControlGet, Total2
   Total += Price ; Total2 ???
   GuiControl, , Total2, % Format("{:0.2f}", Total) ; Total2 ???
BTW, what is Gui 8?
Dyson
Posts: 46
Joined: 03 Jun 2019, 14:09

Re: Lable buttons via Ini File

09 Jul 2019, 02:32

Code: Select all

Gui, 8:Font, s12

Gui, 8:Add, Edit, x1200 y10 w300 h370 vMenu2 hwndHMENU2
Gui, 8:Add, Edit, x1400 y380 w100 h30 vTotal2 Right2, 0.00
Gui, 8:Add, text, x1350 y385, Total:

Gui, 8:Font, s26
Gui, 8:Add, text, x750 y10, %ClerkName%
Gui, 8:Font, s12
gui, 8:Add, button, gmenu w100 h100, Take Away
Gui, 8:Add, button, gClear x1100 y410 w70 h70, C
Gui, 8:Add, button, gAddTextMenu x1100 y480 w70 h70, 7
Gui, 8:Add, button, gAddTextMenu x1100 y550 w70 h70, 4
Gui, 8:Add, button, gAddTextMenu x1100 y620 w70 h70, 1
Gui, 8:Add, button, gAddTextMenu x1100 y690 w70 h70, 0

Gui, 8:Add, button, x1170 y410 w70 h70, X
Gui, 8:Add, button, gAddTextMenu x1170 y480 w70 h70, 8
Gui, 8:Add, button, gAddTextMenu x1170 y550 w70 h70, 5
Gui, 8:Add, button, gAddTextMenu x1170 y620 w70 h70, 2
Gui, 8:Add, button, gAddTextMenu x1170 y690 w70 h70, 00

Gui, 8:Add, button, gSignOff x1240 y410 w70 h70, Sign Off
Gui, 8:Add, button, gAddTextMenu x1240 y480 w70 h70, 9
Gui, 8:Add, button, gAddTextMenu x1240 y550 w70 h70, 6
Gui, 8:Add, button, gAddTextMenu x1240 y620 w70 h70, 3
Gui, 8:Add, button, gAddTextMenu x1240 y690 w70 h70, .

Gui, 8:Add, button, x1310 y410 w140 h70, Cheque
Gui, 8:Add, button, x1310 y480 w140 h140, Card
Gui, 8:Add, button, x1310 y620 w140 h140, Cash
basically a replica of gui5, but this is where I input the money handed over, to get the change etc so like say the order price comes to 17.99 and they hand me a 20 note I press in 20.00 and it comes up with change: 2.01
(still working on the math part of the code)
Dyson
Posts: 46
Joined: 03 Jun 2019, 14:09

Re: Lable buttons via Ini File

09 Jul 2019, 02:48

this is from the order screen where it calculates the total, works fine:
Untitled.png
Untitled.png (152.41 KiB) Viewed 2646 times
then once pressed payment it goes here but the total is 2x the price, if i added something else it changes to the correct total Plus the last item entered x2
Untitled2.png
Untitled2.png (102.79 KiB) Viewed 2646 times
if you notice the total is actually 0.40 more than it should be here:
Untitled3.png
Untitled3.png (104.33 KiB) Viewed 2646 times
just me
Posts: 9423
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: Lable buttons via Ini File

09 Jul 2019, 02:58

Code: Select all

AddToOrder:
   ...
   Gui, 5:Default
   GuiControlGet, Total
   Total += Price   ; <<<<<<<<< Price added once
   GuiControl, , Total, % Format("{:0.2f}", Total)
   DllCall("SendMessage", "Ptr", HMENU, "UInt", 0x00B1, "Ptr", -1, "Ptr", -2) ; EM_SETSEL
   Order := Menu . "		" . Price . "`r`n" . (OptNumber ? "(" . Options[OptNumber] . ")`r`n" : "")
   DllCall("SendMessage", "Ptr", HMENU, "UInt", 0x00C2, "Ptr", True, "Str", Order) ; EM_REPLACESEL
   Gui, 8:Default
   GuiControlGet, Total2  ; <<<<<<<<<< not used
   Total += Price  ; <<<<<<<<< Price added the second time
   GuiControl, , Total2, % Format("{:0.2f}", Total)
   DllCall("SendMessage", "Ptr", HMENU2, "UInt", 0x00B1, "Ptr", -1, "Ptr", -2) ; EM_SETSEL
   Order := Menu . "		" . Price . "`r`n" . (OptNumber ? "(" . Options[OptNumber] . ")`r`n" : "")
   DllCall("SendMessage", "Ptr", HMENU2, "UInt", 0x00C2, "Ptr", True, "Str", Order) ; EM_REPLACESEL
Return
Dyson
Posts: 46
Joined: 03 Jun 2019, 14:09

Re: Lable buttons via Ini File

09 Jul 2019, 12:07

Fab knew I messed up somewhere thanks just me.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Google [Bot] and 117 guests