Gtk2::Ex::Entry::Pango

Gtk2 Entry that accepts Pango markup.
Download

Gtk2::Ex::Entry::Pango Ranking & Summary

Advertisement

  • Rating:
  • License:
  • Perl Artistic License
  • Price:
  • FREE
  • Publisher Name:
  • Emmanuel Rodriguez
  • Publisher web site:
  • http://debian.potyl.com/

Gtk2::Ex::Entry::Pango Tags


Gtk2::Ex::Entry::Pango Description

Gtk2 Entry that accepts Pango markup. Gtk2::Ex::Entry::Pango is a Gtk2 entry that accepts Pango markup.SYNOPSIS use Gtk2::Ex::Entry::Pango; # You can use any method defined in Gtk2::Entry or set_markup() my $entry = Gtk2::Ex::Entry::Pango->new(); $entry->set_markup('< i >Pan< /i >go is < span color="red" >fun< /span >'); # Create a simple search field my $search = Gtk2::Ex::Entry::Pango->new(); $search->set_empty_markup("< span color='grey' size='smaller' >Search...< /span >"); # Realtime validation - accept only ASCII letters my $validation = Gtk2::Ex::Entry::Pango->new(); $validation->signal_connect(changed => sub { my $text = $validation->get_text; # Validate the entry's text if ($text =~ /^*$/) { return; } # Mark the string as being erroneous my $escaped = Glib::Markup::escape_text($text); $validation->set_markup("< span underline='error' underline_color='red' >$escaped< /span >"); $validation->signal_stop_emission_by_name('changed'); });HIERARCHYGtk2::Ex::Entry::Pango is a subclass of Gtk2::Entry. Glib::Object +----Glib::InitiallyUnowned +----Gtk2::Object +----Gtk2::Widget +----Gtk2::Entry +----Gtk2::Ex::Entry::PangoGtk2::Ex::Entry::Pango is a Gtk2::Entry that can accept Pango markup for various purposes (for more information about Pango text markup language see http://library.gnome.org/devel/pango/stable/PangoMarkupFormat.html).The widget allows Pango markup to be used for input as an alternative to set_text or for setting a default value when the widget is empty. The default value when empty is ideal for standalone text entries that have no accompanying label (such as a text field for a search).This widget allows for the text data to be entered either through the normal methods provided by Gtk2::Entry or to use the method "set_markup". It's possible to switch between two methods for applying the text. The standard Gtk2::Entry methods will always apply a text without styles while set_markup() will use a style.The widget Gtk2::Ex::Entry::Pango keeps track of which style to apply by listening to the signal changed. This has some important consequences. If an instance needs to provide it's own changed listener that calls set_markup() then the signal changed has to be stopped otherwise the layout will be lost. The following code snippet show how to stop the emission of the changed signal: my $entry = Gtk2::Ex::Entry::Pango->new(); $entry->signal_connect(changed => sub { # Validate the text my $text = $entry->get_text; if (validate($text)) { return; } # Mark the text as being erroneous my $escaped = Glib::Markup::escape_text($text); $entry->set_markup("< span underline='error' underline_color='red' >$escaped< /span >"); $entry->signal_stop_emission_by_name('changed'); });Another important thing to note is that Gtk2::Entry::set_text() will not update it's content if the input text is the same as the text already stored. This means that if set text is called with the same string it will not emit the signal changed and the widget will not pickup that the markup styles have to be dropped. This is true even it the string displayed uses markup, as long as the contents are the same set_text() will not make an update. The method "clear_markup" can be used for safely clearing the markup text. Requirements: · Perl


Gtk2::Ex::Entry::Pango Related Software