使用虚拟ListCtrl复制并粘贴wxpython中的行 [英] Copy and paste rows in wxpython using a virtual ListCtrl

查看:582
本文介绍了使用虚拟ListCtrl复制并粘贴wxpython中的行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在wxpython中使用虚拟的ListCtrl。我试图从列表中选择几行,然后将行值复制/粘贴到文本文件或可能的电子表格中。
如何将选定的行复制到剪贴板(使用CTRL-C)?我应该绑定哪个事件?
谢谢!

解决方案

看一下列表控件的wxPython演示,我想你必须做点什么如下所示:

  index = self.list.GetFirstSelected()
value =%s:%s\\ \\ n%(self.list.GetItemText(index),self.getColumnText(index,1)))

如果要使用CTRL-C,则需要使用AcceleratorTable,这意味着您将绑定到EVT_MENU,并将该提到的代码放在该处理程序中。以下是wx中的Accerators教程: http:// www.blog.pythonlibrary.org/2010/12/02/wxpython-keyboard-shortcuts-accelerators/



另一方面,我几乎总是使用ObjectListView而不是ListCtrl,因为它给我一个每行的对象模型,我发现比使用行和列索引更容易访问。它采取一种稍微不同的方法和心态,但我认为这是值得的: http://www.blog.pythonlibrary.org/2009/12/23/wxpython-using-objectlistview-instead-of-a-listctrl/


I'm using a virtual ListCtrl in wxpython. I am trying to select several rows from the list and then copy / paste the row value to a text file, or possibly spreadsheet. How would I copy the selected rows to clipboard (using CTRL-C)? Which event should I bind? Thanks!

解决方案

Looking at the wxPython demo for the list control, I think you'd have to do something like the following:

index = self.list.GetFirstSelected()
value = "      %s: %s\n" % (self.list.GetItemText(index), self.getColumnText(index, 1)))

You would need to use an AcceleratorTable if you want to use CTRL-C, which means that you'd bind to EVT_MENU and put the code I mentioned in that handler. Here's a tutorial on Accerators in wx: http://www.blog.pythonlibrary.org/2010/12/02/wxpython-keyboard-shortcuts-accelerators/

On the other hand, I almost always use ObjectListView instead of ListCtrl as it gives me an object model of each row which I find a lot easier to access than using row and column indexes. It takes a slightly different approach and mindset, but I think it's worth it: http://www.blog.pythonlibrary.org/2009/12/23/wxpython-using-objectlistview-instead-of-a-listctrl/

这篇关于使用虚拟ListCtrl复制并粘贴wxpython中的行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