Re: "Label" entries

Hi again,

I did the same for my XML application (xacobeo). I've extracted the code and
released it as a CPAN module Gtk2::Ex::Entry::Pango (see Take a look at the
examples that I've provided with the CPAN bundle.

 Can't you just copy the perl module in your application? The CPAN bundle
has only a single perl module. Otherwise take a look at xacobeo (see it uses glade for the UI and has a
plain simple Gtk::Entry created by glade that's "pimped" to become a
"pangofied" entry just by adding some signal handlers.

Yes. Yes I can. Sorry, this was written after a lot of fnargling of
another (quite horrible) package that refused to install anywhere but
the core libs, so my brain was slightly asleep. It works quite well
(using only set_empty_markup), although I had to change line 430 from:

                        $attributes = Gtk2::Pango::AttrList->new();


                        ($attributes) = Gtk2::Pango->parse_markup('');

because the ye-ancient version of Gtk2 we have installed is obviously
not up to scratch.

It works _almost_ exactly as I want - I'm just going to add in the
bits that hide the empty markup when focus comes in and restores it if
necessary when focus goes out. Turns out there's a little gotcha there
too. This:

use Gtk2 "-init";
use Gtk2::Ex::Entry::Pango;
$m = Gtk2::Window->new;
$e = Gtk2::Ex::Entry::Pango->new;
$e->signal_connect("focus-in-event" => sub
{$e->set_empty_markup("")});  ### HERE!
$e->signal_connect("focus-out-event" => sub
{$e->set_empty_markup("<b>EMPTY</b>") if $e->get_text eq ""});
$f = Gtk2::Entry->new;
$v = Gtk2::VBox->new;

Doesn't update the empty markup until the entry is edited on focus in,
but if you change the ### HERE! line to:

$e->signal_connect("focus-in-event" => sub {$e->set_empty_markup("<b></b>")});

all works fine. I'm guessing the lack of actual pango markup in ""
causes a short-circuit in the code that skips the update until
something else changes.

Otherwise, perfect. Thanks for all the comments in there too - nice to
not have to twist my brain into too many knots to understand it :)


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