copy to clipboard

"[email protected]" <[email protected]> Mon, 27 Dec 2021 14:14:58 -0800 (PST)
Newsgroups gmane.comp.python.wxpython
Message-ID <[email protected]>
------=_Part_2910_260610179.1640643298732
Content-Type: multipart/alternative; 
	boundary="----=_Part_2911_699633283.1640643298732"

------=_Part_2911_699633283.1640643298732
Content-Type: text/plain; charset="UTF-8"

 

probably been asked before, but I can't seem to find a solution, getting an 
error after repeatedly Ctrl-c using clipboard, pasted resulting message box 
into notepad and get
[Window Title]
Shop Error

[Content]
Failed to put data on the clipboard (error -2147221040: OpenClipboard 
Failed)

[OK]

also happens using the following example code 

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

using Python 3.6.8 
4.1.0 msw (phoenix) wxWidgets 3.1.4
windows 10


thanks in advance.

Johnny

-- 
You received this message because you are subscribed to the Google Groups "wxPython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
To view this discussion on the web visit https://groups.google.com/d/msgid/wxpython-users/e6ebab3f-a4c4-47d3-baad-c9b3b3b6ca9dn%40googlegroups.com.

------=_Part_2911_699633283.1640643298732
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable




=09
	<span></span>
=09
=09

<p>
probably been asked before, but I can't seem to find a solution, getting an=
 error
after repeatedly Ctrl-c using clipboard, pasted resulting message box
into notepad and get</p><div>[Window Title]<br>Shop Error<br><br>[Content]<=
br>Failed to put data on the clipboard (error -2147221040: OpenClipboard Fa=
iled)<br><br>[OK]</div><div><br></div><div>also happens using the following=
 example code&nbsp;</div><div><br></div><div>
<span><span><span>import</span> wx

<span>#####################################################################=
###</span>
<span>class</span> <span>ClipboardPanel</span>(wx.Panel):
    <span>""""""</span>

    <span>#----------------------------------------------------------------=
------</span>
    <span>def</span> __init__(self, parent):
        <span>"""Constructor"""</span>
        wx.Panel.__init__(self, parent)

        lbl =3D wx.StaticText(self, label=3D<span>"Enter text to copy to cl=
ipboard:"</span>)
        self.text =3D wx.TextCtrl(self, style=3Dwx.TE_MULTILINE)
        copyBtn =3D wx.Button(self, label=3D<span>"Copy"</span>)
        copyBtn.Bind(wx.EVT_BUTTON, self.onCopy)
        copyFlushBtn =3D wx.Button(self, label=3D<span>"Copy and Flush"</sp=
an>)
        copyFlushBtn.Bind(wx.EVT_BUTTON, self.onCopyAndFlush)

        sizer =3D wx.BoxSizer(wx.VERTICAL)
        sizer.Add(lbl, <span>0</span>, wx.ALL, <span>5</span>)
        sizer.Add(self.text, <span>1</span>, wx.EXPAND)
        sizer.Add(copyBtn, <span>0</span>, wx.ALL|wx.CENTER, <span>5</span>=
)
        sizer.Add(copyFlushBtn, <span>0</span>, wx.ALL|wx.CENTER, <span>5</=
span>)
        self.SetSizer(sizer)

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

    <span>#----------------------------------------------------------------=
------</span>
    <span>def</span> <span>onCopyAndFlush</span>(<span>self, event</span>):
        <span>""""""</span>
        self.dataObj =3D wx.TextDataObject()
        self.dataObj.SetText(self.text.GetValue())
        <span>if</span> wx.TheClipboard.Open():
            wx.TheClipboard.SetData(self.dataObj)
            wx.TheClipboard.Flush()
        <span>else</span>:
            wx.MessageBox(<span>"Unable to open the clipboard"</span>, <spa=
n>"Error"</span>)

        self.GetParent().Close()

<span>#####################################################################=
###</span>
<span>class</span> <span>ClipboardFrame</span>(wx.Frame):
    <span>""""""</span>

    <span>#----------------------------------------------------------------=
------</span>
    <span>def</span> __init__(self):
        <span>"""Constructor"""</span>
        wx.Frame.__init__(self, <span>None</span>, title=3D<span>"Clipboard=
 Tutorial"</span>)
        panel =3D ClipboardPanel(self)
        self.Show()


<span>if</span> __name__ =3D=3D <span>"__main__"</span>:
    app =3D wx.App(<span>False</span>)
    frame =3D ClipboardFrame()
    app.MainLoop()</span></span>

</div><div><br></div><div>using Python 3.6.8 <br></div><div>4.1.0 msw (phoe=
nix) wxWidgets 3.1.4</div><div>windows 10</div><div><br></div><div><br></di=
v><div>thanks in advance.</div><div><br></div><div>Johnny<br></div>

<p></p>

-- <br />
You received this message because you are subscribed to the Google Groups &=
quot;wxPython-users&quot; group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:[email protected]">wxpy=
[email protected]</a>.<br />
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/d/msgid/wxpython-users/e6ebab3f-a4c4-47d3-baad-c9b3b3b6ca9dn%40googlegro=
ups.com?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.com/d=
/msgid/wxpython-users/e6ebab3f-a4c4-47d3-baad-c9b3b3b6ca9dn%40googlegroups.=
com</a>.<br />

------=_Part_2911_699633283.1640643298732--

------=_Part_2910_260610179.1640643298732--