使用虚拟ListCtrl复制并粘贴wxpython中的行 [英] Copy and paste rows in wxpython using a virtual 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屋!