mirror of
https://github.com/SoftFever/OrcaSlicer.git
synced 2025-07-15 10:47:50 -06:00
Almost working c++ status bar
Signed-off-by: tamasmeszaros <meszaros.q@gmail.com>
This commit is contained in:
parent
5ee106fbf9
commit
9e2d48ff3b
13 changed files with 442 additions and 156 deletions
|
@ -62,13 +62,14 @@ sub new {
|
|||
eval { Wx::ToolTip::SetAutoPop(32767) };
|
||||
|
||||
# initialize status bar
|
||||
$self->{statusbar} = Slic3r::GUI::ProgressStatusBar->new($self, Wx::NewId);
|
||||
$self->{statusbar} = Slic3r::GUI::ProgressStatusBar->new();
|
||||
# $self->{statusbar}->SetParent($self, Wx::NewId);
|
||||
$self->{statusbar}->Embed;
|
||||
$self->{statusbar}->SetStatusText(L("Version ").$Slic3r::VERSION.L(" - Remember to check for updates at http://github.com/prusa3d/slic3r/releases"));
|
||||
$self->SetStatusBar($self->{statusbar});
|
||||
|
||||
|
||||
# Make the global status bar and its progress indicator available in C++
|
||||
$appController->set_global_progress_indicator(
|
||||
$self->{statusbar}->{prog}->GetId(),
|
||||
$self->{statusbar}->GetProgId(),
|
||||
$self->{statusbar}->GetId(),
|
||||
);
|
||||
|
||||
|
|
|
@ -4,141 +4,143 @@ package Slic3r::GUI::ProgressStatusBar;
|
|||
use strict;
|
||||
use warnings;
|
||||
|
||||
use Wx qw(:gauge :misc);
|
||||
use base 'Wx::StatusBar';
|
||||
# use Wx qw(:gauge :misc);
|
||||
# use base 'Wx::StatusBar';
|
||||
|
||||
sub new {
|
||||
my $class = shift;
|
||||
my $self = $class->SUPER::new(@_);
|
||||
|
||||
$self->{busy} = 0;
|
||||
$self->{timer} = Wx::Timer->new($self);
|
||||
$self->{prog} = Wx::Gauge->new($self, wxGA_HORIZONTAL, 100, wxDefaultPosition, wxDefaultSize);
|
||||
$self->{prog}->Hide;
|
||||
$self->{cancelbutton} = Wx::Button->new($self, -1, "Cancel", wxDefaultPosition, wxDefaultSize);
|
||||
$self->{cancelbutton}->Hide;
|
||||
|
||||
$self->SetFieldsCount(3);
|
||||
$self->SetStatusWidths(-1, 150, 155);
|
||||
|
||||
Wx::Event::EVT_TIMER($self, \&OnTimer, $self->{timer});
|
||||
Wx::Event::EVT_SIZE($self, \&OnSize);
|
||||
Wx::Event::EVT_BUTTON($self, $self->{cancelbutton}, sub {
|
||||
$self->{cancel_cb}->();
|
||||
$self->{cancelbutton}->Hide;
|
||||
});
|
||||
|
||||
return $self;
|
||||
}
|
||||
our $cancel_cb;
|
||||
|
||||
sub DESTROY {
|
||||
my $self = shift;
|
||||
$self->{timer}->Stop if $self->{timer} && $self->{timer}->IsRunning;
|
||||
}
|
||||
|
||||
sub OnSize {
|
||||
my ($self, $event) = @_;
|
||||
# sub new {
|
||||
# my $class = shift;
|
||||
# my $self = $class->SUPER::new(@_);
|
||||
|
||||
my %fields = (
|
||||
# 0 is reserved for status text
|
||||
1 => $self->{cancelbutton},
|
||||
2 => $self->{prog},
|
||||
);
|
||||
|
||||
foreach (keys %fields) {
|
||||
my $rect = $self->GetFieldRect($_);
|
||||
my $offset = &Wx::wxGTK ? 1 : 0; # add a cosmetic 1 pixel offset on wxGTK
|
||||
my $pos = [$rect->GetX + $offset, $rect->GetY + $offset];
|
||||
$fields{$_}->Move($pos);
|
||||
$fields{$_}->SetSize($rect->GetWidth - $offset, $rect->GetHeight);
|
||||
}
|
||||
|
||||
$event->Skip;
|
||||
}
|
||||
|
||||
sub OnTimer {
|
||||
my ($self, $event) = @_;
|
||||
# $self->{busy} = 0;
|
||||
# $self->{timer} = Wx::Timer->new($self);
|
||||
# $self->{prog} = Wx::Gauge->new($self, wxGA_HORIZONTAL, 100, wxDefaultPosition, wxDefaultSize);
|
||||
# $self->{prog}->Hide;
|
||||
# $self->{cancelbutton} = Wx::Button->new($self, -1, "Cancel", wxDefaultPosition, wxDefaultSize);
|
||||
# $self->{cancelbutton}->Hide;
|
||||
|
||||
if ($self->{prog}->IsShown) {
|
||||
$self->{timer}->Stop;
|
||||
}
|
||||
$self->{prog}->Pulse if $self->{_busy};
|
||||
}
|
||||
# $self->SetFieldsCount(3);
|
||||
# $self->SetStatusWidths(-1, 150, 155);
|
||||
|
||||
# Wx::Event::EVT_TIMER($self, \&OnTimer, $self->{timer});
|
||||
# Wx::Event::EVT_SIZE($self, \&OnSize);
|
||||
# Wx::Event::EVT_BUTTON($self, $self->{cancelbutton}, sub {
|
||||
# $self->{cancel_cb}->();
|
||||
# $self->{cancelbutton}->Hide;
|
||||
# });
|
||||
|
||||
# return $self;
|
||||
# }
|
||||
|
||||
# sub DESTROY {
|
||||
# my $self = shift;
|
||||
# $self->{timer}->Stop if $self->{timer} && $self->{timer}->IsRunning;
|
||||
# }
|
||||
|
||||
# sub OnSize {
|
||||
# my ($self, $event) = @_;
|
||||
|
||||
# my %fields = (
|
||||
# # 0 is reserved for status text
|
||||
# 1 => $self->{cancelbutton},
|
||||
# 2 => $self->{prog},
|
||||
# );
|
||||
|
||||
# foreach (keys %fields) {
|
||||
# my $rect = $self->GetFieldRect($_);
|
||||
# my $offset = &Wx::wxGTK ? 1 : 0; # add a cosmetic 1 pixel offset on wxGTK
|
||||
# my $pos = [$rect->GetX + $offset, $rect->GetY + $offset];
|
||||
# $fields{$_}->Move($pos);
|
||||
# $fields{$_}->SetSize($rect->GetWidth - $offset, $rect->GetHeight);
|
||||
# }
|
||||
|
||||
# $event->Skip;
|
||||
# }
|
||||
|
||||
# sub OnTimer {
|
||||
# my ($self, $event) = @_;
|
||||
|
||||
# if ($self->{prog}->IsShown) {
|
||||
# $self->{timer}->Stop;
|
||||
# }
|
||||
# $self->{prog}->Pulse if $self->{_busy};
|
||||
# }
|
||||
|
||||
sub SetCancelCallback {
|
||||
my $self = shift;
|
||||
my ($cb) = @_;
|
||||
$self->{cancel_cb} = $cb;
|
||||
$cb ? $self->{cancelbutton}->Show : $self->{cancelbutton}->Hide;
|
||||
$cancel_cb = $cb;
|
||||
# $cb ? $self->{cancelbutton}->Show : $self->{cancelbutton}->Hide;
|
||||
}
|
||||
|
||||
sub Run {
|
||||
my $self = shift;
|
||||
my $rate = shift || 100;
|
||||
if (!$self->{timer}->IsRunning) {
|
||||
$self->{timer}->Start($rate);
|
||||
}
|
||||
}
|
||||
# sub Run {
|
||||
# my $self = shift;
|
||||
# my $rate = shift || 100;
|
||||
# if (!$self->{timer}->IsRunning) {
|
||||
# $self->{timer}->Start($rate);
|
||||
# }
|
||||
# }
|
||||
|
||||
sub GetProgress {
|
||||
my $self = shift;
|
||||
return $self->{prog}->GetValue;
|
||||
}
|
||||
# sub GetProgress {
|
||||
# my $self = shift;
|
||||
# return $self->{prog}->GetValue;
|
||||
# }
|
||||
|
||||
sub SetProgress {
|
||||
my $self = shift;
|
||||
my ($val) = @_;
|
||||
if (!$self->{prog}->IsShown) {
|
||||
$self->ShowProgress(1);
|
||||
}
|
||||
if ($val == $self->{prog}->GetRange) {
|
||||
$self->{prog}->SetValue(0);
|
||||
$self->ShowProgress(0);
|
||||
} else {
|
||||
$self->{prog}->SetValue($val);
|
||||
}
|
||||
}
|
||||
# sub SetProgress {
|
||||
# my $self = shift;
|
||||
# my ($val) = @_;
|
||||
# if (!$self->{prog}->IsShown) {
|
||||
# $self->ShowProgress(1);
|
||||
# }
|
||||
# if ($val == $self->{prog}->GetRange) {
|
||||
# $self->{prog}->SetValue(0);
|
||||
# $self->ShowProgress(0);
|
||||
# } else {
|
||||
# $self->{prog}->SetValue($val);
|
||||
# }
|
||||
# }
|
||||
|
||||
sub SetRange {
|
||||
my $self = shift;
|
||||
my ($val) = @_;
|
||||
# sub SetRange {
|
||||
# my $self = shift;
|
||||
# my ($val) = @_;
|
||||
|
||||
if ($val != $self->{prog}->GetRange) {
|
||||
$self->{prog}->SetRange($val);
|
||||
}
|
||||
}
|
||||
# if ($val != $self->{prog}->GetRange) {
|
||||
# $self->{prog}->SetRange($val);
|
||||
# }
|
||||
# }
|
||||
|
||||
sub ShowProgress {
|
||||
my $self = shift;
|
||||
my ($show) = @_;
|
||||
# sub ShowProgress {
|
||||
# my $self = shift;
|
||||
# my ($show) = @_;
|
||||
|
||||
$self->{prog}->Show($show);
|
||||
$self->{prog}->Pulse;
|
||||
}
|
||||
# $self->{prog}->Show($show);
|
||||
# $self->{prog}->Pulse;
|
||||
# }
|
||||
|
||||
sub StartBusy {
|
||||
my $self = shift;
|
||||
my $rate = shift || 100;
|
||||
# sub StartBusy {
|
||||
# my $self = shift;
|
||||
# my $rate = shift || 100;
|
||||
|
||||
$self->{_busy} = 1;
|
||||
$self->ShowProgress(1);
|
||||
if (!$self->{timer}->IsRunning) {
|
||||
$self->{timer}->Start($rate);
|
||||
}
|
||||
}
|
||||
# $self->{_busy} = 1;
|
||||
# $self->ShowProgress(1);
|
||||
# if (!$self->{timer}->IsRunning) {
|
||||
# $self->{timer}->Start($rate);
|
||||
# }
|
||||
# }
|
||||
|
||||
sub StopBusy {
|
||||
my $self = shift;
|
||||
# sub StopBusy {
|
||||
# my $self = shift;
|
||||
|
||||
$self->{timer}->Stop;
|
||||
$self->ShowProgress(0);
|
||||
$self->{prog}->SetValue(0);
|
||||
$self->{_busy} = 0;
|
||||
}
|
||||
# $self->{timer}->Stop;
|
||||
# $self->ShowProgress(0);
|
||||
# $self->{prog}->SetValue(0);
|
||||
# $self->{_busy} = 0;
|
||||
# }
|
||||
|
||||
sub IsBusy {
|
||||
my $self = shift;
|
||||
return $self->{_busy};
|
||||
}
|
||||
# sub IsBusy {
|
||||
# my $self = shift;
|
||||
# return $self->{_busy};
|
||||
# }
|
||||
|
||||
1;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue