mirror of
https://github.com/OrcaSlicer/OrcaSlicer.git
synced 2026-07-10 20:41:41 +00:00
feat: Python Plugins
This commit is contained in:
134
src/slic3r/GUI/PluginProgressDialog.cpp
Normal file
134
src/slic3r/GUI/PluginProgressDialog.cpp
Normal file
@@ -0,0 +1,134 @@
|
||||
#include "PluginProgressDialog.hpp"
|
||||
|
||||
#include <utility>
|
||||
|
||||
namespace Slic3r { namespace GUI {
|
||||
|
||||
PluginProgressDialog::PluginProgressDialog(wxWindow* parent,
|
||||
const wxString& title,
|
||||
const wxString& message,
|
||||
int maximum,
|
||||
int style,
|
||||
CloseHandler on_destroyed)
|
||||
: wxProgressDialog(title, message, maximum, parent, style)
|
||||
, m_pulse_message(message)
|
||||
, m_on_destroyed(std::move(on_destroyed))
|
||||
{
|
||||
Bind(wxEVT_CLOSE_WINDOW, &PluginProgressDialog::on_close_window, this);
|
||||
}
|
||||
|
||||
PluginProgressDialog::~PluginProgressDialog()
|
||||
{
|
||||
stop_pulse();
|
||||
|
||||
if (m_on_destroyed)
|
||||
m_on_destroyed();
|
||||
}
|
||||
|
||||
PluginProgressDialog* PluginProgressDialog::create_dialog(wxWindow* parent,
|
||||
const wxString& title,
|
||||
const wxString& message,
|
||||
int maximum,
|
||||
int style,
|
||||
CloseHandler on_destroyed)
|
||||
{
|
||||
return new PluginProgressDialog(parent, title, message, maximum, style, std::move(on_destroyed));
|
||||
}
|
||||
|
||||
bool PluginProgressDialog::pulse(PluginProgressDialog* dialog, const wxString& message)
|
||||
{
|
||||
return dialog != nullptr ? dialog->pulse(message) : false;
|
||||
}
|
||||
|
||||
bool PluginProgressDialog::update(PluginProgressDialog* dialog, int value, const wxString& message)
|
||||
{
|
||||
return dialog != nullptr ? dialog->update(value, message) : false;
|
||||
}
|
||||
|
||||
void PluginProgressDialog::start_pulse(PluginProgressDialog* dialog, int interval_ms, const wxString& message)
|
||||
{
|
||||
if (dialog != nullptr)
|
||||
dialog->start_pulse(interval_ms, message);
|
||||
}
|
||||
|
||||
void PluginProgressDialog::stop_pulse(PluginProgressDialog* dialog)
|
||||
{
|
||||
if (dialog != nullptr)
|
||||
dialog->stop_pulse();
|
||||
}
|
||||
|
||||
void PluginProgressDialog::request_close(PluginProgressDialog* dialog)
|
||||
{
|
||||
if (dialog != nullptr)
|
||||
dialog->close();
|
||||
}
|
||||
|
||||
bool PluginProgressDialog::pulse(const wxString& message)
|
||||
{
|
||||
if (!m_open)
|
||||
return false;
|
||||
|
||||
if (!message.empty())
|
||||
m_pulse_message = message;
|
||||
|
||||
return Pulse(message);
|
||||
}
|
||||
|
||||
bool PluginProgressDialog::update(int value, const wxString& message)
|
||||
{
|
||||
if (!m_open)
|
||||
return false;
|
||||
|
||||
if (!message.empty())
|
||||
m_pulse_message = message;
|
||||
|
||||
return Update(value, message);
|
||||
}
|
||||
|
||||
void PluginProgressDialog::start_pulse(int interval_ms, const wxString& message)
|
||||
{
|
||||
if (!m_open)
|
||||
return;
|
||||
|
||||
if (!message.empty())
|
||||
m_pulse_message = message;
|
||||
|
||||
stop_pulse();
|
||||
|
||||
m_timer = std::make_unique<wxTimer>(this);
|
||||
Bind(wxEVT_TIMER, &PluginProgressDialog::on_timer, this, m_timer->GetId());
|
||||
m_timer->Start(interval_ms > 0 ? interval_ms : 1);
|
||||
}
|
||||
|
||||
void PluginProgressDialog::stop_pulse()
|
||||
{
|
||||
if (!m_timer)
|
||||
return;
|
||||
|
||||
Unbind(wxEVT_TIMER, &PluginProgressDialog::on_timer, this, m_timer->GetId());
|
||||
m_timer->Stop();
|
||||
m_timer.reset();
|
||||
}
|
||||
|
||||
void PluginProgressDialog::close()
|
||||
{
|
||||
if (!m_open)
|
||||
return;
|
||||
|
||||
m_open = false;
|
||||
stop_pulse();
|
||||
Destroy();
|
||||
}
|
||||
|
||||
void PluginProgressDialog::on_close_window(wxCloseEvent& /*event*/)
|
||||
{
|
||||
close();
|
||||
}
|
||||
|
||||
void PluginProgressDialog::on_timer(wxTimerEvent& /*event*/)
|
||||
{
|
||||
if (m_open)
|
||||
Pulse(m_pulse_message);
|
||||
}
|
||||
|
||||
}} // namespace Slic3r::GUI
|
||||
Reference in New Issue
Block a user