Fix for SPE-2225 and SPE-2228

* Don't select "Printer" tab after printer technology change from selection in right panel
* Delete "Physical printer" tab after deletion last preset from physical printer

+ show_printer_webview_tab() is moved into MainFrame
+ TopBar: use AddNewPage and InsertNewPage as overridden functions for AddPage and InsertPage
This commit is contained in:
YuSanka 2024-04-15 10:06:23 +02:00 committed by Lukas Matena
parent 3d4f2a7bba
commit 2c0f826d89
6 changed files with 89 additions and 90 deletions

View File

@ -3707,34 +3707,8 @@ void GUI_App::handle_connect_request_printer_pick(std::string msg)
void GUI_App::show_printer_webview_tab()
{
//bool show, const DynamicPrintConfig& dpc
if (DynamicPrintConfig* dpc = preset_bundle->physical_printers.get_selected_printer_config(); dpc == nullptr) {
this->mainframe->select_tab(size_t(0));
mainframe->remove_printer_webview_tab();
} else {
std::string url = dpc->opt_string("print_host");
if (url.find("http://") != 0 && url.find("https://") != 0) {
url = "http://" + url;
}
// set password / api key
if (dynamic_cast<const ConfigOptionEnum<AuthorizationType>*>(dpc->option("printhost_authorization_type"))->value == AuthorizationType::atKeyPassword) {
mainframe->set_printer_webview_api_key(dpc->opt_string("printhost_apikey"));
}
#if 0 // The user password authentication is not working in prusa link as of now.
else {
mainframe->set_printer_webview_credentials(dpc->opt_string("printhost_user"), dpc->opt_string("printhost_password"));
}
#endif // 0
// add printer or change url
if (mainframe->get_printer_webview_tab_added()) {
mainframe->set_printer_webview_tab_url(from_u8(url));
} else {
mainframe->add_printer_webview_tab(from_u8(url));
}
}
mainframe->show_printer_webview_tab(preset_bundle->physical_printers.get_selected_printer_config());
}
} // GUI
} //Slic3r

View File

