diff --git a/src/diffpy/pdfgui/control/fitstructure.py b/src/diffpy/pdfgui/control/fitstructure.py index f643c994..515fdec5 100644 --- a/src/diffpy/pdfgui/control/fitstructure.py +++ b/src/diffpy/pdfgui/control/fitstructure.py @@ -252,7 +252,7 @@ def _restoreAtomConstraints(self, acd): acd -- dictionary obtained from _popAtomConstraints() """ for i, a in enumerate(self.initial): - if not a in acd: + if a not in acd: continue # there are some constraints for atom a siteindex = i + 1 diff --git a/src/diffpy/pdfgui/control/organizer.py b/src/diffpy/pdfgui/control/organizer.py index 31a5a095..ecf140b8 100644 --- a/src/diffpy/pdfgui/control/organizer.py +++ b/src/diffpy/pdfgui/control/organizer.py @@ -230,28 +230,31 @@ def organization(self): return org - def __forward_spdiameter(self): + def __forward_spdiameter(strucs, datasets, calcs): """Copy spdiameter value loaded from fit or calculation to phase. - This method takes care of loading old PDFgui projects where + This function handles loading old PDFgui projects where spdiameter belonged to FitDataSet or Calculation classes. - It should be called only from the Organizer.load method. """ # Jump out if any of structures has spdiameter set - for stru in self.strucs: + for stru in strucs: if stru.getvar("spdiameter"): return - # Search datasets for spdiameter and its constraints - spd_assigned = lambda ds: bool(ds.spdiameter) - spd_constrained = lambda ds: "spdiameter" in ds.constraints + + # Helper function to check if spdiameter is assigned + def spd_assigned(ds): + return bool(ds.spdiameter) + + # Helper function to check if spdiameter is constrained + def spd_constrained(ds): + return "spdiameter" in ds.constraints + # Figure out the value and constraint for spdiameter. - # The highest priority is for a dataset with constrained spdiameter, - # then for dataset with assigned spdiameter and finally from - # a calculation. spd_val = spd_cns = None - constrained_datas = list(filter(spd_constrained, self.datasets)) - assigned_datas = list(filter(spd_assigned, self.datasets)) - assigned_calcs = list(filter(spd_assigned, self.calcs)) + constrained_datas = list(filter(spd_constrained, datasets)) + assigned_datas = list(filter(spd_assigned, datasets)) + assigned_calcs = list(filter(spd_assigned, calcs)) + if constrained_datas: spd_val = constrained_datas[0].spdiameter spd_cns = constrained_datas[0].constraints["spdiameter"] @@ -259,15 +262,18 @@ def __forward_spdiameter(self): spd_val = assigned_datas[0].spdiameter elif assigned_calcs: spd_val = assigned_calcs[0].spdiameter - # assign spd_val to all structures that don't have it set - for stru in self.strucs: + + # Assign spd_val to all structures that don't have it set + for stru in strucs: if spd_val and not stru.getvar("spdiameter"): stru.setvar("spdiameter", spd_val) if spd_cns: stru.constraints.setdefault("spdiameter", spd_cns) - # finally remove any spdiameter constraints from all datasets - for ds in self.datasets: + + # Finally remove any spdiameter constraints from all datasets + for ds in datasets: ds.constraints.pop("spdiameter", None) + return diff --git a/src/diffpy/pdfgui/control/pdfguicontrol.py b/src/diffpy/pdfgui/control/pdfguicontrol.py index bb39baa8..15632a0d 100644 --- a/src/diffpy/pdfgui/control/pdfguicontrol.py +++ b/src/diffpy/pdfgui/control/pdfguicontrol.py @@ -58,7 +58,7 @@ def __init__(self, gui=None): self.fittingQueue = [] self.currentFitting = None self.queueManager = PDFGuiControl.QueueManager(self) - ##self.startQueue() + # self.startQueue() def reset(self): """clean up for a new project""" diff --git a/src/diffpy/pdfgui/control/plotter.py b/src/diffpy/pdfgui/control/plotter.py index 77134fb1..aeba7d6b 100644 --- a/src/diffpy/pdfgui/control/plotter.py +++ b/src/diffpy/pdfgui/control/plotter.py @@ -622,7 +622,11 @@ def export(self, filename): header = "# Generated on %s by %s.\n" % (time.ctime(), getpass.getuser()) header += "# This file was created by PDFgui.\n" outfile.write(header) - deblank = lambda s: "".join(s.split()) + + def deblank(s): + """Removes all whitespace from string s""" + return "".join(s.split()) + xylist = [(c.x, c.y) for c in self.curves] xynames = [(_transName(c.xStr), deblank(c.name)) for c in self.curves] _exportCompactData(outfile, xylist, xynames) diff --git a/src/diffpy/pdfgui/doc/manual/extractEquations.py b/src/diffpy/pdfgui/doc/manual/extractEquations.py index 4c32814e..ce3a9819 100644 --- a/src/diffpy/pdfgui/doc/manual/extractEquations.py +++ b/src/diffpy/pdfgui/doc/manual/extractEquations.py @@ -1,4 +1,7 @@ #!/usr/bin/python +import os +import shutil +import sys """Read one or more texinfo files and extract any equations marked in the code with '@EquationMark' macro as PNG files to the images @@ -31,10 +34,6 @@ ############################################################################## # business -import os -import shutil -import sys - def loadEquations(): """Search for equation codes preceded by @EquationMark macro. diff --git a/src/diffpy/pdfgui/doc/tutorial/tui_mno_bond_lengths.py b/src/diffpy/pdfgui/doc/tutorial/tui_mno_bond_lengths.py index 79c1b527..9d99e7ec 100755 --- a/src/diffpy/pdfgui/doc/tutorial/tui_mno_bond_lengths.py +++ b/src/diffpy/pdfgui/doc/tutorial/tui_mno_bond_lengths.py @@ -1,5 +1,12 @@ #!/usr/bin/env python +import pylab + +from diffpy.pdffit2 import PdfFit + +# Import tui (Text User Interface) functions from diffpy.pdfgui +from diffpy.pdfgui import tui + """Extract the shortest Mn-O bond lengths from all fits in PDFgui project. This script loops through all refined phases in PDFgui project and calculates @@ -11,8 +18,6 @@ project_file = "lmo-template.ddp3" output_file = "mno-bond-lengths.dat" -# Import tui (Text User Interface) functions from diffpy.pdfgui -from diffpy.pdfgui import tui # load project file prj = tui.LoadProject(project_file) @@ -21,7 +26,6 @@ # using diffpy.pdffit2 # Create a PDF calculator object that will be used in that function. -from diffpy.pdffit2 import PdfFit pf = PdfFit() @@ -69,7 +73,6 @@ def shortestBond_MnO(stru): # Plot results using matplotlib; pylab is a part of matplotlib that # provides MATLAB-like plotting functions. -import pylab pylab.plot(temperatures, MnO_bond_lengths, "o--") pylab.title("Data from refined phases in PDFgui project %s" % project_file) diff --git a/src/diffpy/pdfgui/gui/dopingseriespanel.py b/src/diffpy/pdfgui/gui/dopingseriespanel.py index 211e2f8e..fd60c1bf 100644 --- a/src/diffpy/pdfgui/gui/dopingseriespanel.py +++ b/src/diffpy/pdfgui/gui/dopingseriespanel.py @@ -18,7 +18,6 @@ import os.path import re -import sys import wx @@ -41,7 +40,10 @@ def __init__(self, *args, **kwds): self.instructionsLabel = wx.StaticText( self, wx.ID_ANY, - "Select a fit from the tree on the left then add datasets and assign\ndoping elements and values below. If you have not set up a fit to be\nthe template for the series, hit cancel and rerun this macro once a\nfit has been created.", + "Select a fit from the tree on the left then add datasets and " + + "assign\ndoping elements and values below. " + + "If you have not set up a fit to be\nthe template for the series, " + + "hit cancel and rerun this macro once a\nfit has been created.", ) self.instructionsLabel.SetFont( wx.Font( @@ -210,7 +212,11 @@ def onAdd(self, event): # wxGlade: DopingSeriesPanel.<event_handler> if not dir: dir = self.mainFrame.workpath - matchstring = "PDF data files (*.gr)|*.gr|PDF fit files (*.fgr)|*.fgr|PDF fit files (*.fit)|*.fit|PDF calculation files (*.cgr)|*.cgr|PDF calculation files (*.calc)|*.calc|All Files|*" + matchstring = ( + "PDF data files (*.gr)|*.gr|PDF fit files (*.fgr)|*.fgr|PDF fit files (*.fit)|" + "*.fit|PDF calculation files (*.cgr)|*.cgr|PDF calculation files (*.calc)|*.calc|" + "All Files|*" + ) d = wx.FileDialog( None, "Choose files", @@ -304,7 +310,7 @@ def onCancel(self, event): # wxGlade: DopingSeriesPanel.<event_handler> self.mainFrame.switchRightPanel("blank") return - ## Utility functions + # Utility functions def checkConfiguration(self): """Verify that the dopant and base are elements. @@ -340,7 +346,7 @@ def fillList(self): self.listCtrlFiles.SetItem(index, 1, shortname) return - ## Needed by mainframe + # Needed by mainframe def treeSelectionUpdate(self, node): """Set the current fit when the tree selection changes.""" nodetype = self.treeCtrlMain.GetNodeType(node) @@ -349,7 +355,7 @@ def treeSelectionUpdate(self, node): self.refresh() return - ## Required by PDFPanel + # Required by PDFPanel def refresh(self): """Block out OK button if there is no fit. diff --git a/src/diffpy/pdfgui/gui/errorreportdialog.py b/src/diffpy/pdfgui/gui/errorreportdialog.py index b93cca76..7e554ac6 100644 --- a/src/diffpy/pdfgui/gui/errorreportdialog.py +++ b/src/diffpy/pdfgui/gui/errorreportdialog.py @@ -207,15 +207,15 @@ def _extractSearchTerms(tbtext): return rv -##### testing code ############################################################ +# 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 + File "...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 + File "...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 + File "...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() @@ -242,4 +242,4 @@ def test(self): app = MyApp(0) app.MainLoop() -##### end of testing code ##################################################### +# end of testing code ##################################################### diff --git a/src/diffpy/pdfgui/gui/errorreportdialog_control_fix.py b/src/diffpy/pdfgui/gui/errorreportdialog_control_fix.py index 71e239ca..c2d91812 100644 --- a/src/diffpy/pdfgui/gui/errorreportdialog_control_fix.py +++ b/src/diffpy/pdfgui/gui/errorreportdialog_control_fix.py @@ -17,7 +17,6 @@ # generated by wxGlade 0.9.3 on Fri Jul 19 16:01:37 2019 import re -import webbrowser # # "Bug report" Dialog @@ -25,6 +24,8 @@ import wx import wx.html +from .errorreportdialog import ErrorReportDialog + # Constants ------------------------------------------------------------------ ISSUESTRACKER = "https://github.com/diffpy/diffpy.pdfgui/issues" @@ -77,7 +78,7 @@ 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_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) @@ -141,18 +142,22 @@ def _extractSearchTerms(tbtext): return rv -##### testing code ############################################################ +# 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() +_EXAMPLE_TRACEBACK = ( + r"""Traceback (most recent call last): """ + r"""File 'C:\DiffPy\Python25\lib\site-packages\diffpy.pdfgui-1.0_r3067_20090410-py2.5.egg""" + r"""\diffpy\pdfgui\gui\errorwrapper.py', line 60, in _f """ + r"""return func(*args, **kwargs) """ + r"""File 'C:\DiffPy\Python25\lib\site-packages\diffpy.pdfgui-1.0_r3067_20090410-py2.5.egg""" + r"""\diffpy\pdfgui\gui\mainframe.py', line 2176, in onSave """ + r"""self.control.save(self.fullpath) """ + r"""File 'C:\DiffPy\Python25\lib\site-packages\diffpy.pdfgui-1.0_r3067_20090410-py2.5.egg""" + r"""\diffpy\pdfgui\control\pdfguicontrol.py', line 507, in save """ + r"""self.projfile = projfile.encode('ascii') """ + r"""UnicodeDecodeError: 'ascii' codec can't decode byte 0xb0 in position """ + r"""115: ordinal not in range(128)""" +).strip() class MyApp(wx.App): @@ -176,4 +181,4 @@ def test(self): app = MyApp(0) app.MainLoop() -##### end of testing code ##################################################### +# end of testing code ##################################################### diff --git a/src/diffpy/pdfgui/gui/extendedplotframe.py b/src/diffpy/pdfgui/gui/extendedplotframe.py index 848b54d6..297a7670 100644 --- a/src/diffpy/pdfgui/gui/extendedplotframe.py +++ b/src/diffpy/pdfgui/gui/extendedplotframe.py @@ -20,8 +20,6 @@ import os.path import matplotlib - -matplotlib.use("WXAgg") import wx from matplotlib.artist import setp from matplotlib.backends.backend_wxagg import FigureCanvasWxAgg as FigureCanvas @@ -32,6 +30,8 @@ from diffpy.pdfgui.gui.pdfguiglobals import iconpath from diffpy.pdfgui.gui.wxextensions import wx12 +matplotlib.use("WXAgg") + DATA_SAVE_ID = wx12.NewIdRef() @@ -303,7 +303,7 @@ def __translateStyles(self, style): symbolSize = style["symbolSize"] symbolColor = colorDict.get(style["symbolColor"], "k") properties.update( - { #'linewidth':0.0, # doesn't affect any + { # 'linewidth':0.0, # doesn't affect any "markerfacecolor": symbolColor, "markeredgecolor": color, "marker": symbol,