Re: Drawing widgets in a custom cellrenderer



Hi Muppet,

Thank you for the quick reply and example. Although your example does actually eventually let me accomplish what I need (I'm not being ungrateful, I truly appreciate and learn from your numerous invaluable contributions :) ), it doesn't use a treeview/treeviewcolumn combination, something I was looking to employ for the functions like sorting, reordering, searching, etc (searching especially).

 Also, since I've spent quite sometime trying to hack together a solution, I'd be content and finally rest in knowing whether or not it is possible around a custom cellrenderer.

http://faq.pygtk.org/index.py?req=show&file=faq13.045.htp (How do I create a custom gtk.CellRenderer?)  seems to mention a draw() method (since deprecated) which I assume would have equated to Gtk2::Gdk::Drawable::draw() (which is also long-gone) in perl-gtk2. So, if Gtk2::Gdk::Drawable::draw() was really deprecated, what method can be used instead, I don't see any of the Gtk2::Gdk::Drawable method's being candidates for the job. This is all new territory for me.

Anymore thoughts and ideas would be welcome.

Thanks again,

Shalom

On Wed, Mar 19, 2008 at 3:00 AM, muppet <scott asofyet org> wrote:

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]