[perl-Gtk3] Add overrides for various button constructors
- From: Torsten SchÃnfeld <tsch src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [perl-Gtk3] Add overrides for various button constructors
- Date: Fri, 25 Jan 2013 19:29:27 +0000 (UTC)
commit 4713cb5c510dd3da7c0ed0d1fe570c66849bb1e6
Author: Torsten SchÃnfeld <kaffeetisch gmx de>
Date: Fri Jan 25 20:29:01 2013 +0100
Add overrides for various button constructors
NEWS | 1 +
lib/Gtk3.pm | 35 ++++++++++++++++++++++++++++-------
t/overrides.t | 52 +++++++++++++++++++++++++++++++++++++++++++++++++++-
3 files changed, 80 insertions(+), 8 deletions(-)
---
diff --git a/NEWS b/NEWS
index f4d2402..254977b 100644
--- a/NEWS
+++ b/NEWS
@@ -8,6 +8,7 @@
* Add overrides for Gtk3::RecentChooserDialog.
* Add overrides for Gtk3::TextBuffer.
* Add an override for Gtk3::main_level.
+* Add overrides for various button constructors.
* Add overrides for Gtk3::Gdk::RGBA.
* Add Gtk3::EVENT_PROPAGATE and Gtk3::EVENT_STOP.
* In Gtk3::TreeModel::get, if no columns are specified, use all columns.
diff --git a/lib/Gtk3.pm b/lib/Gtk3.pm
index 5697cbb..d299e24 100644
--- a/lib/Gtk3.pm
+++ b/lib/Gtk3.pm
@@ -597,13 +597,24 @@ sub Gtk3::Builder::connect_signals {
}
}
-sub Gtk3::Button::new {
- my ($class, $label) = @_;
- if (defined $label) {
- return $class->new_with_mnemonic ($label);
- } else {
- return Glib::Object::Introspection->invoke (
- $_GTK_BASENAME, 'Button', 'new', @_);
+{
+ no strict 'refs';
+ my @button_classes = ([Button => 'new_with_mnemonic'],
+ [CheckButton => 'new_with_mnemonic'],
+ [ColorButton => 'new_with_color'],
+ [FontButton => 'new_with_font'],
+ [ToggleButton => 'new_with_mnemonic']);
+ foreach my $button_pair (@button_classes) {
+ my ($button_class, $button_ctor) = @$button_pair;
+ *{'Gtk3::' . $button_class . '::new'} = sub {
+ my ($class, $thing) = @_;
+ if (defined $thing) {
+ return $class->$button_ctor ($thing);
+ } else {
+ return Glib::Object::Introspection->invoke (
+ $_GTK_BASENAME, $button_class, 'new', @_);
+ }
+ }
}
}
@@ -797,6 +808,16 @@ sub Gtk3::InfoBar::new_with_buttons {
&Gtk3::InfoBar::new;
}
+sub Gtk3::LinkButton::new {
+ my ($class, $uri, $label) = @_;
+ if (defined $label) {
+ return Gtk3::LinkButton->new_with_label ($uri, $label);
+ } else {
+ return Glib::Object::Introspection->invoke (
+ $_GTK_BASENAME, 'LinkButton', 'new', @_);
+ }
+}
+
sub Gtk3::ListStore::new {
return _common_tree_model_new ('ListStore', @_);
}
diff --git a/t/overrides.t b/t/overrides.t
index 11e5f6d..4900137 100644
--- a/t/overrides.t
+++ b/t/overrides.t
@@ -5,7 +5,7 @@ BEGIN { require './t/inc/setup.pl' };
use strict;
use warnings;
-plan tests => 112;
+plan tests => 123;
# Gtk3::CHECK_VERSION and check_version
{
@@ -44,6 +44,14 @@ plan tests => 112;
ok (1);
}
+# Gtk3::Button::new
+{
+ my $button = Gtk3::Button->new;
+ ok (!defined ($button->get_label));
+ $button = Gtk3::Button->new ('_Test');
+ is ($button->get_label, '_Test');
+}
+
# Gtk3::CellLayout::get_cells
{
my $cell = Gtk3::TreeViewColumn->new;
@@ -55,6 +63,23 @@ plan tests => 112;
is_deeply([$cell->get_cells], [$one, $two]);
}
+# Gtk3::CheckButton::new
+{
+ my $button = Gtk3::CheckButton->new;
+ ok (!defined ($button->get_label));
+ $button = Gtk3::CheckButton->new ('_Test');
+ is ($button->get_label, '_Test');
+}
+
+# Gtk3::ColorButton::new
+{
+ my $button = Gtk3::ColorButton->new;
+ is ($button->get_color->red, 0);
+ my $color = Gtk3::Gdk::Color->new (red => 2**16-1, green => 0, blue => 0);
+ $button = Gtk3::ColorButton->new ($color);
+ is ($button->get_color->red, $color->red);
+}
+
# Gtk3::CssProvider
{
my $css = "GtkButton {font: Cantarelll 10}";
@@ -116,6 +141,23 @@ SKIP: {
is ($dialog->get_action, 'save');
}
+# Gtk3::FontButton::new
+{
+ my $button = Gtk3::FontButton->new;
+ # $button->get_font_name can be anything
+ $button = Gtk3::FontButton->new ('Sans');
+ ok (defined $button->get_font_name);
+}
+
+# Gtk3::LinkButton::new
+{
+ my ($host, $label) = ('http://localhost', 'Local');
+ my $button = Gtk3::LinkButton->new ($host);
+ is ($button->get_label, $host);
+ $button = Gtk3::LinkButton->new ($host, $label);
+ is ($button->get_label, $label);
+}
+
# Gtk3::ListStore::new, set and get
SKIP: {
skip 'tree model ctors not properly supported', 5
@@ -191,6 +233,14 @@ SKIP: {
Gtk3::Stock::set_translate_func ('perl-domain', sub {}, 42);
}
+# Gtk3::ToggleButton::new
+{
+ my $button = Gtk3::ToggleButton->new;
+ ok (!defined ($button->get_label));
+ $button = Gtk3::ToggleButton->new ('_Test');
+ is ($button->get_label, '_Test');
+}
+
# Gtk3::TreeStore::new, set and get
SKIP: {
skip 'tree model ctors not properly supported', 5
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]