diff --git a/src/slic3r/GUI/MainFrame.cpp b/src/slic3r/GUI/MainFrame.cpp index e755ff4da..0550f8ac4 100644 --- a/src/slic3r/GUI/MainFrame.cpp +++ b/src/slic3r/GUI/MainFrame.cpp @@ -2349,7 +2349,7 @@ void MainFrame::init_menubar_as_editor() // } // case ConfigMenuPreferences: // { -// wxGetApp().CallAfter([this] { +// CallAfter([this] { // PreferencesDialog dlg(this); // dlg.ShowModal(); //#if ENABLE_GCODE_LINES_ID_IN_H_SLIDER @@ -2386,7 +2386,7 @@ void MainFrame::init_menubar_as_editor() // Slic3r::GUI::about(); // break; // case BambuStudioMenuPreferences: - // wxGetApp().CallAfter([this] { + // CallAfter([this] { // PreferencesDialog dlg(this); // dlg.ShowModal(); //#if ENABLE_GCODE_LINES_ID_IN_H_SLIDER @@ -3030,7 +3030,7 @@ void MainFrame::open_recent_project(size_t file_id, wxString const & filename) file_id = m_recent_projects.FindFileInHistory(filename); } if (wxFileExists(filename)) { - wxGetApp().CallAfter([this, filename] { + CallAfter([this, filename] { if (wxGetApp().can_load_project()) m_plater->load_project(filename); }); diff --git a/src/slic3r/GUI/MediaPlayCtrl.cpp b/src/slic3r/GUI/MediaPlayCtrl.cpp index 407e89530..797e12be4 100644 --- a/src/slic3r/GUI/MediaPlayCtrl.cpp +++ b/src/slic3r/GUI/MediaPlayCtrl.cpp @@ -311,7 +311,7 @@ void MediaPlayCtrl::ToggleStream() { return std::make_shared(pri); } void on_finish() override { - wxGetApp().CallAfter([ctrl = this->ctrl] { ctrl->ToggleStream(); }); + ctrl->CallAfter([ctrl = this->ctrl] { ctrl->ToggleStream(); }); EndModal(wxID_CLOSE); } }; @@ -585,7 +585,7 @@ void wxMediaCtrl2::DoSetSize(int x, int y, int width, int height, int sizeFlags) if (maxHeight != GetMaxHeight()) { // BOOST_LOG_TRIVIAL(info) << "wxMediaCtrl2::DoSetSize: width: " << width << ", height: " << height << ", maxHeight: " << maxHeight; SetMaxSize({-1, maxHeight}); - Slic3r::GUI::wxGetApp().CallAfter([this] { + CallAfter([this] { if (auto p = GetParent()) { p->Layout(); p->Refresh(); diff --git a/src/slic3r/GUI/Widgets/WebView.cpp b/src/slic3r/GUI/Widgets/WebView.cpp index 59b1a866a..ed1c30067 100644 --- a/src/slic3r/GUI/Widgets/WebView.cpp +++ b/src/slic3r/GUI/Widgets/WebView.cpp @@ -180,14 +180,18 @@ wxWebView* WebView::CreateWebView(wxWindow * parent, wxString const & url) Slic3r::GUI::WKWebView_setTransparentBackground(wkWebView); #endif #ifndef __WIN32__ - Slic3r::GUI::wxGetApp().CallAfter([webView] { + webView->CallAfter([webView] { #endif BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << ": begin to add script message handler for wx."; Slic3r::GUI::wxGetApp().set_adding_script_handler(true); + webView->Bind(wxEVT_DESTROY, [webView] (auto & e) { + webView->RemoveScriptMessageHandler("wx"); + }); if (!webView->AddScriptMessageHandler("wx")) wxLogError("Could not add script message handler"); Slic3r::GUI::wxGetApp().set_adding_script_handler(false); BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << ": finished add script message handler for wx."; + #ifndef __WIN32__ }); #endif diff --git a/src/slic3r/GUI/wxMediaCtrl2.cpp b/src/slic3r/GUI/wxMediaCtrl2.cpp index 6ef78eec6..fd792c9c7 100644 --- a/src/slic3r/GUI/wxMediaCtrl2.cpp +++ b/src/slic3r/GUI/wxMediaCtrl2.cpp @@ -43,7 +43,7 @@ void wxMediaCtrl2::Load(wxURI url) { #ifdef __WIN32__ if (m_imp == nullptr) { - Slic3r::GUI::wxGetApp().CallAfter([] { + CallAfter([] { auto res = wxMessageBox(_L("Windows Media Player is required for this task! Do you want to enable 'Windows Media Player' for your operation system?"), _L("Error"), wxOK | wxCANCEL); if (res == wxOK) { wxString url = IsWindows10OrGreater() @@ -73,7 +73,7 @@ void wxMediaCtrl2::Load(wxURI url) boost::filesystem::path data_dir_path(data_dir_str); auto dll_path = data_dir_path / "plugins" / "BambuSource.dll"; if (boost::filesystem::exists(dll_path)) { - Slic3r::GUI::wxGetApp().CallAfter( + CallAfter( [dll_path] { int res = wxMessageBox(_L("BambuSource has not correctly been registered for media playing! Press Yes to re-register it."), _L("Error"), wxYES_NO); if (res == wxYES) { @@ -82,7 +82,7 @@ void wxMediaCtrl2::Load(wxURI url) } }); } else { - Slic3r::GUI::wxGetApp().CallAfter([] { + CallAfter([] { wxMessageBox(_L("Missing BambuSource component registered for media playing! Please re-install BambuStutio or seek after-sales help."), _L("Error"), wxOK); }); } @@ -131,7 +131,7 @@ void wxMediaCtrl2::Load(wxURI url) } if (!hasplugins) { - Slic3r::GUI::wxGetApp().CallAfter([] { + CallAfter([] { wxMessageBox(_L("Your system is missing H.264 codecs for GStreamer, which are required to play video. (Try installing the gstreamer1.0-plugins-bad or gstreamer1.0-libav packages, then restart Bambu Studio?)"), _L("Error"), wxOK); }); m_error = 101;