I am newy in wxpython (and python too :)) and I am trying to do a custom program for me and to learn, but there is something I cannt do. I have looking for examples of Objectlistview but there aren't so much. I copy/paste/edit code from here (last example) and I want to do something like this to avoid duplicated items:
self.olv = ObjectListView(self, style=wx.LC_REPORT|wx.SUNKEN_BORDER)
...
self.olv.SetDropTarget(MyFileDropTarget(self))
self.setFiles()
self.RemoveDuplicated(self.olv)
def RemoveDuplicated(self, X):
for all in X:
Counter = 0
for B in X:
if X.path(A) == X.path(B):
Counter += 1
if (X.path(A) == X.path(B) and Counter >=2):
Counter += 1
RemoveObject(B)
Any idea or tutorial to do it? Thank you in advance.
Done now :D, ty Mike again.
def __init__(self, window):
"""Constructor"""
wx.FileDropTarget.__init__(self)
self.window = window
self.all_filenames = []
#----------------------------------------------------------------------
def OnDropFiles(self, x, y, filenames):
"""
When files are dropped, update the display
"""
self.entriesList = list() # Actual dropped file entries; duplicates are avoided.
self.haveEntries = False # Tracks actual dropped file entries, but not help entries.
self.RemoveDuplicated(self.all_filenames, filenames)
self.all_filenames += filenames
self.window.updateDisplay(filenames)
print len(all_filenames) , len(filenames)
def RemoveDuplicated(self, X, Y):
for A in X:
for B in Y:
if A == B:
Y.remove(B)
Since what you add to an ObjectListView is basically a list of objects or dicts, you could just run your de-dupe process on that list before setting the widget to those values. You could use Python's set function plus the solution here to de-dupe the objects.
There are a couple of places to look for ObjectListView information: