Changeset 1413


Ignore:
Timestamp:
Jul 6, 2014 12:53:47 PM (7 years ago)
Author:
toby
Message:

Add config support; default expressions

Location:
trunk
Files:
1 added
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/GSASII.py

    r1399 r1413  
    5656    install_with_easyinstall('PyOpenGl')
    5757    print('*******************************************************')         
    58     print('OpenGL has been installed. Please restart GSAS-II')
     58    print('OpenGL has been installed. Restarting GSAS-II')
    5959    print('*******************************************************')         
     60    loc = os.path.dirname(__file__)
     61    subprocess.Popen([sys.executable,os.path.join(loc,'GSASII.py')])
    6062    sys.exit()
    6163   
  • trunk/GSASIIElem.py

    r1392 r1413  
    205205        xsec = open(filename,'Ur')
    206206    except:
    207         print '**** ERROR - File Xsect.dat not found in directory %s' % sys.path[0]
     207        print '**** ERROR - File Xsect.dat not found in directory %s' % os.path.split(filename)[0]
    208208        sys.exit()
    209209    S = '1'
  • trunk/GSASIIexprGUI.py

    r1396 r1413  
    1919the user is asked to assign parameters from the dictionary to each variable.
    2020
     21Default expressions are read from file DefaultExpressions.txt using
     22:func:`GSASIIpath.LoadConfigFile`.
     23
    2124'''
    2225import re
    2326import sys
    2427import wx
     28import os.path
    2529import wx.lib.scrolledpanel as wxscroll
    2630import numpy as np
     31import GSASIIpath
     32GSASIIpath.SetVersionNumber("$Revision$")
    2733import GSASIIgrid as G2gd
    2834import GSASIIpy3 as G2py3
     
    6066    return parmLists
    6167
     68#==========================================================================
     69defaultExpressions = None
     70def LoadDefaultExpressions():
     71    '''Read a configuration file with default expressions from all files named
     72    DefaultExpressions.txt found in the path. Duplicates are removed and
     73    expressions are sorted alphabetically
     74    '''
     75    global defaultExpressions
     76    if defaultExpressions is not None: return # run this routine only once
     77    defaultExpressions = sorted(list(set(GSASIIpath.LoadConfigFile('DefaultExpressions.txt'))))
     78   
    6279#==========================================================================
    6380class ExpressionDialog(wx.Dialog):
     
    148165        self.usedVars = usedVars
    149166        'variable names that have been used and should not be reused by default'
     167        defSize = (620,340) # seems like a good size
     168        'Starting size for dialog'
    150169
    151170        # process dictionary of values and create an index
     
    164183        self.timer = wx.Timer()
    165184        self.timer.Bind(wx.EVT_TIMER,self.OnValidate)
    166 
     185        LoadDefaultExpressions()
    167186        style=wx.DEFAULT_DIALOG_STYLE | wx.RESIZE_BORDER
    168         wx.Dialog.__init__(self, parent, wx.ID_ANY, wintitle, style=style)
     187        wx.Dialog.__init__(self, parent, wx.ID_ANY, wintitle, style=style, size=defSize)
    169188        self.mainsizer = wx.BoxSizer(wx.VERTICAL)
    170189        label = wx.StaticText(self,  wx.ID_ANY, header)
     
    194213            self.exsizer.Add(label, 0, wx.ALL|wx.EXPAND|wx.ALIGN_CENTER_VERTICAL, 0)
    195214
    196         self.exCtrl = wx.TextCtrl(self,  wx.ID_ANY, size=(150,-1),style=wx.TE_PROCESS_ENTER)
     215        #self.exCtrl = wx.TextCtrl(self,  wx.ID_ANY, size=(150,-1),style=wx.TE_PROCESS_ENTER)
     216        self.exCtrl = wx.ComboBox(self, wx.ID_ANY, "", (90, 50), (160, -1),
     217                                  defaultExpressions,
     218                                  wx.CB_DROPDOWN| wx.TE_PROCESS_ENTER
     219                         )
    197220        self.exCtrl.Bind(wx.EVT_CHAR, self.OnChar)
     221        self.exCtrl.Bind(wx.EVT_COMBOBOX, self.OnValidate)
    198222        self.exCtrl.Bind(wx.EVT_TEXT_ENTER, self.OnValidate)
    199223        self.exsizer.Add(self.exCtrl, 1, wx.ALL|wx.EXPAND|wx.ALIGN_CENTER_VERTICAL, 0)
     
    253277        self.exCtrl.SetValue(self.expr)
    254278        self.OnValidate(None)
    255         self.SetMinSize((620,300)) # seems like a good size
     279        self.SetMinSize(defSize)
    256280        #self.errbox.SetAutoLayout(1)
    257281        #self.errbox.SetupScrolling()
     
    288312        '''
    289313        self.Layout()
    290         self.mainsizer.Fit(self)
     314        #self.mainsizer.Fit(self)
    291315        self.SendSizeEvent() # force repaint
    292316        if self.ShowModal() == wx.ID_OK:
     
    483507        self.varbox.Refresh()
    484508        self.Layout()
    485         self.mainsizer.Fit(self)
     509        #self.mainsizer.Fit(self)
    486510        self.SendSizeEvent() # force repaint
    487511        return
  • trunk/GSASIIpath.py

    r1355 r1413  
    8383    return version
    8484
     85def LoadConfigFile(filename):
     86    '''Read a GSAS-II configuration file.
     87    Comments (starting with "%") are removed, as are empty lines
     88   
     89    :param str filename: base file name (such as 'file.dat'). Files with this name
     90      are located from the path and the contents of each are concatenated.
     91    :returns: a list containing each non-empty (after removal of comments) line
     92      found in every matching config file.
     93    '''
     94    info = []
     95    for path in sys.path:
     96        fil = os.path.join(path,filename)
     97        if not os.path.exists(fil): continue
     98        try:
     99            i = 0
     100            fp = open(fil,'r')
     101            for line in fp:
     102                expr = line.split('#')[0].strip()
     103                if expr:
     104                    info.append(expr)
     105                    i += 1
     106            print(str(i)+' lines read from config file '+fil)
     107        finally:
     108            fp.close()
     109    return info
     110
     111
    85112# routines to interface with subversion
    86113def whichsvn():
Note: See TracChangeset for help on using the changeset viewer.