小编Hum*_*lan的帖子

在 Python 3 中未调用覆盖的 TreeCtrl.OnCompareItems() - wxPython 4

我有一个wx.TreeCtrl结构,用户可以按不同的条件(日期、名称、id、降序、升序……)对项目进行排序。这在 Python 2 中工作得很好,但 Python 3(带有 wxPython 4)拒绝排序。该方法CTreeCtrl.OnCompareItems()在 Python 2 中被调用,但在 Python 3 中从未被调用。

在functools.cmp_to_key文档(https://docs.python.org/3/library/functools.html)中我发现了一个提示:Python 3不支持比较函数。令人困惑的是:在wx.TreeCtrl(wxPython 4)的描述中,有一个比较方法OnCompareItems()https://docs.wxpython.org/wx.TreeCtrl.html#wx.TreeCtrl.OnCompareItems)。描述说,与此方法一起我必须使用 RTTI 宏DECLARE_DYNAMIC_CLASS,并且IMPLEMENT_DYNAMIC_CLASS因为基类不知道我覆盖了OnCompareItems(). 我只找到了如何在 C++ 中使用这个宏的描述,但没有找到关于 python 的描述。

我不知道如何让我的程序OnCompareItems()在 Python3/wxPython 4 中调用我的方法。

有人可以帮忙吗?

问候, 洪巴兰

下面有一个反映该问题的小示例程序。它也可以与 Python 2 和 Python 3 一起运行。显示print( 'in CTreeCtrl.OnCompareItems()' )该方法被调用(在 py2 中)或未调用(在 py3 中):

import sys
import wx

class CTreeCtrl( wx.TreeCtrl ):
    def __init__( self, parent ): …
Run Code Online (Sandbox Code Playgroud)

python sorting wxpython python-2.7 python-3.x

5
推荐指数
1
解决办法
240
查看次数

标签 统计

python ×1

python-2.7 ×1

python-3.x ×1

sorting ×1

wxpython ×1