pure-perl widgets, PangoLayout, etc



just made a big commit to gtk2-perl-xs with quite a bit of new features.

PangoContext and PangoLayout are now implemented, along with
$widget->create_pango_layout.

many functions from gdk.h are now implemented, including screen_width,
beep, pointer_grab, keyboard_grab, etc.

and as a really cool feature, it is now possible to create true widgets
with pure perl code.  why do you need this?  if you want to create new
signals to add to a new object you created in perl, to add object
properties, to be treated by the C libraries as a real and distinct
gtype, etc.  it's also really easy:

  # create a new package, just like creating a perl class.
  package MyObject;

  # create a new G::Object-derived type for this package.
  # note that we pass the parent class to this function, along
  # with the name of the current class.  this sets up the @ISA
  # entry for us!  note that if the package name has colons in
  # it, they will be mapped to underscores when actually calling
  # g_type_register.  in general, this shouldn't make a bit of
  # difference to you, but you may see that name in error messages.
  G::Type->register ("MyParent", __PACKAGE__);

  # like the standard DESTROY method called when an object is
  # being destroyed, there are a few more methods that a new
  # G::Object derivative will look for...
  sub INSTANCE_INIT {
          my $self = shift;

          # unfortunately, due to the use of a scalar reference
          # as the object representation, it's not as trivial to
          # store data as you might wish.  we store it in the
          # GObject data keys.  i like to use one hash.
          $self->set_data (data => { ... });
  }

  # not yet implemented are
  #   CLASS_INIT
  #   GET_PROPERTY
  #   SET_PROPERTY

  # the destructor is like always, but there's not usually much to do.
  sub DESTROY { }

  # and now you need a way to create one of these...
  sub new {
          my $class;
          # if it's strictly a G::Object subclass, you can do
          my $gobject = G::Object->_new ($class);
          # if it's a Gtk::Object derivative, 
          my $self = Gtk2::Object->new ($class);
          # or to be clearer that you're creating a widget
          my $self = Gtk2::Widget->new ($class);

          # any extra setup...
          return $self;
  }


there's a new example program, Gtk2/examples/histogramplot.pl, which
demonstrates using drawing primitives and drawing text with PangoLayouts
in a new widget class descended from GtkDrawingArea.  it's pretty nifty,
check it out.

comments and suggestions on all this stuff are most welcome.



note: creating and adding to your class new signals and properties it
not implemented yet.  stay tuned.

-- 
muppet <scott at asofyet dot org>




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