nacerbaaziz Posted July 22, 2022 Posted July 22, 2022 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 expandcollapse popupFunc 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
Moderators Melba23 Posted July 22, 2022 Moderators Posted July 22, 2022 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 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 columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area
nacerbaaziz Posted July 22, 2022 Author Posted July 22, 2022 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.
Moderators Melba23 Posted July 22, 2022 Moderators Posted July 22, 2022 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 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 columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area
junkew Posted July 23, 2022 Posted July 23, 2022 For blind users a screenreader will probably try to speak all those items😀 FAQ 31 How to click some elements, FAQ 40 Test automation with AutoIt, Multithreading CLR .NET Powershell CMDLets
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now