X-Git-Url: https://git.carlh.net/gitweb/?a=blobdiff_plain;f=src%2Fwx%2Fwx_util.cc;h=048f87908e8c72770e973f0450a36767c1b747f3;hb=854f2e5bbb7ffb9758b823af87034033033f3cb8;hp=20fd2df755f30240e93995ac9639386085c67d34;hpb=2b1f823c64e400de11799849c4788d4ee774b286;p=dcpomatic.git diff --git a/src/wx/wx_util.cc b/src/wx/wx_util.cc index 20fd2df75..048f87908 100644 --- a/src/wx/wx_util.cc +++ b/src/wx/wx_util.cc @@ -105,7 +105,7 @@ confirm_dialog (wxWindow* parent, wxString m) string wx_to_std (wxString s) { - return string (s.mb_str ()); + return string (s.ToUTF8 ()); } /** @param s STL string. @@ -123,7 +123,7 @@ int const ThreadedStaticText::_update_event_id = 10000; * @param initial Initial text for the wxStaticText while the computation is being run. * @param fn Function which works out what the wxStaticText content should be and returns it. */ -ThreadedStaticText::ThreadedStaticText (wxWindow* parent, wxString initial, function fn) +ThreadedStaticText::ThreadedStaticText (wxWindow* parent, wxString initial, boost::function fn) : wxStaticText (parent, wxID_ANY, initial) { Bind (wxEVT_COMMAND_TEXT_UPDATED, boost::bind (&ThreadedStaticText::thread_finished, this, _1), _update_event_id); @@ -139,18 +139,26 @@ ThreadedStaticText::~ThreadedStaticText () /** Run our thread and post the result to the GUI thread via AddPendingEvent */ void -ThreadedStaticText::run (function fn) +ThreadedStaticText::run (boost::function fn) +try { wxCommandEvent ev (wxEVT_COMMAND_TEXT_UPDATED, _update_event_id); ev.SetString (std_to_wx (fn ())); GetEventHandler()->AddPendingEvent (ev); } +catch (...) +{ + /* Ignore exceptions; marginally better than the program quitting, but + only marginally. + */ +} /** Called in the GUI thread when our worker thread has finished */ void ThreadedStaticText::thread_finished (wxCommandEvent& ev) { SetLabel (ev.GetString ()); + Finished (); } string @@ -276,3 +284,23 @@ dcpomatic_setup_i18n () dcpomatic_setup_gettext_i18n (wx_to_std (locale->GetCanonicalName ())); } } + +int +wx_get (wxSpinCtrl* w) +{ + return w->GetValue (); +} + +int +wx_get (wxChoice* w) +{ + return w->GetSelection (); +} + +void +run_gui_loop () +{ + while (wxTheApp->Pending ()) { + wxTheApp->Dispatch (); + } +}