Changeset 5127


Ignore:
Timestamp:
Jan 7, 2022 3:17:14 PM (21 months ago)
Author:
toby
Message:

misc CIF fixes (init block name; stop save of default template file name)

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/GSASIIIO.py

    r5099 r5127  
    15541554        self.SeqRefdata = None
    15551555        self.SeqRefhist = None
     1556        self.DelayOpen = False
    15561557        if self.G2frame.GPXtree.IsEmpty(): return # nothing to do
    15571558        histType = None       
     
    17701771            return
    17711772        if self.fp is None:
    1772             raise Exception('Attempt to CloseFile without use of OpenFile')
     1773            if GSASIIpath.GetConfigValue('debug'):
     1774                raise Exception('Attempt to CloseFile without use of OpenFile')
     1775            else:
     1776                print('Attempt to CloseFile without use of OpenFile')
     1777                return
    17731778        if self.fp == sys.stdout: return # debug mode
    17741779        if fp is None:
  • trunk/exports/G2export_CIF.py

    r5115 r5127  
    45194519
    45204520        WriteCIFitem(self.fp, '#--' + 15*'eof--' + '#')
    4521         print("...export completed")
    4522         print('file '+self.fullpath)
     4521        print("...export completed. File created:",self.fullpath)
    45234522        # end of CIF export
    45244523
     
    45414540        self.Controls = Controls
    45424541        self.InitExport(event)
     4542        self.CIFname = ''
    45434543        # load all of the tree into a set of dicts
    45444544        self.loadTree()
     
    51715171                     defaultname='', cifKey="CIF_template"):
    51725172        def _onResetTemplate(event):
    5173             self.CIF = None
    5174             self.dict[self.cifKey] = resetTemplate
     5173            self.CIF_template = resetTemplate
     5174            self.dict[self.cifKey] = None
    51755175            wx.CallAfter(self.repaint)
    51765176        wx.BoxSizer.__init__(self,wx.VERTICAL)
     
    52135213                localTemplate = fil
    52145214                break
    5215 
    5216         if G2dict.get(self.cifKey) == localTemplate and localTemplate:
    5217             self.CIF = localTemplate
    5218             CIFtxt = "Customized template: "+os.path.split(self.CIF)[1]
    5219         elif G2dict.get(self.cifKey) == resetTemplate and resetTemplate:
    5220             self.CIF = resetTemplate
    5221             CIFtxt = "Default template: "+os.path.split(self.CIF)[1]
    5222         elif not G2dict.get(self.cifKey): # empty or None
    5223             if localTemplate:
    5224                 G2dict[self.cifKey] = self.CIF = localTemplate
    5225                 CIFtxt = "Customized template: "+os.path.split(self.CIF)[1]
    5226             elif resetTemplate:
    5227                 G2dict[self.cifKey] = self.CIF = resetTemplate
    5228                 CIFtxt = "Default template: "+os.path.split(self.CIF)[1]
     5215        repeat = True
     5216        while repeat:
     5217            repeat = False
     5218            if G2dict.get(self.cifKey) == localTemplate and localTemplate:
     5219                self.CIF_template = localTemplate
     5220                CIFtxt = "Customized template: "+os.path.split(self.CIF_template)[1]
     5221            elif resetTemplate and G2dict.get(self.cifKey) == resetTemplate:
     5222                self.CIF_template = resetTemplate
     5223                CIFtxt = "Default template: "+os.path.split(self.CIF_template)[1]
     5224            elif not G2dict.get(self.cifKey): # empty or None
     5225                if localTemplate:
     5226                    G2dict[self.cifKey] = self.CIF_template = localTemplate
     5227                    CIFtxt = "Customized template: "+os.path.split(self.CIF_template)[1]
     5228                elif resetTemplate:
     5229                    G2dict[self.cifKey] = None
     5230                    self.CIF_template = resetTemplate
     5231                    CIFtxt = "Default template: "+os.path.split(self.CIF_template)[1]
     5232                else:
     5233                    G2dict[self.cifKey] = self.CIF_template = None
     5234                    CIFtxt = "none (Template not found!)"
     5235            elif type(G2dict[self.cifKey]) is not list and type(
     5236                    G2dict[self.cifKey]) is not tuple:
     5237                if not os.path.exists(G2dict[self.cifKey]):
     5238                    print("\nWarning: previous template file:\n  ",
     5239                              os.path.abspath(G2dict[self.cifKey]),
     5240                              '\nwas not found! Was this file moved or deleted? Resetting to default.')
     5241                    self.CIF_template = None
     5242                    CIFtxt = "none! (file not found)"
     5243                    if resetTemplate:
     5244                        G2dict[self.cifKey] = None
     5245                        repeat = True
     5246                        continue
     5247                else:
     5248                    CIFtxt = "Edited template: "+os.path.split(G2dict[self.cifKey])[1]
     5249                    if GSASIIpath.GetConfigValue('debug'):
     5250                        print('Template file found',os.path.abspath(G2dict[self.cifKey]))
    52295251            else:
    5230                 G2dict[self.cifKey] = self.CIF = None
    5231                 CIFtxt = "none (Template not found!)"
    5232         elif type(G2dict[self.cifKey]) is not list and type(
    5233                 G2dict[self.cifKey]) is not tuple:
    5234             if not os.path.exists(G2dict[self.cifKey]):
    5235                 print("Warning: saved template file,",
    5236                           os.path.abspath(G2dict[self.cifKey]),
    5237                           ' not found!\nWas this file moved or deleted?')
    5238                 self.CIF = None
    5239                 CIFtxt = "none! (file not found)"
    5240                 if resetTemplate:
    5241                     G2dict[self.cifKey] = None
    5242                     wx.CallLater(100,self.repaint)
    5243                     return
    5244             else:
    5245                 CIFtxt = "Edited template: "+os.path.split(G2dict[self.cifKey])[1]
    5246                 if GSASIIpath.GetConfigValue('debug'):
    5247                     print('Template file found',os.path.abspath(G2dict[self.cifKey]))
    5248         else:
    5249             self.CIF = G2dict[self.cifKey]
    5250             CIFtxt = "Customized template is reloaded"
     5252                self.CIF_template = G2dict[self.cifKey]
     5253                CIFtxt = "Customized template is reloaded"
    52515254        # show template source
    52525255        self.Add(wx.StaticText(panel,wx.ID_ANY,CIFtxt))
     
    52585261        but = wx.Button(panel,wx.ID_ANY,"Edit Template")
    52595262        but.Bind(wx.EVT_BUTTON,self._onEditTemplateContents)
    5260         if self.CIF is None: but.Disable() # nothing to edit!
     5263        if self.CIF_template is None: but.Disable() # nothing to edit!
    52615264        if resetTemplate and not CIFtxt.startswith('Default'):
    52625265            hbox.Add(but,0,0,2)
     
    52895292    def _onEditTemplateContents(self,event):
    52905293        'Called to edit the contents of a CIF template'
    5291         if type(self.CIF) is list or  type(self.CIF) is tuple:
    5292             dblk,loopstructure = copy.deepcopy(self.CIF) # don't modify original
     5294        if type(self.CIF_template) is list or  type(self.CIF_template) is tuple:
     5295            dblk,loopstructure = copy.deepcopy(self.CIF_template) # don't modify original
    52935296        else:
    5294             cf = G2obj.ReadCIF(self.CIF)
     5297            cf = G2obj.ReadCIF(self.CIF_template)
    52955298            dblk,loopstructure = CIF2dict(cf)
    52965299        dlg = EditCIFtemplate(self.cifdefs,dblk,loopstructure,self.defaultname)
Note: See TracChangeset for help on using the changeset viewer.