Changeset 1202


Ignore:
Timestamp:
Jan 20, 2014 12:24:54 PM (11 years ago)
Author:
toby
Message:

further refinements on ValidatedTxtCtrl?; update G2VarObj to allow wildcard variables (*::dAx:1 or 1::dAx:*)

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • TabularUnified trunk/GSASIIgrid.py

    r1201 r1202  
    224224      use of a single '?' or '.' character as valid input.
    225225
     226    :param dict OnLeaveArgs: a dict with keyword args that are passed to
     227      the :attr:`OnLeave` function. Defaults to ``{}``
     228
    226229    :param (other): other optional keyword parameters for the
    227230      wx.TextCtrl widget such as Size or Style may be specified.
     
    230233    def __init__(self,parent,loc,key,nDig=None,notBlank=True,min=None,max=None,
    231234                 OKcontrol=None,OnLeave=None,typeHint=None,
    232                  CIFinput=False, **kw):
     235                 CIFinput=False, OnLeaveArgs={}, **kw):
    233236        # save passed values needed outside __init__
    234237        self.result = loc
     
    237240        self.OKcontrol=OKcontrol
    238241        self.OnLeave = OnLeave
     242        self.OnLeaveArgs = OnLeaveArgs
    239243        self.CIFinput = CIFinput
    240244        self.type = str
     
    295299        # When the mouse is moved away or the widget loses focus
    296300        # display the last saved value, if an expression
    297 #        self.Bind(wx.EVT_LEAVE_WINDOW, self._onLoseFocus)
     301        self.Bind(wx.EVT_LEAVE_WINDOW, self._onLeaveWindow)
    298302        self.Bind(wx.EVT_TEXT_ENTER, self._onLoseFocus)
    299303        self.Bind(wx.EVT_KILL_FOCUS, self._onLoseFocus)
     
    396400        if self.OnLeave: self.OnLeave(invalid=self.invalid,
    397401                                      value=self.result[self.key],
    398                                       tc=self)
    399            
     402                                      tc=self,
     403                                      **self.OnLeaveArgs)
     404
     405    def _onLeaveWindow(self,event):
     406        if self.evaluated: self.EvaluateExpression()
     407
    400408    def EvaluateExpression(self):
    401409        '''Show the computed value when an expression is entered to the TextCtrl
  • TabularUnified trunk/GSASIIobj.py

    r1192 r1202  
    12511251    if key is None:
    12521252        return ""
     1253    elif key == "*":
     1254        return "*"
    12531255    else:
    12541256        return dic.get(key,'?')
     
    12661268      object. If a string, it must be of form "p:h:var" or "p:h:var:a", where
    12671269
    1268      * p is the phase number (which may be left blank);
    1269      * h is the histogram number (which may be left blank);
     1270     * p is the phase number (which may be left blank or may be '*' to indicate all phases);
     1271     * h is the histogram number (which may be left blank or may be '*' to indicate all histograms);
    12701272     * a is the atom number (which may be left blank in which case the third colon is omitted).
     1273       The atom number can be specified as '*' if a phase number is specified (not as '*')
    12711274
    12721275      Alternately a single tuple of form (Phase,Histogram,VarName,AtomID) can be used, where
    1273       Phase, Histogram, and AtomID are None or are ranId values and VarName is a string.     
     1276      Phase, Histogram, and AtomID are None or are ranId values (or one can be '*')
     1277      and VarName is a string. Note that if Phase is '*' then the AtomID is an atom number.
    12741278
    12751279    If four positional arguments are supplied, they are:
    12761280
    1277     :param str/int phasenum: The number for the phase
    1278     :param str/int histnum: The number for the histogram
     1281    :param str/int phasenum: The number for the phase (or None or '*')
     1282    :param str/int histnum: The number for the histogram (or None or '*')
    12791283    :param str varname: a single value can be used to create a :class:`G2VarObj`
    1280     :param str/int atomnum: The number for the atom
     1284    :param str/int atomnum: The number for the atom (or None or '*')
    12811285   
    12821286    '''
     
    12941298        elif len(args) == 1 and ':' in args[0]:           
    12951299            lst = args[0].split(':')
    1296             self.phase = PhaseIdLookup.get(lst[0],[None,None])[1]
    1297             self.histogram = HistIdLookup.get(lst[1],[None,None])[1]
     1300            if lst[0] == '*':
     1301                self.phase = '*'
     1302                if len(lst) > 3:
     1303                    self.atom = lst[3]
     1304            else:
     1305                self.phase = PhaseIdLookup.get(lst[0],[None,None])[1]
     1306                if len(lst) > 3:
     1307                    if lst[3] == '*':
     1308                        self.atom = '*'
     1309                    else:
     1310                        self.atom = AtomIdLookup[lst[0]].get(lst[3],[None,None])[1]
     1311
     1312            if lst[1] == '*':
     1313                self.histogram = '*'
     1314            else:
     1315                self.histogram = HistIdLookup.get(lst[1],[None,None])[1]
    12981316            self.name = lst[2]
    1299             if len(lst) > 3:
    1300                 self.atom = AtomIdLookup[lst[0]].get(lst[3],[None,None])[1]
    13011317        elif len(args) == 4:
    1302             self.phase = PhaseIdLookup.get(str(args[0]),[None,None])[1]
    1303             self.histogram = HistIdLookup.get(str(args[1]),[None,None])[1]
     1318            if args[0] == '*':
     1319                self.phase = '*'
     1320                self.atom = args[3]
     1321            else:
     1322                self.phase = PhaseIdLookup.get(str(args[0]),[None,None])[1]
     1323                if args[3] == '*':
     1324                    self.atom = '*'
     1325                elif args[0] is not None:
     1326                    self.atom = AtomIdLookup[args[0]].get(str(args[3]),[None,None])[1]
     1327            if args[1] == '*':
     1328                self.histogram = '*'
     1329            else:
     1330                self.histogram = HistIdLookup.get(str(args[1]),[None,None])[1]
    13041331            self.name = args[2]
    1305             self.atom = AtomIdLookup[args[0]].get(str(args[3]),[None,None])[1]
    13061332        else:
    13071333            raise Exception,"Incorrectly called GSAS-II parameter name"
     
    13181344        :returns: the variable name as a str
    13191345        '''
    1320         ph = _lookup(PhaseRanIdLookup,self.phase)
    1321         hist = _lookup(HistRanIdLookup,self.histogram)
    1322         s = (ph + ":" + hist + ":" +
    1323              str(self.name))
    1324         if self.atom:
    1325             if ph in AtomRanIdLookup:
    1326                 s += ":" + AtomRanIdLookup[ph].get(self.atom,'?')
    1327             else:
    1328                 s += ":?"
     1346        a = ""
     1347        if self.phase == "*":
     1348            ph = "*"
     1349            if self.atom:
     1350                a = ":" + str(self.atom)
     1351        else:
     1352            ph = _lookup(PhaseRanIdLookup,self.phase)
     1353            if self.atom == '*':
     1354                a = ':*'
     1355            elif self.atom:
     1356                if ph in AtomRanIdLookup:
     1357                    a = ":" + AtomRanIdLookup[ph].get(self.atom,'?')
     1358                else:
     1359                    a = ":?"
     1360        if self.histogram == "*":
     1361            hist = "*"
     1362        else:
     1363            hist = _lookup(HistRanIdLookup,self.histogram)
     1364        s = (ph + ":" + hist + ":" + str(self.name)) + a
    13291365        return s
    13301366   
     
    13331369        '''
    13341370        s = "<"
    1335         if self.phase is not None:
     1371        if self.phase == '*':
     1372            s += "Phases: all; "
     1373            if self.atom is not None:
     1374                s += "Atom #" + str(self.atom) + "; "
     1375        elif self.phase is not None:
    13361376            ph =  _lookup(PhaseRanIdLookup,self.phase)
    13371377            s += "Phase: rId=" + str(self.phase) + " (#"+ ph + "); "
    1338         if self.histogram is not None:
     1378            if self.atom == '*':
     1379                s += "Atoms: all; "
     1380            elif self.atom is not None:
     1381                s += "Atom rId=" + str(self.atom)
     1382                if ph in AtomRanIdLookup:
     1383                    s += " (#" + AtomRanIdLookup[ph].get(self.atom,'?') + "); "
     1384                else:
     1385                    s += " (#? -- not found!); "
     1386        if self.histogram == '*':
     1387            s += "Histograms: all; "
     1388        elif self.histogram is not None:
    13391389            hist = _lookup(HistRanIdLookup,self.histogram)
    13401390            s += "Histogram: rId=" + str(self.histogram) + " (#"+ hist + "); "
    1341         if self.atom is not None:
    1342             s += "Atom rId=" + str(self.atom)
    1343             if ph in AtomRanIdLookup:
    1344                 s += " (#" + AtomRanIdLookup[ph].get(self.atom,'?') + "); "
    1345             else:
    1346                 s += " (#? -- not found!); "
    13471391        s += 'Variable name="' + str(self.name) + '">'
    1348         return s+"("+self.varname()+")"
     1392        return s+" ("+self.varname()+")"
    13491393
    13501394    def __eq__(self, other):
Note: See TracChangeset for help on using the changeset viewer.