Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/diffpy/pdfgui/control/controlerrors.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,4 +72,9 @@ class ControlSyntaxError(ControlError):
"""
pass

class TempControlSelectError(ControlError):
"""Temporary define this error to identify the select-control error in python3
"""
pass

# End of file
173 changes: 173 additions & 0 deletions src/diffpy/pdfgui/gui/errorreportdialog_control_fix.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,173 @@
#!/usr/bin/env python
# -*- coding: UTF-8 -*-
##############################################################################
#
# PDFgui by DANSE Diffraction group
# Simon J. L. Billinge
# (c) 2006 trustees of the Michigan State University.
# All rights reserved.
#
# File coded by: Dmitriy Bryndin
#
# See AUTHORS.txt for a list of people who contributed.
# See LICENSE.txt for license information.
#
##############################################################################

# generated by wxGlade 0.9.3 on Fri Jul 19 16:01:37 2019

#
# "Bug report" Dialog
#
import wx
import wx.html
import webbrowser
import re

# Constants ------------------------------------------------------------------

ISSUESTRACKER = "https://github.com/diffpy/diffpy.pdfgui/issues"
USERSMAILINGLIST = "https://groups.google.com/d/forum/diffpy-users"
_WEBSEARCHURL = "https://www.google.com/search?q={query}"


_MSG_ERROR_REPORT = """
<p>
Currently the control-select is not supported in Python3 PDFgui. We will fix this issue in a future version.
Please use shift-select for multiple cells instead.
</p><p>
"""

# ----------------------------------------------------------------------------

class ErrorReportDialogControlFix(wx.Dialog):
def __init__(self, *args, **kwds):
# begin wxGlade: ErrorReportDialog.__init__
kwds["style"] = kwds.get("style", 0) | wx.DEFAULT_DIALOG_STYLE | wx.MAXIMIZE_BOX | wx.MINIMIZE_BOX | wx.RESIZE_BORDER
wx.Dialog.__init__(self, *args, **kwds)
self.SetSize((540, 200))
self.label_header = wx.html.HtmlWindow(self, wx.ID_ANY)
# self.label_log = wx.StaticText(self, wx.ID_ANY, "Error Log:")
# self.text_ctrl_log = wx.TextCtrl(self, wx.ID_ANY, "", style=wx.TE_MULTILINE | wx.TE_READONLY)
# self.static_line_1 = wx.StaticLine(self, wx.ID_ANY)
# self.button_google = wx.Button(self, wx.ID_ANY, "Google This Error")
# self.button_copyErrorLog = wx.Button(self, wx.ID_ANY, "Copy Error Log")
self.button_close = wx.Button(self, wx.ID_CANCEL, "Close")

self.__set_properties()
self.__do_layout()

# self.Bind(wx.EVT_BUTTON, self.onGoogle, self.button_google)
# self.Bind(wx.EVT_BUTTON, self.onCopyErrorLog, self.button_copyErrorLog)
# end wxGlade
self.__customProperties()
return

def __set_properties(self):
# begin wxGlade: ErrorReportDialog.__set_properties
self.SetTitle("Problem Report for PDFgui")
self.SetSize((540, 200))
# end wxGlade

def __do_layout(self):
# begin wxGlade: ErrorReportDialog.__do_layout
sizer_main = wx.BoxSizer(wx.VERTICAL)
sizer_buttons = wx.BoxSizer(wx.HORIZONTAL)
sizer_log = wx.BoxSizer(wx.VERTICAL)
sizer_label = wx.BoxSizer(wx.HORIZONTAL)
sizer_label.Add(self.label_header, 1, wx.EXPAND, 5)
sizer_main.Add(sizer_label, 1, wx.ALL | wx.EXPAND, 5)
# sizer_log.Add(self.label_log, 0, wx.EXPAND | wx.LEFT | wx.RIGHT | wx.TOP, 5)
# sizer_log.Add(self.text_ctrl_log, 1, wx.EXPAND | wx.LEFT | wx.RIGHT, 5)
# sizer_main.Add(sizer_log, 3, wx.EXPAND | wx.LEFT | wx.RIGHT | wx.TOP, 10)
# sizer_main.Add(self.static_line_1, 0, wx.EXPAND | wx.LEFT | wx.RIGHT | wx.TOP, 5)
# sizer_buttons.Add((20, 20), 1, 0, 0)
# sizer_buttons.Add(self.button_google, 0, wx.ALL, 5)
# sizer_buttons.Add(self.button_copyErrorLog, 0, wx.ALL, 5)
sizer_buttons.Add(self.button_close, 0, wx.ALL, 5)
sizer_main.Add(sizer_buttons, 0, wx.EXPAND, 0)
self.SetSizer(sizer_main)
self.Layout()
# end wxGlade

def __customProperties(self):
"""Set custom properties."""
# Events
self.errorReport = True
# self.label_header.Bind(wx.html.EVT_HTML_LINK_CLICKED, self.onURL)
return

def ShowModal(self):
# there are 2 modes: error report and feature request

self.SetTitle("Problem Report for PDFgui")
self.label_header.SetPage(_MSG_ERROR_REPORT)
self.label_header.SetBackgroundColour('')
# self.text_ctrl_log.Show()
self.errorReport = True

wx.Dialog.ShowModal(self)


# end of class ErrorReportDialog

# Helper functions -----------------------------------------------------------

def _extractSearchTerms(tbtext):
"""
Extract search words from a Python exception traceback.

