Device view for third party printers

This commit is contained in:
SoftFever 2022-10-23 16:37:34 +08:00
parent 658d41dd69
commit ff760815ca
6 changed files with 246 additions and 14 deletions

View file

@ -235,6 +235,8 @@ set(SLIC3R_GUI_SOURCES
GUI/Monitor.hpp GUI/Monitor.hpp
GUI/WebViewDialog.cpp GUI/WebViewDialog.cpp
GUI/WebViewDialog.hpp GUI/WebViewDialog.hpp
GUI/PrinterWebView.cpp
GUI/PrinterWebView.hpp
GUI/WebDownPluginDlg.hpp GUI/WebDownPluginDlg.hpp
GUI/WebDownPluginDlg.cpp GUI/WebDownPluginDlg.cpp
GUI/WebGuideDialog.hpp GUI/WebGuideDialog.hpp

View file

@ -73,6 +73,7 @@ wxDEFINE_EVENT(EVT_USER_LOGIN, wxCommandEvent);
// BBS: backup // BBS: backup
wxDEFINE_EVENT(EVT_BACKUP_POST, wxCommandEvent); wxDEFINE_EVENT(EVT_BACKUP_POST, wxCommandEvent);
wxDEFINE_EVENT(EVT_LOAD_URL, wxCommandEvent); wxDEFINE_EVENT(EVT_LOAD_URL, wxCommandEvent);
wxDEFINE_EVENT(EVT_LOAD_PRINTER_URL, wxCommandEvent);
enum class ERescaleTarget enum class ERescaleTarget
{ {
@ -934,6 +935,13 @@ void MainFrame::init_tabpanel()
m_monitor = new MonitorPanel(m_tabpanel, wxID_ANY, wxDefaultPosition, wxDefaultSize); m_monitor = new MonitorPanel(m_tabpanel, wxID_ANY, wxDefaultPosition, wxDefaultSize);
m_tabpanel->AddPage(m_monitor, _L("Device"), std::string("tab_monitor_active"), std::string("tab_monitor_active")); m_tabpanel->AddPage(m_monitor, _L("Device"), std::string("tab_monitor_active"), std::string("tab_monitor_active"));
m_printer_view = new PrinterWebView(m_tabpanel);
Bind(EVT_LOAD_PRINTER_URL, [this](wxCommandEvent &evt) {
wxString url = evt.GetString();
//select_tab(MainFrame::tpMonitor);
m_printer_view->load_url(url);
});
m_auxiliary = new AuxiliaryPanel(m_tabpanel, wxID_ANY, wxDefaultPosition, wxDefaultSize); m_auxiliary = new AuxiliaryPanel(m_tabpanel, wxID_ANY, wxDefaultPosition, wxDefaultSize);
m_tabpanel->AddPage(m_auxiliary, _L("Project"), std::string("tab_auxiliary_avtice"), std::string("tab_auxiliary_avtice")); m_tabpanel->AddPage(m_auxiliary, _L("Project"), std::string("tab_auxiliary_avtice"), std::string("tab_auxiliary_avtice"));
@ -951,6 +959,33 @@ void MainFrame::init_tabpanel()
} }
} }
// SoftFever
void MainFrame::show_device(bool bBBLPrinter) {
if (m_tabpanel->GetPage(3) != m_monitor &&
m_tabpanel->GetPage(3) != m_printer_view) {
BOOST_LOG_TRIVIAL(error) << "Failed to find device tab";
return;
}
if (bBBLPrinter) {
if (m_tabpanel->GetPage(3) != m_monitor) {
m_tabpanel->RemovePage(3);
m_tabpanel->InsertPage(3, m_monitor, _L("Device"),
std::string("tab_monitor_active"),
std::string("tab_monitor_active"));
}
} else {
if (m_tabpanel->GetPage(3) != m_printer_view) {
m_tabpanel->RemovePage(3);
m_tabpanel->InsertPage(3, m_printer_view, _L("Device"),
std::string("tab_monitor_active"),
std::string("tab_monitor_active"));
}
}
}
#ifdef WIN32 #ifdef WIN32
void MainFrame::register_win32_callbacks() void MainFrame::register_win32_callbacks()
{ {
@ -2859,6 +2894,13 @@ void MainFrame::load_url(wxString url)
wxQueueEvent(this, evt); wxQueueEvent(this, evt);
} }
void MainFrame::load_printer_url(wxString url)
{
BOOST_LOG_TRIVIAL(trace) << "load_printer_url:" << url;
auto evt = new wxCommandEvent(EVT_LOAD_PRINTER_URL, this->GetId());
evt->SetString(url);
wxQueueEvent(this, evt);
}
void MainFrame::refresh_plugin_tips() void MainFrame::refresh_plugin_tips()
{ {
if (m_webview != nullptr) if (m_webview != nullptr)

View file

@ -28,6 +28,8 @@
#include "BBLTopbar.hpp" #include "BBLTopbar.hpp"
#include "PrinterWebView.hpp"
#define ENABEL_PRINT_ALL 0 #define ENABEL_PRINT_ALL 0
class Notebook; class Notebook;
@ -307,9 +309,13 @@ public:
//BBS //BBS
void load_url(wxString url); void load_url(wxString url);
void load_printer_url(wxString url);
void refresh_plugin_tips(); void refresh_plugin_tips();
void RunScript(wxString js); void RunScript(wxString js);
//SoftFever
void show_device(bool bBBLPrinter);
// BBS. Replace title bar and menu bar with top bar. // BBS. Replace title bar and menu bar with top bar.
BBLTopbar* m_topbar{ nullptr }; BBLTopbar* m_topbar{ nullptr };
PrintHostQueueDialog* printhost_queue_dlg() { return m_printhost_queue_dlg; } PrintHostQueueDialog* printhost_queue_dlg() { return m_printhost_queue_dlg; }
@ -318,6 +324,7 @@ public:
MonitorPanel* m_monitor{ nullptr }; MonitorPanel* m_monitor{ nullptr };
AuxiliaryPanel* m_auxiliary{ nullptr }; AuxiliaryPanel* m_auxiliary{ nullptr };
WebViewPanel* m_webview { nullptr }; WebViewPanel* m_webview { nullptr };
PrinterWebView* m_printer_view{nullptr};
wxLogWindow* m_log_window { nullptr }; wxLogWindow* m_log_window { nullptr };
// BBS // BBS
//wxBookCtrlBase* m_tabpanel { nullptr }; //wxBookCtrlBase* m_tabpanel { nullptr };

View file

@ -911,30 +911,22 @@ void Sidebar::update_all_preset_comboboxes()
bool is_bbl_preset = preset_bundle.printers.get_edited_preset().is_bbl_vendor_preset(&preset_bundle); bool is_bbl_preset = preset_bundle.printers.get_edited_preset().is_bbl_vendor_preset(&preset_bundle);
auto p_mainframe = wxGetApp().mainframe;
p_mainframe->show_device(is_bbl_preset);
if (is_bbl_preset) { if (is_bbl_preset) {
//only show connection button for not-BBL printer //only show connection button for not-BBL printer
connection_btn->Hide(); connection_btn->Hide();
//only show sync-ams button for BBL printer //only show sync-ams button for BBL printer
ams_btn->Show(); ams_btn->Show();
//update print button default value for bbl or third-party printer //update print button default value for bbl or third-party printer
wxGetApp().mainframe->set_print_button_to_default(MainFrame::PrintSelectType::ePrintPlate); p_mainframe->set_print_button_to_default(MainFrame::PrintSelectType::ePrintPlate);
MonitorPanel *curr_monitor = wxGetApp().mainframe->m_monitor;
if(wxGetApp().mainframe->m_tabpanel->GetPage(3) !=
curr_monitor){
wxGetApp().mainframe->m_tabpanel->InsertPage(3,
curr_monitor, _L("Device"),
std::string("tab_monitor_active"),
std::string("tab_monitor_active"));
}
} else { } else {
connection_btn->Show(); connection_btn->Show();
ams_btn->Hide(); ams_btn->Hide();
wxGetApp().mainframe->set_print_button_to_default(MainFrame::PrintSelectType::eSendGcode); p_mainframe->set_print_button_to_default(MainFrame::PrintSelectType::eSendGcode);
MonitorPanel *curr_monitor = wxGetApp().mainframe->m_monitor; p_mainframe->load_printer_url(wxString::Format("http://%s",preset_bundle.printers.get_edited_preset().config.opt_string("print_host")));
if (wxGetApp().mainframe->m_tabpanel->GetPage(3) == curr_monitor) {
wxGetApp().mainframe->m_tabpanel->RemovePage(3);
}
} }
// Update the print choosers to only contain the compatible presets, update the dirty flags. // Update the print choosers to only contain the compatible presets, update the dirty flags.

View file

@ -0,0 +1,125 @@
#include "PrinterWebView.hpp"
#include "I18N.hpp"
#include "slic3r/GUI/wxExtensions.hpp"
#include "slic3r/GUI/GUI_App.hpp"
#include "slic3r/GUI/MainFrame.hpp"
#include "libslic3r_version.h"
#include <wx/sizer.h>
#include <wx/toolbar.h>
#include <wx/textdlg.h>
#include <slic3r/GUI/Widgets/WebView.hpp>
namespace pt = boost::property_tree;
namespace Slic3r {
namespace GUI {
PrinterWebView::PrinterWebView(wxWindow *parent)
: wxPanel(parent, wxID_ANY, wxDefaultPosition, wxDefaultSize)
{
wxBoxSizer* topsizer = new wxBoxSizer(wxVERTICAL);
// Create the button
bSizer_toolbar = new wxBoxSizer(wxHORIZONTAL);
//m_button_reload = new wxButton(this, wxID_ANY, wxT("Reload"), wxDefaultPosition, wxDefaultSize, 0);
//bSizer_toolbar->Add(m_button_reload, 0, wxALL, 5);
m_url = new wxTextCtrl(this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxTE_PROCESS_ENTER);
bSizer_toolbar->Add(m_url, 1, wxALL | wxEXPAND, 5);
// Create the webview
m_browser = WebView::CreateWebView(this, "");
if (m_browser == nullptr) {
wxLogError("Could not init m_browser");
return;
}
SetSizer(topsizer);
topsizer->Add(m_browser, wxSizerFlags().Expand().Proportion(1));
// Log backend information
if (wxGetApp().get_mode() == comDevelop) {
wxLogMessage(wxWebView::GetBackendVersionInfo().ToString());
wxLogMessage("Backend: %s Version: %s", m_browser->GetClassInfo()->GetClassName(),
wxWebView::GetBackendVersionInfo().ToString());
wxLogMessage("User Agent: %s", m_browser->GetUserAgent());
}
//Zoom
m_zoomFactor = 100;
// Connect the button events
//Bind(wxEVT_BUTTON, &PrinterWebView::OnReload, this, m_button_reload->GetId());
Bind(wxEVT_TEXT_ENTER, &PrinterWebView::OnUrl, this, m_url->GetId());
//Connect the idle events
Bind(wxEVT_CLOSE_WINDOW, &PrinterWebView::OnClose, this);
}
PrinterWebView::~PrinterWebView()
{
BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << " Start";
SetEvtHandlerEnabled(false);
BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << " End";
}
void PrinterWebView::load_url(wxString& url)
{
//this->Show();
//this->Raise();
m_url->SetLabelText(url);
if (wxGetApp().get_mode() == comDevelop)
wxLogMessage(m_url->GetValue());
m_browser->LoadURL(url);
//m_browser->SetFocus();
UpdateState();
}
/**
* Method that retrieves the current state from the web control and updates the
* GUI the reflect this current state.
*/
void PrinterWebView::UpdateState() {
// SetTitle(m_browser->GetCurrentTitle());
m_url->SetValue(m_browser->GetCurrentURL());
}
/**
* Callback invoked when user entered an URL and pressed enter
*/
void PrinterWebView::OnUrl(wxCommandEvent& WXUNUSED(evt))
{
if (wxGetApp().get_mode() == comDevelop)
wxLogMessage(m_url->GetValue());
m_browser->LoadURL(m_url->GetValue());
m_browser->SetFocus();
UpdateState();
}
/**
* Callback invoked when user pressed the "reload" button
*/
void PrinterWebView::OnReload(wxCommandEvent& WXUNUSED(evt))
{
m_browser->Reload();
UpdateState();
}
void PrinterWebView::OnClose(wxCloseEvent& evt)
{
this->Hide();
}
} // GUI
} // Slic3r

View file

@ -0,0 +1,64 @@
#ifndef slic3r_PrinterWebView_hpp_
#define slic3r_PrinterWebView_hpp_
#include "wx/artprov.h"
#include "wx/cmdline.h"
#include "wx/notifmsg.h"
#include "wx/settings.h"
#include "wx/webview.h"
#if wxUSE_WEBVIEW_EDGE
#include "wx/msw/webview_edge.h"
#endif
#include "wx/webviewarchivehandler.h"
#include "wx/webviewfshandler.h"
#include "wx/numdlg.h"
#include "wx/infobar.h"
#include "wx/filesys.h"
#include "wx/fs_arc.h"
#include "wx/fs_mem.h"
#include "wx/stdpaths.h"
#include <wx/panel.h>
#include <wx/tbarbase.h>
#include "wx/textctrl.h"
#include <wx/timer.h>
namespace Slic3r {
namespace GUI {
class PrinterWebView : public wxPanel {
public:
PrinterWebView(wxWindow *parent);
virtual ~PrinterWebView();
void load_url(wxString& url);
void UpdateState();
void OnUrl(wxCommandEvent& evt);
void OnReload(wxCommandEvent& evt);
void OnClose(wxCloseEvent& evt);
private:
wxWebView* m_browser;
wxBoxSizer *bSizer_toolbar;
wxButton * m_button_reload;
wxTextCtrl *m_url;
long m_zoomFactor;
// Last executed JavaScript snippet, for convenience.
// wxString m_javascript;
// wxString m_response_js;
// DECLARE_EVENT_TABLE()
};
} // GUI
} // Slic3r
#endif /* slic3r_Tab_hpp_ */