Gtk2-perl shell (problem with GLib-GObject)



Hi all,

I wrote a small Gtk2 shell. The attached code is the gist of it[1]. You can do things like:
 gish> Gtk2::Window->new->add(Gtk2::Button->new('foobar'))->show_all
The idea is that you can create a package App.pm and continuously edit-reload-inspect it by doing:
 gish> do 'App.pm'
 gish> $app=App->new
 ....
 gish> $app->destroy
This is handy enough. The main problem is that objects that have been Glib::Object::Subclass'ed don't work very well.
 1) You cannot reread such a package. Eg 'do LabelledButton.pm' gives:
GLib-GObject-WARNING **: cannot register existing type `LabelledButton' at /usr/lib/perl5/site_perl/5.8.3/i686-linux/Glib/Object/Subclass.pm line 225. 2) The subclassed widget itself does not work correctly ie. after the first 'do' it loads but does not display correctly. It does display correctly when you load modify 'gish' to load the package at startup.

I would really appreciate it if anybody can shine some light on this?

--
remco
[1] I abbrev'ed. it for clarity.
package LabelledButton;

use Glib::Object::Subclass
  Gtk2::Button::,
  signals => { map => \&on_map, },
  ;


sub on_map {
  my $self = shift;
  $self->set('label'=>'Hello World');
  $self->signal_chain_from_overridden;
}
1;

#!/usr/bin/perl
use blib;                       # so we can use 'local' packages
use Glib ':constants';
use Gtk2 -init;
use Term::ReadLine;
#use LabelledButton;            # Uncomment and it works

BEGIN {                         # we need Gnu since this has a callback iface
  die "Need Term::ReadLine::Gnu\n" unless Term::ReadLine->ReadLine =~ /Gnu/;
}; 

package main;
my $term = new Term::ReadLine 'gish';

#handle every complete line
$term->callback_handler_install('gish> ', sub { 
                                  eval($_[0]); $|=1; # flush STDOUT
                                  warn "$@" if $@;
                                  $term->addhistory($_) if /\S/;
                                });
#make Gtk2 mainloop watch STDIN
Glib::IO->add_watch(fileno($term->IN), 'in', 
                    sub { $term->callback_read_char; return TRUE;});
Gtk2->main;

sub p { local $^W=0;  print @_,substr($_[-1],-1) eq "\n" ? '' : "\n"; }


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