From c6a4cba373448243762242fd54c72726e7b204da Mon Sep 17 00:00:00 2001 From: Pascal Rigaux Date: Fri, 9 Feb 2001 16:00:55 +0000 Subject: add button handling, quite weird behaviour though cuz of newt sillyness --- perl-install/interactive.pm | 4 ++++ perl-install/interactive_gtk.pm | 29 ++++++++++++++++++----------- perl-install/interactive_newt.pm | 21 ++++++++++----------- 3 files changed, 32 insertions(+), 22 deletions(-) (limited to 'perl-install') diff --git a/perl-install/interactive.pm b/perl-install/interactive.pm index 48353c8a8..e584e5336 100644 --- a/perl-install/interactive.pm +++ b/perl-install/interactive.pm @@ -16,6 +16,7 @@ use common qw(:common :functional); #- advanced => wether it is shown in by default or only in advanced mode #- disabled => function returning wether it should be disabled (grayed) #- type => +#- button => (with text, clicked) (type defaults to button if clicked is there) #- bool (with text) #- range (with min, max) #- combo (with list, not_edit) @@ -219,6 +220,9 @@ sub ask_from_entries_refH_powered_normalize { } elsif ($e->{type} eq 'range') { $e->{min} <= $e->{max} or die "bad range min $e->{min} > max $e->{max} (called from " . join(':', caller()) . ")"; ${$e->{val}} = max($e->{min}, min(${$e->{val}}, $e->{max})); + } elsif ($e->{type} eq 'button' || $e->{clicked}) { + $e->{type} = 'button'; + $e->{clicked} ||= sub {}; } $e->{disabled} ||= sub { 0 }; } diff --git a/perl-install/interactive_gtk.pm b/perl-install/interactive_gtk.pm index 8485d34ea..c26f72a4b 100644 --- a/perl-install/interactive_gtk.pm +++ b/perl-install/interactive_gtk.pm @@ -234,6 +234,13 @@ sub ask_from_entries_refW { my $get_all = sub { ${$_->{e}{val}} = $_->{get}->() foreach @widgets_always, @widgets_advanced; }; + my $update = sub { + my ($f) = @_; + return if $ignore; + $get_all->(); + $f->(); + $set_all->(); + }; my $create_widget = sub { my ($e, $ind) = @_; @@ -248,12 +255,7 @@ sub ask_from_entries_refW { } } }; - my $changed = sub { - return if $ignore; - $get_all->(); - $common->{callbacks}{changed}->($ind); - $set_all->(); - }; + my $changed = sub { $update->(sub { $common->{callbacks}{changed}($ind) }) }; my ($w, $real_w, $set, $get, $expand, $size); if ($e->{type} eq 'iconlist') { @@ -277,6 +279,14 @@ sub ask_from_entries_refW { $w->signal_connect(clicked => $changed); $set = sub { $w->set_active($_[0]) }; $get = sub { $w->get_active }; + } elsif ($e->{type} eq 'button') { + $w = Gtk::Button->new($e->{text}); + $w->signal_connect(clicked => sub { + $o->{retval} = 1; + Gtk->main_quit; + $mainw->destroy; + $e->{clicked}(); + }); } elsif ($e->{type} eq 'range') { my $adj = create_adjustment(${$e->{val}}, $e->{min}, $e->{max}); $adj->signal_connect(value_changed => $changed); @@ -317,11 +327,8 @@ sub ask_from_entries_refW { $set = sub { $w->set_text($_[0]) }; $get = sub { $w->get_text }; } - $w->signal_connect(focus_out_event => sub { - return if $ignore; - $get_all->(); - $common->{callbacks}{focus_out}->($ind); - $set_all->(); + $w->signal_connect(focus_out_event => sub { + $update->(sub { $common->{callbacks}{focus_out}($ind) }); }); $tooltips->set_tip($w, $e->{help}) if $e->{help} && !ref($e->{help}); diff --git a/perl-install/interactive_newt.pm b/perl-install/interactive_newt.pm index 0c8671f19..b260d60af 100644 --- a/perl-install/interactive_newt.pm +++ b/perl-install/interactive_newt.pm @@ -101,15 +101,9 @@ sub ask_from_entries_refW { $w = Newt::Component::Checkbox(-1, -1, $e->{text} || '', checkval(${$e->{val}}), " *"); $set = sub { $w->CheckboxSetValue(checkval($_[0])) }; $get = sub { $w->CheckboxGetValue == ord '*' }; -# } elsif ($e->{type} eq 'range') { -# my $adj = create_adjustment(${$e->{val}}, $e->{min}, $e->{max}); -# $adj->signal_connect(value_changed => $changed); -# $w = new Gtk::HScale($adj); -# $w->set_digits(0); -# $w->signal_connect(key_press_event => $may_go_to_next); -# $set = sub { $adj->set_value($_[0]) }; -# $get = sub { $adj->get_value }; - } elsif ($e->{type} =~ /list/) { + } elsif ($e->{type} eq 'button') { + $w = Newt::Component::Button(-1, -1, $e->{text} || ''); + } elsif ($e->{type} =~ /list/) { my ($h, $wi) = (5, 20); my $scroll = @{$e->{list}} > $h ? 1 << 2 : 0; $size = min(int @{$e->{list}}, $h); @@ -188,14 +182,19 @@ sub ask_from_entries_refW { !$error; }; - my $canceled; + my ($canceled, $r); do { - my $r = $form->RunForm; + $r = $form->RunForm; $canceled = $cancel && $$r == $$cancel; } until ($check->($common->{callbacks}{$canceled ? 'canceled' : 'complete'})); $form->FormDestroy; Newt::PopWindow; + + foreach (@widgets) { + $_->{e}{clicked}() if $$r == ${$_->{w}}; + } + !$canceled; } -- cgit v1.2.1