Parameters
----------
tbtext : str
Python exception traceback converted to a string.

Returns
-------
searchterms : list
List of search terms to be used for Google search.
"""
# extract module names and function names from a traceback
modfncpairs = re.findall(
r'File.*?([^/\\]*[.]py).*?, line \d+, in (\w+)',
tbtext, re.MULTILINE)
modfnc = list(sum(modfncpairs, ()))
# find the last line starting with "SomeError: ...".
lasterr = re.findall(r'^\w+Error:.*', tbtext, re.MULTILINE)
rv = modfnc + lasterr[-1:]
return rv

##### testing code ############################################################

_EXAMPLE_TRACEBACK = r"""
Traceback (most recent call last):
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
return func(*args, **kwargs)
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
self.control.save(self.fullpath)
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
self.projfile = projfile.encode('ascii')
UnicodeDecodeError: 'ascii' codec can't decode byte 0xb0 in position 115: ordinal not in range(128)
""".strip()

class MyApp(wx.App):
def OnInit(self):
self.dialog = ErrorReportDialog(None, -1, "")
self.SetTopWindow(self.dialog)
self.test()
self.dialog.ShowModal()
self.dialog.Destroy()
return True

def test(self):
'''Testing code goes here.'''
# self.dialog.text_ctrl_log.SetValue(_EXAMPLE_TRACEBACK)
return

# end of class MyApp

if __name__ == "__main__":
app = MyApp(0)
app.MainLoop()

##### end of testing code #####################################################
9 changes: 9 additions & 0 deletions src/diffpy/pdfgui/gui/errorwrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@
from diffpy.pdfgui.gui.errorreportdialog import ErrorReportDialog
from diffpy.pdfgui.control.controlerrors import ControlError

from diffpy.pdfgui.gui.errorreportdialog_control_fix import ErrorReportDialogControlFix
from diffpy.pdfgui.control.controlerrors import TempControlSelectError

# these methods will not be wrapped in catchFunctionErrors
_EXCLUDED_METHODS = dict.fromkeys(dir(wx.Panel) + dir(wx.Dialog))

Expand Down Expand Up @@ -58,6 +61,12 @@ def _f(*args, **kwargs):
try:
return func(*args, **kwargs)

#to be deleted. temporarily used for show the select-control error.
except TempControlSelectError:
dlg = ErrorReportDialogControlFix(obj.mainFrame)
dlg.ShowModal()
dlg.Destroy()

# Display ControlError error messages in a dialog.
except ControlError as e:
if not hasmf:
Expand Down
8 changes: 7 additions & 1 deletion src/diffpy/pdfgui/gui/phaseconfigurepanel.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
from diffpy.pdfgui.gui import phasepanelutils
from diffpy.utils.wx import gridutils

from diffpy.pdfgui.control.controlerrors import TempControlSelectError

class PhaseConfigurePanel(wx.Panel, PDFPanel):
"""Panel for configuring a phase.
Expand Down Expand Up @@ -451,7 +452,12 @@ def onEditorShown(self, event): # wxGlade: PhaseConfigurePanel.<event_handler>
i = event.GetRow()
j = event.GetCol()
self._focusedText = self.gridAtoms.GetCellValue(i,j)
self._selectedCells = gridutils.getSelectedCells(self.gridAtoms)
# self._selectedCells = gridutils.getSelectedCells(self.gridAtoms)
#TODO: temporary show the error message for control-select.
try:
self._selectedCells = gridutils.getSelectedCells(self.gridAtoms)
except TypeError:
raise TempControlSelectError("controlselecterror")
return

def onCellChange(self, event): # wxGlade: PhaseConfigurePanel.<event_handler>
Expand Down