From 4e463a098a84ead2c3291c03ad6ca8c1ed583503 Mon Sep 17 00:00:00 2001 From: Niels Martin Hansen Date: Sun, 7 Jan 2007 07:10:01 +0000 Subject: [PATCH] Added timer to progress dialog so it updates even when no idle events would normally be fired. Also (unsuccessfully) attempted to reduce the flicker. Originally committed to SVN as r734. --- aegisub/auto4_base.cpp | 14 ++++++++++++++ aegisub/auto4_base.h | 3 +++ 2 files changed, 17 insertions(+) diff --git a/aegisub/auto4_base.cpp b/aegisub/auto4_base.cpp index f0fda7087..558feb0a6 100644 --- a/aegisub/auto4_base.cpp +++ b/aegisub/auto4_base.cpp @@ -312,6 +312,7 @@ namespace Automation4 { , has_inited(false) , script_finished(false) , debug_visible(false) + , data_updated(false) { // make the controls progress_display = new wxGauge(this, -1, 1000, wxDefaultPosition, wxSize(300, 20)); @@ -336,6 +337,12 @@ namespace Automation4 { title_font.SetWeight(wxFONTWEIGHT_BOLD); title_display->SetFont(title_font); + // Set up a timer to regularly update the status + // It doesn't need an event handler attached, as just a the timer in itself + // will ensure that the idle event is fired + update_timer = new wxTimer(); + update_timer->Start(50, false); + sizer->SetSizeHints(this); SetSizer(sizer); Center(); @@ -343,6 +350,7 @@ namespace Automation4 { ProgressSink::~ProgressSink() { + delete update_timer; } void ProgressSink::OnIdle(wxIdleEvent &evt) @@ -368,6 +376,7 @@ namespace Automation4 { // there might actually be some debug output but the debug_visible flag won't // be set before the dialog closes itself. wxMutexLocker lock(data_mutex); + if (!data_updated) return; if (!pending_debug_output.IsEmpty()) { if (!debug_visible) { sizer->Show(debug_output, true); @@ -386,30 +395,35 @@ namespace Automation4 { progress_display->SetValue((int)(progress*10)); task_display->SetLabel(task); title_display->SetLabel(title); + data_updated = false; } void ProgressSink::SetProgress(float _progress) { wxMutexLocker lock(data_mutex); progress = _progress; + data_updated = true; } void ProgressSink::SetTask(const wxString &_task) { wxMutexLocker lock(data_mutex); task = _task; + data_updated = true; } void ProgressSink::SetTitle(const wxString &_title) { wxMutexLocker lock(data_mutex); title = _title; + data_updated = true; } void ProgressSink::AddDebugOutput(const wxString &msg) { wxMutexLocker lock(data_mutex); pending_debug_output << msg; + data_updated = true; } BEGIN_EVENT_TABLE(ProgressSink, wxWindow) diff --git a/aegisub/auto4_base.h b/aegisub/auto4_base.h index 35661a2d3..782433a11 100644 --- a/aegisub/auto4_base.h +++ b/aegisub/auto4_base.h @@ -216,6 +216,7 @@ namespace Automation4 { wxTextCtrl *debug_output; bool debug_visible; + bool data_updated; float progress; wxString task; @@ -223,6 +224,8 @@ namespace Automation4 { wxString pending_debug_output; wxMutex data_mutex; + wxTimer *update_timer; + void OnCancel(wxCommandEvent &evt); void OnInit(wxInitDialogEvent &evt); void OnIdle(wxIdleEvent &evt);