2023-06-10 10:14:12 +08:00
|
|
|
#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>
|
|
|
|
|
|
2023-12-04 14:10:31 +08:00
|
|
|
#include "PhysicalPrinterDialog.hpp"
|
|
|
|
|
//B45
|
|
|
|
|
#include <wx/regex.h>
|
2023-12-07 13:37:35 +08:00
|
|
|
#include <boost/regex.hpp>
|
2023-12-27 13:17:18 +08:00
|
|
|
#include <wx/graphics.h>
|
2023-06-10 10:14:12 +08:00
|
|
|
namespace pt = boost::property_tree;
|
|
|
|
|
|
|
|
|
|
namespace Slic3r {
|
|
|
|
|
namespace GUI {
|
|
|
|
|
|
2023-11-27 11:29:19 +08:00
|
|
|
|
|
|
|
|
wxBEGIN_EVENT_TABLE(MachineListButton, wxButton) EVT_PAINT(MachineListButton::OnPaint) EVT_ENTER_WINDOW(MachineListButton::OnMouseEnter)
|
2023-12-27 13:17:18 +08:00
|
|
|
EVT_LEAVE_WINDOW(MachineListButton::OnMouseLeave)
|
|
|
|
|
//EVT_LEFT_DOWN(MachineListButton::OnMouseLeftDown)
|
|
|
|
|
// EVT_LEFT_UP(MachineListButton::OnMouseLeftUp)
|
|
|
|
|
EVT_SET_FOCUS(MachineListButton::OnSetFocus)
|
|
|
|
|
EVT_KILL_FOCUS(MachineListButton::OnKillFocus) EVT_KEY_DOWN(MachineListButton::OnKeyDown) EVT_KEY_UP(MachineListButton::OnKeyUp)
|
2023-11-27 11:29:19 +08:00
|
|
|
wxEND_EVENT_TABLE()
|
|
|
|
|
|
2023-12-26 15:25:38 +08:00
|
|
|
//B45
|
2023-12-27 13:17:18 +08:00
|
|
|
|
2023-11-27 11:29:19 +08:00
|
|
|
void MachineListButton::OnPaint(wxPaintEvent &event)
|
|
|
|
|
{
|
|
|
|
|
wxPaintDC dc(this);
|
2023-12-26 15:25:38 +08:00
|
|
|
wxRect rect = GetClientRect();
|
2023-12-27 13:17:18 +08:00
|
|
|
if (m_isHovered || m_isSelected)
|
2023-12-26 15:25:38 +08:00
|
|
|
dc.SetBrush(wxBrush(wxColour(100, 100, 105)));
|
2023-12-27 13:17:18 +08:00
|
|
|
else
|
2023-12-26 15:25:38 +08:00
|
|
|
dc.SetBrush(wxBrush(wxColour(67, 67, 71)));
|
2023-12-27 13:17:18 +08:00
|
|
|
if (full_label == "") {
|
2023-12-26 15:25:38 +08:00
|
|
|
dc.DrawRoundedRectangle(rect, 5);
|
|
|
|
|
|
2023-12-27 13:17:18 +08:00
|
|
|
int imgWidth = m_bitmap.GetWidth();
|
|
|
|
|
int imgHeight = m_bitmap.GetHeight();
|
|
|
|
|
int x = (rect.GetWidth() - imgWidth) / 2;
|
|
|
|
|
int y = (rect.GetHeight() - imgHeight) / 2;
|
|
|
|
|
dc.DrawBitmap(m_bitmap, x, y);
|
2023-12-26 15:25:38 +08:00
|
|
|
}
|
2023-12-27 13:17:18 +08:00
|
|
|
else if (m_isSimpleMode) {
|
|
|
|
|
dc.DrawRoundedRectangle(rect, 8);
|
2023-12-26 15:25:38 +08:00
|
|
|
|
2023-11-27 11:29:19 +08:00
|
|
|
dc.SetFont(wxFont(15, wxFONTFAMILY_DEFAULT, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_BOLD));
|
|
|
|
|
dc.SetTextForeground(wxColour(230, 230, 230));
|
2023-12-27 13:17:18 +08:00
|
|
|
dc.DrawText(m_name_text, 10, 10);
|
2023-11-27 11:29:19 +08:00
|
|
|
} else {
|
2023-12-27 13:17:18 +08:00
|
|
|
dc.DrawRoundedRectangle(rect, 8);
|
2023-11-27 11:29:19 +08:00
|
|
|
dc.DrawBitmap(m_bitmap, 10, (GetSize().GetHeight() - m_bitmap.GetHeight()) / 2, true);
|
|
|
|
|
|
|
|
|
|
dc.SetFont(wxFont(15, wxFONTFAMILY_DEFAULT, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_BOLD));
|
|
|
|
|
dc.SetTextForeground(wxColour(230, 230, 230));
|
|
|
|
|
dc.DrawText(m_name_text, 10 + m_bitmap.GetWidth() + 10, 10);
|
|
|
|
|
dc.SetFont(wxFont(10, wxFONTFAMILY_DEFAULT, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_BOLD));
|
|
|
|
|
dc.SetTextForeground(wxColour(174, 174, 174));
|
|
|
|
|
|
|
|
|
|
dc.DrawText("IP:" + m_ip_text, 10 + m_bitmap.GetWidth() + 10, 40);
|
|
|
|
|
|
|
|
|
|
wxBitmap m_bitmap_state = get_bmp_bundle("printer_state", 20)->GetBitmapFor(this);
|
|
|
|
|
dc.DrawBitmap(m_bitmap_state, 10 + m_bitmap.GetWidth() + 10, 55, true);
|
|
|
|
|
|
|
|
|
|
dc.SetFont(wxFont(10, wxFONTFAMILY_DEFAULT, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_BOLD));
|
|
|
|
|
dc.SetTextForeground(wxColour(174, 174, 174));
|
|
|
|
|
|
|
|
|
|
dc.DrawText(m_state_text, 10 + m_bitmap.GetWidth() + m_bitmap_state.GetWidth() + 15, 60);
|
|
|
|
|
if (m_state_text == "printing") {
|
|
|
|
|
dc.SetFont(wxFont(10, wxFONTFAMILY_DEFAULT, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_BOLD));
|
|
|
|
|
dc.SetTextForeground(wxColour(33, 148, 239));
|
|
|
|
|
dc.DrawText(m_progress_text, 10 + m_bitmap.GetWidth() + m_bitmap_state.GetWidth() + 77, 62);
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-12-27 13:17:18 +08:00
|
|
|
}
|
2023-11-27 11:29:19 +08:00
|
|
|
|
2023-12-27 13:17:18 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
void MachineListButton::OnSetFocus(wxFocusEvent &event)
|
|
|
|
|
{
|
|
|
|
|
event.Skip();
|
|
|
|
|
Refresh();
|
2023-11-27 11:29:19 +08:00
|
|
|
}
|
|
|
|
|
|
2023-12-27 13:17:18 +08:00
|
|
|
void MachineListButton::OnKillFocus(wxFocusEvent &event)
|
2023-11-27 11:29:19 +08:00
|
|
|
{
|
2023-12-27 13:17:18 +08:00
|
|
|
event.Skip();
|
2023-11-27 11:29:19 +08:00
|
|
|
Refresh();
|
|
|
|
|
}
|
|
|
|
|
|
2023-12-27 13:17:18 +08:00
|
|
|
void MachineListButton::OnKeyDown(wxKeyEvent &event)
|
2023-11-27 11:29:19 +08:00
|
|
|
{
|
2023-12-27 13:17:18 +08:00
|
|
|
event.Skip();
|
2023-11-27 11:29:19 +08:00
|
|
|
Refresh();
|
|
|
|
|
}
|
|
|
|
|
|
2023-12-27 13:17:18 +08:00
|
|
|
void MachineListButton::OnKeyUp(wxKeyEvent &event)
|
2023-11-27 11:29:19 +08:00
|
|
|
{
|
2023-12-27 13:17:18 +08:00
|
|
|
event.Skip();
|
2023-11-27 11:29:19 +08:00
|
|
|
Refresh();
|
|
|
|
|
}
|
|
|
|
|
|
2023-12-27 13:17:18 +08:00
|
|
|
void MachineListButton::OnMouseEnter(wxMouseEvent &event)
|
2023-11-27 11:29:19 +08:00
|
|
|
{
|
2023-12-27 13:17:18 +08:00
|
|
|
#if defined(__WIN32__) || defined(__WXMAC__)
|
|
|
|
|
m_isHovered = true;
|
|
|
|
|
#else
|
|
|
|
|
SetBackgroundColour(wxColour(100, 100, 105));
|
|
|
|
|
#endif
|
|
|
|
|
Refresh();
|
|
|
|
|
Update();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void MachineListButton::OnMouseLeave(wxMouseEvent &event)
|
|
|
|
|
{
|
|
|
|
|
#if defined(__WIN32__) || defined(__WXMAC__)
|
|
|
|
|
m_isHovered = false;
|
|
|
|
|
#else
|
|
|
|
|
if (m_isSelected)
|
|
|
|
|
SetBackgroundColour(wxColour(100, 100, 105));
|
|
|
|
|
else
|
|
|
|
|
SetBackgroundColour(wxColour(67, 67, 71));
|
|
|
|
|
#endif
|
2023-11-27 11:29:19 +08:00
|
|
|
Refresh();
|
2023-12-27 13:17:18 +08:00
|
|
|
Update();
|
2023-11-27 11:29:19 +08:00
|
|
|
}
|
|
|
|
|
|
2023-12-27 13:17:18 +08:00
|
|
|
//void MachineListButton::OnMouseLeftDown(wxMouseEvent &event)
|
|
|
|
|
//{
|
|
|
|
|
// Refresh();
|
|
|
|
|
//}
|
|
|
|
|
//
|
|
|
|
|
//void MachineListButton::OnMouseLeftUp(wxMouseEvent &event)
|
|
|
|
|
//{
|
|
|
|
|
// if (m_handlerl) {
|
|
|
|
|
// m_handlerl(event);
|
|
|
|
|
// }
|
|
|
|
|
// Refresh();
|
|
|
|
|
//}
|
|
|
|
|
|
2023-11-27 11:29:19 +08:00
|
|
|
|
|
|
|
|
//B45
|
2023-06-10 10:14:12 +08:00
|
|
|
PrinterWebView::PrinterWebView(wxWindow *parent)
|
|
|
|
|
: wxPanel(parent, wxID_ANY, wxDefaultPosition, wxDefaultSize)
|
|
|
|
|
{
|
|
|
|
|
|
2023-11-29 16:16:00 +08:00
|
|
|
#if defined(__WIN32__) || defined(__WXMAC__)
|
|
|
|
|
int leftsizerWidth = 300;
|
|
|
|
|
#else
|
|
|
|
|
int leftsizerWidth = 210;
|
|
|
|
|
#endif
|
2023-11-27 11:29:19 +08:00
|
|
|
topsizer = new wxBoxSizer(wxHORIZONTAL);
|
2023-12-27 13:17:18 +08:00
|
|
|
|
2023-12-26 15:25:38 +08:00
|
|
|
leftScrolledWindow = new wxScrolledWindow(this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxHSCROLL | wxVSCROLL);
|
2023-12-27 13:17:18 +08:00
|
|
|
//leftScrolledWindow->ShowScrollbars(wxSHOW_SB_NEVER, wxSHOW_SB_NEVER);
|
2023-12-26 15:25:38 +08:00
|
|
|
leftScrolledWindow->SetBackgroundColour(wxColour(30, 30, 32));
|
2023-11-27 11:29:19 +08:00
|
|
|
leftsizer = new wxBoxSizer(wxVERTICAL);
|
|
|
|
|
wxFont font(wxFontInfo().Bold());
|
|
|
|
|
|
2023-12-26 15:25:38 +08:00
|
|
|
wxPanel *buttonPanel = new wxPanel(this, wxID_ANY);
|
|
|
|
|
buttonPanel->SetBackgroundColour(wxColour(30, 30, 32));
|
|
|
|
|
wxBoxSizer *buttonSizer = new wxBoxSizer(wxVERTICAL);
|
|
|
|
|
leftallsizer = new wxBoxSizer(wxVERTICAL);
|
2023-12-27 13:17:18 +08:00
|
|
|
|
|
|
|
|
|
2023-11-27 11:29:19 +08:00
|
|
|
wxBoxSizer *titlesizer = new wxBoxSizer(wxHORIZONTAL);
|
2023-12-26 15:25:38 +08:00
|
|
|
text_static = new wxStaticText(buttonPanel, wxID_ANY, "MACHINE LIST", wxDefaultPosition, wxDefaultSize);
|
2023-11-29 16:16:00 +08:00
|
|
|
text_static->SetForegroundColour(wxColour(255, 255, 255));
|
|
|
|
|
text_static->SetFont(wxFont(wxFontInfo(18).Bold()));
|
|
|
|
|
#if defined __linux__
|
|
|
|
|
text_static->SetMinSize(wxSize(200, 40));
|
|
|
|
|
text_static->SetFont(wxFont(wxFontInfo(12).Bold()));
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
titlesizer->Add(text_static, wxSizerFlags().Align(wxALIGN_LEFT).Border(wxALL, 5));
|
2023-11-27 11:29:19 +08:00
|
|
|
titlesizer->AddStretchSpacer();
|
2023-12-04 14:10:31 +08:00
|
|
|
wxBoxSizer *buttonsizer = new wxBoxSizer(wxHORIZONTAL);
|
|
|
|
|
|
2023-12-26 15:25:38 +08:00
|
|
|
m_isSimpleMode = wxGetApp().app_config->get_bool("machine_list_minification");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
buttonPanel->SetSizer(buttonSizer);
|
2023-12-04 14:10:31 +08:00
|
|
|
|
2023-12-27 13:17:18 +08:00
|
|
|
//#if defined(__WIN32__) || defined(__WXMAC__)
|
|
|
|
|
//MachineListButton *add_button = new MachineListButton(buttonPanel, wxID_ANY, "", "", wxDefaultPosition, wxDefaultSize, wxBU_LEFT,
|
|
|
|
|
// wxDefaultValidator, wxButtonNameStr);
|
|
|
|
|
//wxButton *add_button = new wxButton(buttonPanel, wxID_ANY, "", wxDefaultPosition, wxSize(20, 20), wxBORDER_NONE);
|
|
|
|
|
MachineListButton *add_button = new MachineListButton(buttonPanel, wxID_ANY, "", "", wxDefaultPosition, wxDefaultSize, wxBU_LEFT,
|
|
|
|
|
wxDefaultValidator, wxButtonNameStr);
|
|
|
|
|
#if defined(__WIN32__) || defined(__WXMAC__)
|
|
|
|
|
add_button->SetBackgroundColour(wxColour(30, 30, 21));
|
|
|
|
|
add_button->SetBitMap(get_bmp_bundle("add_machine_list", 20)->GetBitmapFor(this));
|
|
|
|
|
#else
|
|
|
|
|
add_button->SetBackgroundColour(wxColour(67, 67, 71));
|
|
|
|
|
#endif
|
|
|
|
|
add_button->SetMinSize(wxSize(40, -1));
|
|
|
|
|
add_button->SetBitmap(*get_bmp_bundle("add_machine_list", 20));
|
|
|
|
|
buttonsizer->Add(add_button, wxSizerFlags().Align(wxALIGN_LEFT).CenterVertical().Border(wxALL, 2));
|
|
|
|
|
add_button->Bind(wxEVT_BUTTON, &PrinterWebView::OnAddButtonClick, this);
|
2023-12-04 14:10:31 +08:00
|
|
|
|
2023-11-29 16:16:00 +08:00
|
|
|
|
2023-12-27 13:17:18 +08:00
|
|
|
//wxButton *delete_button = new wxButton(buttonPanel, wxID_ANY, "", wxDefaultPosition, wxSize(20, 20), wxBORDER_NONE);
|
|
|
|
|
MachineListButton *delete_button = new MachineListButton(buttonPanel, wxID_ANY, "", "", wxDefaultPosition, wxDefaultSize, wxBU_LEFT,
|
|
|
|
|
wxDefaultValidator, wxButtonNameStr);
|
|
|
|
|
#if defined(__WIN32__) || defined(__WXMAC__)
|
|
|
|
|
delete_button->SetBackgroundColour(wxColour(30, 30, 21));
|
|
|
|
|
delete_button->SetBitMap(get_bmp_bundle("delete_machine_list", 20)->GetBitmapFor(this));
|
|
|
|
|
#else
|
|
|
|
|
delete_button->SetBackgroundColour(wxColour(67, 67, 71));
|
|
|
|
|
#endif
|
|
|
|
|
delete_button->SetMinSize(wxSize(40, -1));
|
|
|
|
|
delete_button->SetBitmap(*get_bmp_bundle("delete_machine_list", 20));
|
|
|
|
|
buttonsizer->Add(delete_button, wxSizerFlags().Align(wxALIGN_LEFT).CenterVertical().Border(wxALL, 2));
|
|
|
|
|
delete_button->Bind(wxEVT_BUTTON, &PrinterWebView::OnDeleteButtonClick, this);
|
|
|
|
|
|
|
|
|
|
MachineListButton *edit_button = new MachineListButton(buttonPanel, wxID_ANY, "", "", wxDefaultPosition, wxDefaultSize, wxBU_LEFT,
|
|
|
|
|
wxDefaultValidator, wxButtonNameStr);
|
|
|
|
|
//wxButton *edit_button = new wxButton(buttonPanel, wxID_ANY, "", wxDefaultPosition, wxSize(20, 20), wxBORDER_NONE);
|
|
|
|
|
#if defined(__WIN32__) || defined(__WXMAC__)
|
|
|
|
|
edit_button->SetBackgroundColour(wxColour(30, 30, 21));
|
|
|
|
|
edit_button->SetBitMap(get_bmp_bundle("edit_machine_list", 20)->GetBitmapFor(this));
|
|
|
|
|
#else
|
|
|
|
|
edit_button->SetBackgroundColour(wxColour(67, 67, 71));
|
|
|
|
|
#endif
|
|
|
|
|
edit_button->SetMinSize(wxSize(40, -1));
|
|
|
|
|
edit_button->SetBitmap(*get_bmp_bundle("edit_machine_list", 20));
|
|
|
|
|
buttonsizer->Add(edit_button, wxSizerFlags().Align(wxALIGN_LEFT).CenterVertical().Border(wxALL, 2));
|
|
|
|
|
edit_button->Bind(wxEVT_BUTTON, &PrinterWebView::OnEditButtonClick, this);
|
|
|
|
|
|
|
|
|
|
MachineListButton *refresh_button = new MachineListButton(buttonPanel, wxID_ANY, "", "", wxDefaultPosition, wxDefaultSize,
|
|
|
|
|
wxBU_LEFT, wxDefaultValidator, wxButtonNameStr);
|
|
|
|
|
//wxButton *refresh_button = new wxButton(buttonPanel, wxID_ANY, "", wxDefaultPosition, wxSize(20, 20), wxBORDER_NONE);
|
|
|
|
|
#if defined(__WIN32__) || defined(__WXMAC__)
|
|
|
|
|
refresh_button->SetBackgroundColour(wxColour(30, 30, 21));
|
|
|
|
|
#else
|
|
|
|
|
refresh_button->SetBackgroundColour(wxColour(67, 67, 71));
|
|
|
|
|
#endif
|
|
|
|
|
refresh_button->SetBitMap(get_bmp_bundle("refresh-line", 20)->GetBitmapFor(this));
|
|
|
|
|
refresh_button->SetMinSize(wxSize(40, -1));
|
|
|
|
|
refresh_button->SetBitmap(*get_bmp_bundle("refresh-line", 20));
|
|
|
|
|
buttonsizer->Add(refresh_button, wxSizerFlags().Align(wxALIGN_LEFT).CenterVertical().Border(wxALL, 2));
|
|
|
|
|
refresh_button->Bind(wxEVT_BUTTON, &PrinterWebView::OnRightButtonClick, this);
|
|
|
|
|
#if defined(__WIN32__) || defined(__WXMAC__)
|
2023-11-29 16:16:00 +08:00
|
|
|
|
2023-12-26 15:25:38 +08:00
|
|
|
arrow_button = new wxButton(buttonPanel, wxID_ANY, "", wxDefaultPosition, wxSize(20, 20), wxBORDER_NONE);
|
2023-11-29 16:16:00 +08:00
|
|
|
arrow_button->SetFont(font);
|
2023-12-26 15:25:38 +08:00
|
|
|
arrow_button->SetBackgroundColour(buttonPanel->GetBackgroundColour());
|
|
|
|
|
arrow_button->SetForegroundColour(buttonPanel->GetBackgroundColour());
|
2023-11-29 16:16:00 +08:00
|
|
|
arrow_button->SetMinSize(wxSize(40, -1));
|
2023-12-26 15:25:38 +08:00
|
|
|
if (m_isSimpleMode)
|
|
|
|
|
arrow_button->SetBitmap(*get_bmp_bundle("arrow-right-s-line", 20));
|
|
|
|
|
else
|
2023-12-27 13:17:18 +08:00
|
|
|
arrow_button->SetBitmap(*get_bmp_bundle("arrow-left-s-line", 20));
|
2023-11-29 16:16:00 +08:00
|
|
|
titlesizer->Add(arrow_button, wxSizerFlags().Align(wxALIGN_LEFT).CenterVertical().Border(wxALL, 2));
|
|
|
|
|
arrow_button->Bind(wxEVT_BUTTON, &PrinterWebView::OnLeftButtonClick, this);
|
|
|
|
|
#endif
|
2023-11-27 11:29:19 +08:00
|
|
|
|
|
|
|
|
titlesizer->Layout();
|
2023-12-04 14:10:31 +08:00
|
|
|
buttonsizer->Layout();
|
2023-11-27 11:29:19 +08:00
|
|
|
|
2023-12-26 15:25:38 +08:00
|
|
|
buttonSizer->Add(titlesizer, wxSizerFlags(0).Expand().Align(wxALIGN_TOP).Border(wxALL, 0));
|
|
|
|
|
buttonSizer->Add(buttonsizer, wxSizerFlags(1).Expand().Align(wxALIGN_TOP).Border(wxALL, 0));
|
|
|
|
|
buttonPanel->Layout();
|
|
|
|
|
|
|
|
|
|
leftsizer->SetMinSize(wxSize(300, -1));
|
2023-12-27 13:17:18 +08:00
|
|
|
|
2023-11-27 11:29:19 +08:00
|
|
|
|
|
|
|
|
leftsizer->Layout();
|
|
|
|
|
leftScrolledWindow->SetSizer(leftsizer);
|
|
|
|
|
leftScrolledWindow->SetScrollRate(10, 10);
|
|
|
|
|
leftScrolledWindow->SetMinSize(wxSize(leftsizerWidth, -1));
|
|
|
|
|
leftScrolledWindow->FitInside();
|
2023-12-04 14:10:31 +08:00
|
|
|
|
2023-06-10 10:14:12 +08:00
|
|
|
m_browser = WebView::CreateWebView(this, "");
|
|
|
|
|
if (m_browser == nullptr) {
|
|
|
|
|
wxLogError("Could not init m_browser");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SetSizer(topsizer);
|
2023-12-04 14:10:31 +08:00
|
|
|
|
2023-12-26 15:25:38 +08:00
|
|
|
leftallsizer->Add(buttonPanel, wxSizerFlags(0).Expand());
|
|
|
|
|
leftallsizer->Add(leftScrolledWindow, wxSizerFlags(1).Expand());
|
|
|
|
|
|
|
|
|
|
topsizer->Add(leftallsizer, wxSizerFlags(0).Expand());
|
2023-11-27 11:29:19 +08:00
|
|
|
topsizer->Add(m_browser, wxSizerFlags(1).Expand().Border(wxALL, 0));
|
2023-06-10 10:14:12 +08:00
|
|
|
|
2023-11-27 11:29:19 +08:00
|
|
|
// Zoom
|
|
|
|
|
m_zoomFactor = 100;
|
2023-06-10 10:14:12 +08:00
|
|
|
|
2023-11-27 11:29:19 +08:00
|
|
|
leftScrolledWindow->Bind(wxEVT_SCROLLWIN_TOP, &PrinterWebView::OnScroll, this);
|
|
|
|
|
leftScrolledWindow->Bind(wxEVT_SCROLLWIN_BOTTOM, &PrinterWebView::OnScroll, this);
|
|
|
|
|
leftScrolledWindow->Bind(wxEVT_SCROLLWIN_LINEUP, &PrinterWebView::OnScroll, this);
|
|
|
|
|
leftScrolledWindow->Bind(wxEVT_SCROLLWIN_LINEDOWN, &PrinterWebView::OnScroll, this);
|
|
|
|
|
leftScrolledWindow->Bind(wxEVT_SCROLLWIN_PAGEUP, &PrinterWebView::OnScroll, this);
|
|
|
|
|
leftScrolledWindow->Bind(wxEVT_SCROLLWIN_PAGEDOWN, &PrinterWebView::OnScroll, this);
|
|
|
|
|
|
|
|
|
|
//B45
|
|
|
|
|
Bind(wxEVT_WEBVIEW_SCRIPT_MESSAGE_RECEIVED, &PrinterWebView::OnScriptMessage, this);
|
2023-06-10 10:14:12 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
//Connect the idle events
|
|
|
|
|
Bind(wxEVT_CLOSE_WINDOW, &PrinterWebView::OnClose, this);
|
|
|
|
|
|
2023-12-26 15:25:38 +08:00
|
|
|
if (m_isSimpleMode) {
|
|
|
|
|
arrow_button->SetBitmap(*get_bmp_bundle("arrow-right-s-line", 20));
|
|
|
|
|
leftsizer->SetMinSize(wxSize(190, -1));
|
|
|
|
|
leftScrolledWindow->SetMinSize(wxSize(190, -1));
|
|
|
|
|
text_static->SetFont(wxFont(wxFontInfo(12).Bold()));
|
|
|
|
|
leftsizer->Layout();
|
|
|
|
|
|
|
|
|
|
leftScrolledWindow->Layout();
|
|
|
|
|
buttonSizer->Layout();
|
|
|
|
|
|
|
|
|
|
topsizer->Layout();
|
|
|
|
|
}
|
2023-12-27 13:17:18 +08:00
|
|
|
|
2023-06-10 10:14:12 +08:00
|
|
|
}
|
|
|
|
|
|
2023-11-27 11:29:19 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2023-11-29 16:16:00 +08:00
|
|
|
void PrinterWebView::AddButton(const wxString & device_name,
|
|
|
|
|
const wxString & ip,
|
|
|
|
|
const wxString & machine_type,
|
|
|
|
|
const wxString & fullname,
|
2023-11-27 11:29:19 +08:00
|
|
|
const std::function<void(wxMouseEvent &)> &handler,
|
|
|
|
|
bool isSelected,
|
|
|
|
|
DynamicPrintConfig * cfg_t)
|
|
|
|
|
{
|
2023-11-29 16:16:00 +08:00
|
|
|
wxString Machine_Name = Machine_Name.Format("%s%s", machine_type, "_thumbnail");
|
2023-11-27 11:29:19 +08:00
|
|
|
|
2023-11-29 16:16:00 +08:00
|
|
|
MachineListButton *customButton = new MachineListButton(leftScrolledWindow, wxID_ANY, device_name,
|
|
|
|
|
fullname,
|
|
|
|
|
wxDefaultPosition,
|
|
|
|
|
wxDefaultSize, wxBU_LEFT,
|
2023-11-27 11:29:19 +08:00
|
|
|
wxDefaultValidator, wxButtonNameStr, isSelected);
|
2023-11-29 16:16:00 +08:00
|
|
|
//customButton->SetMinSize(wxSize(80, -1));
|
|
|
|
|
#if defined(__WIN32__) || defined(__WXMAC__)
|
|
|
|
|
customButton->SetBitmap(*get_bmp_bundle(std::string(Machine_Name.mb_str()), 80));
|
|
|
|
|
#endif
|
2023-11-27 11:29:19 +08:00
|
|
|
customButton->SetBitMap(get_bmp_bundle(std::string(Machine_Name.mb_str()), 80)->GetBitmapFor(this));
|
2023-11-29 16:16:00 +08:00
|
|
|
customButton->SetForegroundColour(wxColour(255, 255, 255));
|
|
|
|
|
customButton->SetNameText(device_name);
|
|
|
|
|
customButton->SetIPText(ip);
|
2023-11-27 11:29:19 +08:00
|
|
|
customButton->SetStateText("standby");
|
|
|
|
|
customButton->SetProgressText("(0%)");
|
|
|
|
|
customButton->SetClickHandler(handler);
|
2023-12-27 13:17:18 +08:00
|
|
|
//customButton->Bind(wxEVT_BUTTON, std::bind(&PrinterWebView::OnCustomButtonClick, this,handler));
|
|
|
|
|
customButton->Bind(wxEVT_BUTTON, [this, ip, customButton](wxCommandEvent &event) {
|
|
|
|
|
wxString host = ip;
|
|
|
|
|
if (!host.Lower().starts_with("http"))
|
|
|
|
|
host = wxString::Format("http://%s", host);
|
|
|
|
|
if (!host.Lower().ends_with("10088"))
|
|
|
|
|
host = wxString::Format("%s:10088", host);
|
|
|
|
|
load_url(host);
|
|
|
|
|
customButton->ResumeStatusThread();
|
|
|
|
|
});
|
2023-11-29 16:16:00 +08:00
|
|
|
#if defined(__WIN32__) || defined(__WXMAC__)
|
|
|
|
|
customButton->SetStatusThread(std::move(customButton->CreatThread(device_name,ip, cfg_t)));
|
2023-12-27 13:17:18 +08:00
|
|
|
if (m_isSimpleMode) {
|
|
|
|
|
customButton->SetBitmap(*get_bmp_bundle(std::string("X-MAX 3_thumbnail"), 30));
|
|
|
|
|
customButton->SetSimpleMode(m_isSimpleMode);
|
|
|
|
|
customButton->SetSize(wxSize(180, -1));
|
|
|
|
|
} else {
|
|
|
|
|
customButton->SetBitmap(*get_bmp_bundle(std::string("X-MAX 3_thumbnail"), 80));
|
|
|
|
|
customButton->SetSimpleMode(m_isSimpleMode);
|
|
|
|
|
customButton->SetSize(wxSize(300, -1));
|
|
|
|
|
}
|
2023-11-29 16:16:00 +08:00
|
|
|
#else
|
|
|
|
|
customButton->SetSize(wxSize(200, -1));
|
|
|
|
|
#endif
|
2023-11-27 11:29:19 +08:00
|
|
|
|
|
|
|
|
leftsizer->Add(customButton, wxSizerFlags().Border(wxALL, 1).Expand());
|
|
|
|
|
leftsizer->Layout();
|
|
|
|
|
m_buttons.push_back(customButton);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//B45
|
|
|
|
|
void PrinterWebView::PauseButton()
|
|
|
|
|
{
|
|
|
|
|
//BOOST_LOG_TRIVIAL(error) << " Pause";
|
|
|
|
|
|
|
|
|
|
if (m_buttons.empty()) {
|
|
|
|
|
BOOST_LOG_TRIVIAL(info) << " empty";
|
|
|
|
|
} else {
|
|
|
|
|
for (MachineListButton *button : m_buttons) {
|
|
|
|
|
button->PauseStatusThread();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
//B45
|
|
|
|
|
void PrinterWebView::ResumeButton()
|
|
|
|
|
{
|
|
|
|
|
//BOOST_LOG_TRIVIAL(error) << " Resume";
|
|
|
|
|
|
|
|
|
|
if (m_buttons.empty()) {
|
|
|
|
|
BOOST_LOG_TRIVIAL(info) << " empty";
|
|
|
|
|
} else {
|
|
|
|
|
for (MachineListButton *button : m_buttons) {
|
|
|
|
|
button->ResumeStatusThread();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-12-26 15:25:38 +08:00
|
|
|
//B45
|
|
|
|
|
void PrinterWebView::StopAllThread()
|
|
|
|
|
{
|
|
|
|
|
// BOOST_LOG_TRIVIAL(error) << " Stop";
|
|
|
|
|
|
|
|
|
|
if (m_buttons.empty()) {
|
|
|
|
|
BOOST_LOG_TRIVIAL(info) << " empty";
|
|
|
|
|
} else {
|
|
|
|
|
for (MachineListButton *button : m_buttons) {
|
|
|
|
|
button->StopStatusThread();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-11-27 11:29:19 +08:00
|
|
|
|
2023-12-27 13:17:18 +08:00
|
|
|
//B45
|
2023-12-04 14:10:31 +08:00
|
|
|
void PrinterWebView::UnSelectedButton()
|
|
|
|
|
{
|
|
|
|
|
// BOOST_LOG_TRIVIAL(error) << " Resume";
|
|
|
|
|
|
|
|
|
|
if (m_buttons.empty()) {
|
|
|
|
|
BOOST_LOG_TRIVIAL(info) << " empty";
|
|
|
|
|
} else {
|
|
|
|
|
for (MachineListButton *button : m_buttons) {
|
|
|
|
|
button->SetSelect(false);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2023-11-27 11:29:19 +08:00
|
|
|
//B45
|
|
|
|
|
void PrinterWebView::DeleteButton()
|
|
|
|
|
{
|
|
|
|
|
if (m_buttons.empty()) {
|
|
|
|
|
BOOST_LOG_TRIVIAL(info) <<" empty";
|
|
|
|
|
} else {
|
|
|
|
|
for (MachineListButton *button : m_buttons) {
|
|
|
|
|
|
|
|
|
|
button->StopStatusThread();
|
|
|
|
|
|
|
|
|
|
delete button;
|
|
|
|
|
}
|
|
|
|
|
m_buttons.clear();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2023-12-27 13:17:18 +08:00
|
|
|
//B45
|
2023-11-27 11:29:19 +08:00
|
|
|
void PrinterWebView::SetButtons(std::vector<MachineListButton *> buttons) { m_buttons = buttons; }
|
|
|
|
|
|
|
|
|
|
PrinterWebView::~PrinterWebView()
|
2023-06-10 10:14:12 +08:00
|
|
|
{
|
|
|
|
|
BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << " Start";
|
|
|
|
|
SetEvtHandlerEnabled(false);
|
|
|
|
|
BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << " End";
|
|
|
|
|
}
|
2023-12-26 15:25:38 +08:00
|
|
|
//B45
|
2023-11-27 11:29:19 +08:00
|
|
|
void PrinterWebView::OnLeftButtonClick(wxCommandEvent &event)
|
|
|
|
|
{
|
|
|
|
|
m_isSimpleMode = !m_isSimpleMode;
|
|
|
|
|
|
|
|
|
|
if (!m_isSimpleMode) {
|
2023-12-26 15:25:38 +08:00
|
|
|
wxGetApp().app_config->set("machine_list_minification","0");
|
2023-12-27 13:17:18 +08:00
|
|
|
|
2023-11-29 16:16:00 +08:00
|
|
|
leftsizer->SetMinSize(wxSize(300, -1));
|
2023-11-27 11:29:19 +08:00
|
|
|
leftScrolledWindow->SetMinSize(wxSize(300, -1));
|
|
|
|
|
arrow_button->SetBitmap(*get_bmp_bundle("arrow-left-s-line", 20));
|
2023-11-29 16:16:00 +08:00
|
|
|
text_static->SetFont(wxFont(wxFontInfo(18).Bold()));
|
2023-11-27 11:29:19 +08:00
|
|
|
for (MachineListButton *button : m_buttons) {
|
|
|
|
|
button->SetBitmap(*get_bmp_bundle(std::string("X-MAX 3_thumbnail"), 80));
|
|
|
|
|
button->SetSimpleMode(m_isSimpleMode);
|
2023-11-29 16:16:00 +08:00
|
|
|
button->SetSize(wxSize(300, -1));
|
|
|
|
|
|
2023-11-27 11:29:19 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else {
|
2023-12-26 15:25:38 +08:00
|
|
|
wxGetApp().app_config->set("machine_list_minification", "1");
|
2023-12-27 13:17:18 +08:00
|
|
|
|
2023-11-27 11:29:19 +08:00
|
|
|
arrow_button->SetBitmap(*get_bmp_bundle("arrow-right-s-line", 20));
|
2023-12-26 15:25:38 +08:00
|
|
|
leftsizer->SetMinSize(wxSize(190, -1));
|
|
|
|
|
leftScrolledWindow->SetMinSize(wxSize(190, -1));
|
2023-11-29 16:16:00 +08:00
|
|
|
text_static->SetFont(wxFont(wxFontInfo(12).Bold()));
|
2023-11-27 11:29:19 +08:00
|
|
|
for (MachineListButton *button : m_buttons) {
|
|
|
|
|
button->SetBitmap(*get_bmp_bundle(std::string("X-MAX 3_thumbnail"), 30));
|
|
|
|
|
button->SetSimpleMode(m_isSimpleMode);
|
2023-12-26 15:25:38 +08:00
|
|
|
button->SetSize(wxSize(180, -1));
|
2023-11-27 11:29:19 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
leftsizer->Layout();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
leftScrolledWindow->Layout();
|
|
|
|
|
|
|
|
|
|
topsizer->Layout();
|
2023-12-26 15:25:38 +08:00
|
|
|
UpdateLayout();
|
2023-11-27 11:29:19 +08:00
|
|
|
}
|
2023-12-26 15:25:38 +08:00
|
|
|
//B45
|
2023-11-27 11:29:19 +08:00
|
|
|
void PrinterWebView::OnRightButtonClick(wxCommandEvent &event)
|
|
|
|
|
{
|
|
|
|
|
for (MachineListButton *button : m_buttons) {
|
|
|
|
|
button->ResumeStatusThread();
|
|
|
|
|
}
|
2023-12-27 13:17:18 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void PrinterWebView::OnCustomButtonClick(std::function<void(wxCommandEvent &)> handler, wxCommandEvent &event)
|
|
|
|
|
{
|
|
|
|
|
if (handler) {
|
|
|
|
|
handler(event);
|
|
|
|
|
}
|
2023-12-26 15:25:38 +08:00
|
|
|
Refresh();
|
2023-11-27 11:29:19 +08:00
|
|
|
}
|
|
|
|
|
|
2023-12-04 14:10:31 +08:00
|
|
|
void PrinterWebView::OnAddButtonClick(wxCommandEvent &event)
|
2023-12-27 13:17:18 +08:00
|
|
|
{
|
2023-12-04 14:10:31 +08:00
|
|
|
PhysicalPrinterDialog dlg(this->GetParent(), wxEmptyString);
|
|
|
|
|
if (dlg.ShowModal() == wxID_OK) {
|
|
|
|
|
if (m_handlerl) {
|
|
|
|
|
m_handlerl(event);
|
|
|
|
|
}
|
|
|
|
|
PresetBundle &preset_bundle = *wxGetApp().preset_bundle;
|
|
|
|
|
auto printer = preset_bundle.physical_printers.get_selected_printer();
|
|
|
|
|
std::string printer_name = printer.name;
|
|
|
|
|
wxString host = printer.config.opt_string("print_host");
|
|
|
|
|
|
|
|
|
|
wxString formattedHost = wxString::Format("http://%s", host);
|
|
|
|
|
if (!host.Lower().starts_with("http"))
|
|
|
|
|
wxString formattedHost = wxString::Format("http://%s", host);
|
|
|
|
|
if (!formattedHost.Lower().ends_with("10088"))
|
|
|
|
|
formattedHost = wxString::Format("%s:10088", formattedHost);
|
|
|
|
|
|
2023-12-27 13:17:18 +08:00
|
|
|
std::string fullname = preset_bundle.physical_printers.get_selected_full_printer_name();
|
2023-12-07 13:37:35 +08:00
|
|
|
std::string preset_name = printer.get_preset_name(fullname);
|
|
|
|
|
Preset * preset = wxGetApp().preset_bundle->printers.find_preset(preset_name);
|
|
|
|
|
std::string model_id = "X-MAX 3";
|
|
|
|
|
if (preset != nullptr) {
|
2023-12-26 15:25:38 +08:00
|
|
|
if ((preset->config.opt_string("printer_model").empty()))
|
2023-12-27 13:25:11 +08:00
|
|
|
model_id = "my_printer";
|
2023-12-26 15:25:38 +08:00
|
|
|
else
|
2023-12-27 13:17:18 +08:00
|
|
|
model_id = preset->config.opt_string("printer_model");
|
2023-12-07 13:37:35 +08:00
|
|
|
}
|
2023-12-04 14:10:31 +08:00
|
|
|
|
2023-12-07 13:37:35 +08:00
|
|
|
boost::regex ipRegex(R"(\b(?:\d{1,3}\.){3}\d{1,3}\b)");
|
|
|
|
|
bool isValidIPAddress = boost::regex_match(host.ToStdString(), ipRegex);
|
2023-12-27 13:17:18 +08:00
|
|
|
DynamicPrintConfig *cfg_t = &(printer.config);
|
2023-12-04 14:10:31 +08:00
|
|
|
|
|
|
|
|
UnSelectedButton();
|
|
|
|
|
if (isValidIPAddress)
|
|
|
|
|
AddButton(
|
2023-12-07 13:37:35 +08:00
|
|
|
printer_name, host, model_id, fullname,
|
2023-12-04 14:10:31 +08:00
|
|
|
[formattedHost, this](wxMouseEvent &event) {
|
|
|
|
|
wxString host = formattedHost;
|
|
|
|
|
load_url(host);
|
|
|
|
|
},
|
|
|
|
|
true, cfg_t);
|
|
|
|
|
load_url(formattedHost);
|
|
|
|
|
UpdateLayout();
|
2023-12-27 13:17:18 +08:00
|
|
|
Refresh();
|
2023-12-04 14:10:31 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void PrinterWebView::OnDeleteButtonClick(wxCommandEvent &event) {
|
|
|
|
|
|
|
|
|
|
PresetBundle &preset_bundle = *wxGetApp().preset_bundle;
|
|
|
|
|
for (MachineListButton *button : m_buttons) {
|
|
|
|
|
if ((button->GetSelected())) {
|
|
|
|
|
|
|
|
|
|
wxString msg;
|
|
|
|
|
//if (!note_string.IsEmpty())
|
|
|
|
|
// msg += note_string + "\n";
|
2023-12-07 13:37:35 +08:00
|
|
|
|
2024-01-10 14:06:24 +08:00
|
|
|
#if defined(__WIN32__)
|
2023-12-07 13:37:35 +08:00
|
|
|
msg += format_wxstr(_L("Are you sure you want to delete \"%1%\" printer?"), (button->getLabel()));
|
|
|
|
|
#else
|
|
|
|
|
msg += _L("Are you sure you want to delete ") + (button->getLabel()) + _L("printer?");
|
|
|
|
|
#endif
|
2023-12-27 13:17:18 +08:00
|
|
|
if (MessageDialog(this, msg, _L("Delete Physical Printer"), wxYES_NO | wxNO_DEFAULT | wxICON_QUESTION).ShowModal() != wxID_YES)
|
2023-12-26 15:25:38 +08:00
|
|
|
return;
|
2023-12-04 14:10:31 +08:00
|
|
|
|
|
|
|
|
button->StopStatusThread();
|
2023-12-06 15:28:31 +08:00
|
|
|
preset_bundle.physical_printers.select_printer((button->getLabel()).ToStdString());
|
2023-12-04 14:10:31 +08:00
|
|
|
|
2023-12-06 15:28:31 +08:00
|
|
|
|
|
|
|
|
preset_bundle.physical_printers.delete_selected_printer();
|
2023-12-04 14:10:31 +08:00
|
|
|
|
|
|
|
|
auto it = std::find(m_buttons.begin(), m_buttons.end(), button);
|
|
|
|
|
delete button;
|
|
|
|
|
|
|
|
|
|
if (it != m_buttons.end()) {
|
|
|
|
|
m_buttons.erase(it);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
leftsizer->Detach(button);
|
2023-12-06 15:28:31 +08:00
|
|
|
if (!m_buttons.empty())
|
|
|
|
|
for (MachineListButton *button : m_buttons) {
|
|
|
|
|
button->SetSelect(true);
|
|
|
|
|
wxString formattedHost = wxString::Format("http://%s:10088", button->getIPLabel());
|
|
|
|
|
|
|
|
|
|
load_url(formattedHost);
|
|
|
|
|
preset_bundle.physical_printers.select_printer((button->getLabel()).ToStdString());
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
wxString host = wxString::Format("file://%s/web/qidi/missing_connection.html", from_u8(resources_dir()));
|
|
|
|
|
load_url(host);
|
2023-12-04 14:10:31 +08:00
|
|
|
}
|
2023-12-06 15:28:31 +08:00
|
|
|
|
2023-12-04 14:10:31 +08:00
|
|
|
UpdateLayout();
|
2023-12-27 13:17:18 +08:00
|
|
|
Refresh();
|
2023-12-04 14:10:31 +08:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (m_handlerl) {
|
|
|
|
|
m_handlerl(event);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void PrinterWebView::OnEditButtonClick(wxCommandEvent &event) {
|
|
|
|
|
for (MachineListButton *button : m_buttons) {
|
|
|
|
|
if ((button->GetSelected())) {
|
|
|
|
|
PhysicalPrinterDialog dlg(this->GetParent(), (wxString::FromUTF8((button->getLabel()).ToStdString())));
|
|
|
|
|
//BOOST_LOG_TRIVIAL(error) << __FUNCTION__ << (button->getLabel());
|
|
|
|
|
|
|
|
|
|
//BOOST_LOG_TRIVIAL(error) << __FUNCTION__ << wxString::FromUTF8((button->getLabel()).ToStdString());
|
|
|
|
|
|
|
|
|
|
if (dlg.ShowModal() == wxID_OK) {
|
|
|
|
|
if (m_handlerl) {
|
|
|
|
|
m_handlerl(event);
|
|
|
|
|
}
|
|
|
|
|
PresetBundle &preset_bundle = *wxGetApp().preset_bundle;
|
|
|
|
|
auto printer = preset_bundle.physical_printers.get_selected_printer();
|
|
|
|
|
std::string printer_name = printer.name;
|
|
|
|
|
wxString host = printer.config.opt_string("print_host");
|
|
|
|
|
std::string fullname = preset_bundle.physical_printers.get_selected_full_printer_name();
|
2023-12-07 13:37:35 +08:00
|
|
|
std::string preset_name = printer.get_preset_name(fullname);
|
|
|
|
|
Preset * preset = wxGetApp().preset_bundle->printers.find_preset(preset_name);
|
|
|
|
|
std::string model_id = "X-MAX 3";
|
|
|
|
|
if (preset != nullptr) {
|
|
|
|
|
model_id = preset->config.opt_string("printer_model");
|
|
|
|
|
}
|
2023-12-04 14:10:31 +08:00
|
|
|
DynamicPrintConfig *cfg_t = &(printer.config);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
button->SetNameText((wxString::FromUTF8(printer_name)));
|
|
|
|
|
button->SetIPText(host);
|
|
|
|
|
button->SetLabel(fullname);
|
2023-12-07 13:37:35 +08:00
|
|
|
wxString Machine_Name = Machine_Name.Format("%s%s", model_id, "_thumbnail");
|
2023-12-04 14:10:31 +08:00
|
|
|
|
|
|
|
|
button->SetBitMap(get_bmp_bundle(std::string(Machine_Name.mb_str()), 80)->GetBitmapFor(this));
|
|
|
|
|
UpdateLayout();
|
2023-12-27 13:17:18 +08:00
|
|
|
Refresh();
|
2023-12-04 14:10:31 +08:00
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-11-27 11:29:19 +08:00
|
|
|
|
|
|
|
|
|
2023-11-29 16:16:00 +08:00
|
|
|
//void PrinterWebView::SendRecentList(int images)
|
|
|
|
|
//{
|
|
|
|
|
// boost::property_tree::wptree req;
|
|
|
|
|
// boost::property_tree::wptree data;
|
|
|
|
|
// //wxGetApp().mainframe->get_recent_projects(data, images);
|
|
|
|
|
// req.put(L"sequence_id", "");
|
|
|
|
|
// req.put(L"command", L"studio_set_mallurl");
|
|
|
|
|
// //req.put_child(L"response", data);
|
|
|
|
|
// std::wostringstream oss;
|
|
|
|
|
// pt::write_json(oss, req, false);
|
|
|
|
|
// RunScript(wxString::Format("window.postMessage(%s)", oss.str()));
|
|
|
|
|
//}
|
2023-11-27 11:29:19 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void PrinterWebView::OnScriptMessage(wxWebViewEvent &evt)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
wxLogMessage("Script message received; value = %s, handler = %s", evt.GetString(), evt.GetMessageHandler());
|
|
|
|
|
//std::string response = wxGetApp().handle_web_request(evt.GetString().ToUTF8().data());
|
|
|
|
|
//if (response.empty())
|
|
|
|
|
// return;
|
2023-11-29 16:16:00 +08:00
|
|
|
//SendRecentList(1);
|
2023-11-27 11:29:19 +08:00
|
|
|
///* remove \n in response string */
|
|
|
|
|
//response.erase(std::remove(response.begin(), response.end(), '\n'), response.end());
|
|
|
|
|
//if (!response.empty()) {
|
|
|
|
|
// m_response_js = wxString::Format("window.postMessage('%s')", response);
|
|
|
|
|
// wxCommandEvent *event = new wxCommandEvent(EVT_RESPONSE_MESSAGE, this->GetId());
|
|
|
|
|
// wxQueueEvent(this, event);
|
|
|
|
|
//} else {
|
|
|
|
|
// m_response_js.clear();
|
|
|
|
|
//}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void PrinterWebView::UpdateLayout()
|
|
|
|
|
{
|
2023-12-26 15:25:38 +08:00
|
|
|
wxSize size = leftsizer->GetSize();
|
|
|
|
|
int height = size.GetHeight();
|
|
|
|
|
int Width = size.GetWidth();
|
|
|
|
|
leftScrolledWindow->SetVirtualSize(Width, height);
|
2023-12-04 14:10:31 +08:00
|
|
|
leftsizer->Layout();
|
|
|
|
|
|
|
|
|
|
leftScrolledWindow->Layout();
|
|
|
|
|
|
2023-11-27 11:29:19 +08:00
|
|
|
leftScrolledWindow->FitInside();
|
|
|
|
|
topsizer->Layout();
|
|
|
|
|
if (!m_buttons.empty()) {
|
|
|
|
|
for (MachineListButton *button : m_buttons) {
|
|
|
|
|
button->Layout();
|
|
|
|
|
button->Refresh();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-12-26 15:25:38 +08:00
|
|
|
void PrinterWebView::OnScrollup(wxScrollWinEvent &event)
|
|
|
|
|
{
|
|
|
|
|
height -= 5;
|
|
|
|
|
leftScrolledWindow->Scroll(0, height);
|
|
|
|
|
UpdateLayout();
|
|
|
|
|
event.Skip();
|
|
|
|
|
}
|
|
|
|
|
void PrinterWebView::OnScrolldown(wxScrollWinEvent &event)
|
|
|
|
|
{
|
|
|
|
|
height += 5;
|
|
|
|
|
leftScrolledWindow->Scroll(0, height);
|
|
|
|
|
UpdateLayout();
|
|
|
|
|
event.Skip();
|
|
|
|
|
}
|
2023-06-10 10:14:12 +08:00
|
|
|
|
2023-12-27 13:17:18 +08:00
|
|
|
|
2023-11-27 11:29:19 +08:00
|
|
|
void PrinterWebView::OnScroll(wxScrollWinEvent &event)
|
|
|
|
|
{
|
|
|
|
|
UpdateLayout();
|
|
|
|
|
event.Skip();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//B45
|
2023-06-10 10:14:12 +08:00
|
|
|
void PrinterWebView::load_url(wxString& url)
|
|
|
|
|
{
|
2023-12-26 15:25:38 +08:00
|
|
|
if (m_browser == nullptr || m_web == url)
|
2023-06-10 10:14:12 +08:00
|
|
|
return;
|
2023-12-27 13:17:18 +08:00
|
|
|
//m_web = url;
|
2023-12-04 14:10:31 +08:00
|
|
|
m_browser->LoadURL(url);
|
2023-11-27 11:29:19 +08:00
|
|
|
|
2023-12-04 14:10:31 +08:00
|
|
|
url.Remove(0, 7);
|
|
|
|
|
url.Remove(url.length() - 6);
|
2023-11-27 11:29:19 +08:00
|
|
|
for (MachineListButton *button : m_buttons) {
|
2023-12-04 14:10:31 +08:00
|
|
|
if (url == (button->getIPLabel()))
|
2023-11-27 11:29:19 +08:00
|
|
|
button->SetSelect(true);
|
2023-12-04 14:10:31 +08:00
|
|
|
else
|
2023-11-27 11:29:19 +08:00
|
|
|
button->SetSelect(false);
|
|
|
|
|
}
|
2023-06-10 10:14:12 +08:00
|
|
|
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());
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void PrinterWebView::OnClose(wxCloseEvent& evt)
|
|
|
|
|
{
|
|
|
|
|
this->Hide();
|
|
|
|
|
}
|
|
|
|
|
|
2023-11-27 11:29:19 +08:00
|
|
|
void PrinterWebView::RunScript(const wxString &javascript)
|
|
|
|
|
{
|
|
|
|
|
// Remember the script we run in any case, so the next time the user opens
|
|
|
|
|
// the "Run Script" dialog box, it is shown there for convenient updating.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
WebView::RunScript(m_browser, javascript);
|
|
|
|
|
}
|
2023-06-10 10:14:12 +08:00
|
|
|
} // GUI
|
|
|
|
|
} // Slic3r
|