Re: IconView with widget in place of pixmap..




On Jan 13, 2008, at 1:47 PM, Shawn Ferris wrote:

I was wondering whether it's possible to use the iconview widget and in place of the pixmap, instead I'd like to use another widget. The widget would actually consist of a pixmap still, but in the lower right corner I'd also like to have a checkbutton. Reading through the C-Code, I don't think it's possible.. but I'm not very good at reading/writing C either. I'm really hoping it'd be easier to create a new widget and inherit from IconView, replacing methods that deal with the pixmap with equivelant code to deal with the new widget. Of course, rather than potentially embarking down an impossible path, I thought I'd ask the experts for their opinion. In a perfect world, I'd like to have a nautilus style window (with a places pane) with my particular widget for the directories. (Don't need icons for files, just directories)

My guess is that I should start re-inventing the wheel, because I'm not sure it's going to be easy.. but thought I'd ask.


Gtk2::IconView does, indeed, implement Gtk2::CellLayout, so you can do things like pack your own CellRenderer with its own attributes. I haven't poked too much at it, other than to show that it works, but you may not get all the layout control that you want.


#!/usr/bin/perl -w

use strict;
use Gtk2 -init;
use Glib ':constants';
use File::Basename;

#
# Load up a model with some data.  We'll use all the filenames passed
# in @ARGV.
#

use constant {
        NAME_COLUMN     => 0,
        PIXBUF_COLUMN   => 1,
        BOOL_COLUMN     => 2,
};
my @column_types;
$column_types[NAME_COLUMN] = 'Glib::String';
$column_types[PIXBUF_COLUMN] = 'Gtk2::Gdk::Pixbuf';
$column_types[BOOL_COLUMN] = 'Glib::Boolean';

my $model = Gtk2::ListStore->new (@column_types);
$model->set ($model->append, NAME_COLUMN, basename ($_),
                             PIXBUF_COLUMN, load_file ($_),
                             BOOL_COLUMN, TRUE)
        foreach sort @ARGV;

#
# Now create a rather normal IconView...
#

my $iconview = Gtk2::IconView->new ();
$iconview->set_model ($model);
$iconview->set_text_column (NAME_COLUMN);
$iconview->set_pixbuf_column (PIXBUF_COLUMN);

#
# ...but also pack in a CellRendererToggle to add a checkbox to
# each cell in the IconView.
#
my $toggle_cell = Gtk2::CellRendererToggle->new;
$toggle_cell->set (activatable => TRUE);
$toggle_cell->{column} = BOOL_COLUMN;
$toggle_cell->signal_connect (toggled => sub {
        my ($cell, $path_string) = @_;
        my $column = $cell->{column};
        my $path = Gtk2::TreePath->new_from_string ($path_string);
        my $iter = $model->get_iter ($path);
        $model->set ($iter, $column, !$model->get ($iter, $column));
});
$iconview->pack_end ($toggle_cell, FALSE);
$iconview->add_attribute ($toggle_cell, active => 2);


#
# Now the uninteresting part.
#
my $window = Gtk2::Window->new;
my $scroll = Gtk2::ScrolledWindow->new;
$window->add ($scroll);
$scroll->add ($iconview);
$window->show_all;
$window->signal_connect (destroy => sub { Gtk2->main_quit });
Gtk2->main;

sub load_file {
    my $p = shift;
eval { $p = Gtk2::Gdk::Pixbuf->new_from_file_at_size ($_, 64, 64); };
    print $@ if $@;
    return $p;
}

__END__

--
zella (crying):  I want...
us:  What?
zella (still crying):  I want...  something!





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