Changeset 4343


Ignore:
Timestamp:
Mar 5, 2020 10:48:06 AM (20 months ago)
Author:
toby
Message:

deal with exporters sharing extension in autointegration

Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/GSASIIIO.py

    r4324 r4343  
    19621962def ExportPowderList(G2frame):
    19631963    '''Returns a list of extensions supported by :func:`GSASIIIO:ExportPowder`
    1964     This is used in :meth:`GSASIIimgGUI.AutoIntFrame` only.
     1964    along with their descriptions (note that a extension may be repeated
     1965    but descriptions are unique).
     1966    This is used in :meth:`GSASIIimgGUI.AutoIntFrame` only.
    19651967   
    19661968    :param wx.Frame G2frame: the GSAS-II main data tree window
    19671969    '''
    19681970    extList = []
     1971    extLabel = []
    19691972    for obj in G2frame.exporterlist:
    19701973        if 'powder' in obj.exporttype:
     
    19721975                obj.Writer
    19731976                extList.append(obj.extension)
     1977                extLabel.append(obj.formatName)
    19741978            except AttributeError:
    19751979                pass
    1976     return extList
    1977 
    1978 def ExportPowder(G2frame,TreeName,fileroot,extension):
     1980    return extList,extLabel
     1981
     1982def ExportPowder(G2frame,TreeName,fileroot,extension,hint=''):
    19791983    '''Writes a single powder histogram using the Export routines.
    19801984    This is used in :meth:`GSASIIimgGUI.AutoIntFrame` only.
     
    19851989    :param str extension: extension for file to be written (start with '.'). Must
    19861990      match a powder export routine that has a Writer object.
     1991    :param str hint: a string that must match the export's format
    19871992    '''
    19881993    filename = os.path.abspath(os.path.splitext(fileroot)[0]+extension)
    19891994    for obj in G2frame.exporterlist:
    19901995        if obj.extension == extension and 'powder' in obj.exporttype:
     1996            if hint and hint not in obj.formatName: continue
    19911997            obj.currentExportType = 'powder'
    19921998            obj.InitExport(None)
  • trunk/GSASIIautoInt.py

    r4335 r4343  
    182182
    183183        def TestInput(*args,**kwargs):
    184             'Determine if the start button should be enabled'
     184            '''Determine if the start button should be enabled and
     185            ask for the exporter type with ambiguous extensions
     186            '''
     187            for dfmt,obj in self.fmtlist.items():
     188                fmt = dfmt[1:]
     189                if not self.params['outsel'][fmt]: continue
     190                if fmt in self.multipleFmtChoices: continue
     191                if type(obj) is not list: continue # only one exporter for this
     192                choices = []
     193                for e in obj:
     194                    choices.append(e.formatName)
     195                if len(choices) == 0:
     196                    print('Error: why 0 choices in TestInput?')
     197                    continue
     198                if len(choices) == 1:
     199                    print('Error: why 1 choice in TestInput?')
     200                    self.multipleFmtChoices[fmt] = obj[0].formatName
     201                    continue
     202                # select the format here
     203                dlg = G2G.G2SingleChoiceDialog(self,
     204                        'There is more than one format with a '+
     205                        '.{} output. Choose the one to use'.format(fmt),
     206                        'Choose output format',choices)
     207                dlg.clb.SetSelection(0)  # force a selection
     208                if dlg.ShowModal() == wx.ID_OK and dlg.GetSelection() >= 0:
     209                    self.multipleFmtChoices[fmt] = choices[dlg.GetSelection()]
     210                dlg.Destroy()
     211               
    185212            writingSomething = False
    186213            writingPDF = False
     
    426453        self.params['outdir'] = os.getcwd()
    427454        self.PDFformats = ('I(Q)', 'S(Q)', 'F(Q)', 'G(r)', 'PDFgui')
     455        self.multipleFmtChoices = {}
    428456        #GSASIIpath.IPyBreak_base()
    429457       
     
    492520        sizer = wx.BoxSizer(wx.HORIZONTAL)
    493521        sizer.Add(wx.StaticText(mnpnl, wx.ID_ANY,'Select format(s):'))
    494         for dfmt in self.fmtlist:
     522        for dfmt in sorted(self.fmtlist):
    495523            sizer.Add((6,2)) # add a bit of extra space
    496524            fmt = dfmt[1:]
     
    758786            PDFformats = self.PDFformats
    759787            fmtlist = self.fmtlist
    760             outputModes = (outputSelect,PDFformats,fmtlist,outdir)
     788            outputModes = (outputSelect,PDFformats,fmtlist,outdir,
     789                               self.multipleFmtChoices)
    761790            if PDFobj:
    762791                PDFdict = PDFobj.data
     
    786815    :param tuple outputModes:
    787816    '''
    788     GSASIIpath.IPyBreak()
    789817    (TableMode,ComputePDF,SeparateDir,optPDF) = calcModes
    790     (outputSelect,PDFformats,fmtlist,outdir) = outputModes           
     818    (outputSelect,PDFformats,fmtlist,outdir,multipleFmtChoices) = outputModes
    791819    gpxout = G2sc.G2Project(filename=os.path.splitext(newImage)[0]+'.gpx')
    792820    print('creating',gpxout.filename)
     
    807835            fmt = dfmt[1:]
    808836            if not outputSelect[fmt]: continue
     837            hint = ''
     838            if fmt in multipleFmtChoices:
     839                hint = multipleFmtChoices[fmt]
    809840            if SeparateDir:
    810841                savedir = os.path.join(outdir,fmt)
     
    817848                try:
    818849                    fil = os.path.join(savedir,fname)
    819                     print('Wrote',h.Export(fil,dfmt))
     850                    print('Wrote',h.Export(fil,dfmt,hint))
    820851                except Exception as msg:
    821852                    print('Failed to write {} as {}. Error msg\n{}'
  • trunk/GSASIIimgGUI.py

    r4338 r4343  
    29402940        sizer = wx.BoxSizer(wx.HORIZONTAL)
    29412941        sizer.Add(wx.StaticText(mnpnl, wx.ID_ANY,'Select format(s):'))
    2942         for dfmt in self.fmtlist:
     2942        # format choice selection
     2943        usedfmt = []
     2944        self.multipleFmtChoices = {}
     2945        for dfmt in sorted(self.fmtlist[0]):
    29432946            sizer.Add((6,2)) # add a bit of extra space
    29442947            fmt = dfmt[1:]
    29452948            self.params[fmt] = False
    2946             btn = G2G.G2CheckBox(mnpnl,dfmt,self.params,fmt)
    2947             sizer.Add(btn)
     2949            if fmt in usedfmt: # is extension used more than once
     2950                self.multipleFmtChoices[fmt] = None
     2951            else:
     2952                usedfmt.append(fmt)
     2953                btn = G2G.G2CheckBox(mnpnl,dfmt,self.params,fmt,
     2954                                     OnChange=self.TestInput)
     2955                sizer.Add(btn)
    29482956        lblsizr.Add(sizer)
    29492957        sizer = wx.BoxSizer(wx.HORIZONTAL)
     
    30103018        self.Show()
    30113019        showPDFctrls(None)
     3020       
     3021    def TestInput(self,event):
     3022        for fmt in self.multipleFmtChoices:
     3023            if not self.params[fmt]: continue
     3024            if self.multipleFmtChoices[fmt]: continue
     3025            choices = []
     3026            for f,l in zip(self.fmtlist[0],self.fmtlist[1]):
     3027                if f[1:] == fmt: choices.append(l)
     3028            if len(choices) < 2:
     3029                print('Error: why no choices in TestInput?')
     3030                return
     3031            # select the format here
     3032            dlg = G2G.G2SingleChoiceDialog(self,
     3033                        'There is more than one format with a '+
     3034                        '.{} output. Choose the one to use'.format(fmt),
     3035                        'Choose output format',choices)
     3036            dlg.clb.SetSelection(0)  # force a selection
     3037            if dlg.ShowModal() == wx.ID_OK and dlg.GetSelection() >= 0:
     3038                self.multipleFmtChoices[fmt] = choices[dlg.GetSelection()]
     3039                dlg.Destroy()
     3040            else:
     3041                dlg.Destroy()
     3042                return
    30123043
    30133044    def checkPDFprm(self,ShowContents=False):
     
    31963227            fileroot += namenum
    31973228            # loop over selected formats
    3198             for dfmt in self.fmtlist:
    3199                 if not self.params[dfmt[1:]]: continue
     3229            for fmt in self.params:
     3230                if not self.params[fmt]: continue
     3231                if '.'+fmt not in self.fmtlist[0]: continue
    32003232                if self.params['SeparateDir']:
    3201                     subdir = dfmt[1:]
     3233                    subdir = fmt
    32023234                else:
    32033235                    subdir = ''
     3236                hint = ''
     3237                if self.multipleFmtChoices.get(fmt):
     3238                    hint = self.multipleFmtChoices.get(fmt)
    32043239                fil = os.path.join(self.params['outdir'],subdir,fileroot)
    3205                 G2IO.ExportPowder(G2frame,treename,fil+'.x',dfmt) # dummy extension (.x) is replaced before write)
     3240                G2IO.ExportPowder(G2frame,treename,fil+'.x','.'+fmt,hint=hint) # dummy extension (.x) is replaced before write)
    32063241               
    32073242    def EnableButtons(self,flag):
     
    32753310        # make sure all output directories exist
    32763311        if self.params['SeparateDir']:
    3277             for dfmt in self.fmtlist:
     3312            for dfmt in self.fmtlist[0]:
    32783313                if not self.params[dfmt[1:]]: continue
    32793314                dir = os.path.join(self.params['outdir'],dfmt[1:])
Note: See TracChangeset for help on using the changeset viewer.