Lupo73 Posted January 31, 2009 Author Posted January 31, 2009 I'm trying to implement this function.. but if part of a script is in a function or directly in the rest of the code, is there a difference in the performance of the script? SFTPEx, AutoCompleteInput, _DateTimeStandard(), _ImageWriteResize(), _GUIGraduallyHide(): some AutoIt functions. Lupo PenSuite: all-in-one and completely free selection of portable programs and games. DropIt: a personal assistant to automatically manage your files. ArcThemALL!: application to multi-archive your files and folders.
Lupo73 Posted January 31, 2009 Author Posted January 31, 2009 I have created this function that starts at any item adding: Func DuplicateCheck($item) ; OK ?? Local $nIt, $k, $a, $b, $aa, $bb $nIt = _GUICtrlListView_GetItemCount($hListView) $aa = _GUICtrlListView_GetItemText($hListView, $item, 0) $bb = _GUICtrlListView_GetItemText($hListView, $item, 1) For $k = 0 To $nIt - 1 If Not ($k = $item) Then $a = _GUICtrlListView_GetItemText($hListView, $k, 0) $b = _GUICtrlListView_GetItemText($hListView, $k, 1) If $a = $aa Then If $b = $bb Then _GUICtrlListView_SetItemParam($hListView, $item, 2) ;GUICtrlSetBkColor($item, 0xFFBFBF) EndIf EndIf EndIf Next EndFunc It's not really fast, but faster than the previous solution. Obviously if you know better solutions (I have tried the function you recommend me, adding the parameter line, but didn't work). I'd like also to change the background color of the item if it is a duplicate, but this code "GUICtrlSetBkColor($item, 0xFFBFBF)" doesn't work fine (I think because $item is the number of the item and that function need the ID). Any ideas? Thanks! SFTPEx, AutoCompleteInput, _DateTimeStandard(), _ImageWriteResize(), _GUIGraduallyHide(): some AutoIt functions. Lupo PenSuite: all-in-one and completely free selection of portable programs and games. DropIt: a personal assistant to automatically manage your files. ArcThemALL!: application to multi-archive your files and folders.
PsaltyDS Posted January 31, 2009 Posted January 31, 2009 I have created this function that starts at any item adding: Func DuplicateCheck($item); OK ?? Local $nIt, $k, $a, $b, $aa, $bb $nIt = _GUICtrlListView_GetItemCount($hListView) $aa = _GUICtrlListView_GetItemText($hListView, $item, 0) $bb = _GUICtrlListView_GetItemText($hListView, $item, 1) For $k = 0 To $nIt - 1 If Not ($k = $item) Then $a = _GUICtrlListView_GetItemText($hListView, $k, 0) $b = _GUICtrlListView_GetItemText($hListView, $k, 1) If $a = $aa Then If $b = $bb Then _GUICtrlListView_SetItemParam($hListView, $item, 2) ;GUICtrlSetBkColor($item, 0xFFBFBF) EndIf EndIf EndIf Next EndFunc It's not really fast, but faster than the previous solution. Obviously if you know better solutions (I have tried the function you recommend me, adding the parameter line, but didn't work). I'd like also to change the background color of the item if it is a duplicate, but this code "GUICtrlSetBkColor($item, 0xFFBFBF)" doesn't work fine (I think because $item is the number of the item and that function need the ID). Any ideas? Thanks! That's much better. I don't know how you do quantitative testing against "not really fast" to know when you have "fast enough", but you are getting your result in a single pass now. The question now is how many times you have to call this function and pass through the entire Listview. The point of assembling a string was that it could be done as the ListView was populated. If you keep it in a Global variable you can go back and check for duplicates WITHOUT scanning the ListView, just check against the string and keep it updated. I missed that you wanted to define duplicate by two columns, but that just makes the string slightly more complicated because it needs two delimiters, like: "|" & $aa & "^" & $bb & "|". So that would look like this: ; Global variable keeps all ListView items in a string for duplicate testing ; Formatted "|Item0_Col0^Item0_Col1|Item1_Col0^Item1_Col1|" ; Whith "|" around each item, and "^" between columns Global $sLV_Data = "|" ; ... ; Adding a new LV item $aa = "New Col 0 text" $bb = "New Col 1 Text" $iNewIndex = _GUICtrlListView_AddItem($hListView, $aa) _GUICtrlListView_AddSubItem($hListView, $iNewIndex, $bb, 1) If _IsDuplicateLVItem($aa, $bb) Then _GUICtrlListView_SetItemParam($hListView, $iNewIndex, 2) ; ... ; Function _IsDuplicateLVItem() ; Returns: 1 if duplicate ; 0 if not duplicate, and adds new item to $sLV_Data Func _IsDuplicateLVItem($sCol0, $sCol1) $sTest = $sCol0 & "^" & $sCol1 & "|" If StringInStr($sLV_Data, "|" & $sTest) Then ; Duplicate Return 1 Else ; Not duplicate $sLV_Data &= $sTest Return 0 EndIf EndFunc ;==>_IsDuplicateLVItem Note that the check is done each time an item is added to the ListView, but it only does one test against the string, not a loop through the ListView each time. One bit of housekeeping: Any deletions or editing of the ListView items should be updated in the global string also, but that is easy with one call to StringReplace(). I think you'll find that method about as fast as you're going to get with AutoIt. Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Lupo73 Posted February 1, 2009 Author Posted February 1, 2009 I'll try it..thanks ..and for the problem of the background color can you help me? I have searched in autoit forum but I didn't find help for it, because the "$item" var is the number of the line, not the controlid of it (I need to create items with _GUICtrlListView_AddItem function, but it return the item number so the GUICtrlSetBkColor doesn't work anymore).. SFTPEx, AutoCompleteInput, _DateTimeStandard(), _ImageWriteResize(), _GUIGraduallyHide(): some AutoIt functions. Lupo PenSuite: all-in-one and completely free selection of portable programs and games. DropIt: a personal assistant to automatically manage your files. ArcThemALL!: application to multi-archive your files and folders.
PsaltyDS Posted February 1, 2009 Posted February 1, 2009 I'll try it..thanks..and for the problem of the background color can you help me? I have searched in autoit forum but I didn't find help for it, because the "$item" var is the number of the line, not the controlid of it (I need to create items with _GUICtrlListView_AddItem function, but it return the item number so the GUICtrlSetBkColor doesn't work anymore)...Did you try _GUICtrlListView_SetBkColor()? Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Lupo73 Posted February 1, 2009 Author Posted February 1, 2009 Yes but I need to change the background color only of some "special" items, for example duplicate items, not of the whole listview. I don't know if there is a way to use this function to change only one line color, is there? SFTPEx, AutoCompleteInput, _DateTimeStandard(), _ImageWriteResize(), _GUIGraduallyHide(): some AutoIt functions. Lupo PenSuite: all-in-one and completely free selection of portable programs and games. DropIt: a personal assistant to automatically manage your files. ArcThemALL!: application to multi-archive your files and folders.
PsaltyDS Posted February 2, 2009 Posted February 2, 2009 Yes but I need to change the background color only of some "special" items, for example duplicate items, not of the whole listview. I don't know if there is a way to use this function to change only one line color, is there?Oops. My mistake, I thought you could specify the item index with _GuiCtrlListView_SetBkColor(), but of course you can't.Perhaps try the example script for _GuiCtrlListView_SetItemImage() instead. Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Lupo73 Posted February 3, 2009 Author Posted February 3, 2009 How can I use this alternative for my problem? ...is it really not possible to find the controlid of an item to set its background color? any ideas to how show when an item is a duplicate in the listview? SFTPEx, AutoCompleteInput, _DateTimeStandard(), _ImageWriteResize(), _GUIGraduallyHide(): some AutoIt functions. Lupo PenSuite: all-in-one and completely free selection of portable programs and games. DropIt: a personal assistant to automatically manage your files. ArcThemALL!: application to multi-archive your files and folders.
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