Jump to content

File into list view and other


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 post
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 post
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 post
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 post
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 post
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 post
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 post
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 post
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 post
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 post
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 post
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 post
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 post
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 post
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 post
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 post
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 post
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 post
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 post
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
  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By lIlIIlIllIIIIlI
      $input = $CmdLine[1] $bytes = 1000000 ; 1000000 for 1 MB, 1000 for 1 KB $size = FileGetSize($input) $file = fileopen($input, 16) $max = ceiling($size / $bytes) for $i = 1 to $max $data = fileread($file, $bytes) $output = $input & '_' & $i & 'of' & $max filewrite($output, $data) next ^file split
      file path for a 20MB "video.mp4" is input, it will be output as "video.mp4_1of20", "video.mp4_2of20", etc. change $bytes to affect the split files size, this example made them 1MB (10^6 bytes)
       
      $input = $CmdLine[1] $name = stringtrimright($input, 1 + stringlen($input) - stringinstr($input, '_', 0, -1)) $split = stringsplit($input, 'of', 3) $max = $split[ubound($split) - 1] for $i = 1 to $max $in = $name & '_' & $i & 'of' & $max $file = fileopen($in, 16) $data = fileread($file) fileclose($file) filedelete($in) filewrite($name, $data) next ^ file join
      file path for any of the "video.mp4_Xof20" segments is input. the "video.mp4_Xof20" segments are read and written to "video.mp4" and then deleted, leaving the newly joined "video.mp4" in the end
       
      i made this today because i had a big file that i couldn't really open. i split it into 1000 chunks to make processing and stuff easier. i've also used it to split files to just under 25MB segments so i can attach and mail big files over gmail which is silly but it worked
    • By TheSaint
      I like and have been using TeraCopy, a third party program, for many years. Mostly it is a great program, but it does have some issues. On Windows XP for instance, Thumbs.db files could often hold up a copy or move process until the user manually responded to the error prompt. Some other issues I discuss below.
      PLEASE NOTE - I am not related to or affiliated in any way with the 3rd party TeraCopy program developers.
      ALSO NOTE - I myself have only tested TeraCopy Cure at this point, on Windows 7 (32 bit), and only with the free version of TeraCopy 2.27.
      This program, TeraCopy Cure, is related to another one of my TeraCopy assistant programs, TeraCopy Timer, but aims at being simpler and quicker to use ... if lacking its more advanced features.
      TeraCopy Cure is a frontend for TeraCopy and sets out to make up for its flaws and limitations.
      One of those flaws is queuing order, and the limitation relates to a same destination issue.
      You would think that queue order would be the same as add order, but that is not the case, and if you are doing a mix of COPY and MOVE then the COPY process could easily fail. It could fail with some source items, even if the  COPY process has already started before the same source MOVE process begins ... especially if the destination folder is on the source drive ... only the currently copying file is locked to that process.
      If you drag and drop another source for a same destination as an existing or impending COPY or MOVE process, then usually TeraCopy nicely adds it for you to that existing job. However, you might wish to avoid that, or it might occur during the testing phase of that active process, and then not be properly processed etc. But you are not given a choice and it just gets added.
       
           
      HOW TO USE
      See the right-click menu of the 'Batch List' (lowest field) and the right-click menu of the Tree field, for some useful options.
      (1) If desired, enable 'Auto Start'. NOTE - Even if enabled, this can be bypassed.
      (2) Set the destination folder, either by browsing on the tree or by dragging a folder to the Destination input field or label. Right-clicking on a folder in Explorer will also work, if enabled. The destination folder path will also show in the Tree if that right-click option is enabled.
      (3) Then drag & drop source file or folder onto one of three five areas - Folder (Drive) Tree field, or COPY or MOVE buttons ... this now also includes the source input and label.
      NOTE - If the Folder (Drive) Tree field is used, then you will additionally need to click either the COPY or MOVE button, to have that job added to the Batch List ... but this avoids 'Auto Start' if it is enabled. Drag & dropping to the buttons instead, saves on clicking, but starts the first job etc immediately if 'Auto Start' is enabled.
      (4) If needed and ready, click the START button to run the first job and those that follow.
      More information is included in program and in the NOTES etc sections below.
         
      WARNING - Depending on the amount of content on your destination drive, and folder level depth, and the speed of your PC, display of the full path in the Folder (Drive) Tree can take a while to show ... if you have that (right-click) option enabled ... it isn't by default. I found this feature quite tricky to get right, and I'm still not 100% sure it is now full-proof.
      TeraCopy Cure v1.5.zip  (source is included)
      TeraCopy Cure v1.6.zip  (source is included)
      NOTES
      UPDATES INFORMATION
      OLDER DOWNLOADS
       
    • By Zedna
      #include <WinAPI.au3> $text = FileReadLastChars("C:\Program Files\AutoIt3\Include\Array.au3", 1024) MsgBox(0, 'FileReadLastChars', $text) Func FileReadLastChars($sFile, $nChars)     Local $nBytes     $tBuffer = DLLStructCreate("char["&$nChars&"]")     $hFile = _WinAPI_CreateFile($sFile, 2, 2) ; open for read     _WinAPI_SetFilePointer($hFile, -1 * $nChars, 2) ; from end     _WinAPI_ReadFile($hFile, DLLStructGetPtr($tBuffer), $nChars, $nBytes)     _WinAPI_CloseHandle($hFile)     Return DLLStructGetData($tBuffer, 1) EndFunc ; included as standard UDF since AutoIt 3.2.13.6 version Func _WinAPI_SetFilePointer($hFile, $iPos, $iMethod = 0)     $aResult = DllCall( "kernel32.dll", "long", "SetFilePointer", "hwnd", $hFile, "long", $iPos, "long_ptr", 0, "long", $iMethod)     If @error Then Return SetError(1, 0, -1)     If $aResult[0] = -1 Then Return SetError(2, 0, -1) ; $INVALID_SET_FILE_POINTER = -1     Return $aResult[0] EndFunc ;==>_WinAPI_SetFilePointer Here is my topic about _WinAPI_SetFilePointer()
       
      EDIT: simpler version compatible with latest AutoIt
      $text = FileReadLastChars("C:\Program Files\AutoIt3\Include\Array.au3", 1024) MsgBox(0, 'FileReadLastChars', $text) Func FileReadLastChars($sFile , $nChars) $hFile = FileOpen($sFile, 0) ; open for read FileSetPos($hFile, -1 * $nChars, 2) ; from end $sRet = FileRead($hFile) FileClose($hFile) Return $sRet EndFunc  
    • By Colduction
      Hi dear friends!, i'm sorry for creating a new thread (a new problem), i have over than 9 lists that i want to combine them to be this (in this example, there are 3 test files):


      I've written a little code for splitting main information, but i really confused how to make results as "Output.txt", here is that code:
       
      $sRegex_1 = StringRegExp(FileRead("1.txt"), '(?s:(?<=\=\=\r\n)(.*?)(?=\r\n\=\=))', 3) $sRegex_2 = StringRegExp(FileRead("2.txt"), '(?s:(?<=\=\=\r\n)(.*?)(?=\r\n\=\=))', 3) $sRegex_3 = StringRegExp(FileRead("3.txt"), '(?s:(?<=\=\=\r\n)(.*?)(?=\r\n\=\=))', 3) For $i = 0 To UBound($sRegex_1) - 1 ConsoleWrite($sRegex_1[$i] & @CRLF) For $j = 0 To UBound($sRegex_2) - 1 ConsoleWrite($sRegex_2[$j] & @CRLF) For $k = 0 To UBound($sRegex_3) - 1 ConsoleWrite($sRegex_3[$k] & @CRLF) Next Next Next  
    • By Colduction
      Hi guys!, i have a problem to convert Python code to AutoIt code, in fact i had not coded with Python yet!, this code is about permutation a string's case, i will be happy with your comments :)❤;

      Python code:
       
      # Python code to print all permutations # with respect to cases # Function to generate permutations def permute(inp): n = len(inp) # Number of permutations is 2^n mx = 1 << n # Converting string to lower case inp = inp.lower() # Using all subsequences and permuting them for i in range(mx): # If j-th bit is set, we convert it to upper case combination = [k for k in inp] for j in range(n): if (((i >> j) & 1) == 1): combination[j] = inp[j].upper() temp = "" # Printing current combination for i in combination: temp += i print(temp), # Driver code permute("Hello") # This code is contributed by Sachin Bisht
      My code in AutoIt:
      ; https://www.geeksforgeeks.org/permute-string-changing-case/ _PermuteCase("ABC") Func _PermuteCase($sText) If StringRegExp($sText, "^[A-Za-z]{1,}$") Then Local $iLength = StringLen($sText) ; Get length of the text. Local $iMaxPerm = 2 ^ $iLength ; Number of permutations is 2^n Local $sLow_Text = StringLower($sText) ; Converting string to lower case Local $asChrs = StringToASCIIArray($sLow_Text) ; Split the text into array of chars. For $i = 1 To $iMaxPerm Step 1 For $j = 0 To $asChrs[0] ;................................................... Next Next Else Return SetError(-1, 0, "Error: Input is incorrect!") EndIf EndFunc ;==>_PermuteCase  
       
       
       
       
       
      ====================== SOLUTION by @TheXman ======================
       
×
×
  • Create New...