WxPython: how to implement paste in a grid cell?

bear with me, i have been using wxPython in just one day.

Short version, given the grid.PyGridCellEditor reference and rows, how can I implement the insert function?

This is in the body of a large block of existing code that tries to handle inserting entire rows into the Grid widget, and this block is a special case when the cell edit control is visible and there is only a text line on the text line. clipboard. I can replace the entire cell with whatever is on the clipboard, but I want bona fide paste - either paste the text into the insertion point, or replace the selected text.

The block of code I have now 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?>

      

+1


a source to share


1 answer


I answered my own question because no one else comes to the plate. The solution looks 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()

      



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

+3


a source







All Articles