Jump to content

Help to filter a content list


Go to solution Solved by careca,

Recommended Posts

Hello!

I'm new to programming and AutoIt .... :mad2:

My problem is, this code draws a small window that has a list of files in the directory that is specified (used the '$caminho' variable to assign the desired location). I wanted to make a filter that my window, ie, the user types something and presses 'enter' for example and my list reloads with strings that have to do with what was typed in the filter.  :think:

Thank you!

#include <GuiConstants.au3>
#include <File.au3>
#include <GUIConstantsEx.au3>
#include <Array.au3>
#include <MsgBoxConstants.au3>
#include <ListviewConstants.au3>

;~ ----------v-a-r-i-á-v-e-i-s-------------------------------
Global $foto = Null, $lista, $barraInput
;~ Global Const $caminho = "D:\USERS\Public\Pictures\wall\"
Global Const $caminho = "D:\Imagens\"
;~ ---------------------------------------------------------

Opt("GUIOnEventMode", 1)

guiPrincipal()

Func guiPrincipal()
    $janela = GUICreate("IMPRIMIR ", 600, 500)
    GUISetOnEvent($GUI_EVENT_CLOSE, "fechar");chama a função 'fechar'
    $lista = GUICtrlCreateListView("Imagens ", 20, 30, 200, 350, $LVS_NOSORTHEADER)
    Local $UserList, $X = 0, $aUserList[5000], $I
    $UserList = _FileListToArray($caminho, "*.*", 1)
    $dimensao = UBound($UserList)
    If ($dimensao = 0) Then
        MsgBox(48, "Erro!", "Diretório não encontrado.")
    Else
        For $I = 1 To $UserList[0]
            Local $pString = String($UserList[$I]) ;cada valor do Array 'UserList' está sendo convertido para o tipo String
            GUICtrlCreateListViewItem($pString, $lista)
            $X += 1
        Next
    EndIf
    $BtnVisualizar = GUICtrlCreateButton("Visualizar", 140, 460, 80, 30)
    GUICtrlSetOnEvent(-1, "visualizar")
    GUICtrlCreateLabel("Filtro:", 10, 394, 30, 20)
    $barraInput = GUICtrlCreateInput("", 40, 390, 180, 20)
    GUICtrlSetOnEvent(-1, "filtrarFunc")
    GUISetState()
    While 1
        Sleep(10)
    WEnd
EndFunc   ;==>guiPrincipal


Func filtrarFunc()
    ;se eu utilizar o filtro, devo preencher novamente a lista
    ;contendo apenas itens que possuem a string que eu inseri
    ;dentro da inputText
    $texto = GUICtrlRead($barraInput) ;string
    Local $textoEmArray = StringToASCIIArray($texto) ;ascii
;~ Local $textoEmString = StringFromASCIIArray($textoArray) ;string
    $sItem = GUICtrlRead($lista)
    MsgBox(0, "", $sItem)
;~ $tamanhoLista = UBound($sItem)
;~ MsgBox(0,"",$sString)
;~ #cs
    Local $UserList, $X = 0, $aUserList[5000], $I
    $UserList = _FileListToArray($caminho, "*.*", 1)
    $dimensao = UBound($UserList)
    If ($dimensao = 0) Then
        MsgBox(48, "Erro!", "Diretório não encontrado.")
    Else
;~ For $I = 1 To $UserList[0]
;~ $aArray = _FileListToArrayRec($caminho, $texto, $FLTAR_FILESFOLDERS, $FLTAR_RECUR, $FLTAR_SORT)
;~ _ArrayDisplay($aArray, "Recur with filter")

;~ Local $pString = String($UserList[$I]) ;cada valor do Array 'UserList' está sendo convertido para o tipo String
        ;aqui insiro o código para verificar se a string atual possui a string do inputText....
;~ GUICtrlCreateListViewItem($pString, $lista)
;~ $X += 1
;~ Next
    EndIf
;~ $sItem = StringTrimRight($sItem, 1)
;~ #ce
EndFunc   ;==>filtrarFunc

Func visualizar()
    $sItem = GUICtrlRead(GUICtrlRead($lista))
    $sItem = StringTrimRight($sItem, 1); retira o "|" da string
    If ($foto = Null) Then
        $foto = GUICtrlCreatePic($caminho & $sItem, 230, 50, 358, 200)
    Else
        GUICtrlDelete($foto)
        $foto = GUICtrlCreatePic($caminho & $sItem, 230, 50, 358, 200)
    EndIf
EndFunc   ;==>visualizar

Func fechar()
    Exit
EndFunc   ;==>fechar
Edited by Melba23
Added code tags
Link to comment
Share on other sites

  • Moderators

PhelipeLima,

Welcome to the AutoIt forums. When you post code please use Code tags - see here how to do it. Then you get a scrolling box and syntax colouring as you can see above now I have added the tags. :)

