Skip to content

Commit ddf464c

Browse files
authored
Merge pull request #15 from stevenhua0320/migration-2
chore: resolve python2 deprecation issue
2 parents ab137e9 + c5a1603 commit ddf464c

File tree

2 files changed

+41
-120
lines changed

2 files changed

+41
-120
lines changed

src/diffpy/srxplanargui/calibration.py

Lines changed: 27 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -16,75 +16,32 @@
1616
import re
1717
import sys
1818

19-
import numpy as np
20-
from traits.etsconfig.api import ETSConfig
21-
22-
ETSConfig.toolkit = "qt4"
23-
2419
from diffpy.srxconfutils.tools import module_exists_lower
2520
from diffpy.srxplanar.selfcalibrate import selfCalibrate
2621
from diffpy.srxplanar.srxplanar import SrXplanar
2722
from diffpy.srxplanar.srxplanarconfig import checkMax
28-
from pyface.api import ImageResource, SplashScreen
23+
from pyface.api import ImageResource
2924
from 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

8641
from diffpy.srxplanargui.srxconfig import SrXconfig
8742

43+
ETSConfig.toolkit = "qt"
44+
8845
if 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

445408
def 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

450413
if __name__ == "__main__":

src/diffpy/srxplanargui/help.py

Lines changed: 14 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -13,61 +13,13 @@
1313
##############################################################################
1414
"""Provide help for SrXgui."""
1515

16-
import os
1716
import sys
1817

19-
import numpy as np
2018
from pyface.api import ImageResource
21-
from traits.api import (
22-
Any,
23-
Array,
24-
Bool,
25-
Button,
26-
CFloat,
27-
CInt,
28-
DelegatesTo,
29-
Dict,
30-
Directory,
31-
Enum,
32-
Event,
33-
File,
34-
Float,
35-
HasTraits,
36-
Instance,
37-
Int,
38-
List,
39-
Property,
40-
Range,
41-
Str,
42-
cached_property,
43-
on_trait_change,
44-
property_depends_on,
45-
)
19+
from traits.api import HasTraits, Int, Property, property_depends_on
4620
from traits.etsconfig.api import ETSConfig
47-
from traitsui.api import (
48-
Action,
49-
ArrayEditor,
50-
ButtonEditor,
51-
CheckListEditor,
52-
Controller,
53-
EnumEditor,
54-
Group,
55-
Handler,
56-
HGroup,
57-
HistoryEditor,
58-
ImageEditor,
59-
InstanceEditor,
60-
Item,
61-
RangeEditor,
62-
Tabbed,
63-
TableEditor,
64-
TextEditor,
65-
TitleEditor,
66-
VGroup,
67-
View,
68-
spring,
69-
)
70-
from traitsui.menu import CancelButton, Menu, OKButton, ToolBar
21+
from traitsui.api import Action, Handler, ImageEditor, Item, View
22+
from traitsui.menu import OKButton
7123

7224

7325
class HelpHandler(Handler):
@@ -88,7 +40,7 @@ def _cpReftext(self, info):
8840
class SrXguiHelp(HasTraits):
8941

9042
if sys.platform.startswith("win"):
91-
if ETSConfig.toolkit == "qt4":
43+
if ETSConfig.toolkit == "qt":
9244
hheight = 510
9345
hwidth = 960
9446
else:
@@ -151,9 +103,15 @@ def _get_qsimage(self):
151103
#######################
152104

153105
reftext = """
154-
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)
155-
156-
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
106+
xPDFsuite (main GUI) :X. Yang, P. Juhas, C. L. Farrow and Simon J. L. Billinge
107+
xPDFsuite: an end-to-end software solution for high throughput
108+
pair distribution function transformation,
109+
visualization and analysis, arXiv 1402.3163 (2014)
110+
111+
SrXplanar (2D image integration):X. Yang, P. Juhas, S.J.L. Billinge,
112+
On the estimation of statistical uncertainties on powder diffraction
113+
and small-angle scattering data from two-dimensional X-ray detectors,
114+
J. Appl. Cryst. (2014). 47, 1273-1283
157115
"""
158116

159117
def cpReftext(self):
@@ -163,7 +121,7 @@ def cpReftext(self):
163121

164122
def cpToClipboard(s):
165123
if ETSConfig.toolkit == "qt4":
166-
from pyface.qt import QtCore, QtGui
124+
from pyface.qt import QtGui
167125

168126
cb = QtGui.QApplication.clipboard()
169127
cb.clear(mode=cb.Clipboard)

0 commit comments

Comments
 (0)