]> git.proxmox.com Git - pve-installer.git/commitdiff
UI: add progress and process_events helper
authorThomas Lamprecht <t.lamprecht@proxmox.com>
Mon, 19 Jun 2023 18:04:58 +0000 (20:04 +0200)
committerThomas Lamprecht <t.lamprecht@proxmox.com>
Mon, 19 Jun 2023 19:49:00 +0000 (21:49 +0200)
Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
Proxmox/UI.pm
Proxmox/UI/Base.pm
Proxmox/UI/Gtk3.pm
Proxmox/UI/StdIO.pm
proxinstall

index c876eb66e90813c1c756757be715e9dd30e54ed8..7d8bd4f08930eb3336e842f888eca37d316b1aa9 100644 (file)
@@ -83,4 +83,19 @@ sub display_html {
     return get_ui()->display_html($raw_html, $html_dir);
 }
 
+sub progress {
+    my ($frac, $start, $end, $text) = @_;
+
+    my $part = $end - $start;
+    my $ratio = $start + $frac * $part;
+
+    get_ui()->progress($ratio, $text);
+
+    return $ratio;
+}
+
+sub process_events {
+    get_ui()->process_events();
+}
+
 1;
index 444a9f96b25118145555ff3021b1c27b847ca5ce..05af9c198c504738336bf68e219bb002f1c03341 100644 (file)
@@ -44,4 +44,16 @@ sub display_html {
     croak "implement me in sub-class";
 }
 
+sub progress {
+    my ($self, $ratio, $text) = @_;
+
+    croak "implement me in sub-class";
+}
+
+sub process_events {
+    my ($self) = @_;
+
+    croak "implement me in sub-class";
+}
+
 1;
index 98cdc8c4aec31ad1cf7aa12450d7c4443180f1a5..7bb9ddf12c98efcc2709c72ffa38a8210d6e8c89 100644 (file)
@@ -45,4 +45,19 @@ sub display_html {
     $html_view->load_html($raw_html,  "file://$html_dir/");
 }
 
+sub progress {
+    my ($self, $ratio, $text) = @_;
+
+    my ($bar, $status) = $self->{state}->@{'progress_bar', 'progress_status'};
+
+    $bar->set_fraction($ratio);
+    $bar->set_text(sprintf ("%d%%", int ($ratio * 100)));
+    $status->set_text($text) if defined($text);
+}
+
+sub process_events {
+    my ($self) = @_;
+    Gtk3::main_iteration() while Gtk3::events_pending();
+}
+
 1;
index f62bfb4e2a7b7f07444c3fe3be6d8f1fa57523db..c73e1249ffb43c110425163f5bc1c3fdf6fdddf6 100644 (file)
@@ -35,4 +35,16 @@ sub display_html {
     # ignore for now
 }
 
+sub progress {
+    my ($self, $ratio, $text) = @_;
+
+    print STDOUT "progress: $ratio $text\n";
+}
+
+sub process_events {
+    my ($self) = @_;
+
+    # nothing to do for now?
+}
+
 1;
index c2f8e4051776023b17ec838f2367703dafa30b9b..ffe5230156aceaa2ad82727acb664f27490251fc 100755 (executable)
@@ -308,16 +308,11 @@ my $total_memory = get_memtotal();
 sub update_progress {
     my ($frac, $start, $end, $text) = @_;
 
-    my $part = $end - $start;
-    my $res = $start + $frac * $part;
-
-    $gtk_state->{progress_bar}->set_fraction ($res);
-    $gtk_state->{progress_bar}->set_text(sprintf ("%d%%", int ($res*100)));
-    $gtk_state->{progress_status}->set_text($text) if defined($text);
+    my $res = Proxmox::UI::progress($frac, $start, $end, $text);
 
     display_info() if $res < 0.9;
 
-    Gtk3::main_iteration() while Gtk3::events_pending();
+    Proxmox::UI::process_events();
 }
 
 my $fssetup = {