summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--perl-install/interactive.pm5
-rw-r--r--perl-install/interactive/gtk.pm26
2 files changed, 25 insertions, 6 deletions
diff --git a/perl-install/interactive.pm b/perl-install/interactive.pm
index c32553a88..df28cc27b 100644
--- a/perl-install/interactive.pm
+++ b/perl-install/interactive.pm
@@ -42,14 +42,15 @@ use common;
#- (type defaults to button if clicked or clicked_may_quit is there)
#- (val need not be a reference) (if clicked_may_quit return true, it's as if "Ok" was pressed)
#- label => (val need not be a reference) (type defaults to label if val is not a reference)
-#- bool (with text)
+#- bool (with "text" or "image" (which overrides text) giving an image filename)
#- range (with min, max)
#- combo (with list, not_edit, format)
#- list (with list, icon2f (aka icon), separator (aka tree), format (aka pre_format function),
#- help can be a hash or a function,
#- tree_expanded boolean telling wether the tree should be wide open by default
#- quit_if_double_click boolean
-#- allow_empty_list disables the special cases for 0 and 1 element lists)
+#- allow_empty_list disables the special cases for 0 and 1 element lists
+#- image2f is a subroutine which takes a value of the list as parameter, and returns an array (text, image_file_name))
#- entry (the default) (with hidden)
#
#- heritate from this class and you'll get all made interactivity for same steps.
diff --git a/perl-install/interactive/gtk.pm b/perl-install/interactive/gtk.pm
index bb83cfdd5..2e52b2640 100644
--- a/perl-install/interactive/gtk.pm
+++ b/perl-install/interactive/gtk.pm
@@ -154,19 +154,33 @@ sub create_treeview_tree {
$tree_expanded = to_bool($tree_expanded); #- to reduce "Use of uninitialized value", especially when debugging
my $sep = quotemeta $e->{separator};
- my $tree_model = Gtk2::TreeStore->new(Gtk2::GType->STRING);
+ my $tree_model = Gtk2::TreeStore->new(Gtk2::GType->STRING, Gtk2::GType->OBJECT, Gtk2::GType->STRING);
my $tree = Gtk2::TreeView->new_with_model($tree_model);
$tree->get_selection->set_mode('browse');
$tree->append_column(Gtk2::TreeViewColumn->new_with_attributes(undef, Gtk2::CellRendererText->new, 'text' => 0));
+ $tree->append_column(Gtk2::TreeViewColumn->new_with_attributes(undef, Gtk2::CellRendererPixbuf->new, 'pixbuf' => 1));
+ $tree->append_column(Gtk2::TreeViewColumn->new_with_attributes(undef, Gtk2::CellRendererText->new, 'text' => 2));
$tree->set_headers_visible(0);
+ my @to_unref;
+ $tree->signal_connect(destroy => sub { $_->unref foreach @to_unref });
+ my $build_value = sub {
+ if (exists $e->{image2f}) {
+ my ($text, $image) = $e->{image2f}->($_[0]);
+ [ $text ? (0 => $text) : (),
+ $image ? (1 => do { push @to_unref, my $img = gtkcreate_pixbuf($image); $img }) : () ];
+ } else {
+ [ 0 => $_[0] ];
+ }
+ };
+
my (%wtree, %wleaves, $size, $selected_via_click);
my $parent; $parent = sub {
if (my $w = $wtree{"$_[0]$e->{separator}"}) { return $w }
my $s = '';
foreach (split $sep, $_[0]) {
$wtree{"$s$_$e->{separator}"} ||=
- $tree_model->append_set($s ? $parent->($s) : undef, [ 0 => $_ ]);
+ $tree_model->append_set($s ? $parent->($s) : undef, $build_value->($_));
$size++ if !$s;
$s .= "$_$e->{separator}";
}
@@ -177,7 +191,7 @@ sub create_treeview_tree {
my (%precomp, @ordered_keys);
mapn {
my ($root, $leaf) = $_[0] =~ /(.*)$sep(.+)/ ? ($1, $2) : ('', $_[0]);
- my $iter = $tree_model->append_set($parent->($root), [ 0 => $leaf ]);
+ my $iter = $tree_model->append_set($parent->($root), $build_value->($leaf));
my $pathstr = $tree_model->get_path_str($iter);
$iter->free;
$precomp{$pathstr} = { value => $leaf, fullvalue => $_[0], listvalue => $_[1] };
@@ -394,7 +408,11 @@ sub ask_fromW {
});
$real_w = gtkpack_(Gtk2::HBox->new(0,10), 1, Gtk2::HBox->new(0,0), 0, $w, 1, Gtk2::HBox->new(0,0));
} elsif ($e->{type} eq 'bool') {
- $w = Gtk2::CheckButton->new($e->{text});
+ if ($e->{image}) {
+ $w = gtkadd(Gtk2::CheckButton->new, gtkshow(gtkcreate_img($e->{image})));
+ } else {
+ $w = Gtk2::CheckButton->new($e->{text});
+ }
$w->signal_connect(clicked => $changed);
$set = sub { $w->set_active($_[0]) };
$get = sub { $w->get_active };