首页 \ 问答 \ Wxpython:无法检索有关列表控件项XXX的信息(Wxpython: Couldn't retrieve information about list control item XXX)

Wxpython:无法检索有关列表控件项XXX的信息(Wxpython: Couldn't retrieve information about list control item XXX)

删除选择项时,ErrorMsg加速:“无法检索有关列表控件XXX的信息”。 任何人都可以看看并找到解决方法吗? 感谢您的帮助!

导入wx

DATA = {
0 : (u"Test2", "123456", ),
1 : (u"Test", "123456",),
2 : (u"doe", "156789", ),
3 : (u"John", "13455", )
}


class MyApp(wx.App):

    def OnInit(self):
        frame = MyFrame(None)
        frame.Show()
        self.SetTopWindow(frame)
        return True


class MyFrame(wx.Frame):

    def __init__(self, parent):
        wx.Frame.__init__(self, parent, wx.NewId(), size=(500, -1))
        wx.Frame.CenterOnScreen(self)
        self.panel = MyPanel(self)


class MyPanel(wx.Panel):

    def __init__(self, parent):
        wx.Panel.__init__(self, parent)
        self.list = MyListCtrl(self,3)
        self.add_button = wx.Button(self, label="add")
        h_sizer = wx.BoxSizer(wx.HORIZONTAL)
        h_sizer.Add(self.add_button, proportion=1, flag=wx.ALL, border=5)
        v_sizer = wx.BoxSizer(wx.VERTICAL)
        v_sizer.Add(h_sizer, proportion=0, flag=wx.EXPAND)
        v_sizer.Add(self.list, proportion=1, flag=wx.EXPAND, border=5)
        self.SetSizer(v_sizer)
        self.add_button.Bind(wx.EVT_BUTTON,self.onAdd)

    def onAdd(self, event):
        self.new_w = NewWindow(self)
        self.new_w.Show()


class MyPopupMenu(wx.Menu):

    def __init__(self,parent, item):
        super(MyPopupMenu,self).__init__()
        self.parent = parent
        self.item = item
        menuEdit = wx.MenuItem(self,wx.NewId(), 'edit %s' % item[0])
        self.AppendItem(menuEdit)
        self.Bind(wx.EVT_MENU, self.onEdit, menuEdit)
        menuDel = wx.MenuItem(self,wx.NewId(), 'delete %s' % item[0])
        self.AppendItem(menuDel)
        self.Bind(wx.EVT_MENU, self.OnDelete, menuDel)

    def onEdit(self,e):
        self.parent.parent.edit_w = NewWindow(self.parent.parent)
        self.parent.parent.edit_w.Show()

    def OnDelete(self,e):
        self.parent.DeleteAllItems()

class MyListCtrl(wx.ListCtrl):
    def __init__(self, parent, columns):
        wx.ListCtrl.__init__(self, parent, style=wx.LC_REPORT)
        self.parent = parent
        self.R_MOUSE = 0
        self.InsertColumn(0, "name")
        self.InsertColumn(1, "phone")
        self.InsertColumn(2, "address")
        self.SetColumnWidth(0, 200)
        self.Bind(wx.EVT_LIST_ITEM_SELECTED, self.OnSelect)
        self.Bind(wx.EVT_RIGHT_DOWN, self.OnRightDown)
        self.itemDataMap = {}
        self.refresh_list()


    def refresh_list(self):
        self.DeleteAllItems()
        for entry in DATA.items():
            self.Append(entry[1])
            self.SetItemData(entry[0],entry[0])

    def OnRightDown(self, event):
        self.R_MOUSE = 1
        self.position = event.GetPosition()
        event.Skip()

    def OnSelect(self, event):
        index = event.GetIndex()
        item = []
        for i in range(3):
            item.append(self.GetItem(itemId=index, col=i).GetText())
        self.SetItemState(index, 0, wx.LIST_STATE_SELECTED)
        self.SetItemBackgroundColour(index, wx.Colour(255,255,0))
        if self.R_MOUSE:
            self.R_MOUSE = 0
            self.PopupMenu(MyPopupMenu(self, item), self.position)


class NewWindow(wx.Frame):

    def __init__(self, parent):
        wx.Frame.__init__(self, parent, size=(400,250), style=wx.DEFAULT_FRAME_STYLE)
        self.parent = parent
        self.CenterOnParent()
        panel = wx.Panel(self)


    def onClick(self,event):
        self.Close()


if __name__ == "__main__":
    app = MyApp()
    app.MainLoop()

---------------------------------- **


When deleting select item, ErrorMsg poped up: "can't retrieve information about list control item XXX". Can anyone take a look and find a way to solve it? Appreciate your help!

import wx

DATA = {
0 : (u"Test2", "123456", ),
1 : (u"Test", "123456",),
2 : (u"doe", "156789", ),
3 : (u"John", "13455", )
}


class MyApp(wx.App):

    def OnInit(self):
        frame = MyFrame(None)
        frame.Show()
        self.SetTopWindow(frame)
        return True


class MyFrame(wx.Frame):

    def __init__(self, parent):
        wx.Frame.__init__(self, parent, wx.NewId(), size=(500, -1))
        wx.Frame.CenterOnScreen(self)
        self.panel = MyPanel(self)


class MyPanel(wx.Panel):

    def __init__(self, parent):
        wx.Panel.__init__(self, parent)
        self.list = MyListCtrl(self,3)
        self.add_button = wx.Button(self, label="add")
        h_sizer = wx.BoxSizer(wx.HORIZONTAL)
        h_sizer.Add(self.add_button, proportion=1, flag=wx.ALL, border=5)
        v_sizer = wx.BoxSizer(wx.VERTICAL)
        v_sizer.Add(h_sizer, proportion=0, flag=wx.EXPAND)
        v_sizer.Add(self.list, proportion=1, flag=wx.EXPAND, border=5)
        self.SetSizer(v_sizer)
        self.add_button.Bind(wx.EVT_BUTTON,self.onAdd)

    def onAdd(self, event):
        self.new_w = NewWindow(self)
        self.new_w.Show()


class MyPopupMenu(wx.Menu):

    def __init__(self,parent, item):
        super(MyPopupMenu,self).__init__()
        self.parent = parent
        self.item = item
        menuEdit = wx.MenuItem(self,wx.NewId(), 'edit %s' % item[0])
        self.AppendItem(menuEdit)
        self.Bind(wx.EVT_MENU, self.onEdit, menuEdit)
        menuDel = wx.MenuItem(self,wx.NewId(), 'delete %s' % item[0])
        self.AppendItem(menuDel)
        self.Bind(wx.EVT_MENU, self.OnDelete, menuDel)

    def onEdit(self,e):
        self.parent.parent.edit_w = NewWindow(self.parent.parent)
        self.parent.parent.edit_w.Show()

    def OnDelete(self,e):
        self.parent.DeleteAllItems()

class MyListCtrl(wx.ListCtrl):
    def __init__(self, parent, columns):
        wx.ListCtrl.__init__(self, parent, style=wx.LC_REPORT)
        self.parent = parent
        self.R_MOUSE = 0
        self.InsertColumn(0, "name")
        self.InsertColumn(1, "phone")
        self.InsertColumn(2, "address")
        self.SetColumnWidth(0, 200)
        self.Bind(wx.EVT_LIST_ITEM_SELECTED, self.OnSelect)
        self.Bind(wx.EVT_RIGHT_DOWN, self.OnRightDown)
        self.itemDataMap = {}
        self.refresh_list()


    def refresh_list(self):
        self.DeleteAllItems()
        for entry in DATA.items():
            self.Append(entry[1])
            self.SetItemData(entry[0],entry[0])

    def OnRightDown(self, event):
        self.R_MOUSE = 1
        self.position = event.GetPosition()
        event.Skip()

    def OnSelect(self, event):
        index = event.GetIndex()
        item = []
        for i in range(3):
            item.append(self.GetItem(itemId=index, col=i).GetText())
        self.SetItemState(index, 0, wx.LIST_STATE_SELECTED)
        self.SetItemBackgroundColour(index, wx.Colour(255,255,0))
        if self.R_MOUSE:
            self.R_MOUSE = 0
            self.PopupMenu(MyPopupMenu(self, item), self.position)


class NewWindow(wx.Frame):

    def __init__(self, parent):
        wx.Frame.__init__(self, parent, size=(400,250), style=wx.DEFAULT_FRAME_STYLE)
        self.parent = parent
        self.CenterOnParent()
        panel = wx.Panel(self)


    def onClick(self,event):
        self.Close()


if __name__ == "__main__":
    app = MyApp()
    app.MainLoop()

----------------------------------**


原文:https://stackoverflow.com/questions/21493055
更新时间:2019-07-11 02:28

最满意答案

您应该在EVT_LIST_ITEM_RIGHT_CLICK的另一个事件处理程序中弹出菜单
请尝试以下代码:

import wx

DATA = {
    0 : (u"Test2", "123456", ),
    1 : (u"Test", "123456",),
    2 : (u"doe", "156789", ),
    3 : (u"John", "13455", )
}

class MyApp(wx.App):

    def OnInit(self):
        frame = MyFrame(None)
        frame.Show()
        self.SetTopWindow(frame)
        return True


class MyFrame(wx.Frame):

    def __init__(self, parent):
        wx.Frame.__init__(self, parent, wx.NewId(), size=(500, -1))
        wx.Frame.CenterOnScreen(self)
        self.panel = MyPanel(self)


class MyPanel(wx.Panel):

    def __init__(self, parent):
        wx.Panel.__init__(self, parent)
        self.list = MyListCtrl(self,3)
        self.add_button = wx.Button(self, label="add")
        h_sizer = wx.BoxSizer(wx.HORIZONTAL)
        h_sizer.Add(self.add_button, proportion=1, flag=wx.ALL, border=5)
        v_sizer = wx.BoxSizer(wx.VERTICAL)
        v_sizer.Add(h_sizer, proportion=0, flag=wx.EXPAND)
        v_sizer.Add(self.list, proportion=1, flag=wx.EXPAND, border=5)
        self.SetSizer(v_sizer)
        self.add_button.Bind(wx.EVT_BUTTON,self.onAdd)

    def onAdd(self, event):
        self.new_w = NewWindow(self)
        self.new_w.Show()


class MyPopupMenu(wx.Menu):

    def __init__(self,parent, item):
        super(MyPopupMenu,self).__init__()
        self.parent = parent
        self.item = item
        menuEdit = wx.MenuItem(self,wx.NewId(), 'edit %s' % item.GetText())
        self.AppendItem(menuEdit)
        self.Bind(wx.EVT_MENU, self.onEdit, menuEdit)
        menuDel = wx.MenuItem(self,wx.NewId(), 'delete %s' % item.GetText())
        self.AppendItem(menuDel)
        self.Bind(wx.EVT_MENU, self.OnDelete, menuDel)

    def onEdit(self,e):
        self.parent.parent.edit_w = NewWindow(self.parent.parent)
        self.parent.parent.edit_w.Show()

    def OnDelete(self,e):
        self.parent.DeleteAllItems()


class MyListCtrl(wx.ListCtrl):
    def __init__(self, parent, columns):
        wx.ListCtrl.__init__(self, parent, style=wx.LC_REPORT)
        self.parent = parent
        self.R_MOUSE = 0
        self.InsertColumn(0, "name")
        self.InsertColumn(1, "phone")
        self.InsertColumn(2, "address")
        self.SetColumnWidth(0, 200)
        self.Bind(wx.EVT_LIST_ITEM_SELECTED, self.OnSelect)
        self.Bind(wx.EVT_LIST_ITEM_RIGHT_CLICK, self.onRightClick)

        self.itemDataMap = {}
        self.refresh_list()

    def onRightClick(self,evt):
        pos = evt.GetPosition()
        self.PopupMenu(MyPopupMenu(self, self.itemSel), pos)

    def refresh_list(self):
        self.DeleteAllItems()
        for entry in DATA.items():
            self.Append(entry[1])
            self.SetItemData(entry[0],entry[0])

    def OnSelect(self, event):
        index = event.GetIndex()
        self.itemSel = self.GetItem(itemId=index)

class NewWindow(wx.Frame):

    def __init__(self, parent):
        wx.Frame.__init__(self, parent, size=(400,250), style=wx.DEFAULT_FRAME_STYLE)
        self.parent = parent
        self.CenterOnParent()
        panel = wx.Panel(self)

    def onClick(self,event):
        self.Close()

if __name__ == "__main__":
    app = MyApp()
    app.MainLoop()

You should popup the menu in another event handler for EVT_LIST_ITEM_RIGHT_CLICK
Try following code:

import wx

DATA = {
    0 : (u"Test2", "123456", ),
    1 : (u"Test", "123456",),
    2 : (u"doe", "156789", ),
    3 : (u"John", "13455", )
}

class MyApp(wx.App):

    def OnInit(self):
        frame = MyFrame(None)
        frame.Show()
        self.SetTopWindow(frame)
        return True


class MyFrame(wx.Frame):

    def __init__(self, parent):
        wx.Frame.__init__(self, parent, wx.NewId(), size=(500, -1))
        wx.Frame.CenterOnScreen(self)
        self.panel = MyPanel(self)


class MyPanel(wx.Panel):

    def __init__(self, parent):
        wx.Panel.__init__(self, parent)
        self.list = MyListCtrl(self,3)
        self.add_button = wx.Button(self, label="add")
        h_sizer = wx.BoxSizer(wx.HORIZONTAL)
        h_sizer.Add(self.add_button, proportion=1, flag=wx.ALL, border=5)
        v_sizer = wx.BoxSizer(wx.VERTICAL)
        v_sizer.Add(h_sizer, proportion=0, flag=wx.EXPAND)
        v_sizer.Add(self.list, proportion=1, flag=wx.EXPAND, border=5)
        self.SetSizer(v_sizer)
        self.add_button.Bind(wx.EVT_BUTTON,self.onAdd)

    def onAdd(self, event):
        self.new_w = NewWindow(self)
        self.new_w.Show()


class MyPopupMenu(wx.Menu):

    def __init__(self,parent, item):
        super(MyPopupMenu,self).__init__()
        self.parent = parent
        self.item = item
        menuEdit = wx.MenuItem(self,wx.NewId(), 'edit %s' % item.GetText())
        self.AppendItem(menuEdit)
        self.Bind(wx.EVT_MENU, self.onEdit, menuEdit)
        menuDel = wx.MenuItem(self,wx.NewId(), 'delete %s' % item.GetText())
        self.AppendItem(menuDel)
        self.Bind(wx.EVT_MENU, self.OnDelete, menuDel)

    def onEdit(self,e):
        self.parent.parent.edit_w = NewWindow(self.parent.parent)
        self.parent.parent.edit_w.Show()

    def OnDelete(self,e):
        self.parent.DeleteAllItems()


class MyListCtrl(wx.ListCtrl):
    def __init__(self, parent, columns):
        wx.ListCtrl.__init__(self, parent, style=wx.LC_REPORT)
        self.parent = parent
        self.R_MOUSE = 0
        self.InsertColumn(0, "name")
        self.InsertColumn(1, "phone")
        self.InsertColumn(2, "address")
        self.SetColumnWidth(0, 200)
        self.Bind(wx.EVT_LIST_ITEM_SELECTED, self.OnSelect)
        self.Bind(wx.EVT_LIST_ITEM_RIGHT_CLICK, self.onRightClick)

        self.itemDataMap = {}
        self.refresh_list()

    def onRightClick(self,evt):
        pos = evt.GetPosition()
        self.PopupMenu(MyPopupMenu(self, self.itemSel), pos)

    def refresh_list(self):
        self.DeleteAllItems()
        for entry in DATA.items():
            self.Append(entry[1])
            self.SetItemData(entry[0],entry[0])

    def OnSelect(self, event):
        index = event.GetIndex()
        self.itemSel = self.GetItem(itemId=index)

class NewWindow(wx.Frame):

    def __init__(self, parent):
        wx.Frame.__init__(self, parent, size=(400,250), style=wx.DEFAULT_FRAME_STYLE)
        self.parent = parent
        self.CenterOnParent()
        panel = wx.Panel(self)

    def onClick(self,event):
        self.Close()

if __name__ == "__main__":
    app = MyApp()
    app.MainLoop()
2014-02-01

相关问答

更多

没有关于自动化应用程序中的DevExpress控件的信息(No information about DevExpress controls in automation app)

White是Microsoft UI自动化框架的包装器。 因此,它在AutomationElemement的属性上使用Condition ,以便找到适当的元素。 UISpy基本上是UIA'看到'的视觉反映。 没有其他“低级”属性。 遗憾的是,许多开发人员和控制供应商并未注意为AutomationID或Name属性设置唯一且具有指示性的值,因此很难获得所需的元素。 我能给你的最好的解决方案是创建一个直接与UIA协同工作的辅助方法,而不是White,这使你可以更灵活地搜索你的控件。 例如,如果你有一个 ...

Angular 2 Form“无法找到路径控制”(Angular 2 Form “Cannot find control with path”)

应该在html窗体&你的组件文件中映射formControlName。 <div *ngFor="let list_item of [0,1,2]; let i=index" class="panel panel-default"> {{i + 1}}.) <input type="text" formControlName='{{i}}' placeholder="List Item" class="form-control"> </div> ============ list_item ...

必须是/xxx/xxx以上或/xxx/xxx.xxx的正则表达式

你好,你试试下面这个正则是否满足你的需要呢: var reg = /(\/[a-z]+){2,}(\.[a-z]+)?/; var testStr1 = '/xxx'; // 不满足两个"/xxx"以上 var testStr2 = '/xxx/xxx'; var testStr3 = '/xxx/xxx/yyy/zzz.abc'; // 测试结果 testStr1.match(reg); // null testStr2.match(reg); // ["/xxx/xxx", "/xxx", . ...

Ajax请求列表中的特定项(Ajax request for a specific item in a list)

您可以将客户传递给ng-click指令,如下所示: <a href="#expand-offices" ng-click="expand(customer)">+</a> 然后在控制器中创建一个扩展功能,以客户为输入。 像这样的东西: $scope.expand = function(customer){ //fetch the customer }; You can pass the customer to the ng-click directive like so: <a h ...

使用上下文菜单条创建运行时自定义控件列表项单击事件(creating a List of Custom Controls at run-time using the context menu strip Item Click Event)

您正在使用的MousePosition将位于屏幕坐标中,因此您需要将它们转换为Form的坐标: node.Location = PointToClient(MousePosition); 请注意,菜单单击事件触发时将看到的MousePosition将是单击菜单项时鼠标的位置,而不是右键单击以打开上下文菜单时的位置。 其他几条评论: 不要在click事件中创建一个新的nodeTree - 这将删除前一个树,并且计数永远不会超过1.在构造函数或定义类成员的行中创建它。 不要为“node”或“loca ...

为什么python列表理解控制循环嵌套在当前形式中?(Why are python list comprehension control loops nested in their current form? [duplicate])

首先要看的是PEP 202:列表理解 。 在PEP中,BDFL(Guido van Rossum)宣称: 形式[... for x... for y...]嵌套,最后一个索引变化最快,就像嵌套for循环一样。 但这并没有告诉我们原因 。 Guido van Rossum在“ 从列表理解到发生器表达式的Python历史”中告诉我们 在Python 2.0中添加了列表推导。 这个功能起源于格雷格·尤因(Greg Ewing)的一系列补丁,由Skip Montanaro和Thomas Wouters提供 ...

FindControl找不到控件(FindControl doesn't find control)

您找不到BoundField因为它不是真正的控件。 你必须使用row.Cells[index].Text : outputString.Add(row.Cells[1].Text); You cannot find a BoundField since it's not a real control. You have to use row.Cells[index].Text: outputString.Add(row.Cells[1].Text);

使用linq返回对象的特定属性列表(Return list of specific property of object using linq)

var list = stockItems.Select(item => item.StockID).ToList(); var list = stockItems.Select(item => item.StockID).ToList();

相关文章

更多

最新问答

更多
  • Android宽度:100%修复(网站接管问题)(Android width:100% fix (website takeover issue))
  • C ++函数/方法设计的良好实践(Good practice in C++ function/method design)
  • 计算其他表中不存在的所有记录 - SQL查询(Count all records that does not exist to other table - SQL Query)
  • 为什么我要用JPA共享ID?(Why do I get shared Ids with JPA?)
  • asp.net - 如何显示来自html格式的数据行的字段(asp.net - how to display a field from data row that is in html format)
  • 我们如何使用ActiveRecord从连接表中删除行?(How can we delete rows from a join table by using ActiveRecord?)
  • ng-class搞乱了类的顺序(ng-class messing with the order of classes)
  • oracle 12g无效数字错误(oracle 12g invalid number error)
  • 更改ng-src值onclick(Change ng-src value onclick)
  • 如何在android中自动添加自定义依赖项以创建新项目?(How to add custom dependencies automatically in android for ever a new project is created?)
  • datetime函数在PHP中(datetime function in php)
  • 在javascript中获取会话数组的值(in javascript get the value of a session array)
  • 如何在UTF8中编译LaTeX?(How can I compile LaTeX in UTF8? [closed])
  • Rspec:“array.should == another_array”,但不用担心订单(Rspec: “array.should == another_array” but without concern for order)
  • Logcat错误:无法在android片段中加载视图(Logcat error: unable to load view in android fragments)
  • JavaFX的。(JavaFX. Adding items to the list in different threads is not working)
  • 从GDATA日历资源迁移到Google Calendar Resource api(Migrate from GDATA calendar resource to Google Calendar Resource api)
  • SSRS 2008 - 以零情景处理分割(SSRS 2008 - Dealing with division by zero scenarios)
  • 我如何以编程方式添加一个listView列标题的点击事件(How can I add a listView column header a click event programmatically)
  • Wxpython:无法检索有关列表控件项XXX的信息(Wxpython: Couldn't retrieve information about list control item XXX)
  • 使用Tortoise SVN在SVN存储库中移动目录(Move Directory across SVN repository using Tortoise SVN)
  • 天蓝色服务结构集群中的web api无状态服务是否在一段时间不活动后进入休眠状态?(Do web api stateless services in azure service fabric cluster go to sleep after a period of inactivity?)
  • 我可以设置intelliJ来突出显示PHP编码风格吗?(Can I set intelliJ to highlight php coding style?)
  • 用javafx创建一个Truetype字体文件(Creating a Truetype Font file with javafx)
  • Spring ftp配置错误(Spring ftp configuration is wrong)
  • 使用gsub去除多个字符(Using gsub to strip multiple characters)
  • 续订推送证书并保持当前的App Store App正常工作(Renew Push certificate and keep current App Store App working)
  • js:ES5和ES6之间关于'this'关键字用法的一个令人困惑的观点(js: one confusing point about 'this' keyword usage between ES5 and ES6)
  • window.onload vs $(document).ready()(window.onload vs $(document).ready())
  • 在Swift中,如何声明一个符合一个或多个协议的特定类型的变量?(In Swift, how can I declare a variable of a specific type that conforms to one or more protocols?)