如果在wxPython中使用,如何从Python核心转换错误消息?

时间:2014-05-09 11:51:19

标签: python wxpython

我有一个基于wxPython的应用程序,我的所有字符串都通过gettext进行翻译。现在我想使用本机Python错误消息,例如在文件处理操作中。

Q1:如何翻译来自Python核心的错误消息?这些消息通常是否可翻译,我的意思是完全独立的工作?

Q2:本机错误机制是否有机会建议可以用作wx窗口标题的内容(字符串)? (如果可能的话,这个也可翻译)

(问题3:在这种情况下依赖本机错误消息是好主意还是坏主意?)

例如此版本:

# (not shown here) try opening a file;
# (not shown here) return immediately if ok;
# if not ok:
except IOError:
  dlg = wx.MessageDialog(None, (_("Could not read the file\n%s") % filename_wpath), _("File operation error"), wx.OK | wx.ICON_ERROR)
  result = dlg.ShowModal()
  # etc.

# have no idea if this message covers all possible IOError types

与此版本相比:

# (not shown here) try opening a file;
# (not shown here) return immediately if ok;
# if not ok:
except IOError, e:
  dlg = wx.MessageDialog(None, str(e), _("File operation error"), wx.OK | wx.ICON_ERROR)
  result = dlg.ShowModal()
  # etc.

# example of e error message:
# [Errno 2] No such file or directory: u'D:\\Documents\\Testapp\\Testfile.txt'

0 个答案:

没有答案
相关问题