X-Git-Url: https://main.carlh.net/gitweb/?a=blobdiff_plain;f=src%2Fwx%2Fwx_util.cc;h=23a85534a2123fbbad1fb58c8ec5e1f43b52618c;hb=fb86361c31c35d7df3dede7b40e4b60e2e7f9c1a;hp=103d36d006d1539043f8c357fae1ebdf98ceb0f7;hpb=bdbb254c18b100f8fa66a3707f6b515309d05685;p=dcpomatic.git diff --git a/src/wx/wx_util.cc b/src/wx/wx_util.cc index 103d36d00..23a85534a 100644 --- a/src/wx/wx_util.cc +++ b/src/wx/wx_util.cc @@ -1,5 +1,5 @@ /* - Copyright (C) 2012 Carl Hetherington + Copyright (C) 2012-2014 Carl Hetherington This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -140,11 +140,18 @@ ThreadedStaticText::~ThreadedStaticText () /** Run our thread and post the result to the GUI thread via AddPendingEvent */ void ThreadedStaticText::run (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 @@ -182,6 +189,15 @@ checked_set (wxSpinCtrl* widget, int value) } } +void +checked_set (wxSpinCtrlDouble* widget, double value) +{ + /* XXX: completely arbitrary epsilon */ + if (fabs (widget->GetValue() - value) < 1e-16) { + widget->SetValue (value); + } +} + void checked_set (wxChoice* widget, int value) { @@ -289,3 +305,27 @@ wx_get (wxChoice* w) { return w->GetSelection (); } + +double +wx_get (wxSpinCtrlDouble* w) +{ + return w->GetValue (); +} + +/** @param s String of the form Context|String + * @return translation, or String if no translation is available. + */ +wxString +context_translation (wxString s) +{ + wxString t = wxGetTranslation (s); + if (t == s) { + /* No translation; strip the context */ + int c = t.Find (wxT ("|")); + if (c != wxNOT_FOUND) { + t = t.Mid (c + 1); + } + } + + return t; +}