Jump to content

need opinion about function that add items to list box within a loop


Recommended Posts

Good morning autoit forum users
Please, I need your opinion about this code, can you help me make it faster than it is now?
By the way, this function adds a list of files to my listbox, the items may be more than 100k, need your help please?
Now it takes a lot of time to load items
 

Func arrayDir($folder = $dir)
    If StringRight($folder, 2) = "\\" Then $folder = StringTrimRight($folder, 1)
    Local $files, $next, $num = 0
    FileChangeDir($folder)
    Opt("GUIOnEventMode", 0)
    Local $h_handleLink = $hGUI
    Local $h_handleLinkChild = $WS_CLIPCHILDREN
    If Not (BitAND(WinGetState($h_handleLink, ""), $WIN_STATE_VISIBLE)) Then
        $h_handleLink = False
        $h_handleLinkChild = -1
    EndIf

    Local $PRGWindow = GUICreate("Opening Folder", 200, 200, -1, -1, $h_handleLinkChild, $rtl, $h_handleLink)
    Local $PRGRSLabel = GUICtrlCreateLabel(LNG("openingProcessing", 0), 10, 10, 200, 50)
    Local $PRGRS = GUICtrlCreateProgress(10, 80, 180, 30)
    GUIStartGroup("")
    Local $PRGCancel = GUICtrlCreateButton("cancel", 10, 120, 200, 30)
    GUICtrlSetState(-1, $GUI_focus)
    If $b_transpa Then WinSetTrans($PRGWindow, "", 0)
    GUISetState(@SW_SHOW, $PRGWindow)
    Global $ArrayDirCancel = False
    GUIRegisterMsg($WM_command, "arrayDirCancel")
    Opt("GUICloseOnESC", 1)
    $files = _FileListToArrayRec($folder, $FilesExt, $FLTAR_files + $FLTAR_NOHIDDEN, $FLTAR_RECUR, $FLTAR_SORT, $FLTAR_FULLPATH)
    If IsArray($files) Then
        ;AdlibUnRegister("UpdateProgress")
        $CrntPlayList[0] = False
        _GUICtrlListBox_BeginUpdate($List)
        For $i = 1 To $files[0]
            If ($ArrayDirCancel) Then
                GUIDelete($PRGWindow)
                ExitLoop
            EndIf

            If (_GUICtrlListBox_SelectString($List, _GetFileName($files[$i]) & "|" & $files[$i]) = -1) Then
                _GUICtrlListBox_AddString($List, _GetFileName($files[$i]) & "|" & $files[$i])
                GUICtrlSetData($PRGRS, ($i * 100 / $files[0]))
                GUICtrlSetData($PRGRSLabel, LNG("openingProcessing", $i))
                $aListItems[2] &= $files[$i] & "|"
                $aListItems[0] += 1
                $aListItems[3] &= $aListItems[0] - 1 & "|"
            EndIf

        Next
        _GUICtrlListBox_EndUpdate($List)
        ;AdlibRegister("UpdateProgress", 1000)

        Opt("GUICloseOnESC", 0)
        Opt("GUIOnEventMode", 1)
        GUIDelete($PRGWindow)
        GUISetState(@SW_ENABLE, $hGUI)
        Return $files[0]
    Else
        Opt("GUICloseOnESC", 0)
        Opt("GUIOnEventMode", 1)
        GUIDelete($PRGWindow)
        GUISetState(@SW_ENABLE, $hGUI)
        Return 0
    EndIf
EndFunc   ;==>arrayDir
Func arrayDirCancel($hWnd, $iMsg, $wParam, $lParam)
    Local $nNotifyCode = BitShift($wParam, 16)
    Local $nID = BitAND($wParam, 0x0000FFFF)
    Local $hCtrl = $lParam
    #forceref $hWnd, $iMsg, $wParam, $lParam#cs
    Switch $nNotifyCode
        Case $BN_CLICKED
            $ArrayDirCancel = True
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc   ;==>arrayDirCancel

 

Link to post
Share on other sites
  • Moderators

nacerbaaziz,

In my opinion you need to rethink your whole concept - 100k items in a list box is way too many. How on earth do you expect the user to scroll through all that to find the element they need?

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
2 minutes ago, Melba23 said:

nacerbaaziz,

In my opinion you need to rethink your whole concept - 100k items in a list box is way too many. How on earth do you expect the user to scroll through all that to find the element they need?

M23

 no the list box is only to move with keyboard, the program is for blind users, so there is option to search, and to move one by one.

here the list box is just to make them know the file that is selected and give them the ability to check the list items to remove file or play it or copy the file path.

Link to post
Share on other sites
  • Moderators

nacerbaaziz,

Even with a "search option" I still think trying to put 100k+ items in a list box is not sensible. By all means have a list box so that the blind user can see a selection of items (via a screen reader I presume) but filling and scrolling the control with that many elements is likely to take far too long - as shown by your request to speed up your existing code.

Why not get the user to utilize the search option initially to limit the number of elements to display to a more reasonable value - that way you will make the whole code much faster. Your choice of course, but I do believe that is a better way to go.

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

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.

×
×
  • Create New...