Re: Both Gtk-perl and Gtk2-perl[-xs]

Pascal said:
Are there any example of an application [written in perl] supporting both
Gtk-1 and Gtk-2 ? I'm wondering how I could integrate both...


there's no way to get gtk+-1.x and gtk+-2.x running together in the same
program.  that's because the C libraries themselves both use the same
namespaces, understandably so, because gtk+-2.x is simply the newest version
of gtk+.  trust me, i've tried it -- if you link to both libglib-1.x and
libglib-2.x, the last-linked one gets called, not the "proper" one, and you
invariably get a segfault.  (this, actually, is the entire reason i got into
what has turned into a six-month rewrite of one of my libraries, and indeed
into rewriting the gtk2-perl bindings!)

now, if you want to have the same perl code support using *either* Gtk-Perl
*or* Gtk2-Perl, then, eh, heh, well, it's *possible*, strictly speaking, but
you'd have to be insane to do it.

here's an example of what it would look like:

#!/usr/bin/perl -w

my $gtk;

if (eval "use Gtk2 -init; 1") {
        warn "Gtk2 is available";
        $gtk = 'Gtk2';
} elsif (eval "use Gtk -init; 1") {
        warn "Gtk is available";
        $gtk = 'Gtk';
} else {
        die "neither Gtk2 nor Gtk is available, can't run!\n";

my $window = "$gtk\::Window"->new ('toplevel');
$window->signal_connect (delete_event => sub { $gtk->main_quit; 1 });
my $vbox = "$gtk\::VBox"->new;
$window->add ($vbox);
$vbox->pack_start ("$gtk\::Label"->new ("using $gtk"), 0, 0, 0);
my $button = "$gtk\::Button"->new ("_Quit");
$vbox->pack_start ($button, 0, 0, 0);
$button->signal_connect (clicked => sub { $gtk->main_quit; });



note that i've stuck with lowest-common-denominator stuff like buttons and
boxes and labels, so i got it to work.  i also used the _ to make a point ---
Gtk+ 1.x doesn't support mnemonics like 2.x.  in a substantial portion of
cases, the various structures that you use as hashes in gtk-perl appear as
opaque objects in gtk2-perl, requiring a lot of search-and-replace porting

and, the biggest drawback --- there are no gtk+ 1.x widgets to replace the
GtkCTree and GtkCList and GtkList[1], all of which have been deprecated in 2.x
and thus don't appear.

so, unless you have only very simple dialog-like stuff to support, you really
don't want to support both versions of the perl bindings from one program.

of course, i suppose you could just code the version-bound stuff behind
version checks, but it's a losing proposition.

[1] technically, GtkList is available so you can use GtkCombo, but you
shouldn't use GtkList, m'kay?

muppet <scott at asofyet dot org>

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