Formatted Text and the Clipboard

Hi all,

I'm working on passing formatted text through the Clipboard between the
RichTextCtrl and other programs.

On Windows, it's easy enough. I create a Custom Data Format using:

wx.CustomDataFormat('Rich Text Format')

and I can use this to pass Rich Text Format strings between my program and
Word using my PyRTFParser. I've got it working great on Windows and will be
sharing the code as soon as I get a couple of problems cleared up, probably
in the next couple of days.

But this approach doesn't work on OS X. Well, it works between my
RichTextCtrl-derived control and my RichTextCtrl-derived control, but it
doesn't work between my control and other programs like Word for OS X or
TextEdit. They don't seem to use the "Rich Text Format" custom data string
on OS X like they do on Windows. (That would just be too easy.)

I admit, I lucked into finding the right process on Windows, and my
Google-fu has failed me for OS X.

I see two ways to proceed from here.

One possibility is that I just need the right wx.CustomDataFormat string.
Does anyone know what wx.CustomDataFormat would let me transfer RTF data
through the Clipboard on OS X?

The second possibility is that I can figure it out if I can just query the
Clipboard correctly. Does anyone know how I can ask the Clipboard what data
formats it knows? I can't find any appropriate methods in the
wx.TheClipboard object or in any of the wx.DataFormat and wx.DataObject
objects I've looked at. I hope I'm just being thick and am missing
something obvious. wx.TheClipboard.IsSupported() requires a KNOWN format,
and says my custom data format isn't supported unless I populated the
Clipboard from one of my own controls on OS X. If the Clipboard can just
tell me what data formats it contains, I can figure out which one has RTF
data in it, but I can't figure out how to ask the clipboard that question.

Any suggestions or hints would be greatly appreciated. Thanks in advance,

David K. Woods, Ph.D.
Researcher, Transana Lead Developer
Wisconsin Center for Education Research
University of Wisconsin, Madison
http://www.transana.org

A tool like this one may help:

     http://download.cnet.com/Pasteboard-Inspector/3000-2247_4-54643.html

It looks like "public.rtf" may be what you want, however I don't know if the wx.CustomDataFormat string names are used directly with the OSX system like they are on Windows...

···

On 11/30/10 3:08 PM, David Woods wrote:

Hi all,

I'm working on passing formatted text through the Clipboard between the
RichTextCtrl and other programs.

On Windows, it's easy enough. I create a Custom Data Format using:

wx.CustomDataFormat('Rich Text Format')

and I can use this to pass Rich Text Format strings between my program and
Word using my PyRTFParser. I've got it working great on Windows and will be
sharing the code as soon as I get a couple of problems cleared up, probably
in the next couple of days.

But this approach doesn't work on OS X. Well, it works between my
RichTextCtrl-derived control and my RichTextCtrl-derived control, but it
doesn't work between my control and other programs like Word for OS X or
TextEdit. They don't seem to use the "Rich Text Format" custom data string
on OS X like they do on Windows. (That would just be too easy.)

I admit, I lucked into finding the right process on Windows, and my
Google-fu has failed me for OS X.

I see two ways to proceed from here.

One possibility is that I just need the right wx.CustomDataFormat string.
Does anyone know what wx.CustomDataFormat would let me transfer RTF data
through the Clipboard on OS X?

The second possibility is that I can figure it out if I can just query the
Clipboard correctly. Does anyone know how I can ask the Clipboard what data
formats it knows? I can't find any appropriate methods in the
wx.TheClipboard object or in any of the wx.DataFormat and wx.DataObject
objects I've looked at. I hope I'm just being thick and am missing
something obvious. wx.TheClipboard.IsSupported() requires a KNOWN format,
and says my custom data format isn't supported unless I populated the
Clipboard from one of my own controls on OS X. If the Clipboard can just
tell me what data formats it contains, I can figure out which one has RTF
data in it, but I can't figure out how to ask the clipboard that question.

Any suggestions or hints would be greatly appreciated. Thanks in advance,

