Changeset 2639


Ignore:
Timestamp:
Jan 17, 2017 4:46:55 PM (7 years ago)
Author:
toby
Message:

fix GridFractionEditor? bug on Ubuntu 16.10

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/GSASIIctrls.py

    r2637 r2639  
    29462946
    29472947        self.nextval = self.startValue
    2948         val = self._tc.GetValue().lower()
     2948        val = self._tc.GetValue().lower().strip()
    29492949        if val != self.startValue:
    29502950            changed = True
    29512951            neg = False
    2952             if '-' in val:
     2952            if val.startswith('-'):
    29532953                neg = True
    2954             if '/' in val and '.' not in val:
    2955                 val += '.'
    2956             elif 's' in val and not 'sind(' in val:
    2957                 if neg:
    2958                     val = '-sind('+val.strip('-s')+')'
    2959                 else:
    2960                     val = 'sind('+val.strip('s')+')'
    2961             elif 'c' in val and not 'cosd(' in val:
    2962                 if neg:
    2963                     val = '-cosd('+val.strip('-c')+')'
    2964                 else:
    2965                     val = 'cosd('+val.strip('c')+')'
    2966             try:
    2967                 self.nextval = val = float(eval(val))
    2968             except (SyntaxError,NameError,ZeroDivisionError):
    2969                 val = self.startValue
     2954                val = val[1:]
     2955            # allow old GSAS s20 and c20 etc for sind(20) and cosd(20)
     2956            if val.startswith('s') and '(' not in val:
     2957                val = 'sind('+val.strip('s')+')'
     2958            elif val.startswith('c') and '(' not in val:
     2959                val = 'cosd('+val.strip('c')+')'
     2960            if neg:
     2961                val = '-' + val
     2962            val = G2py3.FormulaEval(val)
     2963            if val:
     2964                self.nextval = val
     2965            else:
    29702966                return None
    2971            
    29722967            if oldVal is None: # this arg appears in 2.9+; before, we should go ahead & change the table
    29732968                grid.GetTable().SetValue(row, col, val) # update the table
     
    29982993    def OnChar(self, evt):
    29992994        key = evt.GetKeyCode()
    3000         if key == 15:
    3001             return
    3002         if key > 255:
     2995        if key < 32 or key >= 127:
    30032996            evt.Skip()
    3004             return
    3005         char = chr(key)
    3006         if char in '.+-/0123456789cosind()':
    3007             self._tc.WriteText(char)
    3008         else:
     2997        elif chr(key).lower() in '.+-*/0123456789cosind()':
    30092998            evt.Skip()
     2999        else:
     3000            evt.StopPropagation()
    30103001           
    30113002################################################################################
     
    42504241    frm.Show(True)
    42514242   
     4243    #======================================================================
     4244    # test Grid with GridFractionEditor
     4245    #======================================================================
     4246    tbl = [[1.,2.,3.],[1.1,2.1,3.1]]
     4247    colTypes = 3*[wg.GRID_VALUE_FLOAT+':10,5',]
     4248    Gtbl = Table(tbl,types=colTypes,rowLabels=['a','b'],colLabels=['1','2','3'])
     4249    Grid = GSGrid(frm)
     4250    Grid.SetTable(Gtbl,True)
     4251    for i in (0,1,2):
     4252        attr = wx.grid.GridCellAttr()
     4253        attr.IncRef()
     4254        attr.SetEditor(GridFractionEditor(Grid))
     4255        Grid.SetColAttr(i, attr)
     4256    frm.SetSize((400,200))
     4257    app.MainLoop()
     4258    sys.exit()
     4259    #======================================================================
     4260    # test Tutorial access
     4261    #======================================================================
    42524262    dlg = OpenTutorial(frm)
    42534263    if dlg.ShowModal() == wx.ID_OK:
Note: See TracChangeset for help on using the changeset viewer.