def show_text_dialog(parent, text, caption): "Create and show a ScrolledMessageDialog" style = wx.CAPTION | wx.CLOSE_BOX | wx.RESIZE_BORDER | wx.SYSTEM_MENU dlg = ScrolledMessageDialog(parent, text, caption, style=style) font = wx.Font(12, wx.MODERN, wx.NORMAL, wx.NORMAL, False, 'Inconsolata') dlg.text.SetFont(font) n_lines = dlg.text.GetNumberOfLines() line_text = dlg.text.GetLineText(0) w, h = dlg.text.GetTextExtent(line_text) dlg.text.SetSize((w + 100, (h + 3) * n_lines + 50)) dlg.Fit() dlg.Show() return dlg
def show_exception_dialog(parent=None, prefix='', exc_info=None, modal=False): """ExceptionDialog(parent=None, prefix='', exc_info=None) show exception info in a dialog parent: parent frame prefix: show in title of window before exception type exc_info: if provided, this is the data from sys.exc_info(). If not, use the current sys.exc_info() modal: if True, show dialog as a modal dialog """ if exc_info is None: info = sys.exc_info() else: info = exc_info if parent is None: parent = wx.GetApp().get_project_frame() filepath = traceback.extract_tb(info[2])[-1:][0][0] try: title = prefix + info[0].__name__ + ' in ' + os.path.split(filepath)[1] except: title = prefix + info[0].__name__ msg = traceback.format_exception(info[0], info[1], info[2]) msg = ''.join(msg) err = ScrolledMessageDialog(parent, msg, title, size=(640, 320), style=wx.DEFAULT_DIALOG_STYLE | wx.RESIZE_BORDER) # scroll to bottom err.Children[0].ShowPosition(len(msg)) if modal: err.ShowModal() else: err.Show() wx.Bell() return