Hi all,

I am writing a Perl/Tk application for Gnome, and would like to use the clipboard to move files between my app and the Gnome file manager. One way is easy: inspecting the clipboard, as set by Gnome.
But setting the clipboard so that Gnome can use it, I have not managed.

Here is my demo program:

#!/opt/perl/bin/perl -w use Tk; use strict; my $mw = 'MainWindow'->new(); my $tb = $mw->Frame->pack( -fill => 'x' ); $tb->Button( -text => "GET CLIPBOARD", -command => \&get_clipboard )->pack( -side => 'left' ); $tb->Button( -text => "SET CLIPBOARD", -command => \&set_clipboard )->pack( -side => 'left' ); MainLoop(); sub get_clipboard { print "\n"; my $own = $mw->SelectionExists( -selection => 'CLIPBOARD' ); if( $own ) { printf "Owner of CLIPBOARD is 0x%x\n",$own; eval { my @targ = $mw->SelectionGet( -selection => 'CLIPBOARD', 'TARGETS' ); for my $targ ( @targ ) { my @t = $mw->SelectionGet( -selection => 'CLIPBOARD', $targ ); local $" = ', '; print "$targ => [ @t ]\n"; } }; my $e = $@; if( $e ) { print $e; } } } sub set_clipboard { print "\n"; $mw->SelectionOwn( -selection => 'CLIPBOARD' ); $mw->SelectionHandle( -selection => 'CLIPBOARD', -type => 'MULTIPLE', -format => 'INTEGER', sub { return ( 325, 323, 324, 462 ) } ); my $file = "/home/philou/Desktop/gtkperl-tutorial.ps"; $mw->SelectionHandle( -selection => 'CLIPBOARD', -type => 'x-special/gnome-copied-files', sub { return "copy\nfile://$file" } ); $mw->SelectionHandle( -selection => 'CLIPBOARD', -type => 'UTF8_STRING', sub { return "file://$file\n" } ); }

get_clipboard works alright, but how to write set_clipboard is a mystery to me. I guess I need to understand what is exactly the 'MULTIPLE' target, and how to set it, and other things too.
Do someone has an idea to do that properly ?

Thanks,

Philippe

In reply to Copy files to Perl/Tk clipboard by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.