summaryrefslogtreecommitdiffstats
path: root/perl-install/keyboard.pm
diff options
context:
space:
mode:
authorThierry Vignaud <tvignaud@mandriva.org>2003-11-24 10:22:30 +0000
committerThierry Vignaud <tvignaud@mandriva.org>2003-11-24 10:22:30 +0000
commit7c6fdae5a9d288c21afd35588b693bac1a2c8006 (patch)
treeddeba3d0df059e8484f2d762c36fa6dadc35259d /perl-install/keyboard.pm
parente1d8160bceaac819dcb0538f03545c44bb1205b7 (diff)
downloaddrakx-7c6fdae5a9d288c21afd35588b693bac1a2c8006.tar
drakx-7c6fdae5a9d288c21afd35588b693bac1a2c8006.tar.gz
drakx-7c6fdae5a9d288c21afd35588b693bac1a2c8006.tar.bz2
drakx-7c6fdae5a9d288c21afd35588b693bac1a2c8006.tar.xz
drakx-7c6fdae5a9d288c21afd35588b693bac1a2c8006.zip
thx perl_checko
Diffstat (limited to 'perl-install/keyboard.pm')
-rw-r--r--perl-install/keyboard.pm2
1 files changed, 1 insertions, 1 deletions
diff --git a/perl-install/keyboard.pm b/perl-install/keyboard.pm
index 672384eb7..121d1cf8e 100644
--- a/perl-install/keyboard.pm
+++ b/perl-install/keyboard.pm
@@ -476,7 +476,7 @@ sub setup {
} elsif (-e (my $f = "$ENV{SHARE_PATH}/keymaps/$kmap.bkmap")) {
load(scalar cat_($f));
} else {
- my $kid = run_program::bg_command(sub {
+ my $kid = bg_command->new(sub {
eval {
require packdrake;
my $packer = new packdrake("$ENV{SHARE_PATH}/keymaps.cz2", quiet => 1);
> 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427
package interactive_gtk; # $Id$

use diagnostics;
use strict;
use vars qw(@ISA);

@ISA = qw(interactive);

use interactive;
use common qw(:common :functional);
use my_gtk qw(:helpers :wrappers);

1;

sub new {
    $::windowheight ||= 400 if $::isStandalone;
    goto &interactive::new;
}
sub enter_console { my ($o) = @_; $o->{suspended} = common::setVirtual(1) }
sub leave_console { my ($o) = @_; common::setVirtual(delete $o->{suspended}) }

sub suspend {}
sub resume {}

sub exit { 
    gtkset_mousecursor_normal(); #- for restoring a normal in any case on standalone
    c::_exit($_[0]) #- workaround 
}

sub ask_from_listW {
    my ($o, $title, $messages, $l, $def) = @_;
    ask_from_list_with_helpW($o, $title, $messages, $l, undef, $def);
}

sub ask_from_list_with_helpW {
    my ($o, $title, $messages, $l, $help, $def) = @_;
    my $r;

    my $w = my_gtk->new(first(deref($title)), %$o);
#gtkset_usize(createScrolledWindow($tree), 300, min(350, $::windowheight - 60)),
    $w->{retval} = $def || $l->[0]; #- nearly especially for the X test case (see timeout in Xconfigurator.pm)
    $w->{rwindow}->set_position('center_always') if $::isStandalone;
    $w->{rwindow}->set_policy(0, 0, 1)  if $::isWizard;
    if (@$l < 5 or $::isWizard) {
	my $defW;
	my $tips = new Gtk::Tooltips;
	my $g = sub { $w->{retval} = $_[1]; };
	my $f = sub { $w->{retval} = $_[1]; Gtk->main_quit };
	my $b;
	$w->sync;
	$::isWizard and my $pixmap = new Gtk::Pixmap( gtkcreate_xpm($w->{window}, $::wizard_xpm)) || die "pixmap $! not found.";
	if ($::isWizard) {
	    gtkset_usize($w->{rwindow}, 500, 400);
	    my $rc = "/etc/gtk/draknet.rc";
	    -r $rc or $rc = common::dirname(__FILE__) . "/draknet.rc";
	    Gtk::Rc->parse($rc) ;
	    my $style = $w->{rwindow}->style->copy();
	    $style->bg_pixmap(0);
	    $style->bg_pixmap(1);
	    $style->bg_pixmap(2);
	    $style->bg_pixmap(3);
	    $style->bg_pixmap(4);
	    $style->bg(0, $style->white());
	    $style->bg(1, $style->white());
	    $style->bg(2, $style->white());
	    $style->bg(3, $style->white());
	    $style->bg(4, $style->white());
	    $style->bg_gc(0, $style->white_gc);
	    $style->bg_gc(1, $style->white_gc);
	    $style->bg_gc(2, $style->white_gc);
	    $style->bg_gc(3, $style->white_gc);
	    $style->bg_gc(4, $style->white_gc);
	    #	$style->engine = undef;
	    #	$style->rc_style = undef;
	    $w->{rwindow}->set_style($style);
	}
	gtkadd($w->{window},
	       gtkpack2_(create_box_with_title($w, @$messages),
			 1,
			 gtkpack3( $::isWizard,
				   new Gtk::HBox(0,0),
				   $::isWizard ? ($pixmap, gtkset_usize(new Gtk::VBox(0,0),30, 0)) : (),
				   gtkpack2__( $::isWizard ? new Gtk::VBox(0,0): ( @$l < 3 && sum(map { length $_ } @$l) < 60 ? create_hbox() : create_vbox()),
					      $::isWizard ? gtkset_usize(new Gtk::VBox(0,0), 0, 30) : (),
						  map {
						      $::isWizard ? $b = new Gtk::RadioButton($b ? ($_, $b) : $_) : ($b = new Gtk::Button($_));
						      $tips->set_tip($b, $help->{$_}) if $help && $help->{$_};
						      $_ eq $def and $defW = $b;
						      $b->signal_connect(clicked => [ $::isWizard ? $g : $f, $_ ]);
						      $b;
						  } @$l, )),
			 0, new Gtk::HSeparator,
			 $::isWizard ? (0, $w->create_okcancel()) : (),
			),
	      );
#	gtk_widget_set_style(EventBox2, style);
#          {
#  	  nowizard:
#  	    gtkadd($w->{window},
#  		   gtkpack(create_box_with_title($w, @$messages),
#  			   gtkadd(@$l < 3 && sum(map { length $_ } @$l) < 60 ? create_hbox() : create_vbox(),
#  				  map {
#  				      $b = new Gtk::Button($_);
#  				      $b->signal_connect(clicked => [ $f, $_ ]);
#  				      $tips->set_tip($b, $help->{$_}) if $help && $help->{$_};
#  				      $_ eq $def and $defW = $b;
#  				      $b;
#  				  } @$l, ),
#  			  ),
#  		  );
#       }

	$defW->grab_focus if $defW;
	$r = $w->main;
    } else {
	#- use ask_from_list_with_help only when needed, as key bindings are
	#- dropped by List (CList does not seems to accepts Tooltips).
	$help ? $w->_ask_from_list_with_help($title, $messages, $l, $help, $def) :
	  $w->_ask_from_list($title, $messages, $l, $def);
	$r = $w->main;
    }
    $r or $::isWizard ? 0 : die "ask_from_list cancel";
}

sub ask_from_treelistW {
    my ($o, $title, $messages, $separator, $l, $def) = @_;
    my $sep = quotemeta $separator;
    my $w = my_gtk->new($title);
    my $tree = Gtk::CTree->new(1, 0);

    my %wtree;
    my $parent; $parent = sub {
	if (my $w = $wtree{"$_[0]$separator"}) { return $w }
	my $s;
	foreach (split $sep, $_[0]) {
	    $wtree{"$s$_$separator"} ||= 
	      $tree->insert_node($s ? $parent->($s) : undef, undef, [$_], 5, (undef) x 4, 0, 0);
	    $s .= "$_$separator";
	}
	$wtree{$s};
    };
    my ($root, $leaf, $wdef, $ndef);
    foreach (@$l) {
	($root, $leaf) = /(.*)$sep(.+)/ or ($root, $leaf) = ('', $_);
	my $node = $tree->insert_node($parent->($root), undef, [$leaf], 5, (undef) x 4, 1, 0);

	if ($def eq $_) {
	    $wdef = $node;
	    my $s; $tree->expand($wtree{$s .= "$_$separator"}) foreach split $sep, $root;
	    foreach my $nb (1 .. @$l) {
		if ($tree->node_nth($nb) == $node) {
		    $tree->set_focus_row($ndef = $nb);
		    last;
		}
	    }
	}
    }
    undef %wtree;

    my $curr;
    my $leave = sub { 
	$curr->row->is_leaf or return;
	my @l; for (; $curr; $curr = $curr->row->parent) { 
	    unshift @l, first $tree->node_get_pixtext($curr, 0);
	}
	$w->{retval} = join $separator, @l;
	Gtk->main_quit;
    };
    $w->{ok_clicked} = $leave;
    $w->{cancel_clicked} = sub { $w->destroy; die "ask_from_list cancel" }; #- make sure windows doesn't live any more.
    gtkadd($w->{window},
	   gtkpack($w->create_box_with_title(@$messages),
		   gtkpack_(new Gtk::VBox(0,7),
			    1, gtkset_usize(createScrolledWindow($tree), 300, min(350, $::windowheight - 60)),
			    0, $w->create_okcancel)));
    $tree->set_column_auto_resize(0, 1);
    $tree->set_selection_mode('browse');
    $tree->signal_connect(tree_select_row => sub { $curr = $_[1]; });
    $tree->signal_connect(button_press_event => sub { &$leave if $_[1]{type} =~ /^2/ });
    $tree->signal_connect(key_press_event => sub {
        my ($w, $e) = @_;
	my $c = chr($e->{keyval} & 0xff);
	$curr or return;
	if ($e->{keyval} >= 0x100 ? $c eq "\r" || $c eq "\x8d" : $c eq ' ') {
	    if ($curr->row->is_leaf) { &$leave }
	    else { $tree->toggle_expansion($curr) }
	}
	1;
    });

    $tree->grab_focus;
    $tree->set_row_height($tree->style->font->ascent + $tree->style->font->descent + 1);
    $w->{rwindow}->show;

    if ($wdef) {
	$tree->select($wdef);
	$tree->node_moveto($wdef, 0, 0.5, 0);
    }


    $w->main or die "ask_from_list cancel";
}

sub ask_many_from_list_with_help_refW {
    my ($o, $title, $messages, @L) = @_;
    my $w = my_gtk->new('', %$o);
    my $tips = new Gtk::Tooltips;
    my @boxes = map {
	my $l = $_;
	my $box = gtkpack(new Gtk::VBox(0,0),
		map_index {
		    my $i = $::i;
		    my $o = Gtk::CheckButton->new($_);
		    $tips->set_tip($o, $l->[1][$i]) if $l->[1][$i];
		    $o->set_active(${$l->[2][$i]});
		    $o->signal_connect(clicked => sub { invbool $l->[2][$i] });
		    $o;
		} @{$l->[0]});
	@{$l->[0]} > 11 ? gtkset_usize(createScrolledWindow($box), 0, 250) : $box;
    } @L;
    gtkadd($w->{window},
	   gtkpack_(create_box_with_title($w, @$messages),
		    (map {; 1, $_ } @boxes),
		    0, $w->create_okcancel,
		   )
	  );
    $w->{ok}->grab_focus;
    $w->main;
}

sub ask_from_entries_refW {
    my ($o, $title, $messages, $l, $val, %hcallback) = @_;
    my ($title_, @okcancel) = deref($title);
    my $ignore = 0; #-to handle recursivity

    my $w = my_gtk->new($title_, %$o);
    $w->sync; # for XPM's creation

    my $set_icon = sub {
	my ($i, $button) = @_;
	gtkdestroy($i->{icon});
	my $f = $i->{icon2f}->(${$i->{val}});
	$i->{icon} = -e $f ?
	  new Gtk::Pixmap(gtkcreate_xpm($w->{window}, $f)) :
	  new Gtk::Label(translate(${$i->{val}}));
	$button->add($i->{icon});
	$i->{icon}->show;
    };

    #-the widgets
    my @widgets = map {
	my $i = $_;

	$i->{type} = "iconlist" if $i->{type} eq "list" && $i->{not_edit} && $i->{icon2f};

	if ($i->{type} eq "list") {
	    my $w = new Gtk::Combo;
	    $w->set_use_arrows_always(1);
	    $w->entry->set_editable(!$i->{not_edit});
	    $w->set_popdown_strings(@{$i->{list}});
	    $w->disable_activate;
	    $w;
	} elsif ($i->{type} eq "iconlist") {
	    my $w = new Gtk::Button;
	    $w->signal_connect(clicked => sub {
		${$i->{val}} = next_val_in_array(${$i->{val}}, $i->{list});
		$set_icon->($i, $w);
	    });
	    $set_icon->($i, $w);
	    gtkpack_(new Gtk::HBox(0,10), 1, new Gtk::HBox(0,0), 0, $w, 1, new Gtk::HBox(0,0), );
	} elsif ($i->{type} eq "bool") {
	    my $w = Gtk::CheckButton->new($i->{text});
	    $w->set_active(${$i->{val}});
	    $w->signal_connect(clicked => sub { $ignore or invbool \${$i->{val}} });
	    $w;
	} elsif ($i->{type} eq "range") {
	    my $adj = create_adjustment(${$i->{val}}, $i->{min}, $i->{max});
	    $adj->signal_connect(value_changed => sub { ${$i->{val}} = $adj->get_value });
	    my $w = new Gtk::HScale($adj);
	    $w->set_digits(0);
	    $w;
	} else {
	    new Gtk::Entry;
	}
    } @{$val};
    my $ok = $w->create_okcancel(@okcancel);

    sub widget {
	my ($w, $ref) = @_;
	($ref->{type} eq "list" && @{$ref->{list}}) ? $w->entry : $w
    }
    my @updates = mapn {
	my ($w, $ref) = @_;
	sub {
	    $ref->{type} =~ /bool|range|iconlist/ and return;
	    ${$ref->{val}} = widget($w, $ref)->get_text;
	};
    } \@widgets, $val;

    my @updates_inv = mapn {
	my ($w, $ref) = @_;
	sub { 
	    $ref->{type} =~ /iconlist/ and return;
	    $ref->{type} eq "bool" ?
	      $w->set_active(${$ref->{val}}) :
	      widget($w, $ref)->set_text(${$ref->{val}})
	};
    } \@widgets, $val;


    for (my $i = 0; $i < @$l; $i++) {
	my $ind = $i; #-cos lexical bindings pb !!
	my $widget = widget($widgets[$i], $val->[$i]);
	my $changed_callback = sub {
	    return if $ignore; #-handle recursive deadlock
	    &{$updates[$ind]};
	    if ($hcallback{changed}) {
		&{$hcallback{changed}}($ind);
		#update all the value
		$ignore = 1;
		&$_ foreach @updates_inv;
		$ignore = 0;
	    };
	};
	my $may_go_to_next = sub {
	    my ($W, $e) = @_;
	    if (($e->{keyval} & 0x7f) == 0xd) {
		$W->signal_emit_stop("key_press_event");
		if ($ind == $#$l) {
		    @$l == 1 ? $w->{ok}->clicked : $w->{ok}->grab_focus;
		} else {
		    widget($widgets[$ind+1],$val->[$ind+1])->grab_focus;
		}
	    }
	};

	if ($hcallback{focus_out}) {
	    my $focusout_callback = sub {
		return if $ignore;
		&{$hcallback{focus_out}}($ind);
		#update all the value
		$ignore = 1;
		&$_ foreach @updates_inv;
		$ignore = 0;
	    };
	    $widget->signal_connect(focus_out_event => $focusout_callback);
	}
	if (ref $widget eq "Gtk::HScale") {
	    $widget->signal_connect(key_press_event => $may_go_to_next);
	}
	if (ref $widget eq "Gtk::Entry") {
	    $widget->signal_connect(changed => $changed_callback);
	    $widget->signal_connect(key_press_event => $may_go_to_next);
	    $widget->set_text(${$val->[$i]{val}});
	    $widget->set_visibility(0) if $val->[$i]{hidden};
	}
	&{$updates[$i]};
    }

    my @entry_list = mapn { [($_[0], $_[1])]} $l, \@widgets;

    gtkadd($w->{window},
	   gtkpack(
		   create_box_with_title($w, @$messages),
		   create_packtable({}, @entry_list),
		   $ok
		   ));
    widget($widgets[0],$val->[0])->grab_focus();
    if ($hcallback{complete}) {
	my $callback = sub {
	    my ($error, $focus) = &{$hcallback{complete}};
	    #-update all the value
	    $ignore = 1;
	    foreach (@updates_inv) { &{$_};}
	    $ignore = 0;
	    if ($error) {
		$focus ||= 0;
		widget($widgets[$focus], $val->[$focus])->grab_focus();
	    } else {
		return 1;
	    }
	};
	$w->main($callback);
    } else {
	$w->main();
    }
}


sub wait_messageW($$$) {
    my ($o, $title, $messages) = @_;

    my $w = my_gtk->new($title, %$o, grab => 1);
    gtkadd($w->{window}, my $hbox = new Gtk::HBox(0,0));
    $hbox->pack_start(my $box = new Gtk::VBox(0,0), 1, 1, 10);  
    $box->pack_start($_, 1, 1, 4) foreach my @l = map { new Gtk::Label($_) } @$messages;

    ($w->{wait_messageW} = $l[$#l])->signal_connect(expose_event => sub { $w->{displayed} = 1 });
    $w->{rwindow}->set_position('center') if $::isStandalone;
    $w->{window}->show_all;
    $w->sync until $w->{displayed};
    $w;
}
sub wait_message_nextW {
    my ($o, $messages, $w) = @_;
    my $msg = join "\n", @$messages;
    return if $msg eq $w->{wait_messageW}->get; #- needed otherwise no expose_event :(
    $w->{displayed} = 0;
    $w->{wait_messageW}->set($msg);
    $w->flush until $w->{displayed};
}
sub wait_message_endW {
    my ($o, $w) = @_;
    $w->destroy;
}

sub kill {
    my ($o) = @_;
    $o->{before_killing} ||= 0;

    while (my $e = shift @tempory::objects) { $e->destroy }
    while (@interactive::objects > $o->{before_killing}) {
	my $w = pop @interactive::objects;
	$w->destroy;
    }
    $o->{before_killing} = @interactive::objects;
}