#NoTrayIcon #include #include #include #include #include #include #include AutoItSetOption("MustDeclareVars",1) AutoItSetOption("GUIOnEventMode", 1) Global $g_aPeople Global $g_aItems Global $g_aColors Global $g_aAttributes[1][1] Global $g_id_combo_People Global $g_id_combo_Color Global $g_id_combo_Item Global $g_id_combo_Location Global $g_id_label_Result Global $g_id_ColorBox Global $g_a_id_label_Location[1] GUI_Window() Func GUI_Window() ; Create App Window Local $hAppWindow = GUICreate("Neato 5000", 500, 500, 190, 122) GUISetOnEvent($GUI_EVENT_CLOSE, "App_Close") ; Create Dummy Button to intercept Return key press GUICtrlCreateButton("",0,0,0,0,-1,-1) ; Create CLOSE Button Local $iBtn_Close = GUICtrlCreateButton("CLOSE",400,450,80,30,-1,-1) GUICtrlSetFont(-1, 14, 400, 0, "") GUICtrlSetOnEvent($iBtn_Close, "App_Close") ; Create People ComboBox $g_id_combo_People = GUICtrlCreateCombo("",10,10,150,25,-1,-1) GUICtrlSetFont(-1, 14, 400, 0, "") GUICtrlSetOnEvent(-1, "Person_Change") ; Create Location ComboBox $g_id_combo_Location = GUICtrlCreateCombo("",10,50,150,25,-1,-1) GUICtrlSetFont(-1, 14, 400, 0, "") GUICtrlSetOnEvent(-1, "Location_Change") ; Create Item ComboBox $g_id_combo_Item = GUICtrlCreateCombo("",200,50,150,25,-1,-1) GUICtrlSetFont(-1, 14, 400, 0, "") GUICtrlSetOnEvent(-1, "Item_Change") ; Create Color ComboBox $g_id_combo_Color = GUICtrlCreateCombo("",10,90,150,25,-1,-1) GUICtrlSetFont(-1, 14, 400, 0, "") GUICtrlSetOnEvent(-1, "Color_Change") ; Create CLOSE Button GUICtrlCreateButton("RANDOMIZE",200,90,150,30,-1,-1) GUICtrlSetFont(-1, 14, 400, 0, "") GUICtrlSetOnEvent(-1, "Items_Randomize") ; Create Color Graphic $g_id_ColorBox = GUICtrlCreateGraphic(10, 130, 50, 25) ; Read ini fle Local $sIniFile = @ScriptDir & "\Attributes.ini" _ReadIni($sIniFile) ; Populate People Combo _GUICtrlComboBox_ResetContent($g_id_combo_People) for $i=0 to ubound($g_aPeople)-1 _GUICtrlComboBox_AddString($g_id_combo_People, $g_aPeople[$i][0]) ;Add names to the combo box Next _GUICtrlComboBox_SetCurSel($g_id_combo_People,0) ;Select 1st combobox item ; Populate Location Combo _GUICtrlComboBox_ResetContent($g_id_combo_Location) for $i=0 to ubound($g_aItems)-1 _GUICtrlComboBox_AddString($g_id_combo_Location, $g_aItems[$i][0]) ;Add names to the combo box Next _GUICtrlComboBox_SetCurSel($g_id_combo_Location,0) ;Select 1st combobox item ; Populate Color Combo _GUICtrlComboBox_ResetContent($g_id_combo_Color) for $i=0 to ubound($g_aColors)-1 _GUICtrlComboBox_AddString($g_id_combo_Color, $g_aColors[$i][0]) ;Add names to the combo box Next _GUICtrlComboBox_SetCurSel($g_id_combo_Color,0) ;Select 1st combobox item ; ReDim Attributes array and populate Local $i_rowsAttributes = ubound($g_aPeople) Local $i_colsAttributes = 1 + (ubound($g_aItems)-1) * 2 redim $g_aAttributes[$i_rowsAttributes][$i_colsAttributes] for $i = 0 to $i_rowsAttributes - 1 $g_aAttributes[$i][0] = $g_aPeople[$i][0] for $j = 1 to ubound($g_aItems)- 1 Local $sValue = IniRead($sIniFile,$g_aPeople[$i][0],$g_aItems[$j][0],"") Local $aValueSplit = StringSplit($sValue,"|",0) if $i = 0 Then $g_aAttributes[$i][1 + ($j-1) * 2] = $g_aItems[$j][0] $g_aAttributes[$i][2 + ($j-1) * 2] = $g_aColors[0][0] Else $g_aAttributes[$i][1 + ($j-1) * 2] = $aValueSplit[1] $g_aAttributes[$i][2 + ($j-1) * 2] = $aValueSplit[2] EndIf Next Next ; Create Labels - can be created dynamically redim $g_a_id_label_Location[ubound($g_aItems)] ; array holding label id's for $i = 1 to ubound($g_aItems) - 1 GUICtrlCreateLabel($g_aItems[$i][0] & ":", 10, 170 + ($i-1) * 40, 100, 25) GUICtrlSetFont(-1,14,0,"") $g_a_id_label_Location[$i] = GUICtrlCreateLabel("", 130, 170 + ($i-1) * 40, 200, 25) GUICtrlSetFont(-1,14,0,"") Next ; Display the App Window GUISetState(@SW_SHOW,$hAppWindow) ; MessageLoop While 1 Sleep(100) WEnd EndFunc Func Show_Details() Local $iPeople = _GUICtrlComboBox_GetCurSel ($g_id_combo_People) if $iPeople = 0 then Return for $i = 1 to ubound($g_aItems) - 1 GUICtrlSetData($g_a_id_label_Location[$i],$g_aAttributes[$iPeople][1 + ($i-1) * 2]) GUICtrlSetColor($g_a_id_label_Location[$i],$g_aAttributes[$iPeople][2 + ($i-1) * 2]) next ;~ Local $iItem = _GUICtrlComboBox_GetCurSel ($g_id_combo_Item) ;~ Local $index = _GUICtrlComboBox_GetCurSel ($g_id_combo_Color) EndFunc func Items_Randomize() ; for each person for $i = 1 to ubound($g_aAttributes) - 1 ; for each location for $j = 1 to ubound($g_aItems) - 1 ; Randomize Item Local $sItem = "" while $sItem = "" Local $index = Random(1, ubound($g_aItems,2)-1,1) $sItem = $g_aItems[$j][$index] wend ; Randomize Color Local $sColor = "" if $sItem = "Nothing" then $sColor = $GUI_BKCOLOR_TRANSPARENT Else $index = Random(2, ubound($g_aColors)-1,1) $sColor = "0x" & _RGB2HEX($g_aColors[$index][1]) EndIf $g_aAttributes[$i][1 + ($j-1) * 2] = $sItem $g_aAttributes[$i][2 + ($j-1) * 2] = $sColor Next Next _ArrayDisplay($g_aAttributes,"Attributes Table") EndFunc ;// Converter: RGB To Hexadecimal format (parameters "Red, Green, Blue" (0-255) Func _RGB2HEX($_rgb) Local $rgbComp = StringSplit( StringStripWS($_rgb, 8), ',') Return Hex( BitAND($rgbComp[1], 255), 2) & Hex( BitAND($rgbComp[2], 255), 2) & Hex( BitAND($rgbComp[3], 255), 2) EndFunc Func Person_Change() Local $index = _GUICtrlComboBox_GetCurSel ($g_id_combo_People) ConsoleWrite("Person Changed: Index(" & $index & ") - " & GUICtrlRead($g_id_combo_People) & @crlf) Show_Details() EndFunc Func Item_Change() Local $index = _GUICtrlComboBox_GetCurSel ($g_id_combo_Item) ConsoleWrite("Item Changed: Index(" & $index & ") - " & GUICtrlRead($g_id_combo_Item) & @crlf) EndFunc Func Color_Change() Local $index = _GUICtrlComboBox_GetCurSel ($g_id_combo_Color) ConsoleWrite("Color Changed: Index(" & $index & ") - " & GUICtrlRead($g_id_combo_Color) & " - " & $g_aColors[$index][1] & @crlf) Local $Color = ($index=0) ? ($GUI_BKCOLOR_TRANSPARENT) : ("0x" & _RGB2HEX($g_aColors[$index][1])) GUICtrlSetBkColor($g_id_ColorBox, $Color) EndFunc Func Location_Change() Local $index = _GUICtrlComboBox_GetCurSel ($g_id_combo_Location) ConsoleWrite("Location Changed: Index(" & $index & ") - " & GUICtrlRead($g_id_combo_Location) & @crlf) ; Populate Item Combo _GUICtrlComboBox_ResetContent($g_id_combo_Item) for $i=1 to ubound($g_aItems) - 1 if not $g_aItems[$index][$i] = "" then _GUICtrlComboBox_AddString($g_id_combo_Item, $g_aItems[$index][$i]) ;Add names to the combo box Next _GUICtrlComboBox_SetCurSel($g_id_combo_Item,0) ;Select 1st combobox item EndFunc Func _ReadIni($sIniFile) If not FileExists($sIniFile) Then ConsoleWrite("Can't find Ini File!" & @CRLF) Exit EndIf Local $aTemp $g_aPeople = _ReadIniSection($sIniFile,"People") $g_aItems = _ReadIniSection($sIniFile,"Items") $g_aColors = _ReadIniSection($sIniFile,"Colors") EndFunc Func _ReadIniSection($sIniFile, $sSection) Local $aTemp = IniReadSection($sIniFile,$sSection) If @error then ConsoleWrite("Error opening section: " & $sSection & " - " & @error & @CRLF) ; Find out max columns Local $i_columnsSection = 1 for $i = 1 to ubound($aTemp)-1 Local $sValue = $aTemp[$i][1] StringReplace($sValue,"|","") if @extended + 1 > $i_columnsSection then $i_columnsSection = @extended + 1 next ; Find out rows Local $i_rowsSection = ubound($aTemp)-1 ; Declare Return array Local $aReturn[$i_rowsSection][$i_columnsSection] ; Populate Return array for $i = 0 to $i_rowsSection-1 $sValue = $aTemp[$i+1][1] Local $aValueSplit = StringSplit($sValue,"|",0) StringReplace($sValue,"|","") for $j = 1 to @extended + 1 $aReturn[$i][$j-1] = $aValueSplit[$j] Next next Return $aReturn EndFunc Func _SaveIni($sIniPath) EndFunc func App_Close() GUIDelete(@GUI_WinHandle) Exit EndFunc