Ignore:
Timestamp:
May 22, 2021 7:13:58 PM (2 years ago)
Author:
toby
Message:

Add mult, divide & incr. options to GridFracEdit?; make GridFracEdit? the default for numeric columns in grids

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/GSASIIctrlGUI.py

    r4912 r4913  
    45014501        self.SetCellBackgroundColour(r,c,color)
    45024502        self.SetReadOnly(r,c,isReadOnly=readonly)
    4503        
     4503
     4504    def SetTable(self, table, *args, **kwargs):
     4505        '''Overrides the standard SetTable method with one that uses
     4506        GridFractionEditor for all numeric columns (unless useFracEdit
     4507        is false)
     4508        '''
     4509        setFracEdit = kwargs.get('useFracEdit',True)
     4510        if 'useFracEdit' in kwargs: del kwargs['useFracEdit']
     4511        wg.Grid.SetTable(self, table, *args, **kwargs)
     4512        if setFracEdit:
     4513            for i,t in enumerate(table.dataTypes):
     4514                if not t.startswith(wg.GRID_VALUE_FLOAT): continue
     4515                attr = wx.grid.GridCellAttr()
     4516                attr.IncRef()
     4517                attr.SetEditor(GridFractionEditor(self))
     4518                self.SetColAttr(i, attr)
     4519
    45044520    def GetSelection(self):
    45054521        #this is to satisfy structure drawing stuff in G2plt when focus changes
     
    47714787class GridFractionEditor(wg.PyGridCellEditor):
    47724788    '''A grid cell editor class that allows entry of values as fractions as well
    4773     as sine and cosine values [as s() and c()]
     4789    as sine and cosine values [as s() and c(), sin() or sind(), etc]. Any valid
     4790    Python expression will be evaluated.
     4791
     4792    The current value can be incremented, multiplied or divided by prefixing
     4793    an expression by +, * or / respectively.
    47744794    '''
    47754795    def __init__(self,grid):
     
    48124832            changed = True
    48134833            neg = False
     4834            mult = False
     4835            divide = False
     4836            add = False
     4837            if val.startswith('*'):
     4838                mult = True
     4839                val = val[1:]
     4840            elif val.startswith('/'):
     4841                divide = True
     4842                val = val[1:]
     4843            elif val.startswith('+'):
     4844                add = True
     4845                val = val[1:]
    48144846            if val.startswith('-'):
    48154847                neg = True
     
    48244856            val = G2py3.FormulaEval(val)
    48254857            if val is not None:
    4826                 self.nextval = val
     4858                if mult:
     4859                    self.nextval *= val
     4860                elif divide:
     4861                    if val != 0: self.nextval /= val
     4862                elif add:
     4863                    self.nextval += val
     4864                else:
     4865                    self.nextval = val
    48274866            else:
    48284867                return None
Note: See TracChangeset for help on using the changeset viewer.