Changeset 1390 for trunk/GSASIIgrid.py


Ignore:
Timestamp:
Jun 20, 2014 11:15:24 AM (8 years ago)
Author:
toby
Message:

revise start, sort out phase fraction vs scale factor label, add configurable label for columns in sequential refinements. Note: the dict (variableLabels) is not saved yet when a seq. refinement is repeated.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/GSASIIgrid.py

    r1386 r1390  
    14081408        mainSizer = wx.BoxSizer(wx.VERTICAL)
    14091409        mainSizer.Add(wx.StaticText(self.panel,-1,self.prompt),0,wx.ALIGN_CENTER)
    1410         self.valItem = wx.TextCtrl(self.panel,-1,value=str(self.value),size=size)
     1410        self.valItem = wx.TextCtrl(self.panel,-1,value=self.value,size=size)
    14111411        mainSizer.Add(self.valItem,0,wx.ALIGN_CENTER)
    14121412        btnsizer = wx.StdDialogButtonSizer()
     
    31463146        return None
    31473147
    3148     def InstallGridToolTip(self, rowcolhintcallback):
     3148    def InstallGridToolTip(self, rowcolhintcallback,
     3149                           colLblCallback=None,rowLblCallback=None):
    31493150        '''code to display a tooltip for each item on a grid
    3150         from http://wiki.wxpython.org/wxGrid%20ToolTips
     3151        from http://wiki.wxpython.org/wxGrid%20ToolTips (buggy!), expanded to
     3152        column and row labels using hints from
     3153        https://groups.google.com/forum/#!topic/wxPython-users/bm8OARRVDCs
    31513154
    31523155        :param function rowcolhintcallback: a routine that returns a text
    3153           string depending on the selected row and column
     3156          string depending on the selected row and column, to be used in
     3157          explaining grid entries.
     3158        :param function colLblCallback: a routine that returns a text
     3159          string depending on the selected column, to be used in
     3160          explaining grid columns (if None, the default), column labels
     3161          do not get a tooltip.
     3162        :param function rowLblCallback: a routine that returns a text
     3163          string depending on the selected row, to be used in
     3164          explaining grid rows (if None, the default), row labels
     3165          do not get a tooltip.
    31543166        '''
    3155         prev_rowcol = [None,None]
    3156         def OnMouseMotion(evt):
    3157             # evt.GetRow() and evt.GetCol() would be nice to have here,
     3167        prev_rowcol = [None,None,None]
     3168        def OnMouseMotion(event):
     3169            # event.GetRow() and event.GetCol() would be nice to have here,
    31583170            # but as this is a mouse event, not a grid event, they are not
    31593171            # available and we need to compute them by hand.
    3160             x, y = self.CalcUnscrolledPosition(evt.GetPosition())
     3172            x, y = self.CalcUnscrolledPosition(event.GetPosition())
    31613173            row = self.YToRow(y)
    31623174            col = self.XToCol(x)
    3163 
    3164             if (row,col) != prev_rowcol and row >= 0 and col >= 0:
    3165                 prev_rowcol[:] = [row,col]
     3175            hinttext = ''
     3176            win = event.GetEventObject()
     3177            if [row,col,win] == prev_rowcol: # no change from last position
     3178                event.Skip()
     3179                return
     3180            if win == self.GetGridWindow() and row >= 0 and col >= 0:
    31663181                hinttext = rowcolhintcallback(row, col)
    3167                 if hinttext is None:
    3168                     hinttext = ''
    3169                 self.GetGridWindow().SetToolTipString(hinttext)
    3170             evt.Skip()
     3182            elif win == self.GetGridColLabelWindow() and col >= 0:
     3183                if colLblCallback: hinttext = colLblCallback(col)
     3184            elif win == self.GetGridRowLabelWindow() and row >= 0:
     3185                if rowLblCallback: hinttext = rowLblCallback(row)
     3186            else: # this should be the upper left corner, which is empty
     3187                event.Skip()
     3188                return
     3189            if hinttext is None: hinttext = ''
     3190            win.SetToolTipString(hinttext)
     3191            prev_rowcol[:] = [row,col,win]
     3192            event.Skip()
    31713193
    31723194        wx.EVT_MOTION(self.GetGridWindow(), OnMouseMotion)
    3173                                                
     3195        if colLblCallback: wx.EVT_MOTION(self.GetGridColLabelWindow(), OnMouseMotion)
     3196        if rowLblCallback: wx.EVT_MOTION(self.GetGridRowLabelWindow(), OnMouseMotion)
     3197                                                   
    31743198################################################################################
    31753199#####  Table
     
    36133637            * 'varyList' - list of variables - identical over all refinements in sequence
    36143638              note that this is the original list of variables, prior to processing
    3615               constraints.
     3639              constraints.
     3640            * 'variableLabels' -- a dict of labels to be applied to each parameter
     3641              (this is created as an empty dict if not present in data).
    36163642            * keyed by histName - dictionaries for all data sets processed, which contains:
    36173643
     
    36593685        for plotting. The column label is reformatted from Unicode to MatPlotLib encoding
    36603686        '''
    3661         plotName = plotSpCharFix(G2frame.SeqTable.GetColLabelValue(col))
     3687        colName = G2frame.SeqTable.GetColLabelValue(col)
     3688        plotName = variableLabels.get(colName,colName)
     3689        plotName = plotSpCharFix(plotName)
    36623690        return plotName,colList[col],colSigs[col]
    36633691           
     
    41844212            return u'\u03c3 = '+str(colSigs[col][row])
    41854213        return ''
     4214    def GridColLblToolTip(col):
     4215        '''Define a tooltip for a column. This will be the user-entered value
     4216        (from data['variableLabels']) or the default name
     4217        '''
     4218        if col < 0 or col > len(colLabels):
     4219            print 'Illegal column #',col
     4220            return
     4221        var = colLabels[col]
     4222        return variableLabels.get(var,G2obj.fmtVarDescr(var))
     4223    def SetLabelString(event):
     4224        '''Define or edit the label for a column in the table, to be used
     4225        as a tooltip and for plotting
     4226        '''
     4227        col = event.GetCol()
     4228        if col < 0 or col > len(colLabels):
     4229            return
     4230        var = colLabels[col]
     4231        lbl = variableLabels.get(var,G2obj.fmtVarDescr(var))
     4232        dlg = SingleStringDialog(G2frame.dataFrame,'Set variable label',
     4233                                 'Set a name for variable '+var,lbl,size=(400,-1))
     4234        if dlg.Show():
     4235            variableLabels[var] = dlg.GetValue()
     4236            print variableLabels
     4237        dlg.Destroy()
     4238       
     4239    #def GridRowLblToolTip(row): return 'Row ='+str(row)
    41864240   
    41874241    # lookup table for unique cell parameters by symmetry
     
    42054259        print 'No sequential refinement results'
    42064260        return
     4261    variableLabels = data.get('variableLabels',{})
     4262    data['variableLabels'] = variableLabels
    42074263    Histograms,Phases = G2frame.GetUsedHistogramsAndPhasesfromTree()
    42084264    Controls = G2frame.PatternTree.GetItemPyData(GetPatternTreeItemId(G2frame,G2frame.root,'Controls'))
     
    44574513    G2frame.dataDisplay.EnableEditing(False)
    44584514    G2frame.dataDisplay.Bind(wg.EVT_GRID_LABEL_LEFT_DCLICK, PlotSelect)
     4515    G2frame.dataDisplay.Bind(wg.EVT_GRID_LABEL_RIGHT_CLICK, SetLabelString)
    44594516    G2frame.dataDisplay.SetRowLabelSize(8*len(histNames[0]))       #pretty arbitrary 8
    44604517    G2frame.dataDisplay.SetMargins(0,0)
     
    44694526            deltaChi = G2frame.SeqTable.GetValue(row,deltaChiCol)
    44704527            if deltaChi > 10.:
    4471                 G2frame.dataDisplay.SetCellStyle(row,deltaChiCol,color=wx.Color(255,0,0))
     4528                G2frame.dataDisplay.SetCellStyle(row,deltaChiCol,color=wx.Colour(255,0,0))
    44724529            elif deltaChi > 1.0:
    4473                 G2frame.dataDisplay.SetCellStyle(row,deltaChiCol,color=wx.Color(255,255,0))
    4474     G2frame.dataDisplay.InstallGridToolTip(GridSetToolTip)
     4530                G2frame.dataDisplay.SetCellStyle(row,deltaChiCol,color=wx.Colour(255,255,0))
     4531    G2frame.dataDisplay.InstallGridToolTip(GridSetToolTip,GridColLblToolTip)
    44754532    #======================================================================
    44764533    # end UpdateSeqResults; done processing sequential results
    44774534    #======================================================================
    4478 
    4479     # make dict with vars for use in PseudoVars
    4480     # name = histNames[0]
    4481     # parmDict = dict(zip(colLabels,zip(*colList)[0]))
    4482     # # create a dict with the refined Ax values for all phases (only)
    4483     # refCellDict = {var:val for var,val in data[name]['newCellDict'].values()}
    4484     # # compute the Ai values for each phase, updated with refined values and
    4485     # # with symmetry constraints applied
    4486     # for pId in Alist:     # loop over phases
    4487     #     Albls = [str(pId)+'::A'+str(i) for i in range(6)]
    4488     #     cellDict = {var:refCellDict.get(var,val) for var,val in zip(Albls,Alist[pId])}
    4489     #     zeroDict = {var:0.0 for var in Albls}
    4490     #     A,zeros = G2stIO.cellFill(str(pId)+'::',SGdata[pId],cellDict,zeroDict)
    4491     #     parmDict.update(dict(zip(Albls,A)))
    4492 
    4493 #    print data[name]['varyList']
    4494 #           
    4495     # print 'vars for PVar dict'
    4496     # for i,(var,val) in enumerate(zip(colLabels,zip(*colList)[0])):
    4497     #     if var in data[name]['varyList']:
    4498     #         print var,Dlookup.get(striphist(var),var),val,parmDict.get(Dlookup.get(striphist(var),var))
    4499     #         pass
    4500     #     #else:
    4501     #     #    print i,var,colSigs[i]
    4502     # print 'vars for PVar dict again'
    45034535   
    45044536################################################################################
Note: See TracChangeset for help on using the changeset viewer.