Sign in to follow this  
Followers 0
Merchants

need a text filter

10 posts in this topic

i got a text file: test1.txt in this file are some text:

File04
file-23

Key2

test-5

test6
 

this wil come in the gui list below

guilist.png

what i want to do:
when i enter in the filter inputbox Ex: test

now i want to update this gui list! that only shows everything with the text: test
so output: test-5 and test6 in this case
 

#include <WindowsConstants.au3>
#include <GUIConstantsEx.au3>
#Include <File.au3>
#NoTrayIcon

Opt("GUICoordMode", 1)

Global $GUI[20], $D2Win

$GUI[0] = GUICreate("test windows", 175, 415)
GUICtrlCreateLabel("Filter", 7, 5)
$GUI[2] = GUICtrlCreateInput("", 5, 20, 165, 25)
$GUI[4] = GuiCtrlCreateList("", 5, 50, 165, 330)
$GUI[3] = GUICtrlCreateButton("Exit", 5, 385, 165, 25)

GUICtrlSetFont($GUI[4], 11, 600, "", "Tahoma")
GUICtrlSetBkColor($GUI[4], 0x000000)
GUICtrlSetColor($GUI[4], 0x948064)
GUICtrlSetFont($GUI[2], 11, 600, "", "Tahoma")
GUICtrlSetBkColor($GUI[2], 0x000000)
GUICtrlSetColor($GUI[2], 0x948064)
WinMove($GUI[0], "", 200, 200, Default, Default)

$Number = 0
$file = FileOpen(@ScriptDir & "\test1.txt", 0)
If $file > -1 Then
    While 1
        $line = FileReadLine($file)
        If @error = -1 Then ExitLoop
        If $Number > 0 Then
            If $Number = _FileCountLines(@ScriptDir & "\test1.txt") Then
                $Text &= $line
            Else
                $Text &= $line & "|"
            EndIf
        Else
            $Text = $line & "|"
        EndIf
        $Number = $Number +1
    WEnd
Else
    $Text = "Error on open file"
EndIf
FileClose($file)

GuiCtrlSetData($GUI[4], $Text)
GUISetStyle($WS_CAPTION, $WS_BORDER)
GUISetState()

While 1
    $GUI[1] = GUIGetMsg($GUI[0])
    Select
        Case $GUI[1] = $GUI_EVENT_CLOSE
            Exit
        Case $GUI[1] = $GUI[3]
            Exit
        Case $GUI[1] = $GUI[2]
            code here
    EndSelect
WEnd

Share this post


Link to post
Share on other sites



Merchants,

I think you will find the code in >this post very useful. :)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

 

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

not bad

still does not work as i want

when i enter a word in the filter that works but when i clear it the hole list is gone or does not dispay all of the items

+ i wana do a func when i dubble click on one of the list items

#include <WindowsConstants.au3>
#include <GUIConstantsEx.au3>
#Include <File.au3>
#include <Array.au3>
#Include <GuiListBox.au3>
#NoTrayIcon

Opt("GUICoordMode", 1)

Global $GUI[20], $D2Win, $hInput, $hList, $sPartialData, $asKeyWords[301], $Number

$GUI[0] = GUICreate("test windows", 175, 415)
GUICtrlCreateLabel("Filter", 7, 5)
$hInput = GUICtrlCreateInput("", 5, 20, 165, 25)
$hList = GuiCtrlCreateList("", 5, 50, 165, 330, BitOR(0x00100000, 0x00200000))
$hButton = GUICtrlCreateButton("Exit", 5, 385, 165, 25)

GUICtrlSetFont($GUI[4], 11, 600, "", "Tahoma")
;GUICtrlSetBkColor($GUI[4], 0x000000)
GUICtrlSetColor($GUI[4], 0x948064)
GUICtrlSetFont($GUI[2], 11, 600, "", "Tahoma")
GUICtrlSetBkColor($GUI[2], 0x000000)
GUICtrlSetColor($GUI[2], 0x948064)
WinMove($GUI[0], "", 200, 200, Default, Default)
Keywords()

GUISetStyle($WS_CAPTION, $WS_BORDER)
$hUP = GUICtrlCreateDummy()
$hDOWN = GUICtrlCreateDummy()
$hENTER = GUICtrlCreateDummy()
GUISetState(@SW_SHOW, $GUI[0])

