Skip to content

Commit b6e75a9

Browse files
committed
DEP: remove importPdffit2Script functionality
* remove `Import pdffit2 Script` menu * remove `MainFrame.onImportScript` GUI handler method * remove `PDFGuiControl.importPdffit2Script` business function
1 parent 65a1ae9 commit b6e75a9

2 files changed

Lines changed: 0 additions & 88 deletions

File tree

src/diffpy/pdfgui/control/pdfguicontrol.py

Lines changed: 0 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
from diffpy.pdfgui.control.fitstructure import FitStructure
2828
from diffpy.pdfgui.control.controlerrors import ControlError
2929
from diffpy.pdfgui.control.controlerrors import ControlFileError
30-
from diffpy.pdfgui.control.controlerrors import ControlRuntimeError
3130
from diffpy.pdfgui.control.controlerrors import ControlTypeError
3231

3332

@@ -333,74 +332,6 @@ def paste(self, dup, target=None, new_name=None, position=None):
333332
target.add(o, position)
334333
return o
335334

336-
def importPdffit2Script(self, scriptfile, args=[]):
337-
"""add fits and calculations from pdffit2 script
338-
339-
scriptfile -- path to old pdffit2 script
340-
args -- optional arguments passed to scriptfile
341-
342-
returns list of imported fits
343-
"""
344-
pyexe = sys.executable
345-
# Build python command to be executed in the child process.
346-
pycommand = '\n'.join([
347-
'from diffpy.pdfgui.control.dumppdffit2script import main',
348-
'main()',
349-
])
350-
# Build argument list. Include the '-u' option so that child
351-
# Python opens it input and output streams in binary mode.
352-
cmdargs = [pyexe, '-u', '-c', pycommand, scriptfile] + args
353-
scriptdir = os.path.dirname(scriptfile)
354-
import platform
355-
from subprocess import Popen, PIPE
356-
cfds = (platform.system() != 'Windows')
357-
pcmd = Popen(cmdargs, cwd=scriptdir,
358-
stdin=PIPE, stdout=PIPE, stderr=PIPE, close_fds=cfds)
359-
# close child standard input
360-
out, err = pcmd.communicate()
361-
status = pcmd.wait()
362-
if status != 0:
363-
raise ControlRuntimeError, \
364-
"Import of pdffit2 script failed:\n" + err
365-
# seems that everything worked fine here
366-
import cPickle
367-
impfits = cPickle.loads(out)
368-
orgnames = [ f.name for f in impfits ]
369-
usednames = dict.fromkeys([ f.name for f in self.fits ])
370-
basename, ext = os.path.splitext(os.path.basename(scriptfile))
371-
start = 0
372-
while True:
373-
start = start + 1
374-
newnames = [ basename + str(i) \
375-
for i in range(start, start+len(impfits)) ]
376-
anyused = [ n for n in newnames if n in usednames ]
377-
if not anyused:
378-
break
379-
# here we have correct new names
380-
# build a dictionary with name translations
381-
old2new = dict(zip(orgnames, newnames))
382-
for fit in impfits:
383-
# items in impfits were stripped, we need to insert normal copy
384-
clothed = fit.copy()
385-
clothed.name = old2new[fit.name]
386-
# take care of linked parameters:
387-
if isinstance(clothed, Fitting):
388-
for idx, par in clothed.parameters.iteritems():
389-
inistr = par.initialStr()
390-
if inistr[:1] == "=":
391-
iniwords = inistr[1:].split(':')
392-
if len(iniwords) == 1:
393-
ininame = iniwords[0]
394-
srcparidx = str(idx)
395-
else:
396-
ininame = ':'.join(iniwords[:-1])
397-
srcparidx = iniwords[-1]
398-
newlinkedname = old2new[ininame]
399-
par.setInitial("=%s:%s" % (newlinkedname, srcparidx))
400-
# finally we can put it in
401-
self.add(clothed)
402-
newfits = self.fits[len(self.fits)-len(impfits):]
403-
return [obj.organization() for obj in newfits]
404335

405336
def load(self, projfile):
406337
"""load project from projfile.

src/diffpy/pdfgui/gui/mainframe.py

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -500,10 +500,6 @@ def __setupMainMenu(self):
500500
"&Stop Fitting", "", wx.ITEM_NORMAL)
501501
self.fitsMenu.Append(self.stopFitItem)
502502
self.fitsMenu.AppendSeparator()
503-
self.impFitItem = wx.MenuItem(self.fitsMenu, wx12.NewIdRef(),
504-
"&Import pdffit2 Script", "", wx.ITEM_NORMAL)
505-
self.fitsMenu.Append(self.impFitItem)
506-
self.fitsMenu.AppendSeparator()
507503
self.expResItem = wx.MenuItem(self.fitsMenu, self.exportResId,
508504
"Export Resu&lts File", "", wx.ITEM_NORMAL)
509505
self.fitsMenu.Append(self.expResItem)
@@ -716,7 +712,6 @@ def __menuBindings(self):
716712
self.Bind(wx.EVT_MENU, self.onRun, id=self.runFitId)
717713
self.Bind(wx.EVT_MENU, self.onStop, id=self.stopFitId)
718714
self.Bind(wx.EVT_MENU, self.onExportRes, id=self.exportResId)
719-
self.Bind(wx.EVT_MENU, self.onImportScript, self.impFitItem)
720715
self.Bind(wx.EVT_MENU, self.onRSeries, self.rseriesItem)
721716
self.Bind(wx.EVT_MENU, self.onTSeries, self.tseriesItem)
722717
self.Bind(wx.EVT_MENU, self.onDSeries, self.dseriesItem)
@@ -2259,20 +2254,6 @@ def onExportRes(self, event):
22592254
d.Destroy()
22602255
return
22612256

2262-
def onImportScript(self, event):
2263-
matchstring = "pdffit2 script files (*.py)|*.py|All Files|*"
2264-
d = wx.FileDialog(None, "Choose a file", self.workpath, "", matchstring)
2265-
if d.ShowModal() == wx.ID_OK:
2266-
fullpath = d.GetPath()
2267-
self.workpath = os.path.dirname(fullpath)
2268-
# Load this file into the control center.
2269-
organizations = self.control.importPdffit2Script(fullpath)
2270-
if organizations:
2271-
self.treeCtrlMain.ExtendProjectTree(organizations, clear=False)
2272-
self.needsSave()
2273-
d.Destroy()
2274-
return
2275-
22762257
def onRSeries(self, event):
22772258
"""Open up the r-series panel."""
22782259
self.setMode("rseries")

0 commit comments

Comments
 (0)