python - wxPython ListCtrl copy to clipboard -
i using listctrl log file viewer can hide "debug" type of columns average user. able select multiple cells can in many other grid-type programs, , right click , "copy", , able paste text doc, email, etc. able select grouping of contiguous cells, rather limited whole rows only.
is there built-in me? how accomplish that? should switch virtual or ultimate listctrl? maybe should using other wxpython class?
a working example:
import wx class frame(wx.frame): def __init__(self): super(frame, self).__init__(none, -1, "list copy test", size=(400, 500)) panel = wx.panel(self, -1) self.listctrl = wx.listctrl(panel, -1, size=(200, 400), style=wx.lc_report) self.listctrl.insertcolumn(0, "column 1", width=180) in xrange(10): self.listctrl.insertstringitem(i, "item %d" % i) self.listctrl.bind(wx.evt_right_up, self.showpopup) def showpopup(self, event): menu = wx.menu() menu.append(1, "copy selected items") menu.bind(wx.evt_menu, self.copyitems, id=1) self.popupmenu(menu) def copyitems(self, event): selecteditems = [] in xrange(self.listctrl.getitemcount()): if self.listctrl.isselected(i): selecteditems.append(self.listctrl.getitemtext(i)) clipdata = wx.textdataobject() clipdata.settext("\n".join(selecteditems)) wx.theclipboard.open() wx.theclipboard.setdata(clipdata) wx.theclipboard.close() print "items on clipboard" app = wx.app(redirect=false) frame = frame() frame.show() app.mainloop()
you mentioned list control, if want select multiple cells, perhaps grid control (excel sheet like) might more suitable. idea still same part list items (or cell items) collected different.
Comments
Post a Comment