# Filling clipboard doesn't work

**URL:** <https://www.ruby-forum.com/t/filling-clipboard-doesnt-work/144257>\
**Category:** wxRuby\
**Created:** [July 27, 2008, 8:06pm UTC](https://www.ruby-forum.com/t/filling-clipboard-doesnt-work/144257 "2008-07-27T20:06:09Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![requiem](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/e9bcb4/32.png) [@requiem](https://www.ruby-forum.com/u/requiem)\
**Post date:** [July 27, 2008, 8:06pm UTC](https://www.ruby-forum.com/t/filling-clipboard-doesnt-work/144257/1 "2008-07-27T20:06:09Z")

</div>

Hello,

I ran into a bit of trouble with my first wxRuby application. I’m using  
ruby 1.8.6 with wxRuby 1.9.7 on x86 Linux (Ubuntu). Didn’t test any  
other platform yet. In my application, I’m trying to access the  
clipboard like this:

Wx::Clipboard.open do |clip|  
clip.set\_data Wx::TextDataObject.new(“TEST”)  
clip.flush  
end

This doesn’t work. While running the app (after the execution of the  
above code), the menu entry “Paste” is enabled in other applications,  
but nothing is in the clipboard (at least nothing happens on pasting).  
After quitting my application, the menu entry is disabled again and the  
clipboard is empty.

How do I access the clip properly?

I still got another question: Is it possible to send key-messages to  
other apps using wxWidgets?

Greeting,  
Niklas B.

---

<div class="post-metadata">

**Author:** ![requiem](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/e9bcb4/32.png) [@requiem](https://www.ruby-forum.com/u/requiem)\
**Post date:** [August 1, 2008, 6:09am UTC](https://www.ruby-forum.com/t/filling-clipboard-doesnt-work/144257/2 "2008-08-01T06:09:48Z")

</div>

Hi Niklas

Niklas B. wrote:

> This doesn’t work. While running the app (after the execution of the  
> above code), the menu entry “Paste” is enabled in other applications,  
> but nothing is in the clipboard (at least nothing happens on pasting).  
> After quitting my application, the menu entry is disabled again and the  
> clipboard is empty.
> 
> How do I access the clip properly?

This code works fine for me on OS X; both while the app is running and  
after it’s ended the text data is available to other apps via Paste,  
.I’ll try it out on Ubuntu later.

> I still got another question: Is it possible to send key-messages to  
> other apps using wxWidgets?

Not as far as I know, sorry.

alex

---

<div class="post-metadata">

**Author:** ![requiem](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/e9bcb4/32.png) [@requiem](https://www.ruby-forum.com/u/requiem)\
**Post date:** [August 1, 2008, 9:47am UTC](https://www.ruby-forum.com/t/filling-clipboard-doesnt-work/144257/3 "2008-08-01T09:47:58Z")

</div>

Alex F. wrote:

> This code works fine for me on OS X;

I tested it on Windows in the meanwhile and it works aswell. But not  
under Ubuntu Hardy/GTK

> .I’ll try it out on Ubuntu later.

Thanks, that would be very nice!

Greetings,  
Niklas

---

<div class="post-metadata">

**Author:** ![requiem](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/e9bcb4/32.png) [@requiem](https://www.ruby-forum.com/u/requiem)\
**Post date:** [August 15, 2008, 7:41pm UTC](https://www.ruby-forum.com/t/filling-clipboard-doesnt-work/144257/4 "2008-08-15T19:41:27Z")

</div>

Alex F. wrote:

> Niklas B. wrote:
> 
> > I ran into a bit of trouble with my first wxRuby application. I’m using  
> > ruby 1.8.6 with wxRuby 1.9.7 on x86 Linux (Ubuntu). Didn’t test any  
> > other platform yet. In my application, I’m trying to access the  
> > clipboard like this:
> > 
> > Wx::Clipboard.open do |clip|  
> > Does it help to paste to other applications if you add

clip.use\_primary\_selection

here? Looking at the wxWidgets drag’n’drop sample, this is needed under  
X to share with other applications.

> > clip.set\_data Wx::TextDataObject.new(“TEST”)  
> > clip.flush  
> > end
> > 
> > This doesn’t work. While running the app (after the execution of the  
> > above code), the menu entry “Paste” is enabled in other applications,  
> > but nothing is in the clipboard (at least nothing happens on pasting).  
> > After quitting my application, the menu entry is disabled again and the  
> > clipboard is empty.

It might be worth checking if the data is at least available within your  
own application. After doing the set\_data, trying retrieving it with  
something like

Wx::Clipboard.open do | clip |  
data = Wx::TextDataObject.new  
clip.get\_data(data)  
p data.get\_text  
end

> This code works fine for me on OS X; both while the app is running and  
> after it’s ended the text data is available to other apps via Paste,  
> .I’ll try it out on Ubuntu later.  
> I tried it out on Ubuntu and unfortunately I can confirm that neither  
> within-application or inter-application copying via the Clipboard is  
> working for me. However I’m using Ubuntu within a VirtualBox VM at the  
> moment and this has some clipboard integration with the host OS - so I’d  
> like to this out as the source of the problem.

thanks  
alex

---

<div class="post-metadata">

**Author:** ![requiem](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/e9bcb4/32.png) [@requiem](https://www.ruby-forum.com/u/requiem)\
**Post date:** [August 16, 2008, 4:02pm UTC](https://www.ruby-forum.com/t/filling-clipboard-doesnt-work/144257/5 "2008-08-16T16:02:43Z")

</div>

Niklas B. wrote:

> 

OK. Thanks for trying anyway.

> this doesn’t work either, this prints out my old clipboard content (before running the app).  
> is there a way i can help finding the source of this problem?  
> You could try adding Wx::Log.add\_trace\_mask(‘clipboard’) before the  
> Clipboard operations. This may give you some more debugging output. But  
> I tried this already and it all looks in order - the formats are matched  
> etc. It’s announcing that STRING\_UTF8 and STRING data are available  
> which is correct. Let me know if you see something different.

I spent a few hours trying this under gdb and comparing to the wxWidgets  
dnd sample. My hunch is that it’s something to do with the way the C++  
classes are mapped onto Ruby. wxWidgets uses a pretty complex structure  
of virtual methods in DataObject\* that are hard to translate. For  
example TextDataObject#get\_data\_size always seems to report 0 in wxRuby,  
which seems wrong.

I’ll keep looking into it  
cheers  
alex

---

<div class="post-metadata">

**Author:** ![requiem](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/e9bcb4/32.png) [@requiem](https://www.ruby-forum.com/u/requiem)\
**Post date:** [August 16, 2008, 2:00pm UTC](https://www.ruby-forum.com/t/filling-clipboard-doesnt-work/144257/6 "2008-08-16T14:00:20Z")

</div>

Hello,

Alex F. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Does it help to paste to other applications if you add
> 
> clip.use\_primary\_selection
> 
> here?

unfortunately it does not.

> It might be worth checking if the data is at least available within your  
> own application. After doing the set\_data, trying retrieving it with  
> something like
> 
> Wx::Clipboard.open do | clip |  
> data = Wx::TextDataObject.new  
> clip.get\_data(data)  
> p data.get\_text  
> end

this doesn’t work either, this prints out my old clipboard content  
(before running the app).  
is there a way i can help finding the source of this problem?

Greetings,  
Niklas
