From ab7a22f5dbb1eeddba8708024c2b0c5ceeafc127 Mon Sep 17 00:00:00 2001 From: Pascal Rigaux Date: Thu, 16 Dec 2004 13:20:08 +0000 Subject: much simpler code using mygtk2 --- perl-install/Xconfig/resolution_and_depth.pm | 116 +++++++++++---------------- 1 file changed, 49 insertions(+), 67 deletions(-) (limited to 'perl-install/Xconfig') diff --git a/perl-install/Xconfig/resolution_and_depth.pm b/perl-install/Xconfig/resolution_and_depth.pm index df72bc31d..5953f7a4e 100644 --- a/perl-install/Xconfig/resolution_and_depth.pm +++ b/perl-install/Xconfig/resolution_and_depth.pm @@ -209,13 +209,14 @@ sub configure_auto_install { sub choose_gtk { my ($in, $card, $default_resolution, @resolutions) = @_; - my ($chosen_x_res, $chosen_y_res, $chosen_Depth) = @$default_resolution{'X', 'Y', 'Depth'}; - $chosen_x_res ||= 640; + my $chosen_Depth = $default_resolution->{Depth}; + my $chosen_res = { X => $default_resolution->{X} || 640, Y => $default_resolution->{Y} }; my %x_res2depth; push @{$x_res2depth{$_->{X}}}, $_->{Depth} foreach @resolutions; my %depth2x_res; push @{$depth2x_res{$_->{Depth}}}, $_->{X} foreach @resolutions; require ugtk2; + mygtk2->import; ugtk2->import(qw(:create :helpers :wrappers)); my $W = ugtk2->new(N("Resolution")); @@ -231,83 +232,64 @@ sub choose_gtk { %h; }; - my ($depth_combo, $x_res_combo) = (Gtk2::ComboBox->new_text, Gtk2::ComboBox->new_text); - - my $pix_colors = Gtk2::Image->new; - my $set_chosen_Depth_image = sub { - $pix_colors->set_from_file(ugtk2::_find_imgfile( - $chosen_Depth >= 24 ? "colors.png" : - $chosen_Depth >= 15 ? "colors16.png" : "colors8.png")); - }; - - my $set_chosen_Depth = sub { - $chosen_Depth = $_[0]; - $depth_combo->entry->set_text(translate($depth2text{$chosen_Depth})); - $set_chosen_Depth_image->(); - }; - - my $pixmap_mo = Gtk2::Image->new; - my $set_chosen_resolution = sub { - $chosen_x_res = $_[0]; - if ($_[1]) { - $chosen_y_res = $_[1]; - } else { - #- take one - my $one = find { $_->{X} eq $chosen_x_res } @resolutions; - $chosen_y_res = $one->{Y}; - } - my $image = $monitor_images_x_res{$chosen_x_res} or internal_error("no image for resolution $chosen_x_res"); - $pixmap_mo->set_from_file($image); - $x_res_combo->entry->set_text($chosen_x_res . "x" . $chosen_y_res); - }; - $x_res_combo->set_popdown_strings(uniq map { "$_->{X}x$_->{Y}" } sort { $a->{X} <=> $b->{X} } @resolutions); - $set_chosen_resolution->($chosen_x_res, $chosen_y_res); + my $depth_combo = gtknew('ComboBox', width => 220, + text_ref => \$chosen_Depth, + format => sub { translate($depth2text{$_[0]}) }, + list => [ ikeys %depth2x_res ], + changed => sub { + if (!member($chosen_res->{X}, @{$depth2x_res{$chosen_Depth}})) { + my $X = max(@{$depth2x_res{$chosen_Depth}}); + #- take one + my $one = find { $_->{X} eq $X } @resolutions; + gtkval_modify(\$chosen_res, $one); + } + }); + my $res2text = sub { "$_[0]{X}x$_[0]{Y}" }; + my $res_combo = gtknew('ComboBox', + text_ref => \$chosen_res, + format => $res2text, + list => [ uniq_ { $res2text->($_) } sort { $a->{X} <=> $b->{X} } @resolutions ], + changed => sub { + if (!member($chosen_Depth, @{$x_res2depth{$chosen_res->{X}}})) { + gtkval_modify(\$chosen_Depth, max(@{$x_res2depth{$chosen_res->{X}}})); + } + }); + my $pix_colors = gtknew('Image', + file_ref => \$chosen_Depth, + format => sub { + $_[0] >= 24 ? "colors.png" : $_[0] >= 15 ? "colors16.png" : "colors8.png"; + }); + my $pixmap_mo = gtknew('Image', + file_ref => \$chosen_res, + format => sub { + $monitor_images_x_res{$_[0]{X}} or internal_error("no image for resolution $chosen_res->{X}"); + }); my $help_sub = $in->interactive_help_sub_display_id('configureX_resolution'); gtkadd($W->{window}, gtkpack_($W->create_box_with_title(N("Choose the resolution and the color depth"), if_($card->{BoardName}, "(" . N("Graphics card: %s", $card->{BoardName}) . ")"), ), - 1, gtkpack2(Gtk2::VBox->new(0,0), - gtkpack2__(Gtk2::VBox->new(0, 15), - $pixmap_mo, - gtkpack2(Gtk2::HBox->new(0,0), - create_packtable({ col_spacings => 5, row_spacings => 5 }, - [ $x_res_combo, Gtk2::Label->new("") ], - [ $depth_combo, gtkadd(gtkset_shadow_type(Gtk2::Frame->new, 'etched_out'), $pix_colors) ], - ), - ), - ), - ), + 1, '', + 0, $pixmap_mo, + 0, gtknew('HBox', children => [ + 1, '', + 0, gtknew('Table', col_spacings => 5, row_spacings => 5, + children => [ + [ $res_combo, gtknew('Label', text => "") ], + [ $depth_combo, gtknew('Frame', shadow_type => 'etched_out', child => $pix_colors) ], + ]), + 1, '', + ]), + 1, '', 0, gtkadd($W->create_okcancel(N("Ok"), N("Cancel"), '', if_($help_sub, [ N("Help"), $help_sub, 1 ]))), )); - $depth_combo->set_popdown_strings(map { translate($depth2text{$_}) } ikeys %depth2x_res); - $depth_combo->entry->set_size_request(220, -1); - $depth_combo->entry->signal_connect(changed => sub { - my %txt2depth = reverse %depth2text; - my $s = $depth_combo->entry->get_text; - $chosen_Depth = $txt2depth{untranslate($s, keys %txt2depth)}; - $set_chosen_Depth_image->(); - - if (!member($chosen_x_res, @{$depth2x_res{$chosen_Depth}})) { - $set_chosen_resolution->(max(@{$depth2x_res{$chosen_Depth}})); - } - }); - $x_res_combo->entry->signal_connect(changed => sub { - $set_chosen_resolution->($1, $2) if $x_res_combo->entry->get_text =~ /(\d+)x(\d+)/; - - if (!member($chosen_Depth, @{$x_res2depth{$chosen_x_res}})) { - $set_chosen_Depth->(max(@{$x_res2depth{$chosen_x_res}})); - } - }); - $set_chosen_resolution->($chosen_x_res, $chosen_y_res); - $set_chosen_Depth->($chosen_Depth); $W->{ok}->grab_focus; $W->main or return; - find { $_->{X} == $chosen_x_res && - $_->{Y} == $chosen_y_res && + find { $_->{X} == $chosen_res->{X} && + $_->{Y} == $chosen_res->{Y} && $_->{Depth} == $chosen_Depth } @resolutions; } -- cgit v1.2.1