Changeset 1080 for trunk/G2cif.py


Ignore:
Timestamp:
Oct 3, 2013 9:29:47 PM (8 years ago)
Author:
toby
Message:

revise export menu; add multiple selection to G2gd.ItemSelector?

File:
1 copied

Legend:

Unmodified
Added
Removed
  • trunk/G2cif.py

    r1077 r1080  
    11#!/usr/bin/env python
    22# -*- coding: utf-8 -*-
    3 #G2cif
    43########### SVN repository information ###################
    54# $Date$
     
    5150        super(self.__class__,self).__init__( # fancy way to say <parentclass>.__init__
    5251            G2frame=G2frame,
    53             formatName = 'full CIF',
     52            formatName = 'Full CIF',
    5453            extension='.cif',
    5554            longFormatName = 'Export project as CIF'
    5655            )
     56        self.exporttype = ['project']
    5757        self.author = ''
    5858        self.mode = 'full'
    59         self.exporttype = 'project'
    60 
    61     def export(self):
     59
     60    def Exporter(self,event=None):
    6261        '''Export a CIF. Export can be full or simple (as set by self.mode).
    6362        "simple" skips data, distances & angles, etc. and can only include
    6463        a single phase while "full" is intended for for publication submission.
    6564        '''
    66    
    67 # ===== define functions for export method =======================================
     65
     66#***** define functions for export method =======================================
    6867        def openCIF(filnam):
    6968            'opens the output file'
     
    12591258            self.cifdefs.SetTitle('Edit CIF settings')
    12601259            vbox = wx.BoxSizer(wx.VERTICAL)
     1260            vbox.Add(wx.StaticText(self.cifdefs, wx.ID_ANY,'Creating file '+str(self.filename)))
    12611261            but = wx.Button(self.cifdefs, wx.ID_ANY,'Edit CIF Author')
    12621262            but.Bind(wx.EVT_BUTTON,EditAuthor)
     
    12871287                    0,wx.EXPAND|wx.ALIGN_LEFT|wx.ALL)
    12881288                cpnl.SetSizer(cbox)
    1289                 but = wx.Button(cpnl, wx.ID_ANY,'Edit distance/angle ranges')
    1290                 #cbox.Add(but,0,wx.ALIGN_CENTER,3)
     1289                if phasedict['General']['Type'] == 'nuclear': 
     1290                    but = wx.Button(cpnl, wx.ID_ANY,'Edit distance/angle ranges')
     1291                    cbox.Add(but,0,wx.ALIGN_LEFT,0)
     1292                    cbox.Add((-1,2))
     1293                    but.phasedict = self.Phases[phasenam]  # set a pointer to current phase info
     1294                    but.Bind(wx.EVT_BUTTON,EditRanges)     # phase bond/angle ranges
     1295                    but = wx.Button(cpnl, wx.ID_ANY,'Set distance/angle publication flags')
     1296                    but.phase = phasenam  # set a pointer to current phase info     
     1297                    but.Bind(wx.EVT_BUTTON,SelectDisAglFlags)     # phase bond/angle ranges
     1298                    cbox.Add(but,0,wx.ALIGN_LEFT,0)
    12911299                cbox.Add((-1,2))
    1292                 cbox.Add(but,0,wx.ALIGN_LEFT,0)
    1293                 but.phasedict = self.Phases[phasenam]  # set a pointer to current phase info     
    1294                 but.Bind(wx.EVT_BUTTON,EditRanges)     # phase bond/angle ranges
    1295                 but = wx.Button(cpnl, wx.ID_ANY,'Set distance/angle publication flags')
    1296                 but.phase = phasenam  # set a pointer to current phase info     
    1297                 but.Bind(wx.EVT_BUTTON,SelectDisAglFlags)     # phase bond/angle ranges
    1298                 cbox.Add((-1,2))
    1299                 cbox.Add(but,0,wx.ALIGN_LEFT,0)
    13001300            for i in sorted(self.powderDict.keys()):
    13011301                G2gd.HorizontalLine(cbox,cpnl)         
     
    15081508            dlg.ShowModal()
    15091509           
    1510 # ===== end of functions for export method =======================================
     1510#***** end of functions for export method =======================================
    15111511#=================================================================================
    15121512
     
    15161516        # create a dict with refined values and their uncertainties
    15171517        self.loadParmDict()
     1518        if self.SetupExport(event,
     1519                            AskFile=(self.mode=='simple')
     1520                            ): return # set export parameters
    15181521
    15191522        # Someday: get restraint & constraint info
     
    15251528
    15261529        self.CIFdate = dt.datetime.strftime(dt.datetime.now(),"%Y-%m-%dT%H:%M")
    1527         # index powder and single crystal histograms
    1528         self.powderDict = {}
    1529         self.xtalDict = {}
    1530         for hist in self.Histograms:
    1531             i = self.Histograms[hist]['hId']
    1532             if hist.startswith("PWDR"):
    1533                 self.powderDict[i] = hist
    1534             elif hist.startswith("HKLF"):
    1535                 self.xtalDict[i] = hist
    15361530        # is there anything to export?
    15371531        if len(self.Phases) == len(self.powderDict) == len(self.xtalDict) == 0:
    15381532           self.G2frame.ErrorDialog(
    15391533               'Empty project',
    1540                'Project does not contain interconnected data & phase(s)')
     1534               'Project does not contain any data or phases. Are they interconnected?')
    15411535           return
    15421536        # get the project file name
     
    16361630                    instnam = histblk["Instrument Parameters"][0]['InstrName']
    16371631                    break # ignore all but 1st data histogram
    1638         if self.quickmode:
    1639             fil = self.askSaveFile()
    1640         else:
    1641             fil = self.defSaveFile()
    1642         if not fil: return
    16431632        if not self.quickmode: # give the user a chance to edit all defaults
    16441633            self.cifdefs = wx.Dialog(
     
    16541643        # Start writing the CIF - single block
    16551644        #======================================================================
    1656         print('Writing CIF output to file '+fil+"...")
    1657         openCIF(fil)
    1658         if oneblock:
     1645        print('Writing CIF output to file '+str(self.filename)+"...")
     1646        openCIF(self.filename)
     1647        if self.currentExportType == 'single' or self.currentExportType == 'powder':
     1648            hist = self.histnam
     1649            print hist
     1650            self.CIFname = self.histnam[5:40].replace(' ','')
     1651            print 'hist',self.CIFname
     1652            WriteCIFitem('data_'+self.CIFname)
     1653            if hist.startswith("PWDR"):
     1654                WritePowderData(hist)
     1655            elif hist.startswith("HKLF"):
     1656                WriteSingleXtalData(hist)
     1657            else:
     1658                print "should not happen"
     1659        elif oneblock:
    16591660            WriteCIFitem('data_'+self.CIFname)
    16601661            if phasenam is None: # if not already selected, select the first phase (should be one)
     
    17451746                    instnam = histblk["Sample Parameters"]['InstrName']
    17461747                    instnam = instnam.replace(' ','')
    1747                     i = histblk['hId']
     1748                    j = histblk['hId']
    17481749                    datablockidDict[hist] = (str(self.CIFdate) + "|" + str(self.CIFname) + "|" +
    17491750                                             str(self.shortauthorname) + "|" +
    1750                                              instnam + "_hist_"+str(i))
     1751                                             instnam + "_hist_"+str(j))
    17511752                    WriteCIFitem(loopprefix,datablockidDict[hist])
    17521753                for i in sorted(self.xtalDict.keys()):
     
    18331834        # end of CIF export
    18341835
    1835 class ExportSimpleCIF(ExportCIF):
     1836class ExportPhaseCIF(ExportCIF):
    18361837    '''Used to create a simple CIF of at most one phase. Uses exact same code as
    1837     :class:`ExportCIF` except that `self.mode` is set to simple.
     1838    :class:`ExportCIF` except that `self.mode` is set to "simple". Shows up in menu as
     1839    Quick CIF
    18381840
    18391841    :param wx.Frame G2frame: reference to main GSAS-II frame
     
    18421844        G2IO.ExportBaseclass.__init__(self,
    18431845            G2frame=G2frame,
    1844             formatName = 'full CIF',
     1846            formatName = 'Quick CIF',
    18451847            extension='.cif',
    1846             longFormatName = 'Export project as CIF'
     1848            longFormatName = 'Export one phase in CIF'
    18471849            )
     1850        self.exporttype = ['phase']
     1851        # CIF-specific items
    18481852        self.author = ''
    18491853        self.mode = 'simple'
    1850         self.exporttype = 'phase'
     1854
     1855class ExportDataCIF(ExportCIF):
     1856    '''Used to create a simple CIF containing diffraction data only. Uses exact same code as
     1857    :class:`ExportCIF` except that `self.mode` is set to "simple" and `self.currentExportType`
     1858    is set to "single" or "powder" in `self.SetupExport`. Shows up in menus as Data-only CIF.
     1859
     1860    :param wx.Frame G2frame: reference to main GSAS-II frame
     1861    '''
     1862    def __init__(self,G2frame):
     1863        G2IO.ExportBaseclass.__init__(self,
     1864            G2frame=G2frame,
     1865            formatName = 'Data-only CIF',
     1866            extension='.cif',
     1867            longFormatName = 'Export data as CIF'
     1868            )
     1869        self.exporttype = ['single','powder']
     1870        # CIF-specific items
     1871        self.author = ''
     1872        self.mode = 'simple'
    18511873
    18521874#===============================================================================
Note: See TracChangeset for help on using the changeset viewer.