@ -476,13 +476,12 @@ void MainFrame::update_layout()
m_plater->Reparent(m_tabpanel);
m_plater->Layout();
#ifdef _WIN32
if (!wxGetApp().tabs_as_menu())
#endif
dynamic_cast<TopBar*>(m_tabpanel)->InsertPage(0, m_plater, _L("Plater"), std::string("plater"), true);
#ifdef _WIN32
if (wxGetApp().tabs_as_menu())
m_tabpanel->InsertPage(0, m_plater, _L("Plater"));
else
m_tabpanel->InsertPage(0, m_plater, _L("Plater"));
#endif
dynamic_cast<TopBar*>(m_tabpanel)->InsertNewPage(0, m_plater, _L("Plater"), std::string("plater"), true);
m_main_sizer->Add(m_tabpanel, 1, wxEXPAND | wxTOP, 1);
m_plater->Show();
m_tabpanel->Show();
@ -503,13 +502,12 @@ void MainFrame::update_layout()
m_main_sizer->Add(m_tabpanel, 1, wxEXPAND);
m_plater_page = new wxPanel(m_tabpanel);
#ifdef _WIN32
if (!wxGetApp().tabs_as_menu())
#endif
dynamic_cast<TopBar*>(m_tabpanel)->InsertPage(0, m_plater_page, _L("Plater"), std::string("plater"), true);
#ifdef _WIN32
if (wxGetApp().tabs_as_menu())
m_tabpanel->InsertPage(0, m_plater_page, _L("Plater")); // empty panel just for Plater tab
else
m_tabpanel->InsertPage(0, m_plater_page, _L("Plater")); // empty panel just for Plater tab */
#endif
dynamic_cast<TopBar*>(m_tabpanel)->InsertNewPage(0, m_plater_page, _L("Plater"), std::string("plater"), true);
m_plater->Show();
break;
}
@ -847,7 +845,7 @@ void MainFrame::add_connect_webview_tab()
{
if (m_connect_webview_added) {
return;
} // parameters of InsertPage (to prevent ambigous overloaded function)
} // parameters of InsertNewPage (to prevent ambigous overloaded function)
// insert to positon 4, if physical printer is already added, it moves to 5
// order of tabs: Plater - Print Settings - Filaments - Printers - Prusa Connect - Prusa Link
size_t n = 4;
@ -855,7 +853,7 @@ void MainFrame::add_connect_webview_tab()
const wxString text(L"Prusa Connect");
const std::string bmp_name = "";
bool bSelect = false;
dynamic_cast<TopBar*>(m_tabpanel)->InsertPage(n, page, text, bmp_name, bSelect);
dynamic_cast<TopBar*>(m_tabpanel)->InsertNewPage(n, page, text, bmp_name, bSelect);
m_connect_webview->load_default_url_delayed();
m_connect_webview_added = true;
}
@ -872,6 +870,41 @@ void MainFrame::remove_connect_webview_tab()
m_connect_webview->logout();
}
void MainFrame::show_printer_webview_tab(DynamicPrintConfig* dpc)
{
// if physical printer is selected
if (dpc) {
std::string url = dpc->opt_string("print_host");
if (url.find("http://") != 0 && url.find("https://") != 0) {
url = "http://" + url;
}
// set password / api key
if (dynamic_cast<const ConfigOptionEnum<AuthorizationType>*>(dpc->option("printhost_authorization_type"))->value == AuthorizationType::atKeyPassword) {
set_printer_webview_api_key(dpc->opt_string("printhost_apikey"));
}
#if 0 // The user password authentication is not working in prusa link as of now.
else {
mset_printer_webview_credentials(dpc->opt_string("printhost_user"), dpc->opt_string("printhost_password"));
}
#endif // 0
// add printer or change url
if (get_printer_webview_tab_added()) {
set_printer_webview_tab_url(from_u8(url));
}
else {
add_printer_webview_tab(from_u8(url));
}
}
// if physical printer isn't selected, so delete page from TopBar
else {
if (m_tabpanel->GetPageText(m_tabpanel->GetSelection()) == _L("Physical Printer"))
select_tab(size_t(0));
remove_printer_webview_tab();
}
}
void MainFrame::add_printer_webview_tab(const wxString& url)
{
if (m_printer_webview_added) {
@ -891,8 +924,7 @@ void MainFrame::remove_printer_webview_tab()
}
m_printer_webview_added = false;
m_printer_webview->Hide();
// always remove the last tab
dynamic_cast<TopBar*>(m_tabpanel)->RemovePage(m_tabpanel->GetPageCount() - 1);
dynamic_cast<TopBar*>(m_tabpanel)->RemovePage(m_tabpanel->FindPage(m_printer_webview));
}
void MainFrame::set_printer_webview_tab_url(const wxString& url)
{
@ -902,7 +934,8 @@ void MainFrame::set_printer_webview_tab_url(const wxString& url)
}
m_printer_webview->clear();
m_printer_webview->set_default_url(url);
if (m_tabpanel->GetSelection() == int(m_tabpanel->GetPageCount() - 1)) {
if (m_tabpanel->GetSelection() == m_tabpanel->FindPage(m_printer_webview)) {
m_printer_webview->load_url(url);
} else {
m_printer_webview->load_default_url_delayed();

View File

@ -218,6 +218,8 @@ public:
void add_connect_webview_tab();
void remove_connect_webview_tab();
void show_printer_webview_tab(DynamicPrintConfig* dpc);
void add_printer_webview_tab(const wxString& url);
void remove_printer_webview_tab();
void set_printer_webview_tab_url(const wxString& url);

View File

@ -717,8 +717,6 @@ void Sidebar::on_select_preset(wxCommandEvent& evt)
* and for SLA presets they should be deleted
*/
m_object_list->update_object_list_by_printer_technology();
wxGetApp().show_printer_webview_tab();
}
#ifdef __WXMSW__

View File

@ -3619,6 +3619,8 @@ void Tab::load_current_preset()
on_preset_loaded();
else
wxGetApp().sidebar().update_objects_list_extruder_column(1);
// Check and show "Physical printer" page if needed
wxGetApp().show_printer_webview_tab();
}
// Reload preset pages with the new configuration values.
reload_config();
@ -3646,27 +3648,19 @@ void Tab::load_current_preset()
Page* tmp_page = m_active_page;
m_active_page = nullptr;
for (auto tab : wxGetApp().tabs_list) {
if (tab->type() == Preset::TYPE_PRINTER) { // Printer tab is shown every time
int cur_selection = wxGetApp().tab_panel()->GetSelection();
if (cur_selection != 0)
wxGetApp().tab_panel()->SetSelection(wxGetApp().tab_panel()->GetPageCount() - 1);
if (tab->type() == Preset::TYPE_PRINTER) {
// Printer tab is shown every time
continue;
}
if (tab->supports_printer_technology(printer_technology))
{
#ifdef _WIN32
if (!wxGetApp().tabs_as_menu()) {
#endif
dynamic_cast<TopBar*>(wxGetApp().tab_panel())->InsertPage(wxGetApp().tab_panel()->FindPage(this), tab, tab->title(),"");
#ifdef _WIN32
}
else
if (wxGetApp().tabs_as_menu())
wxGetApp().tab_panel()->InsertPage(wxGetApp().tab_panel()->FindPage(this), tab, tab->title());
else
#endif
#ifdef __linux__ // the tabs apparently need to be explicitly shown on Linux (pull request #1563)
int page_id = wxGetApp().tab_panel()->FindPage(tab);
wxGetApp().tab_panel()->GetPage(page_id)->Show(true);
#endif // __linux__
dynamic_cast<TopBar*>(wxGetApp().tab_panel())->InsertNewPage(wxGetApp().tab_panel()->FindPage(this), tab, tab->title(),"");
}
else {
int page_id = wxGetApp().tab_panel()->FindPage(tab);
@ -4376,8 +4370,11 @@ void Tab::delete_preset()
{
PhysicalPrinter& printer = physical_printers.get_selected_printer();
if (printer.preset_names.size() == 1) {
if (m_presets_choice->del_physical_printer(_L("It's a last preset for this physical printer.")))
if (m_presets_choice->del_physical_printer(_L("It's a last preset for this physical printer."))) {
// Hide "Physical printer" page
wxGetApp().show_printer_webview_tab();
Layout();
}
return;
}

View File

@ -207,37 +207,10 @@ public:
bool bSelect = false)
{
DoInvalidateBestSize();
return InsertPage(GetPageCount(), page, text, bmp_name, bSelect);
return InsertNewPage(GetPageCount(), page, text, bmp_name, bSelect);
}
// override AddPage with using of AddNewPage
bool AddPage( wxWindow* page,
const wxString& text,
bool bSelect = false,
int imageId = NO_IMAGE) override
{
return AddNewPage(page, text, "", bSelect);
}
// Page management
virtual bool InsertPage(size_t n,
wxWindow * page,
const wxString & text,
bool bSelect = false,
int imageId = NO_IMAGE) override
{
if (!wxBookCtrlBase::InsertPage(n, page, text, bSelect, imageId))
return false;
GetTopBarItemsCtrl()->InsertPage(n, text, bSelect);
if (!DoSetSelectionAfterInsertion(n, bSelect))
page->Hide();
return true;
}
bool InsertPage(size_t n,
bool InsertNewPage(size_t n,
wxWindow * page,
const wxString & text,
const std::string& bmp_name = "",
@ -250,10 +223,31 @@ public:
if (bSelect)
SetSelection(n);
else
page->Hide();
return true;
}
// override AddPage with using of AddNewPage
bool AddPage( wxWindow* page,
const wxString& text,
bool bSelect = false,
int imageId = NO_IMAGE) override
{
return AddNewPage(page, text, "", bSelect);
}
// Page management
bool InsertPage(size_t n,
wxWindow * page,
const wxString & text,
bool bSelect = false,
int imageId = NO_IMAGE) override
{
return InsertNewPage(n, page, text, "", bSelect);
}
virtual int SetSelection(size_t n) override
{
GetTopBarItemsCtrl()->SetSelection(n);
@ -456,7 +450,8 @@ protected:
if (win)
{
GetTopBarItemsCtrl()->RemovePage(page);
DoSetSelectionAfterRemoval(page);
// Don't setect any page after deletion some of them
// DoSetSelectionAfterRemoval(page);
}
return win;