Re: Creating custom widget in Perl



On 02/22/01 dLux wrote:
| $ perl -MGtk=-init -e 'print UNIVERSAL::can("Gtk::Button","new"),
| "\n"' CODE(0x815775c)

In my version, it returns still undef! I use the CVS version of
gnome-perl. I am now downloading the debian package of 0.7005.

Again, are you sure you call Gtk->init()? What version of Gtk-Perl
are you using?

| register_subtype() is a method in the Gtk::Object package, it will
| register a new object type within the Gtk type system.

Why do I need to register my widget to the hierarchy? Isn't @ISA enough
for it? I cannot find similar function in GTK+.

Well, in Gtk+ it's called gtk_type_unique()...
There can be two different derivation strategies:
1) your class simply derives from a Gtk class (you create
a new perl class, but not a new Gtk type). In this case
simply setting @ISA is sufficent.
2) your class is also a new Gtk type (you usually need this only if you
want additional args or signals). You need to register_subtype()
and also set @ISA accordingly.

| GTK_OBJECT_INIT?() is used for object-specific initialization and gets
| called for every object you create in that package.

Why we don't use "new" for it? Why it is better?

You can create objects using Gtk::widget::new() directly,
bypassing your constructor. GTK_OBJECT_INIT() is always called,
whatever constructor you call. It is more useful in C where
the programmer is used to make silly assumtions at object creation time,
but it can be occasionally usefult in perl as well.

What advantages are the Gtk-style data handling over the perl hash
keys? Why use Gtk args, if I have a hash reference, where I can
store everything about this widget? What internal Gtk thing wants to
access this?

TMTOWTDI. A future GUI builder will be able to query your
widget for properties for example in a stabdard way an present the
user a property-editor dialog box. My gspeech module could
use your widget's properties to present to the blind user more
information about the state of the widget without having to know
in detail how the widget works and in what language it was implemented...
There are tons of other reason for using args (in the next version
of gtk, you'll also get a property change notification system for free...).

lupus

-- 
-----------------------------------------------------------------
lupus debian org                                     debian/rules
lupus ximian com                             Monkeys do it better




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