Changeset 2521 for trunk/GSASIIpwdGUI.py


Ignore:
Timestamp:
Nov 13, 2016 8:27:56 PM (5 years ago)
Author:
toby
Message:

extensions to Peak List: vary via menu items; animate line dragging; highlight selected peak(s)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/GSASIIpwdGUI.py

    r2519 r2521  
    745745        G2plt.PlotPatterns(G2frame,plotType='PWDR')
    746746           
     747    def SelectVars(rows):
     748        '''Set or clear peak refinement variables for peaks listed in rows
     749        '''
     750        refOpts = {G2frame.dataDisplay.GetColLabelValue(i):i+1 for i in range(G2frame.dataDisplay.GetNumberCols()) if G2frame.dataDisplay.GetColLabelValue(i) != "refine"}
     751        dlg = G2G.G2MultiChoiceDialog(
     752            G2frame.dataFrame,
     753            'Select columns to refine',
     754            'Refinement Selection', sorted(refOpts.keys()),
     755            filterBox=False,toggle=False)
     756        sels = []
     757        try:
     758            if dlg.ShowModal() == wx.ID_OK:
     759                sels = [sorted(refOpts.keys())[i] for i in dlg.GetSelections()]
     760            else:
     761                return
     762        finally:
     763            dlg.Destroy()
     764        for r in rows:
     765            for lbl,c in refOpts.iteritems():
     766                data['peaks'][r][c] = lbl in sels
     767        UpdatePeakGrid(G2frame,data)
     768       
     769    def OnRefineSelected(event):
     770        '''set refinement flags for the selected peaks
     771        '''
     772        rows = list(set([row for row,col in G2frame.dataDisplay.GetSelectedCells()] +
     773                        G2frame.dataDisplay.GetSelectedRows()))
     774        if not rows:
     775            wx.MessageBox('No selected rows. You must select rows or cells before using this command',
     776                          caption='No selected peaks')
     777            return
     778        SelectVars(rows)
     779
     780    def OnRefineAll(event):
     781        '''set refinement flags for all peaks
     782        '''
     783        SelectVars(range(G2frame.dataDisplay.GetNumberRows()))
     784
     785    def onSelectedRow(event):
     786        '''Called when a peak is selected so that it can be highlighted in the plot
     787        '''
     788        event.Skip()
     789        wx.CallAfter(G2plt.PlotPatterns,G2frame,plotType='PWDR')
     790                           
     791    #======================================================================
     792    # beginning of UpdatePeakGrid init
     793    #======================================================================
    747794    G2gd.SetDataMenuBar(G2frame,G2frame.dataFrame.PeakMenu)
    748795    if not G2frame.dataFrame.GetStatusBar():
     
    752799    G2frame.Bind(wx.EVT_MENU, OnCopyPeaks, id=G2gd.wxID_PEAKSCOPY)
    753800    G2frame.Bind(wx.EVT_MENU, OnUnDo, id=G2gd.wxID_UNDO)
     801    G2frame.Bind(wx.EVT_MENU, OnRefineSelected, id=G2frame.dataFrame.peaksSel.GetId())
     802    G2frame.Bind(wx.EVT_MENU, OnRefineAll, id=G2frame.dataFrame.peaksAll.GetId())
    754803    G2frame.Bind(wx.EVT_MENU, OnLSQPeakFit, id=G2gd.wxID_LSQPEAKFIT)
    755804    G2frame.Bind(wx.EVT_MENU, OnOneCycle, id=G2gd.wxID_LSQONECYCLE)
     
    807856    G2frame.dataDisplay.Bind(wg.EVT_GRID_CELL_CHANGE, RefreshPeakGrid)
    808857    G2frame.dataDisplay.Bind(wx.EVT_KEY_DOWN, KeyEditPeakGrid)
     858    G2frame.dataDisplay.Bind(wg.EVT_GRID_LABEL_LEFT_CLICK, onSelectedRow)
     859    G2frame.dataDisplay.Bind(wg.EVT_GRID_CELL_LEFT_CLICK, onSelectedRow)
    809860    G2frame.dataDisplay.SetMargins(0,0)
    810861    G2frame.dataDisplay.AutoSizeColumns(False)
    811862    G2frame.dataFrame.setSizePosLeft([535,350])
    812863    G2frame.dataFrame.SendSizeEvent()
    813        
     864
    814865################################################################################
    815866#####  Background
Note: See TracChangeset for help on using the changeset viewer.