diff --git a/dpx/srxplanargui/calibration.py b/dpx/srxplanargui/calibration.py index efe0b5f..03f643a 100644 --- a/dpx/srxplanargui/calibration.py +++ b/dpx/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 dpx.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") @@ -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 @@ -206,11 +163,8 @@ def callPyFAICalibration(self, image=None, dspacefile=None): import subprocess - try: - os.environ.pop("QT_API") - except: - pass - subprocess.call(calicmd) + os.environ.pop("QT_API", None) + subprocess.run(calicmd, check=True) # integrate image ponifile = os.path.splitext(str(image))[0] + ".poni" @@ -227,7 +181,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,12 +210,12 @@ 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): for mode, showresults in zip( - ["x", "y", "x", "y"], [False, False, False, True] + ["x", "y", "x", "y"], [False, False, False, True] ): selfCalibrate( self.srx, @@ -290,7 +244,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 +254,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 +277,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 +329,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 +375,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 +403,9 @@ def _qmaxChanged(self): def findFloat(line): - temp = re.findall("[-+]?\d*\.\d+|[-+]?\d+", line) - return map(float, temp) + """Extract all floats from a string and return them as a list.""" + pattern = r"[-+]?\d*\.\d+|[-+]?\d+" + return [float(x) for x in re.findall(pattern, line)] if __name__ == "__main__": diff --git a/dpx/srxplanargui/help.py b/dpx/srxplanargui/help.py index e0bb9b4..4b893e9 100644 --- a/dpx/srxplanargui/help.py +++ b/dpx/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): @@ -150,10 +102,17 @@ def _get_qsimage(self): # reference ####################### - 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 + 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 """ def cpReftext(self): @@ -162,8 +121,8 @@ def cpReftext(self): def cpToClipboard(s): - if ETSConfig.toolkit == "qt4": - from pyface.qt import QtCore, QtGui + if ETSConfig.toolkit == "qt": + from pyface.qt import QtGui cb = QtGui.QApplication.clipboard() cb.clear(mode=cb.Clipboard)