Re: gtk2-perl-xs - changing textview fonts



Steven Usdansky said:
I just downloaded gtk2-perl-xs from CVS yesterday, hoping to translate one
of my old gtk-based C programs into perl, and am at a loss as to how to get
a  Gtk2::TextView to use a fixed font (Courier 12 would be just fine). I'm a
newbie to both perl and gtk2, so any hand-holding would be greatly
appreciated. --


the fundamentals of font handling are quite different between gtk 1.x and 2.x.
 also, the TextView/TextBuffer stuff is completely new.

the text widget overview in the api reference docs
[http://developer.gnome.org/doc/API/2.0/gtk/TextWidget.html] have a small
example of setting the font for the entire textview.  translated to
gtk2-perl-xs, that would be (roughly)

  $view = Gtk2::TextView->new;

  $buffer = $view->get_buffer;

  $buffer->set_text ("Hello, this is some text");

  # Change default font throughout the widget
  $font_desc = Gtk2::Pango::FontDescription->from_string ("Serif 15");
  $view->modify_font ($font_desc);

  # Use a tag to change the color for just one part of the widget
  $tag = $buffer->create_tag ("blue_foreground", foreground => "blue");
  $start = $buffer->get_iter_at_offset (7);
  $end = $buffer->get_iter_at_offset (12);
  $buffer->apply_tag ($tag, $start, $end);

the things to note there are that gtk2-perl-xs always returns iters, it never
modifies one (in C you pass a pointer to one which gets set).

i also take advantage of the => operator to make the key => value relationship
a little more explicit; you could also write that in a more C-ish way as

  $tag = $buffer->create_tag ("blue_foreground", "foreground", "blue");

i recommend reading the overviews in the C docs, as they help.  there's a
bunch of example code in the Gtk2/examples and Gtk2/gtk-demo directories
(although the whole gtk-demo isn't finished, so the parts don't die when you
close their windows).



-- 
muppet <scott at asofyet dot org>





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