--
Robin Dunn
Software Craftsman
http://wxPython.org

> Hi all,
>
> I'm working on passing formatted text through the Clipboard between
> the RichTextCtrl and other programs.
>
> On Windows, it's easy enough. I create a Custom Data Format using:
>
> wx.CustomDataFormat('Rich Text Format')
>
> and I can use this to pass Rich Text Format strings between
my program
> and Word using my PyRTFParser. I've got it working great
on Windows
> and will be sharing the code as soon as I get a couple of problems
> cleared up, probably in the next couple of days.
>
> But this approach doesn't work on OS X. Well, it works between my
> RichTextCtrl-derived control and my RichTextCtrl-derived
control, but
> it doesn't work between my control and other programs like
Word for OS
> X or TextEdit. They don't seem to use the "Rich Text
Format" custom
> data string on OS X like they do on Windows. (That would
just be too
> easy.)
>
> I admit, I lucked into finding the right process on Windows, and my
> Google-fu has failed me for OS X.
>
> I see two ways to proceed from here.
>
> One possibility is that I just need the right wx.CustomDataFormat
> string. Does anyone know what wx.CustomDataFormat would let me
> transfer RTF data through the Clipboard on OS X?
>
> The second possibility is that I can figure it out if I can
just query
> the Clipboard correctly. Does anyone know how I can ask
the Clipboard
> what data formats it knows? I can't find any appropriate
methods in
> the wx.TheClipboard object or in any of the wx.DataFormat and
> wx.DataObject objects I've looked at. I hope I'm just
being thick and
> am missing something obvious.
wx.TheClipboard.IsSupported() requires
> a KNOWN format, and says my custom data format isn't
supported unless
> I populated the Clipboard from one of my own controls on OS
X. If the
> Clipboard can just tell me what data formats it contains, I
can figure
> out which one has RTF data in it, but I can't figure out how to ask
> the clipboard that question.
>
> Any suggestions or hints would be greatly appreciated. Thanks in
> advance,

A tool like this one may help:

http://download.cnet.com/Pasteboard-Inspector/3000-2247_4-54643.html

It looks like "public.rtf" may be what you want, however I
don't know
if the wx.CustomDataFormat string names are used directly
with the OSX
system like they are on Windows...

Robin,

I'd found a similar tool on Windows, which was how I'd figured things out
there, but hadn't stumbled across one for OS X. The Pasteboard Inspector
was just what I needed.

"public.rtf" works perfectly as text passed to the wx.CustomDataFormat. I
can now pass formatted text between my RichTextCtrl and Word and TextEdit on
OS X. Yay.

I'll update my PyRTFParser and post here when it's ready.

Thank you so much for your help.

David

Wow, this is very good news! David, just to be clear, when you say “between” RTC and Word and such, is that bi-directional (paste formatting into RTC from Word / paste formatting into Word from RTC)? I’m assuming that’s what you mean. And do you know if it could potentially paste images as well, or just formatted text? (I know, I know, asking for a lot there).

Thanks so much for these important contributions to RTC.

Che

···

On Wed, Dec 1, 2010 at 11:08 AM, David transana@gmail.com wrote:

Hi all,

I’m working on passing formatted text through the Clipboard between

the RichTextCtrl and other programs.

On Windows, it’s easy enough. I create a Custom Data Format using:

wx.CustomDataFormat(‘Rich Text Format’)

and I can use this to pass Rich Text Format strings between

my program

and Word using my PyRTFParser. I’ve got it working great

on Windows

and will be sharing the code as soon as I get a couple of problems

cleared up, probably in the next couple of days.

But this approach doesn’t work on OS X. Well, it works between my

RichTextCtrl-derived control and my RichTextCtrl-derived

control, but

it doesn’t work between my control and other programs like

Word for OS

X or TextEdit. They don’t seem to use the "Rich Text

Format" custom

data string on OS X like they do on Windows. (That would

just be too

easy.)

I admit, I lucked into finding the right process on Windows, and my

