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

Add config support; default expressions

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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
Note: See TracChangeset for help on using the changeset viewer.