Re: newbie question: clipboard



On Mon, Jun 02, 2003 at 04:34:26PM +0100, Bruno Tavares wrote:
I am using gtk 1.2 and cant find a way to copy some text to the
clipboard (when the widget is not an editable).

Can you help me?

You don't say what type of widget but I'm going to assume a Gtk::Text
widget. I have the following method attached to a 'copy' button in one
of my apps. 

sub copy_to_clipboard {
  my $self = shift;
  my $text = $self->{_window}->{text};
                                                                                
  # nothing to do
  return unless ($text->get_length());
                                                                                
  if ($text->has_selection) {
    $text->copy_clipboard();
  } else {
    $text->freeze;
    $text->select_region(0, -1);
    $text->copy_clipboard();
    $text->select_region(0, 0);
    $text->thaw();
  }
                                                                                
  return 1;
}

-- 
Scott Russell <lnxgeek us ibm com>
IBM Linux Technology Center, System Admin

Attachment: pgpQFBR__UNKo.pgp
Description: PGP signature



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]