代码之家  ›  专栏  ›  技术社区  ›  Bryan Oakley

wxPython:如何在网格单元中实现粘贴?

  •  1
  • Bryan Oakley  · 技术社区  · 15 年前

    请容忍我,我已经使用wxPython一整天了。

    简短的版本是,给定对grid.PyGridCellEditor的引用和字符串,如何实现粘贴函数?

    我的代码块如下所示:

    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 回复  |  直到 15 年前
        1
  •  3
  •   Bryan Oakley    15 年前

    我已经回答了我自己的问题,因为没有其他人站出来。解决方案如下所示:

    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()
    

    这并不能准确地回答我最初的问题,其中包括在变量中包含字符串,但在我的例子中,字符串首先来自剪贴板。如果我真的想粘贴任意字符串,我可以在调用paste()之前将其放在剪贴板上