Jump to content

File into list view and other


31290
 Share

Recommended Posts

Hi Everyone, Happy New Year :sorcerer:

Well, I have a script that gather information about a given switch here at work that output data in a txt file:

txt.thumb.png.f40d19f18ad3e27fa32e256139

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 by 31290

~~~ Doom Shall Never Die, Only The Players ~~~

Link to comment
Share on other sites

  • Moderators

31290,

This should get you started:

#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 by Melba23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

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:

ports.thumb.png.b39dd05ab6df36508c85a76e

Any ideas?

 

Many thanks again!

~~~ Doom Shall Never Die, Only The Players ~~~

Link to comment
Share on other sites

  • Moderators

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

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

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)

data.thumb.png.f875e79f8b8165e60aa89fc8b

By the way, huge thanks to you for the help you provided to me! :drinks:

~~~ Doom Shall Never Die, Only The Players ~~~

Link to comment
Share on other sites

  • Moderators

31290,

locking up sorting in column only is possible

Do 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

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

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.

M23

Yes, 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 ~~~

Link to comment
Share on other sites

  • Moderators

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)
    EndIf

M23:

 

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

  • Moderators

31290,

Here is LarsJ's code integrated into mine - I enjoyed doing that:

#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_NOTIFY

It 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?

M23

Edit: 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 by Melba23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

M23, 

I have no words for that! Really! That's totally awesome :D 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:

2016-01-14_14-31-06.thumb.png.01974bbeeb

The port state is in the Vlan column :/

Thanks :)

~~~ Doom Shall Never Die, Only The Players ~~~

Link to comment
Share on other sites

  • Moderators

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

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

  • Moderators

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:

#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_NOTIFY

If you still have problems, then please let me see the file containing the lines causing difficulty so I can refine the process further.

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

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 ~~~

Link to comment
Share on other sites

  • Moderators

31290,

Il n'y a pas de quoi.

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

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)

ipphone.thumb.png.6f2183384b8a6b45cf0f44
I hope my explanations are clear enough for you ;) So much thanks :D 

idmul.txt

id.txt

idmul.txt

~~~ Doom Shall Never Die, Only The Players ~~~

Link to comment
Share on other sites

  • Moderators

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 by Melba23
Additional comments

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

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 :D :

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":

2016-01-18_09-38-15.png.f8c25723a80d528b
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 ~~~

Link to comment
Share on other sites

  • Moderators

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

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

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 ~~~

Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...