Google-fu has failed me for OS X.

I see two ways to proceed from here.

One possibility is that I just need the right wx.CustomDataFormat

string. Does anyone know what wx.CustomDataFormat would let me

transfer RTF data through the Clipboard on OS X?

The second possibility is that I can figure it out if I can

just query

the Clipboard correctly. Does anyone know how I can ask

the Clipboard

what data formats it knows? I can’t find any appropriate

methods in

the wx.TheClipboard object or in any of the wx.DataFormat and

wx.DataObject objects I’ve looked at. I hope I’m just

being thick and

am missing something obvious.

wx.TheClipboard.IsSupported() requires

a KNOWN format, and says my custom data format isn’t

supported unless

I populated the Clipboard from one of my own controls on OS

X. If the

Clipboard can just tell me what data formats it contains, I

can figure

out which one has RTF data in it, but I can’t figure out how to ask

the clipboard that question.

Any suggestions or hints would be greatly appreciated. Thanks in

advance,

A tool like this one may help:

http://download.cnet.com/Pasteboard-Inspector/3000-2247_4-54643.html

It looks like “public.rtf” may be what you want, however I

don’t know

if the wx.CustomDataFormat string names are used directly

with the OSX

system like they are on Windows…

Robin,

I’d found a similar tool on Windows, which was how I’d figured things out

there, but hadn’t stumbled across one for OS X. The Pasteboard Inspector

was just what I needed.

“public.rtf” works perfectly as text passed to the wx.CustomDataFormat. I

can now pass formatted text between my RichTextCtrl and Word and TextEdit on

OS X. Yay.

I’ll update my PyRTFParser and post here when it’s ready.

Message

···

Hi all,

I’m working on passing formatted text through the Clipboard between
the RichTextCtrl and other programs.

On Windows, it’s easy enough. I create a Custom Data Format using:

wx.CustomDataFormat(‘Rich Text Format’)

and I can use this to pass Rich Text Format strings between
my program
and Word using my PyRTFParser. I’ve got it working great
on Windows
and will be sharing the code as soon as I get a couple of problems
cleared up, probably in the next couple of days.

But this approach doesn’t work on OS X. Well, it works between my
RichTextCtrl-derived control and my RichTextCtrl-derived
control, but
it doesn’t work between my control and other programs like
Word for OS
X or TextEdit. They don’t seem to use the “Rich Text
Format” custom
data string on OS X like they do on Windows. (That would
just be too
easy.)

I admit, I lucked into finding the right process on Windows, and my
Google-fu has failed me for OS X.

I see two ways to proceed from here.

One possibility is that I just need the right wx.CustomDataFormat
string. Does anyone know what wx.CustomDataFormat would let me
transfer RTF data through the Clipboard on OS X?

The second possibility is that I can figure it out if I can
just query
the Clipboard correctly. Does anyone know how I can ask
the Clipboard
what data formats it knows? I can’t find any appropriate
methods in
the wx.TheClipboard object or in any of the wx.DataFormat and
wx.DataObject objects I’ve looked at. I hope I’m just
being thick and
am missing something obvious.
wx.TheClipboard.IsSupported() requires
a KNOWN format, and says my custom data format isn’t
supported unless
I populated the Clipboard from one of my own controls on OS
X. If the
Clipboard can just tell me what data formats it contains, I
can figure
out which one has RTF data in it, but I can’t figure out how to ask
the clipboard that question.

Any suggestions or hints would be greatly appreciated. Thanks in
advance,

A tool like this one may help:

http://download.cnet.com/Pasteboard-Inspector/3000-2247_4-54643.html

It looks like “public.rtf” may be what you want, however I
don’t know
if the wx.CustomDataFormat string names are used directly
with the OSX
system like they are on Windows…

Robin,

I'd found a similar tool on Windows, which was how I'd figured things out
there, but hadn't stumbled across one for OS X.  The Pasteboard Inspector
was just what I needed.

