wx python 3.0.2 经典 'CheckListBox' 对象没有属性 'GetItemHeight'
wx python 3.0.2 classic 'CheckListBox' object has no attribute 'GetItemHeight'
调查将我的 wx 2.8 python 应用程序移植到 wx 3.0.2 classic(是时候了)和 运行 进入这个障碍。显然 GetItemHeight 不再是 CheckListBox class 的一部分:
bash\basher\patcher_dialog.py:519: wxPyDeprecationWarning: Accessing deprecated property.
mouseItem = (event.m_y/self.gPatchers.GetItemHeight() +
Traceback (most recent call last):
File "bash\basher\patcher_dialog.py", line 519, in OnMouse
mouseItem = (event.m_y/self.gPatchers.GetItemHeight() +
AttributeError: 'CheckListBox' object has no attribute 'GetItemHeight'
人们使用它们在鼠标事件处理程序中获得悬停的项目(下面的 gPatchers 是 wx.CheckListBox
):
def OnMouse(self,event):
if event.Moving():
mouseItem = (event.m_y/self.gPatchers.GetItemHeight() +
self.gPatchers.GetScrollPos(wx.VERTICAL))
if mouseItem != self.mouseItem:
self.mouseItem = mouseItem
self.MouseEnteredItem(mouseItem)
elif event.Leaving():
self.gTipText.SetLabel(self.defaultTipText)
self.mouseItem = -1
event.Skip()
那么我如何在 wx python 3.0.2 中实现这一点?
编辑: 交叉张贴在 wx-users 邮件列表中:https://groups.google.com/forum/#!topic/wxpython-users/mMYr-51sE4s
您好,您可以尝试以下技巧来做到这一点。
I couldn't try this with your code but it is also the way you can find the height of CheckListBox
self.gPatchers.GetClientRect()[3]
It will return the height in pixel.
GetClientRect() method will return tuple of 4 value (x,y,width,height)
您可以简单地使用基础 class ListBox
中的 HitTest
来查找给定 x/y 坐标处的项目。 Item 是列表元素的 int
索引。该文档适用于 wxPython phoenix,但在 wxPython MSW classic 3.0.2.
下工作相同
# lb is a wx.(Check)ListBox instance
lb.Bind(wx.EVT_MOTION, self.OnMouse)
def OnMouse(self, evt):
obj = evt.GetEventObject()
x, y = evt.GetPosition()
if isinstance(obj, wx.ListBox):
item = obj.HitTest(wx.Point(x, y))
# do something with item index information
调查将我的 wx 2.8 python 应用程序移植到 wx 3.0.2 classic(是时候了)和 运行 进入这个障碍。显然 GetItemHeight 不再是 CheckListBox class 的一部分:
bash\basher\patcher_dialog.py:519: wxPyDeprecationWarning: Accessing deprecated property.
mouseItem = (event.m_y/self.gPatchers.GetItemHeight() +
Traceback (most recent call last):
File "bash\basher\patcher_dialog.py", line 519, in OnMouse
mouseItem = (event.m_y/self.gPatchers.GetItemHeight() +
AttributeError: 'CheckListBox' object has no attribute 'GetItemHeight'
人们使用它们在鼠标事件处理程序中获得悬停的项目(下面的 gPatchers 是 wx.CheckListBox
):
def OnMouse(self,event):
if event.Moving():
mouseItem = (event.m_y/self.gPatchers.GetItemHeight() +
self.gPatchers.GetScrollPos(wx.VERTICAL))
if mouseItem != self.mouseItem:
self.mouseItem = mouseItem
self.MouseEnteredItem(mouseItem)
elif event.Leaving():
self.gTipText.SetLabel(self.defaultTipText)
self.mouseItem = -1
event.Skip()
那么我如何在 wx python 3.0.2 中实现这一点?
编辑: 交叉张贴在 wx-users 邮件列表中:https://groups.google.com/forum/#!topic/wxpython-users/mMYr-51sE4s
您好,您可以尝试以下技巧来做到这一点。
I couldn't try this with your code but it is also the way you can find the height of CheckListBox
self.gPatchers.GetClientRect()[3]
It will return the height in pixel. GetClientRect() method will return tuple of 4 value (x,y,width,height)
您可以简单地使用基础 class ListBox
中的 HitTest
来查找给定 x/y 坐标处的项目。 Item 是列表元素的 int
索引。该文档适用于 wxPython phoenix,但在 wxPython MSW classic 3.0.2.
# lb is a wx.(Check)ListBox instance
lb.Bind(wx.EVT_MOTION, self.OnMouse)
def OnMouse(self, evt):
obj = evt.GetEventObject()
x, y = evt.GetPosition()
if isinstance(obj, wx.ListBox):
item = obj.HitTest(wx.Point(x, y))
# do something with item index information