tags:

views:

266

answers:

1

bear with me, I've been using wxPython for all of one day now.

Short version is, given a reference to a grid.PyGridCellEditor and a string, how can I implement a paste function?

This is in the body of a large block of existing code that tries to handle pasting entire rows in a Grid widget, and this block is the special case where the cell edit control is visible and there's just a plain text string on the clipboard. I can replace the whole cell with what is on the clipboard but I want bona fide paste -- either insert the text at the insertion cursor or replace the selected text.

The block of code I have looks something like this:

def paste(self):
    clipboard = <get contents from the clipboard>
    ....
    if self.IsCellEditControlShown:
        # just do a normal paste here
        celleditor = self.GetCellEditor(row,col)
        <what goes here?>
A: 

I've answered my own question since nobody else is stepping up to the plate. The solution goes something like this:

if self.isCellEditControlShown:
    # _active_row and _active_col are set in the event handler...
    cellEditor = self.GetCellEditor(self._active_row, self._active_col)
    textControl = cellEditor.GetControl()
    textControl.Paste()

That doesn't precisely answer my original question which included having a string in a variable, but in my case that string came from the clipboard in the first place. If I truly wanted to paste an arbitrary string I can just put it on the clipboard before calling Paste()

Bryan Oakley