First of all, warm thanks to everyone taking the time to explain and fix scripts. Despite my brain being allergic to coding, I've managed to build something that answer my needs.
I would like however to optimize it and clean it a bit. Let me explain.
I'm building a tool to help my team write product descriptions (online retailer) in HTML format, using GUI windows with text input boxes, checkboxes, comboboxes, etc. To tailor the GUI to the type of product being processed, upon pressing the hotkey there spawns main GUI window ; according to which type of product is entered and submitted, then spawns one of seven (so far) different GUI windows : one for tees, one for sweaters, one for pants, etc. Once all the information on that 2nd window is entered and submitted, the script proceeds to edit a HTML template with said information. So far so good. The thing is that all these 7 secondary windows share the same "blocks" of GUI, for example : a group of boxes for the fit, another for the pockets, another for the neck, another for the print/embroidery, etc. These groups are the same across the 7 secondary windows, they just happen to display or not depending on relevance for a specific type of product.
Now to the problem at hand Instead of repeating those groups of edit/check/comboboxes each time they're needed, I'd like to store them somewhere once and simply call this_group() or that_group() in each secondary GUI. I found that storing GUI elements inside a function works, and the first, main GUI window works fine with part of it being regular Gui, Add elements, and the other part being GUI_Main(). However, and that's where I'm lost, if I call the GUI functions in the 2nd window, nothing shows up. I have no idea why.
I've tried plenty of things (I'm subscribed to the odd forgotten comma and the like), but to no avail. I'm posting part of the code below, it's a bit long. It's also probably ugly and patchworky, I apologize in advance!
Also English isn't my mothertongue so I might not be using the correct technical words.
Code: Select all
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
SendMode, Input
CoordMode, Mouse, Screen
#SingleInstance, force ; Evite la pop-up d'avertissement lors de relancement du script
WinGetTitle, title, Gestion des Produits
#IfWinActive, Gestion des Produits ; Restreint le fonctionnement du script à la fenêtre Gestion des Produits
;---------VARIABLES----------------------------------------------------------------------------------------------------------------------------------
F6::
WinWait, Gestion des Produits
UniqueID := WinExist("Gestion des Produits")
;-----Liste Catés et Tailles échantillon /!\ l'ordre importe
Cat := "
(
;Abréviat. Caté Groupe
ts , T-shirt, HautIn
sw , Sweat, HautSw
pull , Pull en maille, HautIn
card , Cardigan, HautIn
gil , Gilet, HautIn
doud , Doudoune, HautOut
park , Parka, HautOut
ves , Veste, HautOut
cpv , Coupe-vent, HautOut
bomb , Veste bomber, HautOut
bike , Veste biker, HautOut
blaz , Blazer, HautOut
blou , Blouson, HautOut
mant , Manteau, HautOut
ted , Teddy, HautOut
sjean , Short jean, BasC
schi , Short chino, BasC
sjog , Short jogging, BasC
sjj , Short joggjean, BasC
scargo , Short cargo, BasC
jean , Jean, BasL
pcar , Pantalon à carreaux, BasL
jogp , Jogger pant, BasL
pcargo , Pantalon cargo, BasL
chi , Pantalon chino, BasL
jj , JoggJean, BasL
sal , Salopette, BasL
bask , Baskets, Shoe
boot , Boots, Shoe
chel , Chelsea boots, Shoe
shoe , Chaussures, Shoe
tong , Tongs, Shoe
claq , Claquettes, Shoe
ens , Ensemble, BasL
jogg , Pantalon jogging, BasL
legg , Leggings, BasL
chem , Chemise, HautIn
polo , Polo, HautIn
swim , Short de bain, BasC
bras , Brassière, Underwear
box , Boxer, Underwear
string , String, Underwear
cul , Culotte, Underwear
slip , Slip, Underwear
body , Body, HautIn
scomb , Combishort, HautIn
comb , Combinaison, HautIn
vo , Veste outdoor, HautOut
déb , Débardeur, HautIn
top , Top, HautIn
moc , Mocassins, Shoe
rsw , Robe sweat, HautIn
rob , Robe, HautIn
rts , Robe t-shirt, HautIn
sur , Surchemise, HautOut
)"
;-----Liste groupes de Catés
Haut := "top,déb,ts,sw,pull,card,gil,doud,park,ves,cpv,bomb,bike,blaz,blou,mant,ted,ens,chem,polo,swim,body,scomb,comb,vo"
HautIn := "top,déb,ts,chem,polo,body"
HautSw := "sw,pull,gil,card,comb"
HautOut := "doud,park,blou,ves,cpv,bomb,bike,blaz,mant,ted,vo,sur"
Bas := "jean,pcar,jogp,pcargo,chi,jj,sal,jogg,legg,sjean,schi,sjog,sjj,scargo,scar"
BasL := "jean,pcar,jogp,pcargo,chi,jj,sal,jogg,legg"
BasC := "sjean,sjog,schi,sjj,scargo,scar,scomb,swim"
Underwear := "bras,box,string,cul,slip"
Shoe := "bask,boot,chel,shoe,tong,claq,moc"
;-----Listes de détails pour ComboBox
Style := "tendance|essentiel|urbain|premium|rétro|élégant|confortable|fluide|léger|fitté|casual|vintage|stylé|fashion|de sport|en denim|bicolore"
Visu1 := "logo||logos|visuel|motif|patch|écusson"
Visu2 := "camouflage|Renaissance|tie dye|dégradé|marbre|léopard|reptile|réfléchissant|à rayures|marinière"
Visu3 := "imprimé||brodé|appliqué|gravé|en relief|en strass|en sequins|réfléchissant|imprimé all over|sur la manche|cousu"
Poche1 := "latérales|avant|arrière|poitrine|ventrale"
Poche2 := "zippées|à bouton pression|à bouton classique|à rabat|à velcro|cargo|décoratives|à rabat boutonné"
Capuche1 := "boutonnée amovible |zippée amovible |dissimulée dans le col"
Capuche2 := "avec fourrure synthétique|avec fourrure synthétique amovible|imprimée|doublée fourrure synthétique"
Col := "rond|en V|zippé|classique boutonné|montant|montant zippé|mouton|cheminée|roulé|mao|officier|amplified|tunisien"
Fermeture1 := "par zip métallique|boutonnée|zippée|par rabat|par rabat boutonné|par rabat velcro|par boutons cardigan|par zip asymétrique|par zip"
Fermeture2 := "zip métallique|boutons|zip|rabat|rabat boutonné|bouton classique"
Taille := "Intl||FR|US|IT|Unique"
Entretien := "Lavable en machine à 30°||Lavable en machine à 40°|Lavage à la main|Nettoyage à sec|Entretien par un spécialiste"
Coupe := "Coupe classique|Coupe slim|Coupe skinny|Coupe cintrée|Coupe ajustée|Coupe ample|Coupe oversize|Coupe crop|Coupe raglan"
;-----Année
i9 := 2021 ; À changer fin octobre pour la suivante
;-----Blocs d'interface
Gui_DétailsLibres()
{
global
Gui, Add, Edit, xp y+5 wp+40 r1 vopt1,
Gui, Add, Edit, xp y+5 wp r1 vopt2,
}
Gui_Taille()
{
global
Gui, Add, GroupBox, xp-10 y+20 wp+20 r3.2, Taille
Gui, Add, Edit, xp+10 yp+18 wp-20 r1 vit1, taille normalement
Gui, Add, ComboBox, xp y+5 wp r5 vit2, %Taille%
}
Gui_Main()
{
global
Gui, 1:Add, GroupBox, x10 w260 r6
Gui, 1:Add, Edit, xp+10 yp+18 w240 r1 vi0, Catégorie
Gui, 1:Add, Edit, xp y+5 wp r1 vi1, Marque
Gui, 1:Add, Edit, xp y+5 wp r1 vi2, Modèle
Gui, 1:Add, Edit, xp y+5 w115 r1 vi8, Sexe
Gui, 1:Add, Edit, xp+125 yp wp r1 vi3, Composition
}
;---------ENTREE INFOS PRINCIPALES-------------------------------------------------------------------------------------------------------------------
;-----GUI Master
Gui1:
Gui, Destroy
Gui_Main()
Gui, 1:Add, GroupBox, x10 w260 r7.2
Gui, 1:Add, ComboBox, xp+10 yp+18 w240 r17 Choose1 vi11, %Style%
Gui, 1:Add, ComboBox, xp y+5 wp r17 vi11b, %Style%
Gui, 1:Add, ComboBox, xp y+5 wp r5 vi4, %Visu1%
Gui, 1:Add, ComboBox, xp y+5 wp r10 vi4b, %Visu2%
Gui, 1:Add, ComboBox, xp y+5 wp r10 vi5, %Visu3%
Gui, 1:Add, GroupBox, x10 w260 r1.7
Gui, 1:Add, ComboBox, xp+10 yp+18 w240 r9 Choose1 vi6, %Coupe%
Gui, 1:Add, GroupBox, x10 w260 r3.1
Gui, 1:Add, Edit, xp+10 yp+18 w240 r1 vi7b, Ligue
Gui, 1:Add, Edit, xp y+5 wp r1 vi7, Licence
Gui, 1:Add, Button, x40 y+15 w80 h30 gBouton000, Nope
Gui, 1:Add, Button, x160 yp w80 h30 gBouton1, OK
Gui, 1:-SysMenu Owner%UniqueID% +LastFound
Gui, 1:Show, w280, DescBox
Return
Bouton000:
GuiClose:
ExitApp
Bouton1:
Gui, 1:Submit, Hide
;-----Lecture template
If i0 in Shoe
FileRead, Clipboard, L:\templates\a_sho.txt
Else
FileRead, Clipboard, L:\templates\a_vet.txt
;-----Bifurcation GUI#2 en fonction du groupe-caté
WinWaitClose, DescBox
If (i0 != "Catégorie") {
If (i0 = "ens") {
GoSub, Gui3
WinWaitClose
}
Else if (InStr(HautIn,i0)) {
GoSub, Gui2
WinWaitClose
}
Else if (InStr(HautSw,i0)) {
GoSub, Gui2b
WinWaitClose
}
Else if (InStr(HautOut,i0)) {
GoSub, Gui4
WinWaitClose
}
Else if (InStr(Underwear,i0)) {
GoSub, Gui5
WinWaitClose
}
Else if (InStr(BasL,i0)) {
GoSub, Gui6
WinWaitClose
}
Else if (InStr(BasC,i0)) {
GoSub, Gui7
WinWaitClose
}
Else if (InStr(Shoe,i0)) { ;TEMPORARY
GoSub, Gui7
WinWaitClose
}
}
Else if (i0 = "")
MsgBox, Catégorie manquante !
ExitApp
Run, %A_AHKPath% "%A_ScriptDir%\DescBox_V2.2.ahk" ; Si caté manquante, ferme et relance DescBox
;---------GUI2 = HAUT INDOORS------------------------------------------------------------------------------------------------------------------------
Gui2:
Gui 2:Destroy
;-----Col
Gui, 2:Add, GroupBox, x10 wp300 r1.7, Col
If ((i0 = "ts") || (i0 = "déb") || (i0 = "top") || (i0 = "body")) {
Gui, 2:Add, ComboBox, xp+10 yp+18 wp-20 r13 Choose1 vic3, %Col%
}
Else if ((i0 = "chem") || (i0 = "polo")) {
Gui, 2:Add, ComboBox, xp+10 yp+18 wp-20 r13 Choose4 vic3, %Col%
}
;-----Détails puces
If ((i0 = "ts") || (i0 = "déb") || (i0 = "top")) { ; affiche différents détails optionnels en fonction de la caté
Gui, 2:Add, CheckBox, x20 y+20 w240 h20 vd1, %desc28%
}
Else if (i0 = "chem") {
Gui, 2:Add, CheckBox, x20 y+20 w240 h20 Checked vd1, %desc29%
Gui, 2:Add, CheckBox, xp y+5 wp h20 Checked vd2, %desc7%
Gui, 2:Add, CheckBox, xp y+5 wp h20 vd3, %desc26%
}
Else if (i0 = "polo") {
Gui, 2:Add, CheckBox, x20 y+20 w240 h20 vd1, %desc28%
Gui, 2:Add, CheckBox, xp y+5 wp h20 vd2, %desc26%
}
Else if (i0 = "body") {
Gui, 2:Add, CheckBox, x20 y+20 w240 h20 vd1, %desc22%
}
Gui_DétailsLibres()
;-----Taille
Gui_Taille()
;-----Entretien
Gui, 2:Add, GroupBox, xp-10 y+20 wp+20 r1.7, Entretien
Gui, 2:Add, ComboBox, xp+10 yp+18 wp-20 r5 vi10, %Entretien%
Gui, 2:Add, Button, Hidden w0 h0 Default, Save
Gui, 2:Add, Button, x130 y+15 w80 h30 gBouton2, Fini
Gui, 2:-SysMenu Owner%UniqueID%
Gui, 2:Show, w320, Détails Haut Indoor
Gui, 2:+LastFound
Return
Bouton2:
Gui, 2:Submit
Gosub, Description
Return
;---- SKIPPED THE OTHER 6 SECONDARY GUI WINDOWS
;--------EDITION DU TEMPLATE-------------------------------------------------------------------------------------------------------------------------
Description: ; SubRoutine
WinWaitClose, LastFound
;---- SKIPPED THE WHOLE HTML EDITING PART