Re: Drawing widgets in a custom cellrenderer
- From: muppet <scott asofyet org>
- To: Shalom Bhooshi <s bhooshi gmail com>
- Cc: Gtk2-Perl Mailing List <gtk-perl-list gnome org>
- Subject: Re: Drawing widgets in a custom cellrenderer
- Date: Tue, 18 Mar 2008 23:00:53 -0400
On Mar 18, 2008, at 7:31 PM, Shalom Bhooshi wrote:
Hi Everyone,
I was wondering if it's possible or not to draw widgets into a
custom cellrenderer. Basically, I'm trying to achieve something like
that shown here - http://beagle-project.org/images/b/b2/BeagleScreenie_crop.png
where child rows may either be rendererd as individual treeviews or
iconviews depending on the content within them although occasionally
I might need to render an arbitrary widget too.
What i've tried so far amounts to something derived from examples/
celrenderer_progress.pl but I am stuck at rendering the widget onto
the custom cellrenderer. Now, from what i can understand from the
various examples of custom renderers, you paint an object onto the
widget's style (as per Gtk2::Style::Paint_*) but how is a widget to
be renderered?
It's a trick. :-)
I saw something similar to this recently somewhere on the web, but my
browser history has since been wiped and i can't find it now. Here's
a quick mockup.
Notes: The thing that's being scrolled is actually a vbox, contained
in an event box whose background has been changed to match that of the
treeviews. What i did here was use several expanders containing
treeviews, but you can just use labels as big section headers if you
don't need the roll-up. You can put whatever you like inside, i just
have several copies of the same list. If you want the thing to behave
like a real list, e.g., if you select something in a different list,
you'll have to implement special selection handling. Also, the
prelight color on the expanders is wrong. (So sue me, i knocked it
out in just a couple of minutes... ;-)
-=-=-=-=-=-
#!/usr/bin/env perl
use strict;
use warnings;
use Glib ':constants';
use Gtk2 -init;
use Gtk2::Ex::SimpleList;
my $window = Gtk2::Window->new;
my $scroller = Gtk2::ScrolledWindow->new;
$scroller->set_policy ('automatic', 'automatic');
$window->add ($scroller);
#
# Use an event box, so that we can set its background to the theme's
# "base" color, the same as used by the tree view and text view.
#
my $ebox = Gtk2::EventBox->new;
$ebox->modify_bg (normal => $ebox->get_style->base ('normal'));
#
# Put a vbox into the event box; we'll pack the expanders into this.
#
my $vbox = Gtk2::VBox->new;
$ebox->add ($vbox);
#
# Have to add with viewport since the ebox is not natively scrollable.
#
$scroller->add_with_viewport ($ebox);
#
# Now add our sections, which are just expanders containing tree views.
#
foreach my $section (qw(Things Entities Items Elements)) {
my $expander = Gtk2::Expander->new ("<big><big><b>$section</
b></big></big>");
$expander->set_use_markup (TRUE);
$expander->add (make_a_list ());
$vbox->pack_start ($expander, FALSE, FALSE, 0);
}
$window->signal_connect (destroy => sub {Gtk2->main_quit});
$window->show_all;
Gtk2->main;
sub make_a_list {
my $slist = Gtk2::Ex::SimpleList->new ('icon' => 'pixbuf',
'text' => 'markup');
$slist->set_headers_visible (FALSE);
@{ $slist->{data} } = (
[
stock_icon ('gtk-open'),
"<big><b>Blah blah blah.</b></big>\n"
."Blah blah blah blah blah blah blah blah
blah."
],
[
stock_icon ('gtk-save'),
"<big><b>Blah blah blah.</b></big>\n"
."Blah blah blah blah blah blah blah blah
blah."
],
[
stock_icon ('gtk-cut'),
"<big><b>Blah blah blah.</b></big>\n"
."Blah blah blah blah blah blah blah blah
blah."
],
[
stock_icon ('gtk-paste'),
"<big><b>Blah blah blah.</b></big>\n"
."Blah blah blah blah blah blah blah blah
blah."
],
);
return $slist;
}
sub stock_icon {
my $id = shift;
my $window = (Gtk2::Window->list_toplevels)[0];
return $window->render_icon ($id, 'large-toolbar');
}
__END__
--
Sallah! I said no camels! That's five camels! Can't you count?
-- Indiana Jones
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]