diff options
author | Antoine Ginies <aginies@mandriva.com> | 2005-09-08 08:16:34 +0000 |
---|---|---|
committer | Antoine Ginies <aginies@mandriva.com> | 2005-09-08 08:16:34 +0000 |
commit | e2928fac4711a71c86bc4a7af9eab156050a3a56 (patch) | |
tree | c5204165f3dbd595a64b25b427b89b818f728c00 /common | |
parent | db37e7a1944b89158ca032f145caf237144c108d (diff) | |
download | drakwizard-e2928fac4711a71c86bc4a7af9eab156050a3a56.tar drakwizard-e2928fac4711a71c86bc4a7af9eab156050a3a56.tar.gz drakwizard-e2928fac4711a71c86bc4a7af9eab156050a3a56.tar.bz2 drakwizard-e2928fac4711a71c86bc4a7af9eab156050a3a56.tar.xz drakwizard-e2928fac4711a71c86bc4a7af9eab156050a3a56.zip |
new gtk_log
Diffstat (limited to 'common')
-rw-r--r-- | common/Wizcommon_gtk2.pm | 100 |
1 files changed, 41 insertions, 59 deletions
diff --git a/common/Wizcommon_gtk2.pm b/common/Wizcommon_gtk2.pm index ab9d04f9..9418bde6 100644 --- a/common/Wizcommon_gtk2.pm +++ b/common/Wizcommon_gtk2.pm @@ -21,7 +21,7 @@ package MDK::Wizard::Wizcommon_gtk2; use strict; -use common; +#use common; sub wizard_progress_bar { use lib qw(/usr/lib/libDrakX); @@ -44,77 +44,59 @@ sub wizard_progress_bar { $pbar->set_pulse_step(0.1); local *TMP; - open(TMP, "$command 2>&1 |"); - while ($value = <TMP>) { + open(TMP, "GP_LANG=UTF-8 $command 2>&1 |"); + while (<TMP>) { $timer = Glib::Timeout->add(10, sub {}); $pbar->pulse; - $text2->set_text($value); + s/\033\[[^mG]*[mG]//g; + $text2->set_text($_); gtkflush(); next; $my_win->main; $window1->show_all; - undef $value; + #undef $value; } close TMP; $my_win->destroy; return 0; } +sub gtk_log { + use lib qw(/usr/lib/libDrakX); + use ugtk2 qw(:wrappers); + use mygtk2 qw(gtknew); + my ($command) = @_; + my $log_text = gtknew('TextView'); + my $my_win = ugtk2->new(""); + my $window1 = $my_win->{window}; + #my $pid; + gtkadd($window1, + gtknew('VBox', spacing => 1, children => [ + 1, gtknew('ScrolledWindow', child => $log_text), +# 0, gtksignal_connect(gtknew('Button', text => N("cancel")), clicked => sub { + # if ($pid) { +# $::in->ask_yesorno('', N("The command is still running. Do you want to kill it and quit the Wizard?")) or return; +# kill 9, $pid and system("touch /tmp/wiz_error"); +# } +# } +# ), + ], + ), + ); -my $timeout; -sub gtktext_get_log { - my ($command, $log_w, $log_scroll) = @_; - my $buffer = $log_w->get_buffer; - $buffer->delete($buffer->get_start_iter, $buffer->get_end_iter); - - my ($prev_scroll, $want_scroll_down) = (0, 1); - my $pid = open(my $F, "$command 2>&1 |") or return sub { 1 }; - fcntl($F, c::F_SETFL(), c::O_NONBLOCK()) or die "can't fcntl F_SETFL: $!"; - Glib::Source->remove($timeout) if $timeout; $timeout = ''; - $timeout = Glib::Timeout->add(100, sub { - if ($buffer) { - my $end = $buffer->get_end_iter; - while (defined (my $s = <$F>)) { - $buffer->insert_interactive($end, $s, -1); - } - my $new_scroll = $log_scroll->child->get_vadjustment->get_value; - $want_scroll_down &&= $new_scroll >= $prev_scroll; - $prev_scroll = $new_scroll; - $log_w->scroll_to_iter($end, 0, 0, 0, 0) if $want_scroll_down; - } - if (waitpid($pid, c::WNOHANG()) > 0) { - $buffer->insert_interactive($buffer->get_end_iter, "\n" . "#" x 20 . "\n" . " This script has terminated,\nyou can close this window", -1) if $buffer; - $pid = $timeout = ''; - 0; - } else { - 1; - } - }); - sub { - if ($pid) { - $::in->ask_yesorno('', N("The command is still running. Do you want to kill it and quit the Wizard?")) or return; - kill 9, $pid+1; - 1; - } - $buffer = ''; - 1; - }; -} - -sub run_command_and_log { - use lib qw(/usr/lib/libDrakX); - my ($command, $descr, $when_command_is_over) = @_; - my $w = ugtk2->new(''); - gtkadd(gtkset_size_request($w->{window}, 800, 400), - gtkpack_(gtkset_modal(Gtk2::VBox->new, 1), - 0, $descr, - 1, my $log_scroll = create_scrolled_window(my $log_w = gtkset_editable(Gtk2::TextView->new, 0)), - 0, my $close_w = Gtk2::Button->new(N("Close"))), - ); - my $stop_running = gtktext_get_log($command, $log_w, $log_scroll); - $close_w->signal_connect(clicked => sub { $stop_running->() and $w->destroy and return 0 }); - $close_w->grab_focus; - $w->show; + my $TMP; + open($TMP, "GP_LANG=UTF-8 $command 2>&1 |"); + gtktext_append($log_text, "$command\n\n"); + while (<$TMP>) { + s/\033\[[^mG]*[mG]//g; + gtktext_append($log_text, $_); + gtkflush(); + next; + $my_win->main; + } + $window1->show_all; + close $TMP; + $my_win->destroy; } 1; |