Re: GtkImageView




On Dec 23, 2007, at 7:23 PM, Jeffrey Ratcliffe wrote:

On 22/12/2007, muppet <scott asofyet org> wrote:
interactive.pl:  a quick transliteration of gtkimageview/tests/
interactive.c. Note that the way this program uses the GtkImageTransp
values in the UI manager actions doesn't really play nicely with perl
syntax for enums, so there's a terrible, evil, horrible hack in its
place. If you golf this down to more perlish code, using closures and
such, you can sidestep the problem.

Do you mind my including this in an examples directory, attributing you?

I was getting:

No anim!  Can't call method "set_sensitive" on an undefined value at
./examples/interactive.pl line 74.

*** unhandled exception in callback:
***   FATAL: invalid enum GtkImageTransp value 1, expecting: color /
GTK_IMAGE_TRANSP_COLOR, background / GTK_IMAGE_TRANSP_BACKGROUND, grid
/ GTK_IMAGE_TRANSP_GRID at ./examples/interactive.pl line 206.
***  ignoring at ./examples/interactive.pl line 602.

which the attached patch fixes. But I don't see how to do it
differently with a closure. I'd appreciate a hint.

Unfortunately, i misremembered GtkRadioActionEntry as having a closure slot in each item; it does not. You're stuck with an integer value to distinguish them, and in this situation, the integer enumeration value is rather ideal. For perl interoperability this kinda sucks, and you're left doing something like the evil hack i had. Or, you could use random integers and switch instead on the $action->name, which you conveniently set to the enumeration string name / nick, which is also somewhat evil.

Earlier i'd had problems getting the idea of

sub GTK_IMAGE_TRANSP_GRID { get_enum_value ('Gtk2::ImageTransp', 'grid') }

working, and instead hardcoded it to the integer value; i figure out why that is. You need to have the value table in gtkimageviewperl_gtk_image_transp_get_type() be "static" as well as "const". Without this, the value table is on the stack, and the GType registry winds up pointing at stack garbage after the get_type function has returned, eventually causing SIGSEGV crashes. Also, the g_intern_static_string() call isn't really necessary. See enum.patch.




I attempted to clean up the namespace with the second patch, but now
the tests fail:

Now that everything is under the "Gtk2::ImageView" namespace, the "ignore" pattern in the call to Glib::CodeGen::write_boot() is ignoring all of the packages in the module, so nothing actually gets booted correctly. You need to change that so that it ignores *only* the master package (which is needed to avoid an infinite loop at startup -- see the Glib::CodeGen manpage).

Attachment: boot.diff
Description: Binary data



Attachment: enum.patch
Description: Binary data



--
One, two, free, four, five, six, sebben, eight, nine, ten, elebben, twull, fourteen, sickteen, sebbenteen, eightteen, elebbenteen, fiffeen, elebbenteen!
  -- Zella, aged three, counting to twenty.




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