[Date Prev][Date Next] [Thread Prev][Thread Next]
[Thread Index]
[Date Index]
[Author Index]
Re: gtk priority constants
- From: Torsten Schoenfeld <kaffeetisch gmx de>
- To: gtk-perl-list gnome org
- Subject: Re: gtk priority constants
- Date: Wed, 16 Jan 2008 20:40:06 +0100
On Mon, 2007-12-31 at 08:44 +1100, Kevin Ryde wrote:
> I wonder if the GTK_PRIORITY_RESIZE, GDK_PRIORITY_REDRAW and
> GDK_PRIORITY_EVENTS constants could be offered within perl, perhaps per
> below. They can be good for putting idle or i/o stuff in at levels just
> above or below what gtk will be doing (the redraw is the only one I've
> got an immediate interest in :).
Yeah, having those constants would be good. Unfortunately, our handling
of constants in Gtk2 is a mess. Many constants aren't available at all,
some are wrapped as class methods (like Gtk2::Gdk->TARGET_STRING), some
as class functions (like Gtk2::Gdk::CHARS), and others have their own
small export-only module file (Gtk2/pm/Pango.pm aka. Gtk2::Pango).
So, one way to add new constants would be what you did: add them as
class functions to the respective namespace. That doesn't make them
importable though. For them to be importable, we'd have to add some
Exporter code like we have in Glib. We'd also have to add another small
module file for the GDK_ constants in the Gtk2::Gdk namespace.
Another way might be to put all GTK_, GDK_, and PANGO_ constants we want
right into the Gtk2 namespace and make them importable from there. The
attached patch is a stab at this approach.
So, what's the best way to make those constants available? Where do
people look for them?
--
Bye,
-Torsten
Index: Gtk2.pm
===================================================================
RCS file: /cvsroot/gtk2-perl/gtk2-perl-xs/Gtk2/Gtk2.pm,v
retrieving revision 1.116
diff -u -d -p -r1.116 Gtk2.pm
--- Gtk2.pm 9 Jan 2008 21:55:05 -0000 1.116
+++ Gtk2.pm 16 Jan 2008 19:39:46 -0000
@@ -34,11 +34,26 @@ use Glib;
# gtk+ and pango.
eval "use Cairo;";
+use Exporter;
require DynaLoader;
our $VERSION = '1.172';
-our @ISA = qw(DynaLoader);
+our @ISA = qw(DynaLoader Exporter);
+
+use constant {
+ GDK_PRIORITY_EVENTS => Glib::G_PRIORITY_DEFAULT,
+ GDK_PRIORITY_REDRAW => Glib::G_PRIORITY_HIGH_IDLE + 20,
+ GTK_PRIORITY_RESIZE => Glib::G_PRIORITY_HIGH_IDLE + 10
+};
+
+our %EXPORT_TAGS = (
+ constants => [qw/GDK_PRIORITY_EVENTS
+ GDK_PRIORITY_REDRAW
+ GTK_PRIORITY_RESIZE/],
+);
+our @EXPORT_OK = map { @$_ } values %EXPORT_TAGS;
+$EXPORT_TAGS{all} = \ EXPORT_OK;
sub import {
my $class = shift;
@@ -50,18 +65,23 @@ sub import {
my $init = 0;
my $threads_init = 0;
+ my @unknown_args = ($class);
foreach (@_) {
if (/^-?init$/) {
$init = 1;
} elsif (/-?threads-init$/) {
$threads_init = 1;
} else {
- $class->VERSION ($_);
+ push @unknown_args, $_;
}
}
Gtk2::Gdk::Threads->init if ($threads_init);
Gtk2->init if ($init);
+
+ # call into Exporter for the unrecognized arguments; handles exporting
+ # and version checking
+ Gtk2->export_to_level (1, @unknown_args);
}
# this is critical -- tell dynaloader to load the module so that its
@@ -270,6 +290,22 @@ called, if done by "use Gtk2 -init -thre
=back
+=head1 EXPORTS
+
+Gtk2 exports nothing by default, but some constants are available upon request.
+
+=over
+
+=item Tag: constants
+
+ GTK_PRIORITY_RESIZE
+ GDK_PRIORITY_EVENTS
+ GDK_PRIORITY_REDRAW
+
+=back
+
+See L<Glib> for other standard priority levels.
+
=head1 SEE ALSO
L<perl>(1), L<Glib>(3pm).
Index: t/00.Gtk2.t
===================================================================
RCS file: /cvsroot/gtk2-perl/gtk2-perl-xs/Gtk2/t/00.Gtk2.t,v
retrieving revision 1.21
diff -u -d -p -r1.21 00.Gtk2.t
--- t/00.Gtk2.t 14 May 2006 10:57:07 -0000 1.21
+++ t/00.Gtk2.t 16 Jan 2008 19:39:46 -0000
@@ -14,8 +14,8 @@ use warnings;
# NOTE: this is the bootstrap test -- no Gtk2::TestHelper here!
-use Test::More tests => 35;
-BEGIN { use_ok('Gtk2') };
+use Test::More tests => 41;
+BEGIN { use_ok('Gtk2', ':constants') };
#########################
@@ -43,6 +43,14 @@ is (@version, 3, 'version info is three
ok (Gtk2::Pango->CHECK_VERSION(0,0,0), 'CHECK_VERSION pass');
ok (!Gtk2::Pango->CHECK_VERSION(50,0,0), 'CHECK_VERSION fail');
+my $number = qr/^\d+$/;
+like (Gtk2::GTK_PRIORITY_RESIZE, $number);
+like (Gtk2::GDK_PRIORITY_EVENTS, $number);
+like (Gtk2::GDK_PRIORITY_REDRAW, $number);
+like (GTK_PRIORITY_RESIZE, $number);
+like (GDK_PRIORITY_EVENTS, $number);
+like (GDK_PRIORITY_REDRAW, $number);
+
SKIP:
{
Gtk2->disable_setlocale;
Index: t/version-checks.t
===================================================================
RCS file: t/version-checks.t
diff -N t/version-checks.t
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ t/version-checks.t 16 Jan 2008 19:39:46 -0000
@@ -0,0 +1,15 @@
+#!/usr/bin/perl
+use strict;
+use warnings;
+use Test::More tests => 2;
+
+eval "use Gtk2 ':constants', 1.00;";
+is ($@, '');
+
+eval "use Gtk2 -init, 10.00;";
+like ($@, qr/this is only version/);
+
+__END__
+
+Copyright (C) 2008 by the gtk2-perl team (see the file AUTHORS for the
+full list). See LICENSE for more information.
[Date Prev][Date Next] [Thread Prev][Thread Next]
[Thread Index]
[Date Index]
[Author Index]