"public.rtf" works perfectly as text passed to the wx.CustomDataFormat.  I
can now pass formatted text between my RichTextCtrl and Word and TextEdit on

OS X. Yay.

I'll update my PyRTFParser and post here when it's ready.

Wow, this is very good news! David, just to be clear, when you say “between” RTC and Word and such, is that bi-directional (paste formatting into RTC from Word / paste formatting into Word from RTC)? I’m assuming that’s what you mean. And do you know if it could potentially paste images as well, or just formatted text? (I know, I know, asking for a lot there).

Thanks so much for these important contributions to RTC.   

Che,

Yes, the transfer is bi-directional. And yes, embedded images are transfered. So are unicode characters like Chinese text (at least to the extent I’m able to test as a monolingual American) and hyperlinks.

Style sheets aren’t supported at all, and numbered and bulleted lists aren’t supported yet between RTC and other programs. I haven’t tried what I’ve written on Linux, or with Open Office.

Or at least that’s what it looks like so far. I just got it working yesterday on Windows and this morning on OS X (thanks, Robin), and I haven’t had a chance to test it much. For example, I’ve only transfered images from my RTC to Word and back, but haven’t tried images imported into Word yet. Work keeps getting in the way. You know how that goes.

As an interested party, would you be willing to do a bit of testing for me? If so, contact me off-list (dwoods at wcer dot wisc dot edu) and I’ll send you the files and demo app I’m working on.

David

As promised, I've made my PyRTFParser, including code showing how to use it
to do RTF-formatted text transfer through the clipboard, available at
http://www.transana.org/developers/PyRTFParser . I hope some of you find it
useful.

David K. Woods, Ph.D.
Researcher, Transana Lead Developer
Wisconsin Center for Education Research
University of Wisconsin, Madison
http://www.transana.org

···

On 11/30/10 3:08 PM, David Woods wrote:
> Hi all,
>
> I'm working on passing formatted text through the Clipboard between
> the RichTextCtrl and other programs.
>
> On Windows, it's easy enough. I create a Custom Data Format using:
>
> wx.CustomDataFormat('Rich Text Format')
>
> and I can use this to pass Rich Text Format strings between
my program
> and Word using my PyRTFParser. I've got it working great
on Windows
> and will be sharing the code as soon as I get a couple of problems
> cleared up, probably in the next couple of days.
>
> But this approach doesn't work on OS X. Well, it works between my
> RichTextCtrl-derived control and my RichTextCtrl-derived
control, but
> it doesn't work between my control and other programs like
Word for OS
> X or TextEdit. They don't seem to use the "Rich Text
Format" custom
> data string on OS X like they do on Windows. (That would
just be too
> easy.)
>
> I admit, I lucked into finding the right process on Windows, and my
> Google-fu has failed me for OS X.
>
> I see two ways to proceed from here.
>
> One possibility is that I just need the right wx.CustomDataFormat
> string. Does anyone know what wx.CustomDataFormat would let me
> transfer RTF data through the Clipboard on OS X?
>
> The second possibility is that I can figure it out if I can
just query
> the Clipboard correctly. Does anyone know how I can ask
the Clipboard
> what data formats it knows? I can't find any appropriate
methods in
> the wx.TheClipboard object or in any of the wx.DataFormat and
> wx.DataObject objects I've looked at. I hope I'm just
being thick and
> am missing something obvious.
wx.TheClipboard.IsSupported() requires
> a KNOWN format, and says my custom data format isn't
supported unless
> I populated the Clipboard from one of my own controls on OS
X. If the
> Clipboard can just tell me what data formats it contains, I
can figure
> out which one has RTF data in it, but I can't figure out how to ask
> the clipboard that question.
>
> Any suggestions or hints would be greatly appreciated. Thanks in
> advance,

A tool like this one may help:

http://download.cnet.com/Pasteboard-Inspector/3000-2247_4-54643.html

It looks like "public.rtf" may be what you want, however I
don't know
if the wx.CustomDataFormat string names are used directly
with the OSX
system like they are on Windows...