gpt4 book ai didi

python - TypeError : 'in ' requires string as left operand, not int with ObjectListView wxPython

转载 作者:行者123 更新时间:2023-12-01 04:46:21 29 4
gpt4 key购买 nike

在 Python 2.7 中使用 ObjectListView 时 - 按键盘上的任何字母数字键,我在 IDE 中收到以下消息错误(使用 PyCharm):

C:\Users\dylan_cissou\AppData\Local\Continuum\Anaconda\python.exe C:/Users/dylan_cissou/PycharmProjects/SPA/example.py
Traceback (most recent call last):
File "build\bdist.win-amd64\egg\ObjectListView\ObjectListView.py", line 1410, in _HandleChar
File "build\bdist.win-amd64\egg\ObjectListView\ObjectListView.py", line 1457, in _HandleTypingEvent
TypeError: 'in <string>' requires string as left operand, not int

我应该怎样做才能禁用此消息?我试图找到这两个事件的位置,以便我可以覆盖它们,但我找不到任何事件。

代码示例为:

import wx
from ObjectListView import ObjectListView, ColumnDefn

########################################################################
class Book(object):
"""
Model of the Book object

Contains the following attributes:
'ISBN', 'Author', 'Manufacturer', 'Title'
"""
#----------------------------------------------------------------------
def __init__(self, title, author, isbn, mfg):
self.isbn = isbn
self.author = author
self.mfg = mfg
self.title = title


########################################################################
class MainPanel(wx.Panel):
#----------------------------------------------------------------------
def __init__(self, parent):
wx.Panel.__init__(self, parent=parent, id=wx.ID_ANY)
self.products = [Book("wxPython in Action", "Robin Dunn",
"1932394621", "Manning"),
Book("Hello World", "Warren and Carter Sande",
"1933988495", "Manning")
]

self.dataOlv = ObjectListView(self, wx.ID_ANY, style=wx.LC_REPORT|wx.SUNKEN_BORDER)
self.setBooks()

# Allow the cell values to be edited when double-clicked
self.dataOlv.cellEditMode = ObjectListView.CELLEDIT_SINGLECLICK

# create an update button
updateBtn = wx.Button(self, wx.ID_ANY, "Update OLV")
updateBtn.Bind(wx.EVT_BUTTON, self.updateControl)

# Create some sizers
mainSizer = wx.BoxSizer(wx.VERTICAL)

mainSizer.Add(self.dataOlv, 1, wx.ALL|wx.EXPAND, 5)
mainSizer.Add(updateBtn, 0, wx.ALL|wx.CENTER, 5)
self.SetSizer(mainSizer)

#----------------------------------------------------------------------
def updateControl(self, event):
"""

"""
print "updating..."
product_dict = [{"title":"Core Python Programming", "author":"Wesley Chun",
"isbn":"0132269937", "mfg":"Prentice Hall"},
{"title":"Python Programming for the Absolute Beginner",
"author":"Michael Dawson", "isbn":"1598631128",
"mfg":"Course Technology"},
{"title":"Learning Python", "author":"Mark Lutz",
"isbn":"0596513984", "mfg":"O'Reilly"}
]
data = self.products + product_dict
self.dataOlv.SetObjects(data)

#----------------------------------------------------------------------
def setBooks(self, data=None):
self.dataOlv.SetColumns([
ColumnDefn("Title", "left", 220, "title"),
ColumnDefn("Author", "left", 200, "author"),
ColumnDefn("ISBN", "right", 100, "isbn"),
ColumnDefn("Mfg", "left", 180, "mfg")
])

self.dataOlv.SetObjects(self.products)

########################################################################
class MainFrame(wx.Frame):
#----------------------------------------------------------------------
def __init__(self):
wx.Frame.__init__(self, parent=None, id=wx.ID_ANY,
title="ObjectListView Demo", size=(800,600))
panel = MainPanel(self)

########################################################################
class GenApp(wx.App):

#----------------------------------------------------------------------
def __init__(self, redirect=False, filename=None):
wx.App.__init__(self, redirect, filename)

#----------------------------------------------------------------------
def OnInit(self):
# create frame here
frame = MainFrame()
frame.Show()
return True

#----------------------------------------------------------------------
def main():
"""
Run the demo
"""
app = GenApp()
app.MainLoop()

if __name__ == "__main__":
main()

只需按任意按键,例如“3”、“z”、“x”等...每次都会出现红色错误消息。

感谢您的帮助。

最佳答案

嗯,似乎是 wxPython 的问题,我在 2.8.12 Unicode 版本、3.0.2 和 Python 2.7 上使用 OLV 1.3.2 的 Phoenix 中看到了同样的问题

evt.GetUnicodeKey 应根据 Phoenix 文档返回一个字符串: http://wxpython.org/Phoenix/docs/html/KeyEvent.html?highlight=getkeycode#KeyEvent.GetUnicodeKey

根据 Robin Dunn 的说法,这是不正确的,它应该返回一个 int。

我在 wxPython-dev 上发布了一个关于此的问题。

我将在olv._HandleTypingEvent中进行更改,如下所示::

if evt.GetUnicodeKey() == 0:
uniChar = chr(evt.GetKeyCode())
else:
uniChar = evt.GetUnicodeKey()
if uniChar not in string.printable:
return False

至:

if evt.GetUnicodeKey() == 0:
uniChar = chr(evt.GetKeyCode())
else:
uniChar = chr(evt.GetUnicodeKey())
if uniChar not in string.printable:
return False

关于python - TypeError : 'in <string>' requires string as left operand, not int with ObjectListView wxPython,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29302875/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com