Re: Some general questions on gtk2, gnome2 + perl
- From: zentara <zentara1 sbcglobal net>
- To: gtk-perl-list gnome org
- Subject: Re: Some general questions on gtk2, gnome2 + perl
- Date: Tue, 6 Feb 2007 08:05:12 -0500
On Tue, 6 Feb 2007 10:43:42 +0100
"January Weiner" <january weiner gmail com> wrote:
I am considering switching a moderately large project (12 k lines)
from perl-tk to perl-gtk. For the start, I have few questions:
1) where can I find a tutorial on handling selections, i.e. getting
the X selection buffer contents into my program? I do not need
anything fancy. I have found the following doc:
http://gtk2-perl.sourceforge.net/doc/pod/Gtk2/Clipboard.html
but I can't make heads or tails out of it.
Yeah it's tricky. Here is a simple example ( a full example by muppet at bottom of post)
#!/usr/bin/perl
use warnings;
use strict;
use Gtk2 'init';
#my $clipboard = Gtk2::Clipboard->get_for_display(
# Gtk2::Gdk::Display->open($ENV{'DISPLAY'}),
# Gtk2::Gdk::Atom->new('GDK_SELECTION_CLIPBOARD'));
#to paste menu
my $clipboard = Gtk2::Clipboard->get(Gtk2::Gdk->SELECTION_CLIPBOARD);
#to mouse
my $clipboard1 = Gtk2::Clipboard->get(Gtk2::Gdk->SELECTION_PRIMARY);
my $time = time();
print "$time\n";
$clipboard->clear;
$clipboard1->clear;
$clipboard->set_text($time);
$clipboard1->set_text($time);
#need the mainloop
Gtk2->main;
__END__
2) is there an easy method of exporting the gnome2 canvas widget to
postscript or pdf? Something like canvas->postscript() from perl/tk
would be great
No. You can easily grab a screenshot of the visible canvas area, and
I worked out a clunky way of grabbing the entire scrolled canvas, see
http://perlmonks.org?node_id=582317
3) is there any tutorial / example set for gnome2 canvas in perl? I
can only find some api references, but I would need something easier
to start with.
The problem is that the Gnome2::Canvas's development has been frozen,
and not being worked on anymore. It dosn't mean the canvas won't work,
but it is being left behind. There are replacements coming, which are better,
most noticeably the Papyrus canvas, but it dosn't have a Perl port yet.
The best source of examples, is the canvas_demo which comes
with the Perl module. It contains examples of how to do almost
everything. It will teach you alot, to split the demo sections, into
individual scripts.
My observations of comparing the Gnome2::Canvas to the Tk canvas.
1. No tags in Gtk2, you need to make and keep track of your own.
2. No dashed lines in Gtk2.
3. Gtk2 has alpha transparency, and cool "per-pixel-scaling" which means
you can scale nicely, although text won't scale.
So there are pros and cons to it.
#####################################################################
Here is muppet's clipboard demo.
#!/usr/bin/perl
# by muppet on gtk2-perl maillist
use warnings;
use strict;
use Gtk2 -init;
use Glib qw(FALSE TRUE);
my $window = Gtk2::Window->new;
$window->set_size_request(500,200);
$window->signal_connect( destroy => sub { Gtk2->main_quit } );
my $textview = Gtk2::TextView->new;
$textview->set_editable(TRUE);
$textview->get_buffer->create_tag( 'tt', family => 'Monospace' );
#$textview->signal_connect(
# paste_clipboard => sub {
# my ($view) = @_;
#
# # the paste-clipboard signal is emitted by the keybindings for
# # pasting from the clipboard selection.
# do_paste( $view, Gtk2::Gdk->SELECTION_PRIMARY );
# }
#);
$textview->signal_connect(
button_press_event => sub {
my ( $view, $event ) = @_;
if ( $event->button == 2 ) {
# middle mouse buttons paste from the primary selection.
do_paste( $view, Gtk2::Gdk->SELECTION_PRIMARY );
}
return FALSE;
}
);
my $scroller = Gtk2::ScrolledWindow->new;
$scroller->add($textview);
$window->add($scroller);
$window->show_all;
Gtk2->main;
sub do_paste {
my ( $view, $atom ) = @_;
my $clipboard = $view->get_clipboard($atom);
# if you wanted to insert the text, you could do it like this...
#$view->get_buffer->paste_clipboard ($clipboard, undef, TRUE);
# or, we'll do something else.
# wait_for_text requests the contents of the clipboard as a string,
# and runs a main loop to wait for the server to return it.
# that means stuff can happen before this call finishes.
my $text = $clipboard->wait_for_text;
# and now we get fancy just because it's fun.
my $buffer = $view->get_buffer;
# $buffer->delete( $buffer->get_bounds );
# $buffer->insert( $buffer->get_end_iter, "User wants to paste\n" );
$buffer->insert_with_tags_by_name( $buffer->get_end_iter, $text, 'tt' );
# $buffer->insert(
# $buffer->get_end_iter,
# "\nBut we're read-only, so we ain't gonna let
#him."
# );
}
__END__
zentara
--
I'm not really a human, but I play one on earth.
http://zentara.net/japh.html
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]