ENH: rebuild warning dialog with frame

Change-Id: Id4a8ab80ecec30b668de59556823dad6838276fe
This commit is contained in:
tao.jin 2022-11-26 10:49:42 +08:00 committed by Lane.Wei
parent 5b7ebc3684
commit 2ffa56633c
8 changed files with 133 additions and 64 deletions

View file

@ -343,7 +343,7 @@ void UpdateVersionDialog::update_version_info(wxString release_note, wxString ve
}
SecondaryCheckDialog::SecondaryCheckDialog(wxWindow* parent, wxWindowID id, const wxString& title, enum ButtonStyle btn_style, const wxPoint& pos, const wxSize& size, long style)
:DPIDialog(parent, id, title, pos, size, style)
:DPIFrame(parent, id, title, pos, size, style)
{
std::string icon_path = (boost::format("%1%/images/BambuStudioTitle.ico") % resources_dir()).str();
SetIcon(wxIcon(encode_path(icon_path.c_str()), wxBITMAP_TYPE_ICO));
@ -385,10 +385,7 @@ SecondaryCheckDialog::SecondaryCheckDialog(wxWindow* parent, wxWindowID id, cons
wxCommandEvent evt(EVT_SECONDARY_CHECK_CONFIRM, GetId());
e.SetEventObject(this);
GetEventHandler()->ProcessEvent(evt);
if (this->IsModal())
EndModal(wxID_YES);
else
this->Close();
this->Hide();
});
m_button_cancel = new Button(this, _L("Cancel"));
@ -400,10 +397,7 @@ SecondaryCheckDialog::SecondaryCheckDialog(wxWindow* parent, wxWindowID id, cons
m_button_cancel->SetCornerRadius(FromDIP(12));
m_button_cancel->Bind(wxEVT_LEFT_DOWN, [this](wxMouseEvent& e) {
if (this->IsModal())
EndModal(wxID_NO);
else
this->Close();
this->Hide();
});
if (btn_style != CONFIRM_AND_CANCEL)
@ -420,6 +414,7 @@ SecondaryCheckDialog::SecondaryCheckDialog(wxWindow* parent, wxWindowID id, cons
m_sizer_right->Add(sizer_button, 0, wxEXPAND | wxRIGHT | wxLEFT, FromDIP(35));
m_sizer_right->Add(0, 0, 0, wxTOP,FromDIP(18));
Bind(wxEVT_CLOSE_WINDOW, [this](auto& e) {this->Hide();});
SetSizer(m_sizer_right);
Layout();
@ -457,6 +452,39 @@ void SecondaryCheckDialog::update_text(wxString text)
m_sizer_main->Fit(this);
}
void SecondaryCheckDialog::on_show()
{
// recover button color
wxMouseEvent evt_ok(wxEVT_LEFT_UP);
m_button_ok->GetEventHandler()->ProcessEvent(evt_ok);
wxMouseEvent evt_cancel(wxEVT_LEFT_UP);
m_button_cancel->GetEventHandler()->ProcessEvent(evt_cancel);
this->Show();
this->SetFocus();
}
bool SecondaryCheckDialog::is_english_text(wxString str)
{
std::regex reg("^[0-9a-zA-Z]+$");
std::smatch matchResult;
std::string pattern_Special = "{}[]<>~!@#$%^&*(),.?/ :";
for (auto i = 0; i < str.Length(); i++) {
std::string regex_str = wxString(str[i]).ToStdString();
if(std::regex_match(regex_str, matchResult, reg)){
continue;
}
else {
int result = pattern_Special.find(regex_str.c_str());
if (result < 0 || result > pattern_Special.length()) {
return false;
}
}
}
return true;
}
wxString SecondaryCheckDialog::format_text(wxStaticText* st, wxString str, int warp)
{
if (wxGetApp().app_config->get("language") != "zh_CN") { return str; }

View file

@ -80,7 +80,7 @@ public:
Button* m_button_cancel;
};
class SecondaryCheckDialog : public DPIDialog
class SecondaryCheckDialog : public DPIFrame
{
public:
enum ButtonStyle {
@ -98,9 +98,11 @@ public:
long style = wxCLOSE_BOX | wxCAPTION
);
void update_text(wxString text);
void on_show();
bool is_english_text(wxString str);
wxString format_text(wxStaticText* st, wxString str, int warp);
~SecondaryCheckDialog();
void on_dpi_changed(const wxRect& suggested_rect) override;
void on_dpi_changed(const wxRect& suggested_rect);
wxBoxSizer* m_sizer_main;
wxScrolledWindow *m_vebview_release_note {nullptr};

View file

@ -21,7 +21,6 @@
#include "Plater.hpp"
#include "BitmapCache.hpp"
#include "BindDialog.hpp"
#include "ReleaseNote.hpp"
namespace Slic3r { namespace GUI {
@ -1935,7 +1934,12 @@ void SelectMachineDialog::on_ok_btn(wxCommandEvent &event)
if (!is_same_printer_type || has_slice_warnings) {
wxString confirm_title = _L("Warning");
SecondaryCheckDialog confirm_dlg(this, wxID_ANY, confirm_title);
if (confirm_dlg == nullptr) {
confirm_dlg = new SecondaryCheckDialog(this, wxID_ANY, confirm_title);
confirm_dlg->Bind(EVT_SECONDARY_CHECK_CONFIRM, [this](wxCommandEvent &e) {
this->on_ok();
});
}
wxString info_msg = wxEmptyString;
for (auto i = 0; i < confirm_text.size(); i++) {
@ -1947,10 +1951,9 @@ void SelectMachineDialog::on_ok_btn(wxCommandEvent &event)
}
}
confirm_dlg.update_text(info_msg);
if (confirm_dlg.ShowModal() == wxID_YES) {
this->on_ok();
}
confirm_dlg->update_text(info_msg);
confirm_dlg->on_show();
} else {
this->on_ok();
}
@ -2938,6 +2941,9 @@ bool SelectMachineDialog::Show(bool show)
SelectMachineDialog::~SelectMachineDialog()
{
delete m_refresh_timer;
if (confirm_dlg != nullptr)
delete confirm_dlg;
}
EditDevNameDialog::EditDevNameDialog(Plater *plater /*= nullptr*/)

View file

@ -25,6 +25,7 @@
#include <wx/srchctrl.h>
#include "AmsMappingPopup.hpp"
#include "ReleaseNote.hpp"
#include "GUI_Utils.hpp"
#include "wxExtensions.hpp"
#include "DeviceManager.hpp"
@ -279,6 +280,8 @@ private:
wxColour m_colour_def_color{wxColour(255, 255, 255)};
wxColour m_colour_bold_color{wxColour(38, 46, 48)};
SecondaryCheckDialog* confirm_dlg = nullptr;
protected:
MaterialHash m_materialList;
std::vector<FilamentInfo> m_filaments;

View file

@ -12,7 +12,6 @@
#include "libslic3r/Thread.hpp"
#include "RecenterDialog.hpp"
#include "ReleaseNote.hpp"
namespace Slic3r { namespace GUI {
@ -1175,6 +1174,13 @@ StatusPanel::~StatusPanel()
m_calibration_btn->Disconnect(wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler(StatusPanel::on_start_calibration), NULL, this);
m_options_btn->Disconnect(wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler(StatusPanel::on_show_print_options), NULL, this);
m_button_unload->Disconnect(wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler(StatusPanel::on_start_unload), NULL, this);
// remove warning dialogs
if (m_print_error_dlg != nullptr)
delete m_print_error_dlg;
if (abort_dlg != nullptr)
delete abort_dlg;
}
void StatusPanel::init_scaled_buttons()
@ -1262,12 +1268,14 @@ void StatusPanel::on_subtask_pause_resume(wxCommandEvent &event)
void StatusPanel::on_subtask_abort(wxCommandEvent &event)
{
SecondaryCheckDialog abort_dlg(this->GetParent(), wxID_ANY, _L("Cancel print"));
abort_dlg.update_text(_L("Are you sure you want to cancel this print?"));
abort_dlg.Bind(EVT_SECONDARY_CHECK_CONFIRM, [this](wxCommandEvent &e) {
if (obj) obj->command_task_abort();
});
abort_dlg.ShowModal();
if (abort_dlg == nullptr) {
abort_dlg = new SecondaryCheckDialog(this->GetParent(), wxID_ANY, _L("Cancel print"));
abort_dlg->Bind(EVT_SECONDARY_CHECK_CONFIRM, [this](wxCommandEvent &e) {
if (obj) obj->command_task_abort();
});
}
abort_dlg->update_text(_L("Are you sure you want to cancel this print?"));
abort_dlg->on_show();
}
void StatusPanel::error_info_reset()
@ -1425,9 +1433,9 @@ void StatusPanel::show_error_message(wxString msg)
if (m_panel_error_txt->IsShown()) {
error_info_reset();
}
if (m_print_error_dlg.get() != nullptr) {
if (m_print_error_dlg.get()->IsShown()) {
m_print_error_dlg.get()->EndModal(wxID_OK);
if (m_print_error_dlg != nullptr) {
if (m_print_error_dlg->IsShown()) {
m_print_error_dlg->Hide();
}
}
} else {
@ -1436,9 +1444,11 @@ void StatusPanel::show_error_message(wxString msg)
m_panel_error_txt->Show();
BOOST_LOG_TRIVIAL(info) << "show print error! error_msg = " << msg;
m_print_error_dlg = std::make_shared<SecondaryCheckDialog>(this->GetParent(), wxID_ANY, _L("Warning"), SecondaryCheckDialog::ButtonStyle::ONLY_CONFIRM);
m_print_error_dlg.get()->update_text(msg);
m_print_error_dlg.get()->ShowModal();
if (m_print_error_dlg == nullptr) {
m_print_error_dlg = new SecondaryCheckDialog(this->GetParent(), wxID_ANY, _L("Warning"), SecondaryCheckDialog::ButtonStyle::ONLY_CONFIRM);
}
m_print_error_dlg->update_text(msg);
m_print_error_dlg->on_show();
}
}

View file

@ -257,7 +257,8 @@ protected:
PrintOptionsDialog* print_options_dlg { nullptr };
CalibrationDialog* calibration_dlg {nullptr};
AMSMaterialsSetting *m_filament_setting_dlg{nullptr};
std::shared_ptr<SecondaryCheckDialog> m_print_error_dlg = nullptr;
SecondaryCheckDialog* m_print_error_dlg = nullptr;
SecondaryCheckDialog* abort_dlg = nullptr;
wxString m_request_url;
bool m_start_loading_thumbnail = false;

View file

@ -4,7 +4,6 @@
#include "GUI.hpp"
#include "GUI_App.hpp"
#include "libslic3r/Thread.hpp"
#include "ReleaseNote.hpp"
namespace Slic3r {
namespace GUI {
@ -268,6 +267,9 @@ MachineInfoPanel::~MachineInfoPanel()
{
// Disconnect Events
m_button_upgrade_firmware->Disconnect(wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler(MachineInfoPanel::on_upgrade_firmware), NULL, this);
if (confirm_dlg != nullptr)
delete confirm_dlg;
}
void MachineInfoPanel::update(MachineObject* obj)
@ -661,30 +663,30 @@ void MachineInfoPanel::upgrade_firmware_internal() {
void MachineInfoPanel::on_upgrade_firmware(wxCommandEvent &event)
{
SecondaryCheckDialog* confirm_dlg = new SecondaryCheckDialog(this->GetParent(), wxID_ANY, _L("Update firmware"));
confirm_dlg->update_text(_L("Are you sure you want to update? This will take about 10 minutes. Do not turn off the power while the printer is updating."));
confirm_dlg->Bind(EVT_SECONDARY_CHECK_CONFIRM, [this](wxCommandEvent &e) {
if (m_obj) {
m_obj->command_upgrade_confirm();
}
});
if (confirm_dlg->ShowModal()) {
delete confirm_dlg;
if (confirm_dlg == nullptr) {
confirm_dlg = new SecondaryCheckDialog(this->GetParent(), wxID_ANY, _L("Update firmware"));
confirm_dlg->Bind(EVT_SECONDARY_CHECK_CONFIRM, [this](wxCommandEvent& e) {
if (m_obj) {
m_obj->command_upgrade_confirm();
}
});
}
confirm_dlg->update_text(_L("Are you sure you want to update? This will take about 10 minutes. Do not turn off the power while the printer is updating."));
confirm_dlg->on_show();
}
void MachineInfoPanel::on_consisitency_upgrade_firmware(wxCommandEvent &event)
{
SecondaryCheckDialog* confirm_dlg = new SecondaryCheckDialog(this->GetParent(), wxID_ANY, _L("Update firmware"));
confirm_dlg->update_text(_L("Are you sure you want to update? This will take about 10 minutes. Do not turn off the power while the printer is updating."));
confirm_dlg->Bind(EVT_SECONDARY_CHECK_CONFIRM, [this](wxCommandEvent &e) {
if (m_obj) {
m_obj->command_consistency_upgrade_confirm();
}
});
if (confirm_dlg->ShowModal()) {
delete confirm_dlg;
if (confirm_dlg == nullptr) {
confirm_dlg = new SecondaryCheckDialog(this->GetParent(), wxID_ANY, _L("Update firmware"));
confirm_dlg->Bind(EVT_SECONDARY_CHECK_CONFIRM, [this](wxCommandEvent& e) {
if (m_obj) {
m_obj->command_consistency_upgrade_confirm();
}
});
}
confirm_dlg->update_text(_L("Are you sure you want to update? This will take about 10 minutes. Do not turn off the power while the printer is updating."));
confirm_dlg->on_show();
}
void MachineInfoPanel::on_show_release_note(wxMouseEvent &event)
@ -746,7 +748,11 @@ UpgradePanel::UpgradePanel(wxWindow *parent, wxWindowID id, const wxPoint &pos,
UpgradePanel::~UpgradePanel()
{
if (force_dlg != nullptr)
delete force_dlg ;
if (consistency_dlg != nullptr)
delete consistency_dlg ;
}
void UpgradePanel::msw_rescale()
@ -799,14 +805,18 @@ void UpgradePanel::update(MachineObject *obj)
if (m_obj && m_show_forced_hint) {
if (m_obj->upgrade_force_upgrade) {
m_show_forced_hint = false; //lock hint
SecondaryCheckDialog force_dlg(this->GetParent(), wxID_ANY, _L("Update firmware"), SecondaryCheckDialog::ButtonStyle::CONFIRM_AND_CANCEL, wxDefaultPosition, wxDefaultSize, wxPD_APP_MODAL | wxCLOSE_BOX | wxCAPTION);
force_dlg.update_text(_L(
"An important update was detected and needs to be run before printing can continue. Do you want to update now? You can also update later from 'Upgrade firmware'."
));
force_dlg->Bind(EVT_SECONDARY_CHECK_CONFIRM, &MachineInfoPanel::on_upgrade_firmware, m_push_upgrade_panel);
if (force_dlg->ShowModal()) {
delete force_dlg;
if (force_dlg == nullptr) {
force_dlg = new SecondaryCheckDialog(this->GetParent(), wxID_ANY, _L("Update firmware"), SecondaryCheckDialog::ButtonStyle::CONFIRM_AND_CANCEL, wxDefaultPosition, wxDefaultSize);
force_dlg->Bind(EVT_SECONDARY_CHECK_CONFIRM, [this](wxCommandEvent& e) {
if (m_obj) {
m_obj->command_upgrade_confirm();
}
});
}
force_dlg->update_text(_L(
"An important update was detected and needs to be run before printing can continue. Do you want to update now? You can also update later from 'Upgrade firmware'."
));
force_dlg->on_show();
}
}
@ -818,14 +828,18 @@ void UpgradePanel::update(MachineObject *obj)
if (m_obj && m_show_consistency_hint) {
if (m_obj->upgrade_consistency_request) {
m_show_consistency_hint = false;
SecondaryCheckDialog consistency_dlg(this->GetParent(), wxID_ANY, _L("Update firmware"), SecondaryCheckDialog::ButtonStyle::CONFIRM_AND_CANCEL, wxDefaultPosition, wxDefaultSize, wxPD_APP_MODAL | wxCLOSE_BOX | wxCAPTION);
consistency_dlg.update_text(_L(
"The firmware version is abnormal. Repairing and updating are required before printing. Do you want to update now? You can also update later on printer or update next time starting the studio."
));
consistency_dlg->Bind(EVT_SECONDARY_CHECK_CONFIRM, &MachineInfoPanel::on_consisitency_upgrade_firmware, m_push_upgrade_panel);
if (consistency_dlg->ShowModal()) {
delete consistency_dlg;
if (consistency_dlg == nullptr) {
consistency_dlg = new SecondaryCheckDialog(this->GetParent(), wxID_ANY, _L("Update firmware"), SecondaryCheckDialog::ButtonStyle::CONFIRM_AND_CANCEL, wxDefaultPosition, wxDefaultSize);
consistency_dlg->Bind(EVT_SECONDARY_CHECK_CONFIRM, [this](wxCommandEvent& e) {
if (m_obj) {
m_obj->command_consistency_upgrade_confirm();
}
});
}
consistency_dlg->update_text(_L(
"The firmware version is abnormal. Repairing and updating are required before printing. Do you want to update now? You can also update later on printer or update next time starting the studio."
));
consistency_dlg->on_show();
}
}

View file

@ -6,6 +6,7 @@
#include "Widgets/ProgressBar.hpp"
#include <slic3r/GUI/DeviceManager.hpp>
#include <slic3r/GUI/Widgets/ScrolledWindow.hpp>
#include "ReleaseNote.hpp"
namespace Slic3r {
@ -77,6 +78,8 @@ protected:
int last_status = -1;
std::string last_status_str = "";
SecondaryCheckDialog* confirm_dlg = nullptr;
void upgrade_firmware_internal();
void on_show_release_note(wxMouseEvent &event);
@ -136,6 +139,8 @@ protected:
int last_consistency_hint_status = -1;
bool m_show_forced_hint = true;
bool m_show_consistency_hint = true;
SecondaryCheckDialog* force_dlg{ nullptr };
SecondaryCheckDialog* consistency_dlg{ nullptr };
public:
UpgradePanel(wxWindow *parent, wxWindowID id = wxID_ANY, const wxPoint &pos = wxDefaultPosition, const wxSize &size = wxDefaultSize, long style = wxTAB_TRAVERSAL);