$sCurr_Input = ""
$iCurrIndex = -1
Dim $AccelKeys[3][2]=[["{UP}", $hUP], ["{DOWN}", $hDOWN], ["{ENTER}", $hENTER]]
GUISetAccelerators($AccelKeys)

While 1

    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $hList
            $sChosen = GUICtrlRead($hList)
            If $sChosen <> "" Then GUICtrlSetData($hInput, $sChosen)
        Case $hButton
            Exit
        Case $hUP
            If $sPartialData <> "" Then
                $iCurrIndex -= 1
                If $iCurrIndex < 0 Then $iCurrIndex = 0
                _GUICtrlListBox_SetCurSel($hList, $iCurrIndex)
            EndIf
        Case $hDOWN
            If $sPartialData <> "" Then
                $iTotal = _GUICtrlListBox_GetCount($hList)
                $iCurrIndex += 1
                If $iCurrIndex > $iTotal - 1 Then $iCurrIndex = $iTotal - 1
                _GUICtrlListBox_SetCurSel($hList, $iCurrIndex)
            EndIf
        Case $hENTER
            If $iCurrIndex <> -1 Then
                $sText = _GUICtrlListBox_GetText($hList, $iCurrIndex)
                GUICtrlSetData($hInput, $sText)
                $iCurrIndex = -1
                _GUICtrlListBox_SetCurSel($hList, $iCurrIndex)
            EndIf
    EndSwitch

        CheckInputText()
    ; If input has changed, refill list with matching items
    If GUICtrlRead($hInput) <> $sCurr_Input Then
        CheckInputText()
        $sCurr_Input = GUICtrlRead($hInput)
    EndIf

WEnd

Func CheckInputText()

    $sPartialData = "|" ; Start with delimiter so new data always replaces old
    Local $sInput = GUICtrlRead($hInput)
    If $sInput <> "" Then
        For $i = 0 To $Number
            If StringInStr($asKeyWords[$i], $sInput) <> 0 Then $sPartialData &= $asKeyWords[$i] & "|"
        Next
        GUICtrlSetData($hList, $sPartialData)
    EndIf
EndFunc   ;==>CheckInputText

Func Keywords()

    Local $sData
    $Number = 0
    $file = FileOpen(@ScriptDir & "\test1.txt", 0)
    If $file > -1 Then
        While 1
            $line = FileReadLine($file)
            If @error = -1 Then ExitLoop
            If $Number > 0 Then
                If $Number = _FileCountLines(@ScriptDir & "\test1.txt") Then
                    $asKeyWords[$Number] = $line
                    $sData = $asKeyWords[$Number]
                Else
                    $asKeyWords[$Number] = $line
                    $sData &= $asKeyWords[$Number] & "|"
                EndIf
            Else
                $asKeyWords[$Number] = $line
                $sData = $asKeyWords[$Number] & "|"
            EndIf
            $Number = $Number +1
        WEnd
    Else
        $sData = "Error on open file"
    EndIf
    FileClose($file)
    GUICtrlSetData($hList, $sData)
    $iCurrIndex = -1
    _GUICtrlListBox_SetCurSel($hList, $iCurrIndex)

EndFunc   ;==>Keywords
Edited by Merchants

Share this post


Link to post
Share on other sites

Merchants,

 

still does not work as i want

I did not say it was a complete solution. :whistle:

Perhaps you can work on the code to change it to meet your requirements - I am watching Belgium-USA and I will not be free to do anything until tomorrow. ;)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

 

Share this post


Link to post
Share on other sites

 

I did not say it was a complete solution

"true"

hope it is a good game have fun

al see it again tomorrow

Share this post


Link to post
Share on other sites

Hi Merchants,

** Caution **

When trying to dig pieces out of M23's code be prepared to dig long and deep.

A couple of observations:

There is no need for the array $GUI.  You only store the handle from the origional guicreate function.  You are referencing other offsets within the array and the are all zeros.
 

I changed the way the input file is read.  It is inefficient to run _FileCountLines inside a loop.
 

I changed the filter to be driven by the $EN_CHANGED message for the inputbox.

 

The way I declare variables is a matter of style.  You can declare them all at the beginning, in fact, some advocate this. 

 

A single mouse click on any item produces conosle output.  This is where you would execute something.

 

Like most things, this is one of many ways to do what you are requesting.  I hope this helps.

#include <WindowsConstants.au3>
#include <GUIConstantsEx.au3>
#include <Array.au3>
#include <GuiListBox.au3>
#include <EditConstants.au3>

#NoTrayIcon

