RE: [gtk-list] Re: Perl/Gtk: how to get the data from a Gtk::Lis
- From: Kenneth Albanowski <kjahds kjahds com>
- To: tile primenet com
- cc: gtk-list redhat com
- Subject: RE: [gtk-list] Re: Perl/Gtk: how to get the data from a Gtk::Lis
- Date: Wed, 15 Apr 1998 01:20:04 -0400 (EDT)
On Tue, 14 Apr 1998 tile@primenet.com wrote:
> Efficient but it goes against convention. It's like using public data in C++
> or gotos in C. Say the key he chooses to store data in becomes an important
> part of the list module... he would have to go through his entire program and
> replace all occurances he uses the key to retrieve the data. One big mess
> that could easily have been avoided early on.
Since this is the first time the subject has ever come up, we can make
decisions now to prevent various glitches. For one thing, none of the Perl
interfaces currently store data in the the Perl shadow object (other than
in some underscored utility slots, like '_gtk'), so it's perfectly safe to
store data there. All access to Gtk data is via methods. It's possible
this will change, but I don't expect it to happen.
I'm a bit puzzled by your general statement on this issue, as I really
can't think of any other sensible way of doing this -- in _any_ GUI
environment, not just Gtk. You've basically got three options to deal with
list items: store data in some slot in the list items themselves, use the
list index directly into an external array, or iterate over the labels of
the list items. That last is relatively tedious in Gtk, since lists don't
hold strings directly, and is less useful if you aren't just picking
strings.
Gtk itself certainly seems to encourage the slot approach, what with the
user_data and object_data mechanism. (It's best to consider the perl hash
access as the direct eqivalent of this, since object_data isn't easy to
support directly in Perl as the data isn't typed.)
> For his purposes it is the most portable and logical way to go about this
> without going against convention.
Fair enough: I just wanted to point out a feature of PerlGtk that isn't
terribly obvious.
> You do make a good point about attaching other types of data onto the
> list items. Even though you would lose portability to other languages,
> i don't see why it wouldn't be possible to build such a thing into
> Perl/Gtk and legitimize it.
It's already there. :-)
The exact same thing can be done from C, using object_data (and I'd be
surprised if people haven't already figured this out.)
I'll admit that Perl hash values aren't terribly easy to access from C
code, although it's certainly not impossible (just some hooks into the
PerlGtk hooks).
If object_data had types, it would be quite simple to hook it up in Perl,
as well.
--
Kenneth Albanowski (kjahds@kjahds.com, CIS: 70705,126)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]