wx.Theclipboard

41 views
Skip to first unread message

Nathan smith

unread,
Jan 8, 2024, 7:39:57 AMJan 8
to wxpytho...@googlegroups.com
Hello,


Would someone mind awfully writing me an example script ath shows me how
to copy multiple formats to the clipboard and paste/

What I want to achieve here is:

I have one object that is plane text,

and another object that is bytes.

I want basically to be able to set the clipboard with both formats, then
in the paste function say if the plain text is present, set that to a
variable, if the bytes format is present, use that too.


Thanks in advance,

Nathan

Dietmar Schwertberger

unread,
Jan 8, 2024, 11:48:56 AMJan 8
to wxpytho...@googlegroups.com
On 08.01.2024 13:39, Nathan smith wrote:
> I want basically to be able to set the clipboard with both formats,
> then in the paste function say if the plain text is present, set that
> to a variable, if the bytes format is present, use that too.


You need to use wx.DataObjectComposite.

The code at the top of the documentation page should get you started:
https://docs.wxpython.org/wx.DataObjectComposite.html?highlight=wx%20dataobjectcomposite#wx.DataObjectComposite


Regards,

Dietmar

David Woods

unread,
Jan 8, 2024, 11:56:16 AMJan 8
to wxpytho...@googlegroups.com
Hi Nathan,

Your request is not a small ask, and I don't have time to write
something new and custom and targeted to your specific situation.

If you want an example of using the Clipboard with complex data, take a
look at https://github.com/DKWoods/PyParserDemo, starting with the
PyParserDemo.py file's OnCutCopy() and OnPaste() methods, which handle
transferring formatted text between a wxPython app and a word
processor.  It uses wx.DataObjectComposite() to pass both formatted and
plain text versions of the data being passed through the clipboard.  In
OnPaste(), you can see the code attempt to find formatted text and if
that fails, to use plain text.

To run my code, which demonstrates DOCx and RTF support for the wxPython
RichTextCtrl, you will need to install the python-docx module fork from
my repository as well as wxPython.

Hope that helps.

David

Nathan smith

unread,
Jan 8, 2024, 3:21:40 PMJan 8
to wxpytho...@googlegroups.com, David Woods
Evening David and Dietmar,


thank you both for your responses.

I have now finished reading through the information you  both pointed me
too and can say gladly, goal achieved!


David, apologies if I came across as one of these "waaa, code it for
meeeee!" types, totally was not my intention and what you did was
actually what I was hoping for, a here is how this does it approach, now
you figure it out.


All the best,

Nathan
Reply all
Reply to author
Forward
0 new messages