Skip to content

Instantly share code, notes, and snippets.

@TLMcode
Last active December 10, 2015 20:08
Show Gist options
  • Save TLMcode/4485650 to your computer and use it in GitHub Desktop.
Save TLMcode/4485650 to your computer and use it in GitHub Desktop.
GUI Options for collaborative project with AHk user guest3456
DetectHiddenWindows, On
SetWorkingDir % A_ScriptDir
IniFile = config.ini
Loop 2 ; << THIS LOOP ONLY CHECKS AND DOWNLOADS THE DEMO PICTURES. IT CAN BE REMOVED!
UrlDownloadToFile, % "http://cwmb.zxq.net/" ( img:=((i:=!i) ? "" : "s_" ) "pic.jpg" )
, % !FileExist( img ) ? img : ""
;///// GUI/Control variables
ListView = ListView
Button = Button
Name = Name
CheckBox1 = CheckBoxA ; do not remove the variable names!
CheckBox2 = CheckBoxB ; they also fix a weird bug!!
GuiNum := 1
Gui, %GuiNum%:Default
WinCnt:=0
cW:=200, bO:=4.5, it:=10, pH:=150, pW:=180
ListViewRows:=12, GroupBoxHeight:=230
Gui, Font, s9, Arial
Gui, Add, DropDownList, % "Section vDropDown y20 x30 w" cW
Gui, Add, Button, % "vABtn ys w" (b:=cW/2-bO), % Button
GuiControlGet, AButtonDim, Pos, ABtn
Gui, Add, Text, % "h" it " w" (AButtonDimX-AButtonDimW)
Gui, Add, ListView, % "AltSubmit NoSortHdr -Multi Section gGetLBItem xs "
. "vListView w" cW " r" ListViewRows, % ListView "|ch1|ch2|pic"
GuiControlGet, ListViewDim, Pos, ListView
ReadINI(IniFile)
Gui, Add, Button, % "gAddItem ys" AButtonDimH*2 " w" b, add
Gui, Add, Button, % "gRemItem w" b, remove
Gui, Add, Button, % "gMoveUp w" 0 "y"
Gui, Add, Button, % "gMoveUp w" b "y", up
Gui, Add, Button, % "gMoveDown w" b, down
Gui, Add, GroupBox, % "xs vGB h" GroupBoxHeight " w" (AButtonDimX+AButtonDimW-2)
GuiControlGet, GrpBoxDim, Pos, GB
Gui, Add, Text, % "xp+10 y" (g:=GrpBoxDimY+20), % Name
Gui, Add, Edit, % "vNameItem w" (GrpBoxDimW-80)
Gui, Add, Picture, % "vPicture Section h" pH " w" pW, pic.jpg ; << REMOVE pic.jpg ONCE UR CODE IS COMPLETE!
GuiControlGet, PicDim, Pos, Picture
Gui, Add, Checkbox, % "gUpdateCB vCB1 Section ys" PicDimH/2-20, % CheckBox1
Gui, Add, Checkbox, % "gUpdateCB vCB2 xs ys30", % CheckBox2
Gui, Add, Text, % "ys" (GrpBoxDimY-GrpBoxDimH) " h" it
Gui, Show, NA, % GuiTitle:="Options"
Control, Disable, , SysHeader321, % GuiTitle
GetWindows()
Return
;///// Labels
UpdateCB:
LV_GetText(UCBName,LV_GetNext(),1)
If ( UCBName!="ListView" ) {
Loop 2
GuiControlGet, UCBst%A_Index%,, CB%A_Index%
LV_Modify(LV_GetNext(),"", UCBName, UCBst1, UCBst2)
UpdateINI(IniFile)
}
Return
AddItem:
GuiControlGet, NameItem, , NameItem
If ( NameItem ) {
Loop 2
GuiControlGet, CB%A_Index%St, , CB%A_Index%
LV_Add("", NameItem, CB1St, CB2St, "pic" LV_GetCount())
LV_Modify(LV_GetNext(), "-Select")
GuiControl,, NameItem
UpdateINI(IniFile)
}
GoSub, ClrClkBoxes
Return
RemItem:
LV_Delete(LV_GetNext()), UpdateINI(IniFile)
GoSub, ClrClkBoxes
LV_Modify(LV_GetNext(), "-Select")
Return
GetLBItem:
LV_GetText(fTxt, LV_GetNext())
If ( A_GuiEvent=="I" ) {
LV_GetText( curPic, LV_GetNext(), 4) ; << MICHAEL THIS RETURNS THE PIC POSITON ( eg. if ListView had 2 items, it would return Pic3.jpg )
GuiControl,, Picture, s_pic.jpg ; % curPic ; << CHANGE THIS FROM s_pic.jpg TO % curPic
GuiControl,, NameItem, % ( fTxt!="ListView" ? fTxt : "" )
Loop 2 {
LV_GetText(T%A_Index%, LV_GetNext(), A_Index+1)
GuiControl,, CB%A_Index%, % (RegExMatch(t:=T%A_Index%, "\b\d\b")
? t : CheckBox%A_Index%) ; <- bug fix
}
} Else If ( A_GuiEvent=="f" )
GoSub, ClrClkBoxes
Return
MoveUp:
MoveItem("up"), UpdateINI(IniFile)
Return
MoveDown:
MoveItem("down"), UpdateINI(IniFile)
Return
ClrClkBoxes:
Loop 2
GuiControl,, CB%A_Index%, 0
Return
;///// Functions
GetWindows() {
WinGet, WinList, List
Loop % WinList {
WinGetTitle, WinTitle, % "ahk_id " WinList%A_Index%
WinTitlesList.=((w:=WinTitle) && WinTitle!="Start" ? w "|" : "")
}
GuiControl,, DropDown, % WinTitlesList
}
MoveItem(dir) {
If (LV_GetNext() && !(dir="up" && LV_GetNext()=1)) {
LV_GetText(Name, LV_GetNext(), 1), LV_GetText(cbStat1, LV_GetNext(), 2)
LV_GetText(cbStat2, LV_GetNext(), 3), LV_GetText(pic, LV_GetNext(), 4)
LV_Insert(LV_GetNext()+((d:=dir="down") ? 2 : -1 ),"", Name, cbStat1, cbStat2, pic)
cRow := LV_GetNext()+(d ? 1 : -2 )
LV_Delete(LV_GetNext())
}
}
ReadINI(IniFile) {
While CurVal!="ERROR" {
IniRead, CurVal, % IniFile, Names, % "Name_" A_Index
RegExMatch(CurVal, "(.*)_\d+_(\d)_(\d)_(.*)", CurVal_)
LV_Add("",(CurVal!="ERROR" ? CurVal_1 : ), CurVal_2, CurVal_3, CurVal_4)
LV_ModifyCol(1, 196), LV_ModifyCol(2, 0), LV_ModifyCol(3, 0), LV_ModifyCol(4, 0)
}
}
UpdateINI(IniFile) {
FileDelete % ( IniFile, Name:=!Name )
While ( Name ) {
LV_GetText(Name, A_Index, 1), LV_GetText(cbStat1, A_Index, 2)
LV_GetText(cbStat2, A_Index, 3), LV_GetText(pic, A_Index, 4)
CurItem := Name "_" A_Index "_" cbStat1 "_" cbStat2 "_" pic
If ( Name )
IniWrite, % CurItem, % IniFile, Names, % "Name_" A_Index
}
}
GuiClose:
ExitApp
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment