|
| 1 | +#!/usr/bin/env python |
| 2 | +# -*- coding: UTF-8 -*- |
| 3 | +############################################################################## |
| 4 | +# |
| 5 | +# PDFgui by DANSE Diffraction group |
| 6 | +# Simon J. L. Billinge |
| 7 | +# (c) 2006 trustees of the Michigan State University. |
| 8 | +# All rights reserved. |
| 9 | +# |
| 10 | +# File coded by: Dmitriy Bryndin |
| 11 | +# |
| 12 | +# See AUTHORS.txt for a list of people who contributed. |
| 13 | +# See LICENSE.txt for license information. |
| 14 | +# |
| 15 | +############################################################################## |
| 16 | + |
| 17 | +# generated by wxGlade 0.9.3 on Fri Jul 19 16:01:37 2019 |
| 18 | + |
| 19 | +# |
| 20 | +# "Bug report" Dialog |
| 21 | +# |
| 22 | +import wx |
| 23 | +import wx.html |
| 24 | +import webbrowser |
| 25 | +import re |
| 26 | + |
| 27 | +# Constants ------------------------------------------------------------------ |
| 28 | + |
| 29 | +ISSUESTRACKER = "https://github.com/diffpy/diffpy.pdfgui/issues" |
| 30 | +USERSMAILINGLIST = "https://groups.google.com/d/forum/diffpy-users" |
| 31 | +_WEBSEARCHURL = "https://www.google.com/search?q={query}" |
| 32 | + |
| 33 | + |
| 34 | +_MSG_ERROR_REPORT = """ |
| 35 | +<p> |
| 36 | +Currently the control-select is not supported in Python3 PDFgui. We will fix this issue in a future version. |
| 37 | +Please use shift-select for multiple cells instead. |
| 38 | +</p><p> |
| 39 | +""" |
| 40 | + |
| 41 | +# ---------------------------------------------------------------------------- |
| 42 | + |
| 43 | +class ErrorReportDialogControlFix(wx.Dialog): |
| 44 | + def __init__(self, *args, **kwds): |
| 45 | + # begin wxGlade: ErrorReportDialog.__init__ |
| 46 | + kwds["style"] = kwds.get("style", 0) | wx.DEFAULT_DIALOG_STYLE | wx.MAXIMIZE_BOX | wx.MINIMIZE_BOX | wx.RESIZE_BORDER |
| 47 | + wx.Dialog.__init__(self, *args, **kwds) |
| 48 | + self.SetSize((540, 200)) |
| 49 | + self.label_header = wx.html.HtmlWindow(self, wx.ID_ANY) |
| 50 | + # self.label_log = wx.StaticText(self, wx.ID_ANY, "Error Log:") |
| 51 | + # self.text_ctrl_log = wx.TextCtrl(self, wx.ID_ANY, "", style=wx.TE_MULTILINE | wx.TE_READONLY) |
| 52 | + # self.static_line_1 = wx.StaticLine(self, wx.ID_ANY) |
| 53 | + # self.button_google = wx.Button(self, wx.ID_ANY, "Google This Error") |
| 54 | + # self.button_copyErrorLog = wx.Button(self, wx.ID_ANY, "Copy Error Log") |
| 55 | + self.button_close = wx.Button(self, wx.ID_CANCEL, "Close") |
| 56 | + |
| 57 | + self.__set_properties() |
| 58 | + self.__do_layout() |
| 59 | + |
| 60 | + # self.Bind(wx.EVT_BUTTON, self.onGoogle, self.button_google) |
| 61 | + # self.Bind(wx.EVT_BUTTON, self.onCopyErrorLog, self.button_copyErrorLog) |
| 62 | + # end wxGlade |
| 63 | + self.__customProperties() |
| 64 | + return |
| 65 | + |
| 66 | + def __set_properties(self): |
| 67 | + # begin wxGlade: ErrorReportDialog.__set_properties |
| 68 | + self.SetTitle("Problem Report for PDFgui") |
| 69 | + self.SetSize((540, 200)) |
| 70 | + # end wxGlade |
| 71 | + |
| 72 | + def __do_layout(self): |
| 73 | + # begin wxGlade: ErrorReportDialog.__do_layout |
| 74 | + sizer_main = wx.BoxSizer(wx.VERTICAL) |
| 75 | + sizer_buttons = wx.BoxSizer(wx.HORIZONTAL) |
| 76 | + sizer_log = wx.BoxSizer(wx.VERTICAL) |
| 77 | + sizer_label = wx.BoxSizer(wx.HORIZONTAL) |
| 78 | + sizer_label.Add(self.label_header, 1, wx.EXPAND, 5) |
| 79 | + sizer_main.Add(sizer_label, 1, wx.ALL | wx.EXPAND, 5) |
| 80 | + # sizer_log.Add(self.label_log, 0, wx.EXPAND | wx.LEFT | wx.RIGHT | wx.TOP, 5) |
| 81 | + # sizer_log.Add(self.text_ctrl_log, 1, wx.EXPAND | wx.LEFT | wx.RIGHT, 5) |
| 82 | + # sizer_main.Add(sizer_log, 3, wx.EXPAND | wx.LEFT | wx.RIGHT | wx.TOP, 10) |
| 83 | + # sizer_main.Add(self.static_line_1, 0, wx.EXPAND | wx.LEFT | wx.RIGHT | wx.TOP, 5) |
| 84 | + # sizer_buttons.Add((20, 20), 1, 0, 0) |
| 85 | + # sizer_buttons.Add(self.button_google, 0, wx.ALL, 5) |
| 86 | + # sizer_buttons.Add(self.button_copyErrorLog, 0, wx.ALL, 5) |
| 87 | + sizer_buttons.Add(self.button_close, 0, wx.ALL, 5) |
| 88 | + sizer_main.Add(sizer_buttons, 0, wx.EXPAND, 0) |
| 89 | + self.SetSizer(sizer_main) |
| 90 | + self.Layout() |
| 91 | + # end wxGlade |
| 92 | + |
| 93 | + def __customProperties(self): |
| 94 | + """Set custom properties.""" |
| 95 | + # Events |
| 96 | + self.errorReport = True |
| 97 | + # self.label_header.Bind(wx.html.EVT_HTML_LINK_CLICKED, self.onURL) |
| 98 | + return |
| 99 | + |
| 100 | + def ShowModal(self): |
| 101 | + # there are 2 modes: error report and feature request |
| 102 | + |
| 103 | + self.SetTitle("Problem Report for PDFgui") |
| 104 | + self.label_header.SetPage(_MSG_ERROR_REPORT) |
| 105 | + self.label_header.SetBackgroundColour('') |
| 106 | + # self.text_ctrl_log.Show() |
| 107 | + self.errorReport = True |
| 108 | + |
| 109 | + wx.Dialog.ShowModal(self) |
| 110 | + |
| 111 | + |
| 112 | +# end of class ErrorReportDialog |
| 113 | + |
| 114 | +# Helper functions ----------------------------------------------------------- |
| 115 | + |
| 116 | +def _extractSearchTerms(tbtext): |
| 117 | + """ |
| 118 | + Extract search words from a Python exception traceback. |
| 119 | +
|
| 120 | + Parameters |
| 121 | + ---------- |
| 122 | + tbtext : str |
| 123 | + Python exception traceback converted to a string. |
| 124 | +
|
| 125 | + Returns |
| 126 | + ------- |
| 127 | + searchterms : list |
| 128 | + List of search terms to be used for Google search. |
| 129 | + """ |
| 130 | + # extract module names and function names from a traceback |
| 131 | + modfncpairs = re.findall( |
| 132 | + r'File.*?([^/\\]*[.]py).*?, line \d+, in (\w+)', |
| 133 | + tbtext, re.MULTILINE) |
| 134 | + modfnc = list(sum(modfncpairs, ())) |
| 135 | + # find the last line starting with "SomeError: ...". |
| 136 | + lasterr = re.findall(r'^\w+Error:.*', tbtext, re.MULTILINE) |
| 137 | + rv = modfnc + lasterr[-1:] |
| 138 | + return rv |
| 139 | + |
| 140 | +##### testing code ############################################################ |
| 141 | + |
| 142 | +_EXAMPLE_TRACEBACK = r""" |
| 143 | +Traceback (most recent call last): |
| 144 | + File "C:\DiffPy\Python25\lib\site-packages\diffpy.pdfgui-1.0_r3067_20090410-py2.5.egg\diffpy\pdfgui\gui\errorwrapper.py", line 60, in _f |
| 145 | + return func(*args, **kwargs) |
| 146 | + File "C:\DiffPy\Python25\lib\site-packages\diffpy.pdfgui-1.0_r3067_20090410-py2.5.egg\diffpy\pdfgui\gui\mainframe.py", line 2176, in onSave |
| 147 | + self.control.save(self.fullpath) |
| 148 | + File "C:\DiffPy\Python25\lib\site-packages\diffpy.pdfgui-1.0_r3067_20090410-py2.5.egg\diffpy\pdfgui\control\pdfguicontrol.py", line 507, in save |
| 149 | + self.projfile = projfile.encode('ascii') |
| 150 | +UnicodeDecodeError: 'ascii' codec can't decode byte 0xb0 in position 115: ordinal not in range(128) |
| 151 | +""".strip() |
| 152 | + |
| 153 | +class MyApp(wx.App): |
| 154 | + def OnInit(self): |
| 155 | + self.dialog = ErrorReportDialog(None, -1, "") |
| 156 | + self.SetTopWindow(self.dialog) |
| 157 | + self.test() |
| 158 | + self.dialog.ShowModal() |
| 159 | + self.dialog.Destroy() |
| 160 | + return True |
| 161 | + |
| 162 | + def test(self): |
| 163 | + '''Testing code goes here.''' |
| 164 | + # self.dialog.text_ctrl_log.SetValue(_EXAMPLE_TRACEBACK) |
| 165 | + return |
| 166 | + |
| 167 | +# end of class MyApp |
| 168 | + |
| 169 | +if __name__ == "__main__": |
| 170 | + app = MyApp(0) |
| 171 | + app.MainLoop() |
| 172 | + |
| 173 | +##### end of testing code ##################################################### |
0 commit comments