Re: "Label" entries





On Fri, May 1, 2009 at 5:37 AM, Matthew Braid <ptkperl mdb id au> wrote:
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
> http://search.cpan.org/perldoc?Gtk2::Ex::Entry::Pango). 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
> http://search.cpan.org/perldoc?Xacobeo) 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
Ouf! I was starting to wonder what I messed up in the installation :)
Â
(using only set_empty_markup), although I had to change line 430 from:

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

to:

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

because the ye-ancient version of Gtk2 we have installed is obviously
not up to scratch.
I will upload the module and take this into account. It's a pity that people with an old version of Gtk2 can't use because of a missing function.
Â
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:
I never though of erasing the default text when the widget has it's focus. I should add this to the widget.

use Gtk2 "-init";
use Gtk2::Ex::Entry::Pango;
$m = Gtk2::Window->new;
$e = Gtk2::Ex::Entry::Pango->new;
$e->set_empty_markup("<b>EMPTY</b>");
$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;
$v->add($e);
$v->add($f);
$m->add($v);
$m->show_all;
Gtk2->main;

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>")});
I will try to take a look at this.


--
Emmanuel Rodriguez


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