Re: need your help for Gtk3 and Moose
[email protected] (Shlomi Fish) Tue, 13 May 2014 09:41:39 +0300
| Newsgroups | perl.moose |
|---|---|
| Message-ID | <[email protected]> |
Hi Tsuyoshi, On Tue, 13 May 2014 15:02:18 +0900 tsuyoshi okita <[email protected]> wrote: > Dear, > > I am a newbie to Moose. > I have been trying to use Moose for Gtk3, and I do not think Moose is > happy with Builder. > After Moose load ui file, has 'root_window' tries to get main_window > object, and it seems this is where the problem gets generated. > I've attached a patch to fix the problem. With it, the program runs fine her. Note that I removed some isa => ... specifiers because I thought they were the problem, but I don't think they were necessary. The main change was adding sanity checks (Which are also not necessary) and converting an attribute to "lazy => 1" so it will be initialised in the right time. Hope it works fine for you. Regards, Shlomi Fish -- ----------------------------------------------------------------- Shlomi Fish http://www.shlomifish.org/ Optimising Code for Speed - http://shlom.in/optimise Q: I’ll be about 6.5 milliard Terran years next September. — http://www.shlomifish.org/humour/Star-Trek/We-the-Living-Dead/ Please reply to list if it's a mailing list post - http://shlom.in/reply .
gtk3_moose.diff
(text/x-patch, 1.3 KB)
diff -u -r ORIG/gtk3_moose_with_builder.pl NEW/gtk3_moose_with_builder.pl
--- ORIG/gtk3_moose_with_builder.pl 2014-05-13 09:33:48.941813572 +0300
+++ NEW/gtk3_moose_with_builder.pl 2014-05-13 09:38:19.203687439 +0300
@@ -38,9 +38,19 @@
);
has 'builder' => (
is => 'rw',
- isa => 'Gtk3::Builder',
+ lazy => 1,
+ # isa => 'Gtk3::Builder',
default => sub {
- return Gtk3::Builder->new;
+ my ( $self ) = @_;
+ my $ret = Gtk3::Builder->new;
+
+ if (!defined($ret)) {
+ die "Cannot init Gtk3::Builder";
+ }
+ $ret->add_from_file($self->ui_file);
+ $ret->connect_signals(undef);
+
+ return $ret;
},
trigger => sub {
my ( $self ) = @_;
@@ -53,7 +63,7 @@
#--------------------
# I believe this is causing the problem.
#--------------------
- isa => 'GObject',
+ # isa => 'GObject',
#isa => 'Gtk3::Object',
lazy_build => 1,
trigger => sub {
@@ -63,10 +73,17 @@
);
sub _build_root_window {
my ( $self ) = @_;
+
#--------------------
# I believe this is causing the problem.
#--------------------
- return $self->builder->get_object('toplevel');
+ my $ret = $self->builder->get_object('toplevel');
+
+ if (!defined($ret)) {
+ die "Could not get toplevel object.";
+ }
+
+ return $ret;
}
sub quit_app {
Gtk3->main_quit;
Only in NEW/: gtk3_moose_with_builder.pl~