Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Flake8v2 #138

Merged
merged 12 commits into from
Jul 31, 2024
2 changes: 1 addition & 1 deletion src/diffpy/pdfgui/control/fitstructure.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 10 additions & 3 deletions src/diffpy/pdfgui/control/organizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,15 @@
from diffpy.pdfgui.control.pdfcomponent import PDFComponent


# Search datasets for spdiameter and its constraints
def spd_assigned(ds):
return bool(ds.spdiameter)


def spd_constrained(ds):
return "spdiameter" in ds.constraints


class Organizer(PDFComponent):
"""Base class for Fitting. It holds separate lists of datasets,
strucs and calculations
Expand Down Expand Up @@ -241,9 +250,7 @@ def __forward_spdiameter(self):
for stru in self.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

# 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
Expand Down
2 changes: 1 addition & 1 deletion src/diffpy/pdfgui/control/pdfguicontrol.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"""
Expand Down
6 changes: 5 additions & 1 deletion src/diffpy/pdfgui/control/plotter.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,11 @@ def _buildStyle(plotter, name, group, yNames):
return style


def deblank(s):
"""Remove all whitespace from the given string."""
return "".join(s.split())


class Plotter(PDFComponent):
"""Plots a single graph. It can have multiple curves."""

Expand Down Expand Up @@ -622,7 +627,6 @@ 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())
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)
Expand Down
7 changes: 3 additions & 4 deletions src/diffpy/pdfgui/doc/manual/extractEquations.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -31,10 +34,6 @@
##############################################################################
# business

import os
import shutil
import sys


def loadEquations():
"""Search for equation codes preceded by @EquationMark macro.
Expand Down
12 changes: 8 additions & 4 deletions src/diffpy/pdfgui/doc/tutorial/tui_mno_bond_lengths.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,17 @@
are plotted versus temperature and saved to "mno-bond-lengths.dat" file.
"""

import pylab

from diffpy.pdffit2 import PdfFit

# Import tui (Text User Interface) functions from diffpy.pdfgui
from diffpy.pdfgui import tui

# PDFgui project file
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)
Expand All @@ -21,7 +26,7 @@
# using diffpy.pdffit2

# Create a PDF calculator object that will be used in that function.
from diffpy.pdffit2 import PdfFit


pf = PdfFit()

Expand Down Expand Up @@ -69,7 +74,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)
Expand Down
18 changes: 12 additions & 6 deletions src/diffpy/pdfgui/gui/dopingseriespanel.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

import os.path
import re
import sys

import wx

Expand All @@ -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(
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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)
Expand All @@ -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.
Expand Down
13 changes: 8 additions & 5 deletions src/diffpy/pdfgui/gui/errorreportdialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,15 +207,18 @@ 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 "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
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
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()
Expand All @@ -242,4 +245,4 @@ def test(self):
app = MyApp(0)
app.MainLoop()

##### end of testing code #####################################################
# end of testing code #####################################################
21 changes: 13 additions & 8 deletions src/diffpy/pdfgui/gui/errorreportdialog_control_fix.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,15 @@
# generated by wxGlade 0.9.3 on Fri Jul 19 16:01:37 2019

import re
import webbrowser

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

from .errorreportdialog import ErrorReportDialog

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

ISSUESTRACKER = "https://github.com/diffpy/diffpy.pdfgui/issues"
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -141,17 +142,21 @@ 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 "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
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
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)
UnicodeDecodeError: 'ascii' codec can't decode byte 0xb0 in position 115: \
ordinal not in range(128)
""".strip()


Expand All @@ -176,4 +181,4 @@ def test(self):
app = MyApp(0)
app.MainLoop()

##### end of testing code #####################################################
# end of testing code #####################################################
6 changes: 3 additions & 3 deletions src/diffpy/pdfgui/gui/extendedplotframe.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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()


Expand Down Expand Up @@ -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,
Expand Down
Loading