If you were prepared to use a List rather than a ListView, then >this code should give you good start - although it will need some modification. ;)

Take a look and come back if you have any questions. :)

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

  • Solution

Experimenta isto:

#include <GuiConstants.au3>
#include <File.au3>
#include <GUIConstantsEx.au3>
#include <Array.au3>
#include <MsgBoxConstants.au3>
#include <ListviewConstants.au3>
#include <GuiListView.au3>

;~ ----------v-a-r-i-á-v-e-i-s-------------------------------
Global $foto = Null, $lista, $barraInput
Global Const $caminho = FileSelectFolder('Pasta', '', 0, '')
;~ ---------------------------------------------------------

Opt("GUIOnEventMode", 1)

guiPrincipal()

Func guiPrincipal()
    $janela = GUICreate("IMPRIMIR ", 600, 500)
    GUISetOnEvent($GUI_EVENT_CLOSE, "fechar");chama a função 'fechar'
    $lista = GUICtrlCreateListView("Imagens ", 20, 30, 200, 350, $LVS_NOSORTHEADER)
    GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 0, 170)
    Local $UserList, $X = 0, $aUserList[5000], $I
    $UserList = _FileListToArray($caminho, "*.*", 1)
    $dimensao = UBound($UserList)
    If ($dimensao = 0) Then
        MsgBox(48, "Erro!", "Diretório não encontrado.")
    Else
        For $I = 1 To $UserList[0]
            Local $pString = String($UserList[$I]) ;cada valor do Array 'UserList' está sendo convertido para o tipo String
            GUICtrlCreateListViewItem($pString, $lista)
            $X += 1
        Next
    EndIf
    $BtnVisualizar = GUICtrlCreateButton("Visualizar", 140, 460, 80, 30)
    GUICtrlSetOnEvent(-1, "visualizar")
    GUICtrlCreateLabel("Filtro:", 10, 394, 30, 20)
    $barraInput = GUICtrlCreateInput("", 40, 390, 180, 20)
    GUICtrlSetOnEvent(-1, "filtrarFunc")
    GUISetState()
    While 1
        Sleep(10)
    WEnd
EndFunc   ;==>guiPrincipal


Func filtrarFunc()
    $texto = GUICtrlRead($barraInput) ;string
    _GUICtrlListView_DeleteAllItems($lista)
    Local $I, $UserList
    $UserList = _FileListToArray($caminho, '*', 1)
    ConsoleWrite('$UserList[0] '& $UserList[0] &@CRLF)
    ConsoleWrite('error '& @error &@CRLF)
        For $I = 1 To $UserList[0]
            $Str = StringInStr($UserList[$I], $texto, 0)
            If $Str = 0 Then
            ;Skip
            Else
            GUICtrlCreateListViewItem($UserList[$I], $lista)
            EndIf
        Next
EndFunc   ;==>filtrarFunc

Func visualizar()
    $sItem = GUICtrlRead(GUICtrlRead($lista))
    $sItem = StringTrimRight($sItem, 1); retira o "|" da string
    If ($foto = Null) Then
        $foto = GUICtrlCreatePic($caminho &'\'& $sItem, 230, 50, 358, 200)
    Else
        GUICtrlDelete($foto)
        $foto = GUICtrlCreatePic($caminho &'\'& $sItem, 230, 50, 358, 200)
    EndIf
EndFunc   ;==>visualizar

Func fechar()
    Exit
EndFunc   ;==>fechar

EDIT: Forgot the filter thing, working on it.

EDIT: Done, test it out

Edited by careca
Spoiler

Renamer - Rename files and folders, remove portions of text from the filename etc.

GPO Tool - Export/Import Group policy settings.

MirrorDir - Synchronize/Backup/Mirror Folders

BeatsPlayer - Music player.

Params Tool - Right click an exe to see it's parameters or execute them.

String Trigger - Triggers pasting text or applications or internet links on specific strings.

Inconspicuous - Hide files in plain sight, not fully encrypted.

Regedit Control - Registry browsing history, quickly jump into any saved key.

Time4Shutdown - Write the time for shutdown in minutes.

Power Profiles Tool - Set a profile as active, delete, duplicate, export and import.

Finished Task Shutdown - Shuts down pc when specified window/Wndl/process closes.

NetworkSpeedShutdown - Shuts down pc if download speed goes under "X" Kb/s.

IUIAutomation - Topic with framework and examples

Au3Record.exe

Link to comment
Share on other sites

Thank you Melba23!!

Valeuuuuu Careca, não conhecia essa função 'StringInStr', muito boaaa!! Sem contar com os outros detalhes q vc implementou no código, curti muito! Agora quero fazer uma função para imprimir, vou tentar aqui, falou!! :thumbsup:

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

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...