Re: "Label" entries





On Thu, Apr 30, 2009 at 8:55 AM, Matthew Braid <ptkperl mdb id au> wrote:
Hi,

I'm trying to create an entry that acts a bit like the entries found
in vista and on some websites - where if no data has been entered some
text is displayed in the entry, usually greyed out.
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.

I've got the focus-in and focus-out actions working fine, and I'm now
working on a subclass so that the get_text function will return '' if
nothing has been entered even if there is 'grey text' displayed, but
so far I can't see a way of making the text inside the entry grey (or
in fact making it change in any way). Gtk2::Ex::Entry::Pango looks
promising, but installing new packages is...problematic... in my
current environment.
Â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.

I thought about doing some messing around by setting the entry to be
insensitive when unedited (looks greyed out), and putting an event box
over it to catch focus events (or in fact _any_ event), but this:

use Gtk2 "-init";
$mw = Gtk2::Window->new;
$e = Gtk2::Entry->new;
$e->set_text("TEXT");
$e->set_sensitive(0);
$f = ÂGtk2::EventBox->new;
$f->signal_connect(event => sub {print "HIT"});
$mw->add($f);
$f->add($e);
$f->set_above_child(1); # Even with this!
$mw->show_all; Gtk2->main

doesn't work.

Does anyone have any helpful ideas? I'm continuing on without the
colouring anyway in the hopes that a solution can just be added in.
If you really want to write your's from scratch I will strongly suggest that you read the source code of Gtk2::Ex::Entry::Pango I've added a lot of comments for the developers that peek inside because this was a bit tricky.

A Gtk2::Entry is a small MVC (model/view/controler) and has a model (the data stored) and a view the data to display. Most of the type the data stored is the same as the data displayed, the main exception is with the passwords fields where a strange character is displayed instead. You can modify the data displayed by using pango. The problem with pango is that the display string is quite volatile each graphical update of the widget (after a redraw) will loose your display string and the widget will revert to it's default data display. This doesn't seem too tricky but a Gtk2::Entry has a curson blinking! This is a lot of redraws. The trick is to connect your own signals that will redisplay your default string when the widget gets redrawn.


TIA,
MB
_______________________________________________
gtk-perl-list mailing list
gtk-perl-list gnome org
http://mail.gnome.org/mailman/listinfo/gtk-perl-list



--
Emmanuel Rodriguez


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