From b5a6fe52b5fd2f3a07a51c05e21c6315af147f9e Mon Sep 17 00:00:00 2001 From: tao wang Date: Tue, 5 Nov 2024 12:08:19 +0800 Subject: [PATCH] FIX:Fixed the use of wxwidget method in other threads jira:[for thread issue] Change-Id: I62f5b6913d9bc25ac6c81517ef20f28fa34d0124 --- src/slic3r/GUI/ReleaseNote.cpp | 76 +++++++++++++++++++--------------- src/slic3r/GUI/ReleaseNote.hpp | 4 ++ 2 files changed, 46 insertions(+), 34 deletions(-) diff --git a/src/slic3r/GUI/ReleaseNote.cpp b/src/slic3r/GUI/ReleaseNote.cpp index 3e942ec72..5fc809bb8 100644 --- a/src/slic3r/GUI/ReleaseNote.cpp +++ b/src/slic3r/GUI/ReleaseNote.cpp @@ -33,11 +33,13 @@ wxDEFINE_EVENT(EVT_CHECKBOX_CHANGE, wxCommandEvent); wxDEFINE_EVENT(EVT_ENTER_IP_ADDRESS, wxCommandEvent); wxDEFINE_EVENT(EVT_CLOSE_IPADDRESS_DLG, wxCommandEvent); wxDEFINE_EVENT(EVT_CHECK_IP_ADDRESS_FAILED, wxCommandEvent); +wxDEFINE_EVENT(EVT_CHECK_IP_ADDRESS_LAYOUT, wxCommandEvent); wxDEFINE_EVENT(EVT_SECONDARY_CHECK_RETRY, wxCommandEvent); wxDEFINE_EVENT(EVT_PRINT_ERROR_STOP, wxCommandEvent); wxDEFINE_EVENT(EVT_UPDATE_NOZZLE, wxCommandEvent); wxDEFINE_EVENT(EVT_JUMP_TO_HMS, wxCommandEvent); wxDEFINE_EVENT(EVT_JUMP_TO_LIVEVIEW, wxCommandEvent); +wxDEFINE_EVENT(EVT_UPDATE_TEXT_MSG, wxCommandEvent); ReleaseNoteDialog::ReleaseNoteDialog(Plater *plater /*= nullptr*/) : DPIDialog(static_cast(wxGetApp().mainframe), wxID_ANY, _L("Release Note"), wxDefaultPosition, wxDefaultSize, wxCAPTION | wxCLOSE_BOX) @@ -1736,6 +1738,14 @@ InputIpAddressDialog::InputIpAddressDialog(wxWindow *parent) on_cancel(); closeTimer->Stop(); }); + + Bind(EVT_UPDATE_TEXT_MSG, &InputIpAddressDialog::update_test_msg_event, this); + Bind(EVT_CHECK_IP_ADDRESS_LAYOUT, [this](auto& e) { + int mode = e.GetInt(); + switch_input_panel(mode); + Layout(); + Fit(); + }); } void InputIpAddressDialog::switch_input_panel(int index) @@ -1868,9 +1878,27 @@ void InputIpAddressDialog::on_ok(wxMouseEvent& evt) m_thread = new boost::thread(boost::bind(&InputIpAddressDialog::workerThreadFunc, this, str_ip, str_access_code, str_sn, str_model_id)); } +void InputIpAddressDialog::update_test_msg_event(wxCommandEvent& evt) +{ + wxString text = evt.GetString(); + bool beconnect = evt.GetInt(); + update_test_msg(text, beconnect); + Layout(); + Fit(); +} + +void InputIpAddressDialog::post_update_test_msg(wxString text, bool beconnect) +{ + wxCommandEvent event(EVT_UPDATE_TEXT_MSG); + event.SetEventObject(this); + event.SetString(text); + event.SetInt(beconnect); + wxPostEvent(this, event); +} + void InputIpAddressDialog::workerThreadFunc(std::string str_ip, std::string str_access_code, std::string sn, std::string model_id) { - update_test_msg(_L("connecting..."), true); + post_update_test_msg(_L("connecting..."), true); detectResult detectData; auto result = -1; @@ -1885,44 +1913,31 @@ void InputIpAddressDialog::workerThreadFunc(std::string str_ip, std::string str_ } if (result < 0) { - update_test_msg(wxEmptyString, true); + post_update_test_msg(wxEmptyString, true); if (result == -1) { - update_test_msg(_L("Failed to connect to printer."), false); + post_update_test_msg(_L("Failed to connect to printer."), false); } else if (result == -2) { - update_test_msg(_L("Failed to publish login request."), false); + post_update_test_msg(_L("Failed to publish login request."), false); } else if (result == -3) { - switch_input_panel(1); - //update_test_msg(_L("The device does not support using IP and Access Code for connection."), false); + wxCommandEvent event(EVT_CHECK_IP_ADDRESS_LAYOUT); + event.SetEventObject(this); + event.SetInt(1); + wxPostEvent(this, event); } - - - /*m_button_ok->Enable(true); - StateColor btn_bg_green(std::pair(wxColour(61, 203, 115), StateColor::Pressed), std::pair(wxColour(61, 203, 115), StateColor::Hovered), - std::pair(AMS_CONTROL_BRAND_COLOUR, StateColor::Normal)); - m_button_ok->SetTextColor(StateColor::darkModeColorFor("#FFFFFE")); - m_button_ok->SetBackgroundColor(btn_bg_green); - m_button_ok->SetBorderColor(*wxWHITE);*/ - - Layout(); - Fit(); return; } if (detectData.bind_state == "occupied") { - update_test_msg(wxEmptyString, true); - update_test_msg(_L("The printer has already been bound."), false); - Layout(); - Fit(); + post_update_test_msg(wxEmptyString, true); + post_update_test_msg(_L("The printer has already been bound."), false); return; } if (detectData.connect_type == "cloud") { - update_test_msg(wxEmptyString, true); - update_test_msg(_L("The printer mode is incorrect, please switch to LAN Only."), false); - Layout(); - Fit(); + post_update_test_msg(wxEmptyString, true); + post_update_test_msg(_L("The printer mode is incorrect, please switch to LAN Only."), false); return; } @@ -1938,21 +1953,15 @@ void InputIpAddressDialog::workerThreadFunc(std::string str_ip, std::string str_ closeCount = 1; - update_test_msg(wxEmptyString, true); - update_test_msg(wxString::Format(_L("Connecting to printer... The dialog will close later"), closeCount), true); + post_update_test_msg(wxEmptyString, true); + post_update_test_msg(wxString::Format(_L("Connecting to printer... The dialog will close later"), closeCount), true); closeTimer->Start(1000); - - Layout(); - Fit(); - Refresh(true); } void InputIpAddressDialog::OnTimer(wxTimerEvent& event) { if (closeCount > 0) { closeCount--; - //update_test_msg(wxString::Format(_L("Printer binding successful. The dialog will close in %d seconds"), closeCount), true); - //Refresh(); } else { closeTimer->Stop(); @@ -1975,7 +1984,6 @@ void InputIpAddressDialog::on_check_ip_address_failed(wxCommandEvent& evt) } else { update_test_msg(_L("Connection failed! If your IP and Access Code is correct, \nplease move to step 3 for troubleshooting network issues"), false); - //m_trouble_shoot->Show(); Layout(); Fit(); } diff --git a/src/slic3r/GUI/ReleaseNote.hpp b/src/slic3r/GUI/ReleaseNote.hpp index 3df2c92eb..95c547a63 100644 --- a/src/slic3r/GUI/ReleaseNote.hpp +++ b/src/slic3r/GUI/ReleaseNote.hpp @@ -50,6 +50,7 @@ wxDECLARE_EVENT(EVT_UPDATE_NOZZLE, wxCommandEvent); wxDECLARE_EVENT(EVT_LOAD_VAMS_TRAY, wxCommandEvent); wxDECLARE_EVENT(EVT_JUMP_TO_HMS, wxCommandEvent); wxDECLARE_EVENT(EVT_JUMP_TO_LIVEVIEW, wxCommandEvent); +wxDECLARE_EVENT(EVT_UPDATE_TEXT_MSG, wxCommandEvent); class ReleaseNoteDialog : public DPIDialog { @@ -324,6 +325,8 @@ public: void check_ip_address_failed(int result); void on_check_ip_address_failed(wxCommandEvent& evt); void on_ok(wxMouseEvent& evt); + void update_test_msg_event(wxCommandEvent &evt); + void post_update_test_msg(wxString text, bool beconnect); void workerThreadFunc(std::string str_ip, std::string str_access_code, std::string sn, std::string model_id); void OnTimer(wxTimerEvent& event); void on_text(wxCommandEvent& evt); @@ -335,6 +338,7 @@ wxDECLARE_EVENT(EVT_CLOSE_IPADDRESS_DLG, wxCommandEvent); wxDECLARE_EVENT(EVT_CHECKBOX_CHANGE, wxCommandEvent); wxDECLARE_EVENT(EVT_ENTER_IP_ADDRESS, wxCommandEvent); wxDECLARE_EVENT(EVT_CHECK_IP_ADDRESS_FAILED, wxCommandEvent); +wxDECLARE_EVENT(EVT_CHECK_IP_ADDRESS_LAYOUT, wxCommandEvent); }} // namespace Slic3r::GUI