support dark theme for plugin progress dialog

This commit is contained in:
SoftFever
2026-07-04 22:14:55 +08:00
parent f47eee24d3
commit 383969d456
3 changed files with 34 additions and 10 deletions

View File

@@ -10,11 +10,15 @@ PluginProgressDialog::PluginProgressDialog(wxWindow* parent,
int maximum,
int style,
CloseHandler on_destroyed)
: wxProgressDialog(title, message, maximum, parent, style)
: ProgressDialog(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);
// 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()
@@ -120,11 +124,6 @@ void PluginProgressDialog::close()
Destroy();
}
void PluginProgressDialog::on_close_window(wxCloseEvent& /*event*/)
{
close();
}
void PluginProgressDialog::on_timer(wxTimerEvent& /*event*/)
{
if (m_open)

View File

@@ -5,17 +5,24 @@
#include <memory>
#include <wx/event.h>
#include <wx/progdlg.h>
#include <wx/string.h>
#include <wx/timer.h>
#include <wx/window.h>
#include "Widgets/ProgressDialog.hpp"
namespace Slic3r { namespace GUI {
// A host-owned progress dialog for Python plugins. This class is deliberately
// Python-agnostic; the plugin layer owns any pybind/GIL concerns and marshals
// 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:
using CloseHandler = std::function<void()>;
@@ -52,7 +59,6 @@ public:
bool is_open() const { return m_open; }
private:
void on_close_window(wxCloseEvent& event);
void on_timer(wxTimerEvent& event);
bool m_open{true};

View File

@@ -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));
}
// 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__
//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);
@@ -490,6 +501,14 @@ wxStaticText *ProgressDialog::CreateLabel(const wxString &text, wxSizer *sizer)
wxStaticText *label = new wxStaticText(this, wxID_ANY, text);
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
#if defined(__WXMSW__) || defined(__WXMAC__) || defined(__WXGTK20__)
// value and time centered in one row