【问题标题】:How can I remove duplicated items from an objectlistview (wxpython)?如何从 objectlistview (wxpython) 中删除重复的项目?
【发布时间】:2012-08-13 01:41:54
【问题描述】:

我是 wxpython 的新手(和 python 也是:)),我正在尝试为我做一个自定义程序并学习,但有些事情我不能做。我一直在寻找 Objectlistview 的示例,但没有那么多。我从here(最后一个示例)复制/粘贴/编辑代码,我想做这样的事情以避免重复项:

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)

有任何想法或教程吗?提前谢谢你。

现在完成了:D,又是迈克。

     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)

【问题讨论】:

    标签: wxpython items objectlistview


    【解决方案1】:

    由于您添加到 ObjectListView 的内容基本上是对象或字典的列表,因此您可以在将小部件设置为这些值之前对该列表运行重复数据删除过程。您可以使用 Python 的 set 函数加上解决方案 here 对对象进行重复数据删除。

    有几个地方可以查找 ObjectListView 信息:

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-09-21
      • 2013-09-17
      • 1970-01-01
      • 2015-09-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多