[wxPython] Clipboard problem?

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

[wxPython] Clipboard problem?

Lars Marius Garshol

I'm using the new wxPython 2.1.11 under Win98 and found that the
following Python script does not seem to change the clipboard at all:


  from wxPython.wx import *

  if wxTheClipboard.Open():
    wxTheClipboard.SetData(wxTextDataObject("Hei"))
    wxTheClipboard.Close()
  else:
    print "Couldn't open"


It doesn't print the error message, just completes quietly, but as far
as I can tell with no effect at all.

Is it a bug or have I misunderstood something?

--Lars M.


_______________________________________________
wxPython-users maillist  -  [hidden email]
http://starship.python.net/mailman/listinfo/wxpython-users



Reply | Threaded
Open this post in threaded view
|

Re: [wxPython] Clipboard problem?

Robin Dunn
>
> I'm using the new wxPython 2.1.11 under Win98 and found that the
> following Python script does not seem to change the clipboard at all:
>
>
>   from wxPython.wx import *
>
>   if wxTheClipboard.Open():
>     wxTheClipboard.SetData(wxTextDataObject("Hei"))
>     wxTheClipboard.Close()
>   else:
>     print "Couldn't open"
>
>
> It doesn't print the error message, just completes quietly, but as far
> as I can tell with no effect at all.
>
> Is it a bug or have I misunderstood something?
>

Putting something in the clipboard deosn't actually copy the data and put it
there, it just tells the clipboard where to find the data (in your data
object.)  For this reason the data object needs to live a long time so it
will still be around when some other app requests the data.

One way to do this is to associate the data object with the window that is
putting it in the clipboard:


    def OnCopy(self, event):
        if wxTheClipboard.Open():
        self.do = wxTextDataObject("Hei")
        wxTheClipboard.SetData(self.do)
        wxTheClipboard.Close()
    else:
        print "Couldn't open"


--
Robin Dunn
Software Craftsman
[hidden email]
http://AllDunn.com/robin/
http://AllDunn.com/wxPython/  Check it out!





_______________________________________________
wxPython-users maillist  -  [hidden email]
http://starship.python.net/mailman/listinfo/wxpython-users



Reply | Threaded
Open this post in threaded view
|

Re: [wxPython] Clipboard problem?

Robin Becker-7
In article <004001bf4266$83f85290$[hidden email]>, Robin Dunn
<[hidden email]> writes

>Putting something in the clipboard deosn't actually copy the data and put it
>there, it just tells the clipboard where to find the data (in your data
>object.)  For this reason the data object needs to live a long time so it
>will still be around when some other app requests the data.
>
>One way to do this is to associate the data object with the window that is
>putting it in the clipboard:
>
>
>    def OnCopy(self, event):
>        if wxTheClipboard.Open():
>        self.do = wxTextDataObject("Hei")
>        wxTheClipboard.SetData(self.do)
>        wxTheClipboard.Close()
>    else:
>        print "Couldn't open"
>
...

how does win32 leave stuff actually in the clipboard? Some apps seem
able to die and the clipboard remains valid.
--
Robin Becker

_______________________________________________
wxPython-users maillist  -  [hidden email]
http://starship.python.net/mailman/listinfo/wxpython-users



Reply | Threaded
Open this post in threaded view
|

Re: [wxPython] Clipboard problem?

Lars Marius Garshol
In reply to this post by Robin Dunn

* Robin Dunn
|
| Putting something in the clipboard deosn't actually copy the data
| and put it there, it just tells the clipboard where to find the data
| (in your data object.)  For this reason the data object needs to
| live a long time so it will still be around when some other app
| requests the data.
|
| One way to do this is to associate the data object with the window
| that is putting it in the clipboard:

Aha! Thanks, this solved the problem, and I've now got it working.

--Lars M.


_______________________________________________
wxPython-users maillist  -  [hidden email]
http://starship.python.net/mailman/listinfo/wxpython-users



Reply | Threaded
Open this post in threaded view
|

Re: [wxPython] Clipboard problem?

Robin Dunn
In reply to this post by Robin Becker-7
>
> how does win32 leave stuff actually in the clipboard? Some apps seem
> able to die and the clipboard remains valid.

There is a method of wxClipboard that doesn't seem to be documented.  It's
Flush() and it basically sets a flag that the data the clipboard refers to
will not be deleted upon exit of the application.  Please note however that
this memory will likely be leaked permanently because the code to free the
memory will be gone when the applicaiton exits.  This is why many windows
apps always ask you when they exit if you want to leave a large amount of
data in the clipboard or not.

--
Robin Dunn
Software Craftsman
[hidden email]
http://AllDunn.com/robin/
http://AllDunn.com/wxPython/  Check it out!



_______________________________________________
wxPython-users maillist  -  [hidden email]
http://starship.python.net/mailman/listinfo/wxpython-users