Opened 2 years ago

Closed 2 years ago

#14330 closed defect (duplicate)

Clipboard's flush() method fails in wxPython on linux systems

Reported by: MichaelClerx Owned by:
Priority: normal Milestone:
Component: wxPython Version: 2.8.12
Keywords: clipboard Cc:
Blocked By: Blocking:
Patch: no

Description

Not sure if this is a duplicate of #10515, which is three years old and seems inactive. If so, apologies in advance.

The method wx.TheClipboard.Flush() fails to store data and returns False on Fedora16 using Gnome (and GTK). This was confirmed by a stackexchange user for CentOS but doesn't seem to occur on windows based systems.

The following code snippet reproduces the bug:

import wx

########################################################################
class ClipboardPanel(wx.Panel):
    """"""

    #----------------------------------------------------------------------
    def __init__(self, parent):
        """Constructor"""
        wx.Panel.__init__(self, parent)

        lbl = wx.StaticText(self, label="Enter text to copy to clipboard:")
        self.text = wx.TextCtrl(self, style=wx.TE_MULTILINE)
        copyBtn = wx.Button(self, label="Copy")
        copyBtn.Bind(wx.EVT_BUTTON, self.onCopy)
        copyFlushBtn = wx.Button(self, label="Copy and Flush")
        copyFlushBtn.Bind(wx.EVT_BUTTON, self.onCopyAndFlush)

        sizer = wx.BoxSizer(wx.VERTICAL)
        sizer.Add(lbl, 0, wx.ALL, 5)
        sizer.Add(self.text, 1, wx.EXPAND)
        sizer.Add(copyBtn, 0, wx.ALL|wx.CENTER, 5)
        sizer.Add(copyFlushBtn, 0, wx.ALL|wx.CENTER, 5)
        self.SetSizer(sizer)

    #----------------------------------------------------------------------
    def onCopy(self, event):
        """"""
        self.dataObj = wx.TextDataObject()
        self.dataObj.SetText(self.text.GetValue())
        if wx.TheClipboard.Open():
            wx.TheClipboard.SetData(self.dataObj)
            wx.TheClipboard.Close()
        else:
            wx.MessageBox("Unable to open the clipboard", "Error")

    #----------------------------------------------------------------------
    def onCopyAndFlush(self, event):
        """"""
        self.dataObj = wx.TextDataObject()
        self.dataObj.SetText(self.text.GetValue())
        if wx.TheClipboard.Open():
            wx.TheClipboard.SetData(self.dataObj)
            print wx.TheClipboard.Flush()
        else:
            wx.MessageBox("Unable to open the clipboard", "Error")

        self.GetParent().Close()

########################################################################
class ClipboardFrame(wx.Frame):
    """"""

    #----------------------------------------------------------------------
    def __init__(self):
        """Constructor"""
        wx.Frame.__init__(self, None, title="Clipboard Tutorial")
        panel = ClipboardPanel(self)
        self.Show()


if __name__ == "__main__":
    app = wx.App(False)
    frame = ClipboardFrame()
    app.MainLoop()

Change History (1)

comment:1 Changed 2 years ago by vadz

  • Resolution set to duplicate
  • Status changed from new to closed

Yes, this looks like the same bug. It's inactive because I still don't know how exactly does this stuff work but having two inactive bugs instead of one is not going to help anyhow. Please add yourself to the CC field of the other bug to be notified about any changes to it.

Note: See TracTickets for help on using tickets.