Показать полную графическую версию : [решено] Редактирование txt в GUI
koc9kaca
05-07-2011, 14:49
Доброго времени суток, уважаемые форумчане!
Есть txt файлик, в котором хранится большое количество [Variables] для основного ini файла.
Пример txt:
[Variables]
BGdock=bgdock.png
BGmenu=bgmenu.png
mark=mark.png
Icon1=Icon1.png
Icon2=Icon2.png
Icon3=drawer.png
...
Вот примерный GUI приложения:
http://img195.imageshack.us/img195/7946/36137174.png (http://imageshack.us/photo/my-images/195/36137174.png/)
Надо, чтобы в список выводились наименования строк из txt (BGdock= 'Фон', BGmenu= 'Фон меню', Mark= 'Выделение иконки' и т.д.), в поле ввода при выделении каждого из пунктов в списке по умолчанию выводилась инфа, которая стоит после знака '=' в соответствующей строчке (для 1 строчки 'bgdock.png', для 2 - 'bgmenu' и т.д.). При изменении данных в поле ввода и нажатии кнопки Set они должны подставляться после знака '=', перезаписывая при этом старое значение.
Можете посодействовать в реализации этой примочки?
Не уверен что правильно понял, но вот что получилось:
#include (http://www.autoitscript.com/autoit3/docs/keywords.htm##include) <GUIConstantsEx.au3>
#include (http://www.autoitscript.com/autoit3/docs/keywords.htm##include) <ListBoxConstants.au3>
OnAutoItExitRegister("_OnExitProc")
Global (http://www.autoitscript.com/autoit3/docs/keywords.htm#Global) $sConfig_File = @ScriptDir (http://www.autoitscript.com/autoit3/docs/macros.htm#@scriptdir) & "\Config.ini"
Global (http://www.autoitscript.com/autoit3/docs/keywords.htm#Global) $aIniData = IniReadSection (http://www.autoitscript.com/autoit3/docs/functions/IniReadSection.htm)($sConfig_File, "Variables")
$hGUI = GUICreate (http://www.autoitscript.com/autoit3/docs/functions/GUICreate.htm)("Test Script", 300, 200)
$nList = GUICtrlCreateList (http://www.autoitscript.com/autoit3/docs/functions/GUICtrlCreateList.htm)("", 20, 20, 260, 120, BitXOR (http://www.autoitscript.com/autoit3/docs/functions/BitXOR.htm)($GUI_SS_DEFAULT_LIST, $LBS_SORT))
$nInput = GUICtrlCreateInput (http://www.autoitscript.com/autoit3/docs/functions/GUICtrlCreateInput.htm)("", 20, 150, 200, 20)
$nSet_Button = GUICtrlCreateButton (http://www.autoitscript.com/autoit3/docs/functions/GUICtrlCreateButton.htm)("Set", 225, 150, 55, 20)
For (http://www.autoitscript.com/autoit3/docs/keywords.htm#For) $i = 1 To (http://www.autoitscript.com/autoit3/docs/keywords.htm#To) UBound (http://www.autoitscript.com/autoit3/docs/functions/UBound.htm)($aIniData)-1
GUICtrlSetData (http://www.autoitscript.com/autoit3/docs/functions/GUICtrlSetData.htm)($nList, $aIniData[$i][0])
Next (http://www.autoitscript.com/autoit3/docs/keywords.htm#Next)
GUISetState (http://www.autoitscript.com/autoit3/docs/functions/GUISetState.htm)(@SW_SHOW (http://www.autoitscript.com/autoit3/docs/macros.htm#@sw_show), $hGUI)
While (http://www.autoitscript.com/autoit3/docs/keywords.htm#While) 1
Switch (http://www.autoitscript.com/autoit3/docs/keywords.htm#Switch) GUIGetMsg (http://www.autoitscript.com/autoit3/docs/functions/GUIGetMsg.htm)()
Case (http://www.autoitscript.com/autoit3/docs/keywords.htm#Case) $GUI_EVENT_CLOSE
Exit (http://www.autoitscript.com/autoit3/docs/keywords.htm#Exit)
Case (http://www.autoitscript.com/autoit3/docs/keywords.htm#Case) $nList
$sItem = GUICtrlRead (http://www.autoitscript.com/autoit3/docs/functions/GUICtrlRead.htm)($nList)
For (http://www.autoitscript.com/autoit3/docs/keywords.htm#For) $i = 1 To (http://www.autoitscript.com/autoit3/docs/keywords.htm#To) UBound (http://www.autoitscript.com/autoit3/docs/functions/UBound.htm)($aIniData)-1
If (http://www.autoitscript.com/autoit3/docs/keywords.htm#If) $aIniData[$i][0] = $sItem Then (http://www.autoitscript.com/autoit3/docs/keywords.htm#Then)
GUICtrlSetData (http://www.autoitscript.com/autoit3/docs/functions/GUICtrlSetData.htm)($nInput, $aIniData[$i][1])
ExitLoop (http://www.autoitscript.com/autoit3/docs/keywords.htm#ExitLoop)
EndIf (http://www.autoitscript.com/autoit3/docs/keywords.htm#EndIf)
Next (http://www.autoitscript.com/autoit3/docs/keywords.htm#Next)
Case (http://www.autoitscript.com/autoit3/docs/keywords.htm#Case) $nSet_Button
$sItem = GUICtrlRead (http://www.autoitscript.com/autoit3/docs/functions/GUICtrlRead.htm)($nList)
If (http://www.autoitscript.com/autoit3/docs/keywords.htm#If) $sItem = "" Then (http://www.autoitscript.com/autoit3/docs/keywords.htm#Then)
MsgBox (http://www.autoitscript.com/autoit3/docs/functions/MsgBox.htm)(48, 'Attention', 'No selected item.', 0, $hGUI)
ContinueLoop (http://www.autoitscript.com/autoit3/docs/keywords.htm#ContinueLoop)
EndIf (http://www.autoitscript.com/autoit3/docs/keywords.htm#EndIf)
For (http://www.autoitscript.com/autoit3/docs/keywords.htm#For) $i = 1 To (http://www.autoitscript.com/autoit3/docs/keywords.htm#To) UBound (http://www.autoitscript.com/autoit3/docs/functions/UBound.htm)($aIniData)-1
If (http://www.autoitscript.com/autoit3/docs/keywords.htm#If) $aIniData[$i][0] = $sItem Then (http://www.autoitscript.com/autoit3/docs/keywords.htm#Then)
$aIniData[$i][1] = GUICtrlRead (http://www.autoitscript.com/autoit3/docs/functions/GUICtrlRead.htm)($nInput)
ExitLoop (http://www.autoitscript.com/autoit3/docs/keywords.htm#ExitLoop)
EndIf (http://www.autoitscript.com/autoit3/docs/keywords.htm#EndIf)
Next (http://www.autoitscript.com/autoit3/docs/keywords.htm#Next)
EndSwitch (http://www.autoitscript.com/autoit3/docs/keywords.htm#EndSwitch)
WEnd (http://www.autoitscript.com/autoit3/docs/keywords.htm#WEnd)
Func (http://www.autoitscript.com/autoit3/docs/keywords.htm#Func) _OnExitProc()
IniWriteSection (http://www.autoitscript.com/autoit3/docs/functions/IniWriteSection.htm)($sConfig_File, "Variables", $aIniData)
EndFunc (http://www.autoitscript.com/autoit3/docs/keywords.htm#EndFunc)
koc9kaca
05-07-2011, 17:33
Creat0R ,
Спасибо огромнейшее!!! Практически то, что нужно!
Пара недочётов - сохраняет после закрытия (может быть так и надо), т.е. не "на лету" непосредственно после нажатия кнопки Set; ну и ещё один - инфу хватает только из ini фалов, у меня же переменные хранятся в txt в соседней директории.
Ну да не беда - допилю, Ваш пример очень поможет в изучении AutoIT (открыл его для себя только 21 час назад =))
Пара недочётов »
Это не недочёты...
сохраняет после закрытия (может быть так и надо), т.е. не "на лету" непосредственно после нажатия кнопки Set »
Нигде об этом небыло указано, тут главное что скрипт запоминает это, и да, сохраняет всё на выходе, так правильнее (хотя зависит конечно от предназначения программы, и насколько критично обновление данных).
инфу хватает только из ini фалов, у меня же переменные хранятся в txt в соседней директории. »
Инфу “хватает” из указанного файла в переменной $sConfig_File, я предположил что ini-структура должна хранится именно в нём. В любом случае, имя файла и его расширение можно указать любое, это никак не повлияет на работу скрипта.
© OSzone.net 2001-2012
vBulletin v3.6.4, Copyright ©2000-2025, Jelsoft Enterprises Ltd.
Available in ZeroNet 1osznRoVratMCN3bFoFpR2pSV5c9z6sTC