From 3db57ffe2534a2a5159bef2f64b003c22bf5017c Mon Sep 17 00:00:00 2001 From: stevenhua0320 Date: Thu, 25 Sep 2025 15:42:04 -0400 Subject: [PATCH 1/3] fix flake8 error for two files --- src/diffpy/srxplanargui/calibration.py | 91 ++++++++------------------ src/diffpy/srxplanargui/help.py | 70 ++++---------------- 2 files changed, 41 insertions(+), 120 deletions(-) diff --git a/src/diffpy/srxplanargui/calibration.py b/src/diffpy/srxplanargui/calibration.py index 939b348..e686bd0 100644 --- a/src/diffpy/srxplanargui/calibration.py +++ b/src/diffpy/srxplanargui/calibration.py @@ -16,75 +16,32 @@ import re import sys -import numpy as np -from traits.etsconfig.api import ETSConfig - -ETSConfig.toolkit = "qt4" - from diffpy.srxconfutils.tools import module_exists_lower from diffpy.srxplanar.selfcalibrate import selfCalibrate from diffpy.srxplanar.srxplanar import SrXplanar from diffpy.srxplanar.srxplanarconfig import checkMax -from pyface.api import ImageResource, SplashScreen +from pyface.api import ImageResource from traits.api import ( - Any, - Array, Bool, - Button, - CFloat, - CInt, DelegatesTo, - Dict, Directory, Enum, - Event, File, Float, HasTraits, Instance, Int, - List, - Property, - Range, Str, - cached_property, on_trait_change, - property_depends_on, -) -from traitsui.api import ( - Action, - ArrayEditor, - ButtonEditor, - CheckListEditor, - Controller, - EnumEditor, - Group, - Handler, - HGroup, - HistoryEditor, - ImageEditor, - InstanceEditor, - Item, - RangeEditor, - Tabbed, - TableEditor, - TextEditor, - TitleEditor, - VGroup, - View, - spring, -) -from traitsui.menu import ( - CancelButton, - Menu, - MenuBar, - OKButton, - OKCancelButtons, - ToolBar, ) +from traits.etsconfig.api import ETSConfig +from traitsui.api import Group, Handler, HGroup, Item, VGroup, View +from traitsui.menu import CancelButton, OKButton from diffpy.srxplanargui.srxconfig import SrXconfig +ETSConfig.toolkit = "qt" + if module_exists_lower("pyfai"): import pyFAI @@ -146,7 +103,7 @@ def locatePyFAI(self): pythonbin = sys.executable if sys.platform == "win32": pyFAIdir = os.path.join(sys.exec_prefix, "Scripts") - elif sys.platform == "linux2": + elif sys.platform.startswith("linux"): pyFAIdir = os.path.join(sys.exec_prefix, "bin") else: pyFAIdir = os.path.join(sys.exec_prefix, "bin") @@ -159,7 +116,7 @@ def _pyFAIdirChanged(self): if sys.platform == "win32": caliscript = os.path.join(self.pyFAIdir, "pyFAI-calib.py") intescript = os.path.join(self.pyFAIdir, "pyFAI-waxs.py") - elif sys.platform == "linux2": + elif sys.platform.startswith("linux"): caliscript = os.path.join(self.pyFAIdir, "pyFAI-calib") intescript = os.path.join(self.pyFAIdir, "pyFAI-waxs") else: @@ -170,11 +127,11 @@ def _pyFAIdirChanged(self): return def callPyFAICalibration(self, image=None, dspacefile=None): - if image == None: + if image is None: image = self.image else: self.image = image - if dspacefile == None: + if dspacefile is None: dspacefile = self.dspacefile else: self.dspacefile = dspacefile @@ -208,7 +165,7 @@ def callPyFAICalibration(self, image=None, dspacefile=None): try: os.environ.pop("QT_API") - except: + except ImportWarning: pass subprocess.call(calicmd) @@ -227,7 +184,7 @@ def callPyFAICalibration(self, image=None, dspacefile=None): return def parsePyFAIoutput(self, image=None): - if image == None: + if image is None: image = self.image filename = os.path.splitext(image)[0] + ".xy" @@ -256,7 +213,7 @@ def parsePyFAIoutput(self, image=None): def selfCalibration(self, image=None): # self.addfiles.selected[0].fullname - if image == None: + if image is None: image = self.image if os.path.exists(image) and os.path.isfile(image): @@ -290,7 +247,8 @@ def calibration(self, image=None, dspacefile=None): qmaxcali = Float(10.0) @on_trait_change( - "srxconfig.[xpixelsize, ypixelsize, distance, wavelength, xdimension, ydimension]" + "srxconfig.[xpixelsize, ypixelsize, distance," + "wavelength, xdimension, ydimension]" ) def _qmaxChanged(self): tthmax, qmax = checkMax(self.srxconfig) @@ -299,10 +257,12 @@ def _qmaxChanged(self): return inst1 = Str( - "Please install pyFAI and FabIO to use the calibration function (refer to help)." + "Please install pyFAI and FabIO to use" + "the calibration function (refer to help)." ) inst2 = Str( - "(http://github.com/kif/pyFAI, https://forge.epn-campus.eu/projects/azimuthal/files)" + "(http://github.com/kif/pyFAI," + "https://forge.epn-campus.eu/projects/azimuthal/files)" ) main_View = View( # Item('calibrationmode', style='custom', label='Calibration mode'), @@ -320,7 +280,8 @@ def _qmaxChanged(self): show_border=True, visible_when='calibrationmode=="calibrant"', enabled_when="not missingpyFAI", - label="Please specify the d-space file and the location of pyFAI executable", + label="Please specify the d-space file and" + + " the location of pyFAI executable", ), HGroup( Item( @@ -371,7 +332,8 @@ def _qmaxChanged(self): label="Camera Length(mm)", visible_when='configmode == "TEM"', ), - label="Please specify the wavelength and distance between sample and detector:", + label="Please specify the wavelength and" + + " distance between sample and detector:", show_border=True, visible_when='calibrationmode=="self"', ), @@ -416,7 +378,8 @@ def _qmaxChanged(self): ), ), show_border=True, - label="Plasee specify the dimension of detector and size of pixel:", + label="Plasee specify the dimension of detector" + + " and size of pixel:", visible_when='calibrationmode=="self"', ), HGroup( @@ -443,8 +406,8 @@ def _qmaxChanged(self): def findFloat(line): - temp = re.findall("[-+]?\d*\.\d+|[-+]?\d+", line) - return map(float, temp) + pattern = r"[-+]?\d*\.\d+|[-+]?\d+" + return [float(x) for x in re.findall(pattern, line)] if __name__ == "__main__": diff --git a/src/diffpy/srxplanargui/help.py b/src/diffpy/srxplanargui/help.py index e0bb9b4..50258d7 100644 --- a/src/diffpy/srxplanargui/help.py +++ b/src/diffpy/srxplanargui/help.py @@ -13,61 +13,13 @@ ############################################################################## """Provide help for SrXgui.""" -import os import sys -import numpy as np from pyface.api import ImageResource -from traits.api import ( - Any, - Array, - Bool, - Button, - CFloat, - CInt, - DelegatesTo, - Dict, - Directory, - Enum, - Event, - File, - Float, - HasTraits, - Instance, - Int, - List, - Property, - Range, - Str, - cached_property, - on_trait_change, - property_depends_on, -) +from traits.api import HasTraits, Int, Property, property_depends_on from traits.etsconfig.api import ETSConfig -from traitsui.api import ( - Action, - ArrayEditor, - ButtonEditor, - CheckListEditor, - Controller, - EnumEditor, - Group, - Handler, - HGroup, - HistoryEditor, - ImageEditor, - InstanceEditor, - Item, - RangeEditor, - Tabbed, - TableEditor, - TextEditor, - TitleEditor, - VGroup, - View, - spring, -) -from traitsui.menu import CancelButton, Menu, OKButton, ToolBar +from traitsui.api import Action, Handler, ImageEditor, Item, View +from traitsui.menu import OKButton class HelpHandler(Handler): @@ -88,7 +40,7 @@ def _cpReftext(self, info): class SrXguiHelp(HasTraits): if sys.platform.startswith("win"): - if ETSConfig.toolkit == "qt4": + if ETSConfig.toolkit == "qt": hheight = 510 hwidth = 960 else: @@ -151,9 +103,15 @@ def _get_qsimage(self): ####################### reftext = """ -xPDFsuite (main GUI) :X. Yang, P. Juhas, C. L. Farrow and Simon J. L. Billinge xPDFsuite: an end-to-end software solution for high throughput pair distribution function transformation, visualization and analysis, arXiv 1402.3163 (2014) - -SrXplanar (2D image integration):X. Yang, P. Juhas, S.J.L. Billinge, On the estimation of statistical uncertainties on powder diffraction and small-angle scattering data from two-dimensional X-ray detectors, J. Appl. Cryst. (2014). 47, 1273-1283 +xPDFsuite (main GUI) :X. Yang, P. Juhas, C. L. Farrow and Simon J. L. Billinge +xPDFsuite: an end-to-end software solution for high throughput +pair distribution function transformation, +visualization and analysis, arXiv 1402.3163 (2014) + +SrXplanar (2D image integration):X. Yang, P. Juhas, S.J.L. Billinge, +On the estimation of statistical uncertainties on powder diffraction +and small-angle scattering data from two-dimensional X-ray detectors, +J. Appl. Cryst. (2014). 47, 1273-1283 """ def cpReftext(self): @@ -163,7 +121,7 @@ def cpReftext(self): def cpToClipboard(s): if ETSConfig.toolkit == "qt4": - from pyface.qt import QtCore, QtGui + from pyface.qt import QtGui cb = QtGui.QApplication.clipboard() cb.clear(mode=cb.Clipboard) From 2dc53871f56d57ca97c5f9e8008022625a82bd43 Mon Sep 17 00:00:00 2001 From: stevenhua0320 Date: Thu, 25 Sep 2025 21:40:22 -0400 Subject: [PATCH 2/3] add a white space for string edition, add one edge case of finding float --- src/diffpy/srxplanargui/calibration.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/diffpy/srxplanargui/calibration.py b/src/diffpy/srxplanargui/calibration.py index e686bd0..9404c7c 100644 --- a/src/diffpy/srxplanargui/calibration.py +++ b/src/diffpy/srxplanargui/calibration.py @@ -165,7 +165,7 @@ def callPyFAICalibration(self, image=None, dspacefile=None): try: os.environ.pop("QT_API") - except ImportWarning: + except KeyError: pass subprocess.call(calicmd) @@ -248,7 +248,7 @@ def calibration(self, image=None, dspacefile=None): @on_trait_change( "srxconfig.[xpixelsize, ypixelsize, distance," - "wavelength, xdimension, ydimension]" + " wavelength, xdimension, ydimension]" ) def _qmaxChanged(self): tthmax, qmax = checkMax(self.srxconfig) @@ -258,11 +258,11 @@ def _qmaxChanged(self): inst1 = Str( "Please install pyFAI and FabIO to use" - "the calibration function (refer to help)." + " the calibration function (refer to help)." ) inst2 = Str( "(http://github.com/kif/pyFAI," - "https://forge.epn-campus.eu/projects/azimuthal/files)" + " https://forge.epn-campus.eu/projects/azimuthal/files)" ) main_View = View( # Item('calibrationmode', style='custom', label='Calibration mode'), @@ -406,7 +406,7 @@ def _qmaxChanged(self): def findFloat(line): - pattern = r"[-+]?\d*\.\d+|[-+]?\d+" + pattern = r"[-+]?(?:\d+\.\d*|\.\d+|\d+)" return [float(x) for x in re.findall(pattern, line)] From c5a1603ee43cb9cc72dc4cfe4655c9f008d8270e Mon Sep 17 00:00:00 2001 From: stevenhua0320 Date: Fri, 26 Sep 2025 17:05:35 -0400 Subject: [PATCH 3/3] chore: change misspelling --- src/diffpy/srxplanargui/calibration.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/diffpy/srxplanargui/calibration.py b/src/diffpy/srxplanargui/calibration.py index 9404c7c..5a1b986 100644 --- a/src/diffpy/srxplanargui/calibration.py +++ b/src/diffpy/srxplanargui/calibration.py @@ -378,7 +378,7 @@ def _qmaxChanged(self): ), ), show_border=True, - label="Plasee specify the dimension of detector" + label="Please specify the dimension of detector" + " and size of pixel:", visible_when='calibrationmode=="self"', ),