1616import re
1717import sys
1818
19- import numpy as np
20- from traits .etsconfig .api import ETSConfig
21-
22- ETSConfig .toolkit = "qt4"
23-
2419from diffpy .srxconfutils .tools import module_exists_lower
2520from diffpy .srxplanar .selfcalibrate import selfCalibrate
2621from diffpy .srxplanar .srxplanar import SrXplanar
2722from diffpy .srxplanar .srxplanarconfig import checkMax
28- from pyface .api import ImageResource , SplashScreen
23+ from pyface .api import ImageResource
2924from traits .api import (
30- Any ,
31- Array ,
3225 Bool ,
33- Button ,
34- CFloat ,
35- CInt ,
3626 DelegatesTo ,
37- Dict ,
3827 Directory ,
3928 Enum ,
40- Event ,
4129 File ,
4230 Float ,
4331 HasTraits ,
4432 Instance ,
4533 Int ,
46- List ,
47- Property ,
48- Range ,
4934 Str ,
50- cached_property ,
5135 on_trait_change ,
52- property_depends_on ,
53- )
54- from traitsui .api import (
55- Action ,
56- ArrayEditor ,
57- ButtonEditor ,
58- CheckListEditor ,
59- Controller ,
60- EnumEditor ,
61- Group ,
62- Handler ,
63- HGroup ,
64- HistoryEditor ,
65- ImageEditor ,
66- InstanceEditor ,
67- Item ,
68- RangeEditor ,
69- Tabbed ,
70- TableEditor ,
71- TextEditor ,
72- TitleEditor ,
73- VGroup ,
74- View ,
75- spring ,
76- )
77- from traitsui .menu import (
78- CancelButton ,
79- Menu ,
80- MenuBar ,
81- OKButton ,
82- OKCancelButtons ,
83- ToolBar ,
8436)
37+ from traits .etsconfig .api import ETSConfig
38+ from traitsui .api import Group , Handler , HGroup , Item , VGroup , View
39+ from traitsui .menu import CancelButton , OKButton
8540
8641from diffpy .srxplanargui .srxconfig import SrXconfig
8742
43+ ETSConfig .toolkit = "qt"
44+
8845if module_exists_lower ("pyfai" ):
8946 import pyFAI
9047
@@ -146,7 +103,7 @@ def locatePyFAI(self):
146103 pythonbin = sys .executable
147104 if sys .platform == "win32" :
148105 pyFAIdir = os .path .join (sys .exec_prefix , "Scripts" )
149- elif sys .platform == "linux2" :
106+ elif sys .platform . startswith ( "linux" ) :
150107 pyFAIdir = os .path .join (sys .exec_prefix , "bin" )
151108 else :
152109 pyFAIdir = os .path .join (sys .exec_prefix , "bin" )
@@ -159,7 +116,7 @@ def _pyFAIdirChanged(self):
159116 if sys .platform == "win32" :
160117 caliscript = os .path .join (self .pyFAIdir , "pyFAI-calib.py" )
161118 intescript = os .path .join (self .pyFAIdir , "pyFAI-waxs.py" )
162- elif sys .platform == "linux2" :
119+ elif sys .platform . startswith ( "linux" ) :
163120 caliscript = os .path .join (self .pyFAIdir , "pyFAI-calib" )
164121 intescript = os .path .join (self .pyFAIdir , "pyFAI-waxs" )
165122 else :
@@ -170,11 +127,11 @@ def _pyFAIdirChanged(self):
170127 return
171128
172129 def callPyFAICalibration (self , image = None , dspacefile = None ):
173- if image == None :
130+ if image is None :
174131 image = self .image
175132 else :
176133 self .image = image
177- if dspacefile == None :
134+ if dspacefile is None :
178135 dspacefile = self .dspacefile
179136 else :
180137 self .dspacefile = dspacefile
@@ -208,7 +165,7 @@ def callPyFAICalibration(self, image=None, dspacefile=None):
208165
209166 try :
210167 os .environ .pop ("QT_API" )
211- except :
168+ except KeyError :
212169 pass
213170 subprocess .call (calicmd )
214171
@@ -227,7 +184,7 @@ def callPyFAICalibration(self, image=None, dspacefile=None):
227184 return
228185
229186 def parsePyFAIoutput (self , image = None ):
230- if image == None :
187+ if image is None :
231188 image = self .image
232189
233190 filename = os .path .splitext (image )[0 ] + ".xy"
@@ -256,7 +213,7 @@ def parsePyFAIoutput(self, image=None):
256213
257214 def selfCalibration (self , image = None ):
258215 # self.addfiles.selected[0].fullname
259- if image == None :
216+ if image is None :
260217 image = self .image
261218
262219 if os .path .exists (image ) and os .path .isfile (image ):
@@ -290,7 +247,8 @@ def calibration(self, image=None, dspacefile=None):
290247 qmaxcali = Float (10.0 )
291248
292249 @on_trait_change (
293- "srxconfig.[xpixelsize, ypixelsize, distance, wavelength, xdimension, ydimension]"
250+ "srxconfig.[xpixelsize, ypixelsize, distance,"
251+ " wavelength, xdimension, ydimension]"
294252 )
295253 def _qmaxChanged (self ):
296254 tthmax , qmax = checkMax (self .srxconfig )
@@ -299,10 +257,12 @@ def _qmaxChanged(self):
299257 return
300258
301259 inst1 = Str (
302- "Please install pyFAI and FabIO to use the calibration function (refer to help)."
260+ "Please install pyFAI and FabIO to use"
261+ " the calibration function (refer to help)."
303262 )
304263 inst2 = Str (
305- "(http://github.com/kif/pyFAI, https://forge.epn-campus.eu/projects/azimuthal/files)"
264+ "(http://github.com/kif/pyFAI,"
265+ " https://forge.epn-campus.eu/projects/azimuthal/files)"
306266 )
307267 main_View = View (
308268 # Item('calibrationmode', style='custom', label='Calibration mode'),
@@ -320,7 +280,8 @@ def _qmaxChanged(self):
320280 show_border = True ,
321281 visible_when = 'calibrationmode=="calibrant"' ,
322282 enabled_when = "not missingpyFAI" ,
323- label = "Please specify the d-space file and the location of pyFAI executable" ,
283+ label = "Please specify the d-space file and"
284+ + " the location of pyFAI executable" ,
324285 ),
325286 HGroup (
326287 Item (
@@ -371,7 +332,8 @@ def _qmaxChanged(self):
371332 label = "Camera Length(mm)" ,
372333 visible_when = 'configmode == "TEM"' ,
373334 ),
374- label = "Please specify the wavelength and distance between sample and detector:" ,
335+ label = "Please specify the wavelength and"
336+ + " distance between sample and detector:" ,
375337 show_border = True ,
376338 visible_when = 'calibrationmode=="self"' ,
377339 ),
@@ -416,7 +378,8 @@ def _qmaxChanged(self):
416378 ),
417379 ),
418380 show_border = True ,
419- label = "Plasee specify the dimension of detector and size of pixel:" ,
381+ label = "Please specify the dimension of detector"
382+ + " and size of pixel:" ,
420383 visible_when = 'calibrationmode=="self"' ,
421384 ),
422385 HGroup (
@@ -443,8 +406,8 @@ def _qmaxChanged(self):
443406
444407
445408def findFloat (line ):
446- temp = re . findall ( "[-+]?\d* \.\d+|[-+]? \d+" , line )
447- return map ( float , temp )
409+ pattern = r "[-+]?(?:\d+\.\d*| \.\d+|\d+)"
410+ return [ float ( x ) for x in re . findall ( pattern , line )]
448411
449412
450413if __name__ == "__main__" :
0 commit comments