Opt("GUICoordMode", 1)

Global $iCurrIndex = -1

Global $hGUI = GUICreate("test windows", 175, 415, 200, 200)
GUICtrlCreateLabel("Filter", 7, 5)
Global $hInput = GUICtrlCreateInput("", 5, 20, 165, 25)
Global $hList = GUICtrlCreateList("", 5, 50, 165, 330, BitOR($WS_HSCROLL, $WS_VSCROLL))
Global $hButton = GUICtrlCreateButton("Exit", 5, 385, 165, 25)
GUICtrlSetFont($hButton, 11, 600, "", "Tahoma")
GUICtrlSetColor($hButton, 0x948064)
GUICtrlSetFont($hInput, 11, 600, "", "Tahoma")
GUICtrlSetBkColor($hInput, 0x000000)
GUICtrlSetColor($hInput, 0x948064)
GUISetStyle($WS_CAPTION, $WS_BORDER)
Global $hUP = GUICtrlCreateDummy()
Global $hDOWN = GUICtrlCreateDummy()
Global $hENTER = GUICtrlCreateDummy()
GUISetState(@SW_SHOW, $hGUI)

GUIRegisterMsg($WM_COMMAND, 'WM_COMMAND')

Global $aKeyWords = StringSplit(FileRead(@ScriptDir & '\test1.txt'), @CRLF, 3)
If UBound($aKeyWords) = 1 Then GUICtrlSetData($hInput, 'File Read Error')

Keywords(GUICtrlRead($hInput))

Dim $AccelKeys[3][2] = [["{UP}", $hUP], ["{DOWN}", $hDOWN], ["{ENTER}", $hENTER]]
GUISetAccelerators($AccelKeys)

While 1

    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $hList
            ConsoleWrite('Executing ' & GUICtrlRead($hList) & @CRLF)
        Case $hButton
            Exit
        Case $hUP
            $iCurrIndex -= 1
            If $iCurrIndex < 0 Then $iCurrIndex = 0
            _GUICtrlListBox_SetCurSel($hList, $iCurrIndex)
        Case $hDOWN
            $iTotal = _GUICtrlListBox_GetCount($hList)
            $iCurrIndex += 1
            If $iCurrIndex > $iTotal - 1 Then $iCurrIndex = $iTotal - 1
            _GUICtrlListBox_SetCurSel($hList, $iCurrIndex)
        Case $hENTER
            If $iCurrIndex <> -1 Then
                $sText = _GUICtrlListBox_GetText($hList, $iCurrIndex)
                GUICtrlSetData($hInput, $sText)
                $iCurrIndex = -1
                _GUICtrlListBox_SetCurSel($hList, $iCurrIndex)
            EndIf
    EndSwitch

WEnd

Func Keywords($sFilter)

    Local $shlist = '|'
    For $1 = 0 To UBound($aKeyWords) - 1
        If $sFilter = '' Then
            $shlist &= $aKeyWords[$1] & '|'
            ContinueLoop
        Else
            If StringInStr($aKeyWords[$1], $sFilter) > 0 Then $shlist &= $aKeyWords[$1] & '|'
        EndIf
    Next

    GUICtrlSetData($hList, $shlist)

EndFunc   ;==>Keywords

Func WM_COMMAND($hWnd, $iMsg, $wParam, $lParam)
    Switch BitAND($wParam, 0xFFFF)
        Case $hInput
            Switch BitShift($wParam, 16)
                Case $EN_CHANGE
                    Keywords(GUICtrlRead($hInput))
            EndSwitch
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_COMMAND

kylomas


Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Share this post


Link to post
Share on other sites

very very nice i thank you

i am not wel experience

i have much respect your users like you

Share this post


Link to post
Share on other sites

kylomas,

 

When trying to dig pieces out of M23's code be prepared to dig long and deep

Not quite sure how to take that..... ;)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

 

Share this post


Link to post
Share on other sites

@M23 - Apologies for the vague comment.  Was alluding to how complex and instructive your code is.  Perhaps it was inappropriate.  I blame it on the loss of the U.S to Belgium!

kylomas


Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Share this post


Link to post
Share on other sites

kylomas,

No probs - I was just confused, which is not that hard to do. :wacko:

And commiserations to the USA team - you showed real spirit. For neutrals that was far and away the best match so far in what has been a really good World Cup. The BBC commentators were demanding additional extra time as they did not want it to end! :D

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

 

Share this post


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
Sign in to follow this  
Followers 0