31290 Posted January 12, 2016 Posted January 12, 2016 (edited) Hi Everyone, Happy New Year Well, I have a script that gather information about a given switch here at work that output data in a txt file:What I'd like to do first is to put the file in a list view with the possibility to sort the ports by VLAN, by ports or by Status (and also delete all that concern Duplex / Speed / Type).In a second time, I'd like to bold and color "connected" in green / "disconnected" in red and "err-disabled" in gray. Then, I'd like also to apply a certain color depending on the VLAN number (I have the list of them).And to finish (sorry ^^) when I double click on a list item, I'd like to retrieve information of the selected line for me to do some operation on it.I know this is quite an ask but this is something I don't know how to (don't worry, I've done some researches before) do and also, I'm not familiar with arrays at all.Many thanks for those who can help I've uploaded the output txt file: EPES18.txt Edited January 12, 2016 by 31290 ~~~ Doom Shall Never Die, Only The Players ~~~
Moderators Melba23 Posted January 12, 2016 Moderators Posted January 12, 2016 (edited) 31290, This should get you started: expandcollapse popup#include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <MsgBoxConstants.au3> #include <StringConstants.au3> #include <Array.au3> #include <GuiListView.au3> ; Read file and replace tabs $sContent = StringReplace(FileRead("EPES18.txt"), @TAB, " ") ; Expand possible single space before connection status $sExpanded = StringRegExpReplace($sContent, "(\x20(connected|notconnect|err-disabled))", " $1") ; Replace multiple spaces with | delimiter - max 19 to allow for empty fields $sDelimed = StringRegExpReplace($sExpanded, "(\x20{2,19})", "|") ; Split on @CRLF $aLines = StringSplit($sDelimed, @CRLF, $STR_ENTIRESPLIT) ;_ArrayDisplay($aLines, "", Default, 8) $hGUI = GUICreate("Test", 500, 500) ; Create ListView with first 4 headers $cLV = GUICtrlCreateListView(StringRegExpReplace($aLines[1], "(?U)^(.*\|.*\|.*\|.*)\|.*$", "$1"), 10, 10, 480, 380) GUICtrlSetBkColor($cLV, 0x808080) ; Set column widths For $i = 0 To 3 _GUICtrlListView_SetColumnWidth($cLV, $i, 110) Next ; Add content of first 4 fields in each line For $i = 2 To $aLines[0] $cLVItem = GUICtrlCreateListViewItem(StringRegExpReplace($alines[$i], "(?U)^(.*\|.*\|.*\|.*)\|.*$", "$1"), $cLV) ; Colour according to status If StringInStr($alines[$i], "|connected|") Then GUICtrlSetColor($cLVItem, 0x00FF00) ElseIf StringInStr($alines[$i], "|notconnect|") Then GUICtrlSetColor($cLVItem, 0xFF0000) Else GUICtrlSetColor($cLVItem, 0xC4C4C4) EndIf Next GUISetState() ; Set sort state Local $aSortSense[_GUICtrlListView_GetColumnCount($cLV)] GUIRegisterMsg($WM_NOTIFY, "_WM_NOTIFY") While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit EndSwitch WEnd Func _WM_NOTIFY($hWnd, $imsg, $wParam, $lParam) ; Struct = $tagNMHDR and "int Item;int SubItem" from $tagNMLISTVIEW Local $tStruct = DllStructCreate("hwnd;uint_ptr;int_ptr;int;int", $lParam) If @error Then Return Local $iCode = BitAND(DllStructGetData($tStruct, 3), 0xFFFFFFFF) Switch $iCode Case $LVN_COLUMNCLICK ; Get column index Local $iCol = DllStructGetData($tStruct, 5) ; Sort column _GUICtrlListView_SimpleSort($cLV, $aSortSense, $iCol) Case $NM_DBLCLK $iRow = DllStructGetData($tStruct, 4) ; Row 0 in ListView is row 2 in the array MsgBox($MB_SYSTEMMODAL, "Row Data", $aLines[$iRow + 2]) EndSwitch EndFunc M23 Edit; I amended the file slightly to add some "err-disabled" lines: Edited September 27, 2017 by Melba23 31290 and Skysnake 2 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
31290 Posted January 12, 2016 Author Posted January 12, 2016 M23!That's exactly this kind I'd like!!! So much thanks!!! Now I can try to understand how things work and for sure, my knowledge will grow. Is it possible to color vlans according to their numbers stored in a txt file? For example, if Vlan 13 or Vlan 31 is in a txt file, then color it in bleu. In fact, I'd like to be able to color items in a row depending on their value... Not sure this is well expressed :/Therefore, and as you can see, if I sort the list by the ports twice, I got this:Any ideas? Many thanks again! ~~~ Doom Shall Never Die, Only The Players ~~~
Moderators Melba23 Posted January 12, 2016 Moderators Posted January 12, 2016 31290,Colouring individual sub-items on a line is much more complicated - LarsJ shows how you can do it here.Sorting is done alphabetically - so there is no simple way to avoid that return listing. The alternative would be to extract the data into an array, split the alpha and numeric sections, sort the latter numerically, recombine and then reload the ListView - certainly doable, but a bit of a faff.M23 31290 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
31290 Posted January 12, 2016 Author Posted January 12, 2016 M23, Yeah, that seems to be a hard job. So in this case, do you think locking up sorting in column only is possible?One last question for you and I won't disturb you anymore How can I isolate every items? I tried to play with DllStructGetData but it seems that this is not working. I'd like to get the portnumber (item one), the description (item 2), the state (item 3) and the Vlan (item 4)By the way, huge thanks to you for the help you provided to me! ~~~ Doom Shall Never Die, Only The Players ~~~
Moderators Melba23 Posted January 12, 2016 Moderators Posted January 12, 2016 31290,locking up sorting in column only is possibleDo you mean that you want to prevent sorting in certain columns?To get the separate items from the data, use StringSplit to get the different elements into an array and then select the ones you want:Case $NM_DBLCLK $iRow = DllStructGetData($tStruct, 4) ; Row 0 in ListView is row 2 in the array $sData = $aLines[$iRow + 2] ; Split $aData = StringSplit($sData, "|") MsgBox($MB_SYSTEMMODAL, "Row Data", $aData[1] & @CRLF & $aData[2] & @CRLF & $aData[3] & @CRLF & $aData[4])By the way, do not use a MsgBox inside the handler in your final script - I only did so here for a quick demonstration. I suggest you set a flag or action a dummy control so that you do not block the handler's return.M23 31290 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
31290 Posted January 12, 2016 Author Posted January 12, 2016 Thanks M23 that's very very kind of you. 31290,Do you mean that you want to prevent sorting in certain columns? Yes, I did a typo here People will need to sort columns but if not possible, I'll add a label warning them. But thinking about it, I think this won't be possible... But you never know.By the way, do not use a MsgBox inside the handler in your final script - I only did so here for a quick demonstration. I suggest you set a flag or action a dummy control so that you do not block the handler's return.M23Yes, some items will be set to a global variable for future treatment, set in a txt file and sent to the switch for configuring a port according to our needs Thanks. ~~~ Doom Shall Never Die, Only The Players ~~~
Moderators Melba23 Posted January 12, 2016 Moderators Posted January 12, 2016 31290,If you want to prevent sorting certain columns, then just check which column was clicked inside the handler - this prevents the first column being sorted:Case $LVN_COLUMNCLICK ; Get column index Local $iCol = DllStructGetData($tStruct, 5) If $iCol <> 0 Then ; Sort column _GUICtrlListView_SimpleSort($cLV, $aSortSense, $iCol) EndIfM23: 31290 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
31290 Posted January 12, 2016 Author Posted January 12, 2016 So Cool M23! You rock, as usual!Many many thanks again for your precious help! Keep going Bye Bye ~~~ Doom Shall Never Die, Only The Players ~~~
Moderators Melba23 Posted January 12, 2016 Moderators Posted January 12, 2016 (edited) 31290,Here is LarsJ's code integrated into mine - I enjoyed doing that:expandcollapse popup#include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <StringConstants.au3> #include <Array.au3> #include <GuiListView.au3> ; Read file and replace tabs $sContent = StringReplace(FileRead("EPES18.txt"), @TAB, " ") ; Replace orphaned dashes $sNoDashes = StringReplace($sContent, " - ", " ") ; Expand possible single space before connection status $sExpanded = StringRegExpReplace($sNoDashes, "(\x20(connected|notconnect|err-disabled))", " $1") ; Replace multiple spaces with | delimiter - max 19 to allow for empty fields $sDelimed = StringRegExpReplace($sExpanded, "(\x20{2,19})", "|") ; Split on @CRLF $aLines = StringSplit($sDelimed, @CRLF, $STR_ENTIRESPLIT) ;_ArrayDisplay($aLines, "", Default, 8) $hGUI = GUICreate("Test", 500, 500) ; Create ListView with first 4 headers $cLV = GUICtrlCreateListView(StringRegExpReplace($aLines[1], "(?U)^(.*\|.*\|.*\|.*)\|.*$", "$1"), 10, 10, 480, 380) ; Set column widths For $i = 0 To 3 _GUICtrlListView_SetColumnWidth($cLV, $i, 110) Next ; Add content of first 4 fields in each line For $i = 2 To $aLines[0] $cLVItem = GUICtrlCreateListViewItem(StringRegExpReplace($aLines[$i], "(?U)^(.*\|.*\|.*\|.*)\|.*$", "$1"), $cLV) Next GUIRegisterMsg($WM_NOTIFY, "_WM_NOTIFY") GUISetState() ; Set sort state Local $aSortSense[_GUICtrlListView_GetColumnCount($cLV)] While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit EndSwitch WEnd Func _WM_NOTIFY($hWnd, $imsg, $wParam, $lParam) ; Struct = $tagNMHDR and "int Item;int SubItem" from $tagNMLISTVIEW Local $tStruct = DllStructCreate("hwnd;uint_ptr;int_ptr;int;int", $lParam) If @error Then Return Local $iCode = BitAND(DllStructGetData($tStruct, 3), 0xFFFFFFFF) Switch $iCode Case $LVN_COLUMNCLICK ; Get column index Local $iCol = DllStructGetData($tStruct, 5) If $iCol <> 0 Then ; Sort column _GUICtrlListView_SimpleSort($cLV, $aSortSense, $iCol) EndIf Case $NM_DBLCLK $iRow = DllStructGetData($tStruct, 4) ; Row 0 in ListView is row 2 in the array $sData = $aLines[$iRow + 2] ; Split $aData = StringSplit($sData, "|") ConsoleWrite("Row Data: " & $aData[1] & " - " & $aData[2] & " - " & $aData[3] & " - " & $aData[4] & @CRLF) Case $NM_CUSTOMDRAW Local $tNMLVCUSTOMDRAW = DllStructCreate($tagNMLVCUSTOMDRAW, $lParam) Local $dwDrawStage = DllStructGetData($tNMLVCUSTOMDRAW, "dwDrawStage") Switch $dwDrawStage ; Holds a value that specifies the drawing stage Case $CDDS_PREPAINT ; Before the paint cycle begins Return $CDRF_NOTIFYITEMDRAW ; Notify the parent window of any item-related drawing operations Case $CDDS_ITEMPREPAINT ; Before painting an item Return $CDRF_NOTIFYSUBITEMDRAW ; Notify the parent window of any subitem-related drawing operations Case BitOR($CDDS_ITEMPREPAINT, $CDDS_SUBITEM) ; Before painting a subitem Local $iItem = DllStructGetData($tNMLVCUSTOMDRAW, "dwItemSpec") ; Item index Local $iSubItem = DllStructGetData($tNMLVCUSTOMDRAW, "iSubItem") ; Subitem index ; Gte text of item $sText = _GUICtrlListView_GetItemText($cLV, $iItem, $iSubItem) ; Set default back colour $iBkColour = 0xC0B0B0 ; Now check for our spoecific items Switch $iSubItem Case 2 ; connection Switch $sText Case "connected" $iBkColour = 0x00FF00 Case "notconnect" $iBkColour = 0x0000FF Case "err-disabled" $iBkColour = 0xC4C4C4 EndSwitch Case 3 ; vlan Switch $sText Case "trunk" $iBkColour = 0x00FFFF Case "1" $iBkColour = 0xFFFF00 Case "10" $iBkColour = 0xC4FFC4 Case "13" $iBkColour = 0xFF00FF EndSwitch EndSwitch ; Set required back colour DllStructSetData($tNMLVCUSTOMDRAW, "ClrTextBk", $iBkColour) Return $CDRF_NEWFONT ; $CDRF_NEWFONT must be returned after changing font or colors EndSwitch EndSwitch EndFunc ;==>_WM_NOTIFYIt looks as if the file parsing could do with a bit more work - there are a couple of lines where the delimiters are not correct. It does not help that the file uses a mixture of spaces and tabs to separate the items on each line - and on some lines there are items missing. Can you get the file in a more reasonable CSV format or are you stuck with what you have posted?M23Edit: Recoded the file parsing - it now works for the test file, but I would still recommend trying to get a better delimited file initially as the parsing requirements are a bit arbitrary at the moment. Edited January 13, 2016 by Melba23 31290 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
31290 Posted January 14, 2016 Author Posted January 14, 2016 M23, I have no words for that! Really! That's totally awesome Thanks!To give you the answer, I cannot output to any other file extension because of putty (and more especially plink). If you want, here the code I use to gather a switch information:Run(@ComSpec & ' /c '&$testvariable&'PLINK.EXE '&$currentSwitch&' -l '&$username&' -pw '&$ClearPwd&' sh ver > '&$testvariable&'info'&$currentSwitch&'.txt', @SystemDir, @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD)For sure, a tab delimited file would be easier to deal with. In that case, isn't that possible to transform the txt file in a tab delimited csv one?Because on some lines, I have this:The port state is in the Vlan column :/Thanks ~~~ Doom Shall Never Die, Only The Players ~~~
Moderators Melba23 Posted January 14, 2016 Moderators Posted January 14, 2016 31290,As I mentioned above, the file contains both spaces and tabs as well as many missing "Name" fields - all this makes the converting of the file to a suitably delimited form quite tricky. I will look again at how it might be done, but no promises.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
Moderators Melba23 Posted January 14, 2016 Moderators Posted January 14, 2016 31290,I have completely recoded the delimiter parsing section to deal with the annoying "Name" section - please test this and see if it works for you:expandcollapse popup#include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <StringConstants.au3> #include <Array.au3> #include <GuiListView.au3> ; Read file into array $aLines = FileReadToArray("EPES18.txt") ; Deal with title line $aLines[0] = StringRegExpReplace($aLines[0], "(\x20+)", "|") ; Now the other lines For $i = 1 To UBound($aLines) - 1 ; Extract line $sLine = $aLines[$i] ; Replace tabs with spaces $sLine = StringReplace($sLine, @TAB, " ") ; Extract possible name field $sName = StringRegExpReplace($sLine, "(?U)^.*(\x20.*\x20)(connected|notconnect|err-disabled).*$", "$1") ; Convert multiple spaces to singles $sStrippedName = StringRegExpReplace($sName, "\x20+", " ") ; Set placeholder if no name field If $sStrippedName = " " Then $sStrippedName = " ~ " ; Replace original name string in line with stripped version - add spaces to ensure multiple spaces before and after $sLine = StringReplace($sLine, $sName, " " & $sStrippedName & " ") ; Set delimiters by replacing multiple spaces $sLine = StringRegExpReplace($sLine, "(\x20{2,19})", "|") ; Remove placeholders $sLine = StringReplace($sLine, "~", "") ; Replace existing line with delimited line $aLines[$i] = $sLine Next $hGUI = GUICreate("Test", 500, 500) ; Create ListView with first 4 headers $cLV = GUICtrlCreateListView(StringRegExpReplace($aLines[0], "(?U)^(.*\|.*\|.*\|.*)\|.*$", "$1"), 10, 10, 480, 380) ; Set column widths For $i = 0 To 3 _GUICtrlListView_SetColumnWidth($cLV, $i, 110) Next ; Add content of first 4 fields in each line For $i = 1 To UBound($aLines) - 1 $cLVItem = GUICtrlCreateListViewItem(StringRegExpReplace($aLines[$i], "(?U)^(.*\|.*\|.*\|.*)\|.*$", "$1"), $cLV) Next GUIRegisterMsg($WM_NOTIFY, "_WM_NOTIFY") GUISetState() ; Set sort state Local $aSortSense[_GUICtrlListView_GetColumnCount($cLV)] While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit EndSwitch WEnd Func _WM_NOTIFY($hWnd, $imsg, $wParam, $lParam) ; Struct = $tagNMHDR and "int Item;int SubItem" from $tagNMLISTVIEW Local $tStruct = DllStructCreate("hwnd;uint_ptr;int_ptr;int;int", $lParam) If @error Then Return Local $iCode = BitAND(DllStructGetData($tStruct, 3), 0xFFFFFFFF) Switch $iCode Case $LVN_COLUMNCLICK ; Get column index Local $iCol = DllStructGetData($tStruct, 5) If $iCol <> 0 Then ; Sort column _GUICtrlListView_SimpleSort($cLV, $aSortSense, $iCol) EndIf Case $NM_DBLCLK $iRow = DllStructGetData($tStruct, 4) ; Row 0 in ListView is row 2 in the array $sData = $aLines[$iRow + 2] ; Split $aData = StringSplit($sData, "|") ConsoleWrite("Row Data: " & $aData[1] & " - " & $aData[2] & " - " & $aData[3] & " - " & $aData[4] & @CRLF) Case $NM_CUSTOMDRAW Local $tNMLVCUSTOMDRAW = DllStructCreate($tagNMLVCUSTOMDRAW, $lParam) Local $dwDrawStage = DllStructGetData($tNMLVCUSTOMDRAW, "dwDrawStage") Switch $dwDrawStage ; Holds a value that specifies the drawing stage Case $CDDS_PREPAINT ; Before the paint cycle begins Return $CDRF_NOTIFYITEMDRAW ; Notify the parent window of any item-related drawing operations Case $CDDS_ITEMPREPAINT ; Before painting an item Return $CDRF_NOTIFYSUBITEMDRAW ; Notify the parent window of any subitem-related drawing operations Case BitOR($CDDS_ITEMPREPAINT, $CDDS_SUBITEM) ; Before painting a subitem Local $iItem = DllStructGetData($tNMLVCUSTOMDRAW, "dwItemSpec") ; Item index Local $iSubItem = DllStructGetData($tNMLVCUSTOMDRAW, "iSubItem") ; Subitem index ; Gte text of item $sText = _GUICtrlListView_GetItemText($cLV, $iItem, $iSubItem) ; Set default back colour $iBkColour = 0xC4C4C4 ; Now check for our spoecific items Switch $iSubItem Case 2 ; connection Switch $sText Case "connected" $iBkColour = 0x00FF00 Case "notconnect" $iBkColour = 0x0000FF Case "err-disabled" $iBkColour = 0xC4C4C4 EndSwitch Case 3 ; vlan Switch $sText Case "trunk" $iBkColour = 0x00FFFF Case "1" $iBkColour = 0xFFFF00 Case "10" $iBkColour = 0xC4FFC4 Case "13" $iBkColour = 0xFF00FF EndSwitch EndSwitch ; Set required back colour DllStructSetData($tNMLVCUSTOMDRAW, "ClrTextBk", $iBkColour) Return $CDRF_NEWFONT ; $CDRF_NEWFONT must be returned after changing font or colors EndSwitch EndSwitch EndFunc ;==>_WM_NOTIFYIf you still have problems, then please let me see the file containing the lines causing difficulty so I can refine the process further.M23 31290 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
31290 Posted January 15, 2016 Author Posted January 15, 2016 M23, This is perfectly working now, no more bad formatting.I'd like to thank you again for all you did for me, have a great weekend (if any ^^). I'll buy you a beer sometimes!Au revoir et merci encore! (Yeah, I'm French ^^) ~~~ Doom Shall Never Die, Only The Players ~~~
Moderators Melba23 Posted January 15, 2016 Moderators Posted January 15, 2016 31290,Il n'y a pas de quoi.M23 31290 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
31290 Posted January 15, 2016 Author Posted January 15, 2016 M23, I Need one more little hand, I promise, I stop after that I realized that I was able to gather one last very essential value to the list view, but that one is coming from an other txt file (still no csv).What I'd like to do, is to integrate a fifth column, named "IP Phone" (or something else I don't care for now) with "Yes" or "No" depending if the corresponding port is listed in the output text file. I've attached 2 of them so you can see the structure of them (the idmul.txt that all the ports are configured to support ip phone, VLAN 100 for us)I hope my explanations are clear enough for you So much thanks idmul.txt id.txt idmul.txt ~~~ Doom Shall Never Die, Only The Players ~~~
Moderators Melba23 Posted January 15, 2016 Moderators Posted January 15, 2016 (edited) 31290,Easy! Just replace the existing GUI and ListView creation lines in the earlier script with these:; This is where we parse the main file ; Read IP Phone ID file $sID = Fileread("id.txt") $hGUI = GUICreate("Test", 500, 500) ; Create ListView with first 4 headers plus "IP Phone" $cLV = GUICtrlCreateListView(StringRegExpReplace($aLines[0], "(?U)^(.*\|.*\|.*\|.*)\|.*$", "$1") & "|IP Phone", 10, 10, 480, 380) ; Set column widths For $i = 0 To 4 _GUICtrlListView_SetColumnWidth($cLV, $i, 90) Next ; Add content of first 4 fields in each line plus the IP Phone result For $i = 1 To UBound($aLines) - 1 ; Assume not IP Phone $sIPPhone = "|N" ; Look for the port ID in the file - it will be preceded by a space and followed by either a comma or an EOL If StringRegExp($sID, " " & StringRegExpReplace($aLines[$i], "(?U)^(.*)\|.*$", "$1") & "[,\x0D]") Then ; If found change the set value $sIPPhone = "|Y" EndIf ; Add fields and IP Phone to the ListView $cLVItem = GUICtrlCreateListViewItem(StringRegExpReplace($aLines[$i], "(?U)^(.*\|.*\|.*\|.*)\|.*$", "$1") & $sIPPhone, $cLV) Next GUIRegisterMsg($WM_NOTIFY, "_WM_NOTIFY") GUISetState()That works fine for me with your test files - does it work for you too?And never be afraid to ask - I come here to help and to keep my "little grey cells" in good condition!M23 Edited January 16, 2016 by Melba23 Additional comments 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
31290 Posted January 18, 2016 Author Posted January 18, 2016 M23, On 1/15/2016 at 5:50 PM, Melba23 said: And never be afraid to ask - I come here to help and to keep my "little grey cells" in good condition! That's very kind of you because with your help, I can learn more about things I don't handle. Yes, it is working fine with my files, just a few ajustments to fill my needs bu this is perfect. One question though : I'm trying to get the value of the IPPhone variable defined by this: Global $sIPPhone = "|Not Set" ; Look for the port ID in the file - it will be preceded by a space and followed by either a comma or an EOL If StringRegExp($sID, " " & StringRegExpReplace($aLines[$i], "(?U)^(.*)\|.*$", "$1") & "[,\x0D]") Then ; If found change the set value Global $sIPPhone = "|Set" EndIf and doing this: Global $aIPPhone = StringTrimLeft($sIPPhone,1) ; Global $aIPPhone = _GUICtrlListView_GetItemTextArray ( $cLV , 5) MsgBox($MB_SYSTEMMODAL, "Row Data", $aData[1] & @CRLF & $aData[2] & @CRLF & $aData[3] & @CRLF & $aData[4] & @CRLF & $aIPPhone ) All I get is the "Not Set" value when double clicking on the line were it is "Set": I also tried to get the value with the "_GUICtrlListView_GetItemTextArray" function and by creating an other array but nothing seems to work here :/ Can you please help on this? Oh and I just saw something: When I move the msgbox into the listview, every thing goes white Is it something expected? That was just a remark as when a technician will double click on a port, the listview GUI will be disabled and enabled when operation on said port will be acknowleded. Thanks ~~~ Doom Shall Never Die, Only The Players ~~~
Moderators Melba23 Posted January 18, 2016 Moderators Posted January 18, 2016 31290, This works fine for me: Case $NM_DBLCLK $iRow = DllStructGetData($tStruct, 4) ConsoleWrite("Row Data: " & _GUICtrlListView_GetItemTextString($cLV, $iRow) & @CRLF) As I mentioned above, you should not be using a MsgBox (or any other blocking function) inside a Windows message handler - when the Help file says you should return from the handler ASAP it means it! By blocking the handler you are blocking the flow of Windows messages inside the app and risking a serious crash. In this case, you are blocking the WM_NOTIFY messages which we use to colour the ListView when repainting - hence you get no repaint. If you want to test, use a ConsoleWrite as I did above, or a flag in the idle loop (let me know if you want to see how that can be done). 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
31290 Posted January 18, 2016 Author Posted January 18, 2016 M23, I understood what you said about not using a MsgBox, but I wanted to be sure that all values (port name, description, vlan and IPPhone) were get because I have to display them separately in a new GUI when double clicking on a port. After that, I have operations to perform on said values (change Vlan, change description, etc...) That's why: MsgBox($MB_SYSTEMMODAL, "Row Data", $aData[1] & @CRLF & $aData[2] & @CRLF & $aData[3] & @CRLF & $aData[4] & @CRLF & $aIPPhone ) Is a way for me to be sure of that. To avoid the loss of painting, I can minimize the GUI while the Ports Operations GUI is opened and in anycases, I have to reload almost everything to display updates (generate all the files, etc... But I've already done that) 28 minutes ago, Melba23 said: If you want to test, use a ConsoleWrite as I did above, or a flag in the idle loop (let me know if you want to see how that can be done). If you have time, yes of course, all is good to take Thanks ~~~ Doom Shall Never Die, Only The Players ~~~
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