mirror of
https://git.mirrors.martin98.com/https://github.com/slic3r/Slic3r.git
synced 2025-08-04 01:30:40 +08:00
Try to fix OctoPrint issues. #3789
This commit is contained in:
parent
4c14c656f5
commit
488cc02f53
@ -256,43 +256,10 @@ sub new {
|
|||||||
EVT_LEFT_UP($self->{btn_send_gcode}, sub {
|
EVT_LEFT_UP($self->{btn_send_gcode}, sub {
|
||||||
my (undef, $e) = @_;
|
my (undef, $e) = @_;
|
||||||
|
|
||||||
my $filename = basename($self->{print}->output_filepath($main::opt{output} // ''));
|
my $alt = $e->AltDown;
|
||||||
|
wxTheApp->CallAfter(sub {
|
||||||
if (!$e->AltDown) {
|
$self->prepare_send($alt);
|
||||||
# When the alt key is pressed, bypass the dialog.
|
});
|
||||||
my $dlg = Slic3r::GUI::Plater::OctoPrintSpoolDialog->new($self, $filename);
|
|
||||||
return unless $dlg->ShowModal == wxID_OK;
|
|
||||||
$filename = $dlg->{filename};
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!$Slic3r::GUI::Settings->{octoprint}{overwrite}) {
|
|
||||||
my $progress = Wx::ProgressDialog->new('Querying OctoPrint…',
|
|
||||||
"Checking whether file already exists…", 100, $self, 0);
|
|
||||||
$progress->Pulse;
|
|
||||||
|
|
||||||
my $ua = LWP::UserAgent->new;
|
|
||||||
$ua->timeout(5);
|
|
||||||
my $res = $ua->get("http://" . $self->{config}->octoprint_host . "/api/files/local");
|
|
||||||
$progress->Destroy;
|
|
||||||
if ($res->is_success) {
|
|
||||||
if ($res->decoded_content =~ /"name":\s*"\Q$filename\E"/) {
|
|
||||||
my $dialog = Wx::MessageDialog->new($self,
|
|
||||||
"It looks like a file with the same name already exists in the server. "
|
|
||||||
. "Shall I overwrite it?",
|
|
||||||
'OctoPrint', wxICON_WARNING | wxYES | wxNO);
|
|
||||||
if ($dialog->ShowModal() == wxID_NO) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
my $message = "Error while connecting to the OctoPrint server: " . $res->status_line;
|
|
||||||
Slic3r::GUI::show_error($self, $message);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$self->{send_gcode_file_print} = $Slic3r::GUI::Settings->{octoprint}{start};
|
|
||||||
$self->{send_gcode_file} = $self->export_gcode(Wx::StandardPaths::Get->GetTempDir() . "/" . $filename);
|
|
||||||
});
|
});
|
||||||
EVT_BUTTON($self, $self->{btn_export_stl}, \&export_stl);
|
EVT_BUTTON($self, $self->{btn_export_stl}, \&export_stl);
|
||||||
|
|
||||||
@ -1452,6 +1419,52 @@ sub do_print {
|
|||||||
$self->GetFrame->select_tab(1);
|
$self->GetFrame->select_tab(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sub prepare_send {
|
||||||
|
my ($self, $skip_dialog) = @_;
|
||||||
|
|
||||||
|
return if !$self->{btn_send_gcode}->IsEnabled;
|
||||||
|
my $filename = basename($self->{print}->output_filepath($main::opt{output} // ''));
|
||||||
|
|
||||||
|
if (!$skip_dialog) {
|
||||||
|
# When the alt key is pressed, bypass the dialog.
|
||||||
|
my $dlg = Slic3r::GUI::Plater::OctoPrintSpoolDialog->new($self, $filename);
|
||||||
|
return unless $dlg->ShowModal == wxID_OK;
|
||||||
|
$filename = $dlg->{filename};
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!$Slic3r::GUI::Settings->{octoprint}{overwrite}) {
|
||||||
|
my $progress = Wx::ProgressDialog->new('Querying OctoPrint…',
|
||||||
|
"Checking whether file already exists…", 100, $self, 0);
|
||||||
|
$progress->Pulse;
|
||||||
|
|
||||||
|
my $ua = LWP::UserAgent->new;
|
||||||
|
$ua->timeout(5);
|
||||||
|
my $res = $ua->get(
|
||||||
|
"http://" . $self->{config}->octoprint_host . "/api/files/local",
|
||||||
|
'X-Api-Key' => $self->{config}->octoprint_apikey,
|
||||||
|
);
|
||||||
|
$progress->Destroy;
|
||||||
|
if ($res->is_success) {
|
||||||
|
if ($res->decoded_content =~ /"name":\s*"\Q$filename\E"/) {
|
||||||
|
my $dialog = Wx::MessageDialog->new($self,
|
||||||
|
"It looks like a file with the same name already exists in the server. "
|
||||||
|
. "Shall I overwrite it?",
|
||||||
|
'OctoPrint', wxICON_WARNING | wxYES | wxNO);
|
||||||
|
if ($dialog->ShowModal() == wxID_NO) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
my $message = "Error while connecting to the OctoPrint server: " . $res->status_line;
|
||||||
|
Slic3r::GUI::show_error($self, $message);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$self->{send_gcode_file_print} = $Slic3r::GUI::Settings->{octoprint}{start};
|
||||||
|
$self->{send_gcode_file} = $self->export_gcode(Wx::StandardPaths::Get->GetTempDir() . "/" . $filename);
|
||||||
|
}
|
||||||
|
|
||||||
sub send_gcode {
|
sub send_gcode {
|
||||||
my ($self) = @_;
|
my ($self) = @_;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user