mirror of
https://github.com/OrcaSlicer/OrcaSlicer.git
synced 2026-08-31 13:57:07 +00:00
support dark theme for plugin progress dialog
This commit is contained in:
@@ -10,11 +10,15 @@ PluginProgressDialog::PluginProgressDialog(wxWindow* parent,
|
|||||||
int maximum,
|
int maximum,
|
||||||
int style,
|
int style,
|
||||||
CloseHandler on_destroyed)
|
CloseHandler on_destroyed)
|
||||||
: wxProgressDialog(title, message, maximum, parent, style)
|
: ProgressDialog(title, message, maximum, parent, style)
|
||||||
, m_pulse_message(message)
|
, m_pulse_message(message)
|
||||||
, m_on_destroyed(std::move(on_destroyed))
|
, m_on_destroyed(std::move(on_destroyed))
|
||||||
{
|
{
|
||||||
Bind(wxEVT_CLOSE_WINDOW, &PluginProgressDialog::on_close_window, this);
|
// The base ProgressDialog already binds wxEVT_CLOSE_WINDOW (its OnClose vetoes
|
||||||
|
// a non-cancelable dialog and marks a cancelable one Canceled). We deliberately
|
||||||
|
// don't add a second handler: a user-initiated close surfaces to the plugin as
|
||||||
|
// update()/pulse() returning false, and programmatic close() calls Destroy()
|
||||||
|
// directly, so no extra wiring is needed here.
|
||||||
}
|
}
|
||||||
|
|
||||||
PluginProgressDialog::~PluginProgressDialog()
|
PluginProgressDialog::~PluginProgressDialog()
|
||||||
@@ -120,11 +124,6 @@ void PluginProgressDialog::close()
|
|||||||
Destroy();
|
Destroy();
|
||||||
}
|
}
|
||||||
|
|
||||||
void PluginProgressDialog::on_close_window(wxCloseEvent& /*event*/)
|
|
||||||
{
|
|
||||||
close();
|
|
||||||
}
|
|
||||||
|
|
||||||
void PluginProgressDialog::on_timer(wxTimerEvent& /*event*/)
|
void PluginProgressDialog::on_timer(wxTimerEvent& /*event*/)
|
||||||
{
|
{
|
||||||
if (m_open)
|
if (m_open)
|
||||||
|
|||||||
@@ -5,17 +5,24 @@
|
|||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
#include <wx/event.h>
|
#include <wx/event.h>
|
||||||
#include <wx/progdlg.h>
|
|
||||||
#include <wx/string.h>
|
#include <wx/string.h>
|
||||||
#include <wx/timer.h>
|
#include <wx/timer.h>
|
||||||
#include <wx/window.h>
|
#include <wx/window.h>
|
||||||
|
|
||||||
|
#include "Widgets/ProgressDialog.hpp"
|
||||||
|
|
||||||
namespace Slic3r { namespace GUI {
|
namespace Slic3r { namespace GUI {
|
||||||
|
|
||||||
// A host-owned progress dialog for Python plugins. This class is deliberately
|
// A host-owned progress dialog for Python plugins. This class is deliberately
|
||||||
// Python-agnostic; the plugin layer owns any pybind/GIL concerns and marshals
|
// Python-agnostic; the plugin layer owns any pybind/GIL concerns and marshals
|
||||||
// all calls to the UI thread.
|
// all calls to the UI thread.
|
||||||
class PluginProgressDialog : public wxProgressDialog
|
//
|
||||||
|
// It derives from OrcaSlicer's own Slic3r::GUI::ProgressDialog (a real wxDialog
|
||||||
|
// with themable wx children) rather than the native wxProgressDialog: on Windows
|
||||||
|
// wxProgressDialog is a comctl32 TaskDialog running on a worker thread with no
|
||||||
|
// recolorable wx surface, so it cannot follow OrcaSlicer's (OS-independent) dark
|
||||||
|
// theme. The base themes itself via UpdateDlgDarkUI(this) in its Create().
|
||||||
|
class PluginProgressDialog : public ProgressDialog
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
using CloseHandler = std::function<void()>;
|
using CloseHandler = std::function<void()>;
|
||||||
@@ -52,7 +59,6 @@ public:
|
|||||||
bool is_open() const { return m_open; }
|
bool is_open() const { return m_open; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void on_close_window(wxCloseEvent& event);
|
|
||||||
void on_timer(wxTimerEvent& event);
|
void on_timer(wxTimerEvent& event);
|
||||||
|
|
||||||
bool m_open{true};
|
bool m_open{true};
|
||||||
|
|||||||
@@ -231,6 +231,17 @@ bool ProgressDialog::Create(const wxString &title, const wxString &message, int
|
|||||||
m_sizer_main->Add(m_gauge, 0, wxEXPAND | wxLEFT | wxRIGHT, FromDIP(28));
|
m_sizer_main->Add(m_gauge, 0, wxEXPAND | wxLEFT | wxRIGHT, FromDIP(28));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Optional elapsed/estimated/remaining time labels, created only when the
|
||||||
|
// caller opts in via the wxPD_*_TIME style flags (so callers that don't set
|
||||||
|
// them are unaffected). Update()/Pulse() already refresh these once non-null.
|
||||||
|
if (HasPDFlag(wxPD_ELAPSED_TIME | wxPD_ESTIMATED_TIME | wxPD_REMAINING_TIME)) {
|
||||||
|
wxFlexGridSizer *sizer_times = new wxFlexGridSizer(2, FromDIP(2), FromDIP(8));
|
||||||
|
if (HasPDFlag(wxPD_ELAPSED_TIME)) m_elapsed = CreateLabel(GetElapsedLabel(), sizer_times);
|
||||||
|
if (HasPDFlag(wxPD_ESTIMATED_TIME)) m_estimated = CreateLabel(GetEstimatedLabel(), sizer_times);
|
||||||
|
if (HasPDFlag(wxPD_REMAINING_TIME)) m_remaining = CreateLabel(GetRemainingLabel(), sizer_times);
|
||||||
|
m_sizer_main->Add(sizer_times, 0, wxALIGN_CENTER_HORIZONTAL | wxTOP | wxLEFT | wxRIGHT, FromDIP(12));
|
||||||
|
}
|
||||||
|
|
||||||
#ifdef __WXMSW__
|
#ifdef __WXMSW__
|
||||||
//m_block_left = new wxWindow(m_gauge, wxID_ANY, wxPoint(0, 0), wxSize(FromDIP(2), PROGRESSDIALOG_GAUGE_SIZE.y * 2));
|
//m_block_left = new wxWindow(m_gauge, wxID_ANY, wxPoint(0, 0), wxSize(FromDIP(2), PROGRESSDIALOG_GAUGE_SIZE.y * 2));
|
||||||
//m_block_left->SetBackgroundColour(PROGRESSDIALOG_DEF_BK);
|
//m_block_left->SetBackgroundColour(PROGRESSDIALOG_DEF_BK);
|
||||||
@@ -490,6 +501,14 @@ wxStaticText *ProgressDialog::CreateLabel(const wxString &text, wxSizer *sizer)
|
|||||||
wxStaticText *label = new wxStaticText(this, wxID_ANY, text);
|
wxStaticText *label = new wxStaticText(this, wxID_ANY, text);
|
||||||
wxStaticText *value = new wxStaticText(this, wxID_ANY, wxGetTranslation("unknown"));
|
wxStaticText *value = new wxStaticText(this, wxID_ANY, wxGetTranslation("unknown"));
|
||||||
|
|
||||||
|
// Match the message label's look so the times theme with the rest of the
|
||||||
|
// dialog: PROGRESSDIALOG_GREY_700 is a key in the dark-mode colour map, so
|
||||||
|
// UpdateDlgDarkUI() (called at the end of Create()) remaps it in dark mode.
|
||||||
|
for (wxStaticText *st : {label, value}) {
|
||||||
|
st->SetFont(::Label::Body_13);
|
||||||
|
st->SetForegroundColour(PROGRESSDIALOG_GREY_700);
|
||||||
|
}
|
||||||
|
|
||||||
// select placement most native or nice on target GUI
|
// select placement most native or nice on target GUI
|
||||||
#if defined(__WXMSW__) || defined(__WXMAC__) || defined(__WXGTK20__)
|
#if defined(__WXMSW__) || defined(__WXMAC__) || defined(__WXGTK20__)
|
||||||
// value and time centered in one row
|
// value and time centered in one row
|
||||||
|
|||||||
Reference in New Issue
Block a user