david1337 Posted September 16, 2016 Posted September 16, 2016 (edited) Hey guys I need help to get further with this script Test.txt contains lines like this: _______________ Line1 Line2 Line3 _______________ I have managed to view the content of a txt file in the left side of a GUI like this: #Include <File.au3> #include <GUIConstants.au3> Global $file = FileRead("Test.txt") GUICreate("", 800, 800, 192, 124) $control = GUICtrlCreateEdit($file, 0, 0, 400, 800, $ES_AUTOVSCROLL + $WS_VSCROLL + $ES_READONLY) GUICtrlSetFont(-1, 14, 400, 0, "@Arial Unicode MS") GUICtrlSetBkColor(-1, 0xFFFFFF) GUICtrlSetState($control, $GUI_FOCUS) ;Makes sure that text is not highlighted by default GUISetState(@SW_SHOW) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit EndSwitch WEnd Okay so is it possible to make each line become a clickable item? Say I want to delete Line2, then I highlight it and click a "remove" button. Also an "add" button would be needed to add new lines On Case $GUI_EVENT_CLOSE the changes should be saved to Test.txt (Or with a save button) Is this possible? I hope you can help me :-) Edited September 16, 2016 by david1337
david1337 Posted September 18, 2016 Author Posted September 18, 2016 Can anyone get me in the right direction? :-)
Moderators Melba23 Posted September 18, 2016 Moderators Posted September 18, 2016 david1337, Use a ListView rather than an Edit and my GUIListViewEx UDF will allow you to delete and add lines easily. Give it a try and see how you get on - the link is in my sig. M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area
david1337 Posted September 19, 2016 Author Posted September 19, 2016 Hi Melba Thanks for you reply! How do I make the list vertical, with one item for each line, like I did with GUICtrlCreateEdit? Can't seem to figure this out :S
Moderators Melba23 Posted September 19, 2016 Moderators Posted September 19, 2016 (edited) david1337, Split the text to be read into an array (FileReadToArray or StringSplit) and then add each element (line) to the ListView using GUICtrlCreateListViewItem. The UDF will then let you add/delete lines very easily. M23 Edit: A simple example: #include <GUIConstantsEx.au3> #include <GUIListViewEx.au3> ; Simulate reading the file into an array Global $aLines = ["Line1", "Line2", "Line3"] $hGUI = GUICreate("Test", 500, 500) $cLV = GUICtrlCreateListView(" ", 10, 10, 300, 300) _GUICtrlListView_SetColumnWidth($cLV, 0, 290) $cInsert = GUICtrlCreateButton("Insert Line", 400, 10, 80, 30) $cDelete = GUICtrlCreateButton("Delete Line", 400, 50, 80, 30) GUISetState() ; Intialise ListView $iLV_Index = _GUIListViewEx_Init($cLV) ; Insert lines _GUIListViewEx_Insert($aLines, True) ; Register required messages _GUIListViewEx_MsgRegister(True, False, False, False) While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit Case $cInsert _GUIListViewEx_Insert("New line") Case $cDelete _GUIListViewEx_Delete() EndSwitch WEnd Edited September 19, 2016 by Melba23 Amended code slightly Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area
david1337 Posted September 20, 2016 Author Posted September 20, 2016 Hi Melba Thank you, that worked like a charm. The only thing I have problems with now is to save the file with the edited content. My guess would be something like using a _GUIListViewEx_ReturnArray to view the state of the array, edited or not. (In the below script I try to show this in a msgbox) Then use a filewrite with the new content. Only problem is, I can't get the _GUIListViewEx_ReturnArray to show the valid data - I tried following your GUIListViewEx Guide, and I think that I'm close expandcollapse popup#include <GUIConstantsEx.au3> #include <GUIListViewEx.au3> Global $FileToArray = FileReadToArray("test.txt") $hGUI = GUICreate("Test Text File", 800, 800) $cLV = GUICtrlCreateListView("[Headline]", 10, 10, 400, 775) GUICtrlSetFont(-1, 12, 800, 0, "@Arial Unicode MS") _GUICtrlListView_SetColumnWidth($cLV, 0, 378) $cInsert = GUICtrlCreateButton("Add User", 425, 10, 80, 30) $cDelete = GUICtrlCreateButton("Remove User", 425, 50, 80, 30) GUISetState() ; Intialise ListView $iLV_Index = _GUIListViewEx_Init($cLV) ; Insert lines _GUIListViewEx_Insert($FileToArray, True) ; Register required messages _GUIListViewEx_MsgRegister(True, False, False, False) While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ;An attemp to show the content of the Array after I edited it $updated = _GUIListViewEx_ReturnArray MsgBox(0,"",$updated) Exit Case $cInsert _GUIListViewEx_Insert("New line") Case $cDelete _GUIListViewEx_Delete() EndSwitch WEnd
Moderators Melba23 Posted September 20, 2016 Moderators Posted September 20, 2016 david1337, Using MsgBox to display an array? This works better: Case $GUI_EVENT_CLOSE $aContent = _GUIListViewEx_ReturnArray($iLV_Index) _ArrayDisplay($aContent, "", Default, 8) Exit M23 david1337 1 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area
david1337 Posted September 20, 2016 Author Posted September 20, 2016 (edited) Uhm just ignore that I used MsgBox Had tried so many things that I mixed up my array with a normal list. Anyway, thanks for your help! I got it working now. GUIListViewEx is an indispensable UDF! expandcollapse popup#include <GUIConstantsEx.au3> #include <GUIListViewEx.au3> #include <File.au3> Global $File = "test.txt" Global $FileToArray = FileReadToArray("test.txt") $hGUI = GUICreate("Test Text File", 800, 800) $cLV = GUICtrlCreateListView("[Headline]", 10, 10, 400, 775) GUICtrlSetFont(-1, 12, 800, 0, "@Arial Unicode MS") _GUICtrlListView_SetColumnWidth($cLV, 0, 378) $cInsert = GUICtrlCreateButton("Add Item", 425, 10, 80, 30) $cDelete = GUICtrlCreateButton("Remove Item", 425, 50, 80, 30) GUISetState() ; Intialise ListView $iLV_Index = _GUIListViewEx_Init($cLV) ; Insert lines _GUIListViewEx_Insert($FileToArray, True) ; Register required messages _GUIListViewEx_MsgRegister(True, False, False, False) While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE $aContent = _GUIListViewEx_ReturnArray($iLV_Index) _FileWriteFromArray($File,$aContent) Exit Case $cInsert _GUIListViewEx_Insert("New line") Case $cDelete _GUIListViewEx_Delete() EndSwitch WEnd Edited September 20, 2016 by david1337
Moderators Melba23 Posted September 20, 2016 Moderators Posted September 20, 2016 david1337, Glad you like the UDF - it is a pretty complex beast to master, but does have a lot of functionality. M23 david1337 1 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area
david1337 Posted September 21, 2016 Author Posted September 21, 2016 (edited) Hi Melba I need your help again (or some other genius) When the OK button is clicked it writes the input from $ReadinputboxUsername into my text file, which works as expected. Then it exits the loop, and goes back to the main GUI. Is it possible to update my ListView when the OK button in the childGUI is clicked? In other words: It has to read and show the newly updated content of the text file. expandcollapse popup;______________________________________________ #include <GUIConstantsEx.au3> #include <GUIListViewEx.au3> #include <File.au3> #include <AD.au3> #include <EditConstants.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #include <MsgBoxConstants.au3> ;______________________________________________ Global $MainGUI_MyGUI Global $File = "test.txt" Global $FileToArray = FileReadToArray("test.txt") Call ("MainGUI_MyGUI") Func MainGUI_MyGUI() Local $cAddUser $MainGUI_MyGUI = GUICreate("My GUI", 800, 800, -1, -1) $cLV = GUICtrlCreateListView("[Users]", 10, 10, 400, 775) GUICtrlSetFont(-1, 12, 800, 0, "@Arial Unicode MS") _GUICtrlListView_SetColumnWidth($cLV, 0, 378) $cAddUser = GUICtrlCreateButton("Add User", 425, 10, 80, 30) $cRemoveUser = GUICtrlCreateButton("Remove User", 425, 50, 80, 30) GUISetState(@SW_SHOW, $MainGUI_MyGUI) ; Intialise ListView $iLV_Index = _GUIListViewEx_Init($cLV) ; Insert lines _GUIListViewEx_Insert($FileToArray, True) ; Register required messages _GUIListViewEx_MsgRegister(True, False, False, False) While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE $aContent = _GUIListViewEx_ReturnArray($iLV_Index) _FileWriteFromArray($File,$aContent) ExitLoop Case $cAddUser GUISetState(@SW_DISABLE, $MainGUI_MyGUI) $ChildGUI_AddUser = ChildGUI_AddUser() GUISetState(@SW_ENABLE, $MainGUI_MyGUI) GUIDelete($ChildGUI_AddUser) ; WinActivate($MainGUI_MyGUI) ; <<<<< Activate the ParentGUI again. Case $cRemoveUser _GUIListViewEx_Delete() EndSwitch WEnd EndFunc ;==>Main Func ChildGUI_AddUser() $ChildGUI_AddUser = GUICreate("Find User", 615, 229, -1, -1, -1, -1, $MainGUI_MyGUI) $inputboxUsername = GUICtrlCreateInput("", 192, 16, 233, 21) $Check = GUICtrlCreateButton("Check", 440, 16, 41, 25) $Cancel = GUICtrlCreateButton("Cancel", 520, 160, 81, 65) $OK = GUICtrlCreateButton("OK", 426, 161, 81, 65) GUISetState() While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE ExitLoop Case $Check $ReadinputboxUsername = GUICtrlRead($inputboxUsername) _AD_Open() $fullname = _AD_GetObjectAttribute($ReadinputboxUsername, "name") _AD_Close() $FullNameLabel = GUICtrlCreateLabel($fullname, 150, 64, 200, 100) Case $Cancel ExitLoop Case $OK If Not IsDeclared("ReadinputboxUsername") Then MsgBox(0,"Error", "No user is chosen") Else _FileWriteToLine($File, 1, $ReadinputboxUsername, 0) ExitLoop EndIf EndSwitch WEnd Return $ChildGUI_AddUser EndFunc ;==>ChildGUI_AddUser Edited September 21, 2016 by david1337
l3ill Posted September 21, 2016 Posted September 21, 2016 Yes, call the FileReadToArray Function (again) after the text file has been changed. My Contributions... SnippetBrowser NewSciTE PathFinder Text File Manipulation FTP Connection Tester / INI File - Read, Write, Save & Load Example
david1337 Posted September 21, 2016 Author Posted September 21, 2016 I3iII Thanks for your answer, but that didn't do the trick I'm afraid
l3ill Posted September 21, 2016 Posted September 21, 2016 Well you are going to have to rewrite some of your code for this to work. I suggest making your own function with the FileReadToArray in it and calling it separately when needed (at the beginning, when you click ok... etc) to repopulate (update) your listview My Contributions... SnippetBrowser NewSciTE PathFinder Text File Manipulation FTP Connection Tester / INI File - Read, Write, Save & Load Example
david1337 Posted September 21, 2016 Author Posted September 21, 2016 Hmm can't make it work properly - will have to give it some more work.
l3ill Posted September 21, 2016 Posted September 21, 2016 (edited) I see what you mean... Try This: Spoiler expandcollapse popup#include <GUIConstantsEx.au3> #include <GUIListViewEx.au3> #include <File.au3> #include <AD.au3> #include <EditConstants.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #include <MsgBoxConstants.au3> Global $MainGUI_MyGUI Global $File = "test.txt" Global $FileToArray = FileReadToArray("test.txt") Call("MainGUI_MyGUI") Func MainGUI_MyGUI() Local $cAddUser $MainGUI_MyGUI = GUICreate("My GUI", 800, 800, -1, -1) $cLV = GUICtrlCreateListView("[Users]", 10, 10, 400, 775) GUICtrlSetFont(-1, 12, 800, 0, "@Arial Unicode MS") _GUICtrlListView_SetColumnWidth($cLV, 0, 378) $cAddUser = GUICtrlCreateButton("Add User", 425, 10, 80, 30) $cRemoveUser = GUICtrlCreateButton("Remove User", 425, 50, 80, 30) GUISetState(@SW_SHOW, $MainGUI_MyGUI) ; Intialise ListView $iLV_Index = _GUIListViewEx_Init($cLV) ; Insert lines _GUIListViewEx_Insert($FileToArray, True) ; Register required messages _GUIListViewEx_MsgRegister(True, False, False, False) While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE $aContent = _GUIListViewEx_ReturnArray($iLV_Index) _FileWriteFromArray($File, $aContent) ExitLoop Case $cAddUser GUISetState(@SW_DISABLE, $MainGUI_MyGUI) $ChildGUI_AddUser = ChildGUI_AddUser() GUISetState(@SW_ENABLE, $MainGUI_MyGUI) GUIDelete($ChildGUI_AddUser) ; WinActivate($MainGUI_MyGUI) ; <<<<< Activate the ParentGUI again. Case $cRemoveUser _GUIListViewEx_Delete() EndSwitch WEnd EndFunc ;==>MainGUI_MyGUI Func ChildGUI_AddUser() $ChildGUI_AddUser = GUICreate("Find User", 615, 229, -1, -1, -1, -1, $MainGUI_MyGUI) $inputboxUsername = GUICtrlCreateInput("", 192, 16, 233, 21) $Check = GUICtrlCreateButton("Check", 440, 16, 41, 25) $Cancel = GUICtrlCreateButton("Cancel", 520, 160, 81, 65) $OK = GUICtrlCreateButton("OK", 426, 161, 81, 65) GUISetState() While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE ExitLoop Case $Check $ReadinputboxUsername = GUICtrlRead($inputboxUsername) _AD_Open() $fullname = _AD_GetObjectAttribute($ReadinputboxUsername, "name") _AD_Close() $FullNameLabel = GUICtrlCreateLabel($fullname, 150, 64, 200, 100) Case $Cancel ExitLoop Case $OK If Not IsDeclared("ReadinputboxUsername") Then MsgBox(0, "Error", "No user is chosen") Else _FileWriteToLine($File, 1, $ReadinputboxUsername, 0) _GUIListViewEx_Insert($ReadinputboxUsername) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ADDED LINE ExitLoop EndIf EndSwitch WEnd Return $ChildGUI_AddUser EndFunc ;==>ChildGUI_AddUser Edited September 21, 2016 by l3ill david1337 1 My Contributions... SnippetBrowser NewSciTE PathFinder Text File Manipulation FTP Connection Tester / INI File - Read, Write, Save & Load Example
david1337 Posted September 22, 2016 Author Posted September 22, 2016 I3iII Thanks mate, that was a big help! So simple! And since I wanted to write to the top row, I used: _GUIListViewEx_InsertSpec( 1, $ReadinputboxUsername, $ReadinputboxUsername) And now this became unnecessary: _FileWriteToLine($File, 1, $ReadinputboxUsername, 0) Since I use _FileWriteFromArray on exit.
l3ill Posted September 22, 2016 Posted September 22, 2016 Sweet Glad it worked out! FYI: don't forget to tidy your code... My Contributions... SnippetBrowser NewSciTE PathFinder Text File Manipulation FTP Connection Tester / INI File - Read, Write, Save & Load Example
david1337 Posted September 22, 2016 Author Posted September 22, 2016 Yeah, I guess that the example needs a little polish - anything specific?
l3ill Posted September 22, 2016 Posted September 22, 2016 (edited) No worries. If you are interested see my last code post (15). ( Delete (unnecessary) empty CR and run Tidy ) I understand most people dont clean up until there close to finishing up. Just me being fastidious (anal) Good luck with your project ! Bill Edited September 22, 2016 by l3ill david1337 1 My Contributions... SnippetBrowser NewSciTE PathFinder Text File Manipulation FTP Connection Tester / INI File - Read, Write, Save & Load Example
david1337 Posted September 22, 2016 Author Posted September 22, 2016 Haha omg I wish that I could double like that post Thank you! David
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now