Changeset 3652


Ignore:
Timestamp:
Oct 5, 2018 3:47:53 PM (5 years ago)
Author:
toby
Message:

add keys to cycle through magnetic cells

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/GSASIIplot.py

    r3592 r3652  
    15841584    PlotPatterns(G2frame,newPlot,plotType)
    15851585
    1586 def PlotPatterns(G2frame,newPlot=False,plotType='PWDR',data=None):
     1586def PlotPatterns(G2frame,newPlot=False,plotType='PWDR',data=None,
     1587                     extraKeys=[]):
    15871588    '''Powder pattern plotting package - displays single or multiple powder patterns as intensity vs
    15881589    2-theta, q or TOF. Can display multiple patterns as "waterfall plots" or contour plots. Log I
     
    18041805                G2frame.Interpolate = 'nearest'
    18051806            dlg.Destroy()
     1807        elif event.key in [KeyItem[0] for KeyItem in extraKeys]:
     1808            for KeyItem in extraKeys:
     1809                if event.key == KeyItem[0]:
     1810                    KeyItem[1]()
     1811                    break
    18061812        else:
    1807 #            print 'no binding for key',event.key
     1813            print('no binding for key',event.key)
    18081814            #GSASIIpath.IPyBreak()
    18091815            return
    1810         wx.CallAfter(PlotPatterns,G2frame,newPlot=newPlot,plotType=plottype)
     1816        wx.CallAfter(PlotPatterns,G2frame,newPlot=newPlot,plotType=plottype,extraKeys=extraKeys)
    18111817       
    18121818    def OnMotion(event):
     
    20512057                data['sigDict'] = {}    #now invalid
    20522058                G2pdG.UpdatePeakGrid(G2frame,data)
    2053                 PlotPatterns(G2frame,plotType=plottype)
     2059                PlotPatterns(G2frame,plotType=plottype,extraKeys=extraKeys)
    20542060            else:                                                   #picked a peak list line
    20552061                # prepare to animate move of line
     
    20832089                G2frame.GPXtree.SetItemPyData(LimitId,data)
    20842090                G2pdG.UpdateLimitsGrid(G2frame,data,plottype)
    2085                 wx.CallAfter(PlotPatterns,G2frame,plotType=plottype)
     2091                wx.CallAfter(PlotPatterns,G2frame,plotType=plottype,extraKeys=extraKeys)
    20862092            else:                                                   #picked a limit line
    20872093                # prepare to animate move of line
     
    21042110                    data[1][1] = max(xy[0],data[1][0])
    21052111                G2frame.GPXtree.SetItemPyData(LimitId,data)
    2106                 wx.CallAfter(PlotPatterns,G2frame,plotType=plottype)
     2112                wx.CallAfter(PlotPatterns,G2frame,plotType=plottype,extraKeys=extraKeys)
    21072113            else:                                                   #picked a limit line
    21082114                G2frame.itemPicked = pick
     
    21682174                elif mode == 'Del':
    21692175                    del backDict['FixedPoints'][G2frame.fixPtMarker]
    2170                     wx.CallAfter(PlotPatterns,G2frame,plotType=plottype)
     2176                    wx.CallAfter(PlotPatterns,G2frame,plotType=plottype,extraKeys=extraKeys)
    21712177                return
    21722178               
     
    21832189            G2frame.cid = None
    21842190        if event.xdata is None or event.ydata is None: # ignore drag if cursor is outside of plot
    2185             wx.CallAfter(PlotPatterns,G2frame,plotType=plottype)
     2191            wx.CallAfter(PlotPatterns,G2frame,plotType=plottype,extraKeys=extraKeys)
    21862192            return
    21872193        if not G2frame.PickId:
     
    21922198            if Page.toolbar._active:    # prevent ops. if a toolbar zoom button pressed
    21932199                # after any mouse release event (could be a zoom), redraw magnification lines
    2194                 if magLineList: wx.CallAfter(PlotPatterns,G2frame,plotType=plottype)
     2200                if magLineList: wx.CallAfter(PlotPatterns,G2frame,plotType=plottype,extraKeys=extraKeys)
    21952201                return
    21962202            # Background page, deal with fixed background points
     
    22272233                backDict['FixedPoints'][G2frame.fixPtMarker] = xy
    22282234                G2frame.itemPicked = None
    2229                 wx.CallAfter(PlotPatterns,G2frame,plotType=plottype)
     2235                wx.CallAfter(PlotPatterns,G2frame,plotType=plottype,extraKeys=extraKeys)
    22302236                return
    22312237       
    22322238        if G2frame.itemPicked is None:
    22332239            # after any mouse release event (could be a zoom), redraw magnification lines
    2234             if magLineList: wx.CallAfter(PlotPatterns,G2frame,plotType=plottype)
     2240            if magLineList: wx.CallAfter(PlotPatterns,G2frame,plotType=plottype,extraKeys=extraKeys)
    22352241            return
    22362242        if DifLine[0] is G2frame.itemPicked:   # respond to dragging of the difference curve
     
    22392245            Page.plotStyle['delOffset'] = -ypos
    22402246            G2frame.itemPicked = None
    2241             wx.CallAfter(PlotPatterns,G2frame,plotType=plottype)
     2247            wx.CallAfter(PlotPatterns,G2frame,plotType=plottype,extraKeys=extraKeys)
    22422248            return
    22432249        elif G2frame.itemPicked in G2frame.MagLines: # drag of magnification marker
     
    23262332                        else:       #1st row of refl ticks
    23272333                            Page.plotStyle['refOffset'] = event.ydata
    2328         PlotPatterns(G2frame,plotType=plottype)
     2334        PlotPatterns(G2frame,plotType=plottype,extraKeys=extraKeys)
    23292335        G2frame.itemPicked = None
    23302336       
     
    23392345        newPlot = True
    23402346        G2frame.Cmax = 1.0
    2341         Page.canvas.mpl_connect('key_press_event', OnPlotKeyPress)
     2347#        Page.canvas.mpl_connect('key_press_event', OnPlotKeyPress)
    23422348        Page.canvas.mpl_connect('motion_notify_event', OnMotion)
    23432349        Page.canvas.mpl_connect('pick_event', OnPick)
    23442350        Page.canvas.mpl_connect('button_release_event', OnRelease)
    23452351        Page.canvas.mpl_connect('button_press_event',OnPress)
     2352        Page.bindings = []
     2353    # redo OnPlotKeyPress binding each time the Plot is updated
     2354    # since needs values that may have been changed after 1st call
     2355    for b in Page.bindings:
     2356        Page.canvas.mpl_disconnect(b)
     2357    Page.bindings = []
     2358    Page.bindings.append(
     2359        Page.canvas.mpl_connect('key_press_event', OnPlotKeyPress)
     2360    )
    23462361    if 'PWDR' in G2frame.GPXtree.GetItemText(G2frame.PickId):
    23472362        Histograms,Phases = G2frame.GetUsedHistogramsAndPhasesfromTree()
     
    24142429                Page.plotStyle['logPlot'] or Page.plotStyle['sqrtPlot'] or G2frame.Contour):
    24152430        Page.Choice = Page.Choice + ('a: add magnification region',)
     2431    for KeyItem in extraKeys:
     2432        Page.Choice = Page.Choice + (KeyItem[0] + ': '+KeyItem[2],)
    24162433    magLineList = [] # null value indicates no magnification
    24172434    Page.toolbar.updateActions = None # no update actions
  • trunk/GSASIIpwdGUI.py

    r3646 r3652  
    33693369            G2frame.GPXtree.SetItemPyData(UnitCellsId,data)
    33703370       
     3371    KeyList = []
     3372    def ClearCurrentShowNext():
     3373        KeepShowNext(False)
     3374    KeyList += [['j',ClearCurrentShowNext,'Show next Mag. Spc. Group, clear keep flag on current']]       
     3375    def KeepCurrentShowNext():
     3376        KeepShowNext(True)
     3377    KeyList += [['k',KeepCurrentShowNext,'Show next Mag. Spc. Group, keep current']]       
     3378    def KeepShowNext(KeepCurrent=True):
     3379        '''Show next "keep" item in Magnetic Space Group list, possibly resetting the
     3380        keep flag for the current displayed cell
     3381        '''
     3382        for i in range(len(magcells)): # find plotted setting
     3383            if magcells[i]['Use']: break
     3384        else:
     3385            return # no Try is set
     3386        if not KeepCurrent:  # clear current
     3387            magcells[i]['Keep'] = False
     3388            MagCellsTable.SetValue(i,2,False)
     3389        keeps = [j for j in range(i+1,len(magcells)) if magcells[j]['Keep']]
     3390        if not keeps:
     3391            if not KeepCurrent: magDisplay.ForceRefresh()
     3392            return # no remaining Keep-flagged entries
     3393        next = keeps[0]
     3394        # update table
     3395        magcells[i]['Use'] = False
     3396        MagCellsTable.SetValue(i,1,False)
     3397        magcells[next]['Use'] = True
     3398        MagCellsTable.SetValue(next,1,True)
     3399        # get SG info and plot
     3400        SGData = magcells[next]['SGData']
     3401        A = G2lat.cell2A(magcells[next]['Cell'][:6]) 
     3402        G2frame.HKL = G2pwd.getHKLpeak(1.0,SGData,A,Inst)
     3403        G2plt.PlotPatterns(G2frame,extraKeys=KeyList)
     3404        magDisplay.ForceRefresh()
     3405        # change Scroll to display new setting
     3406        xscroll = G2frame.dataWindow.GetScrollPos(wx.HORIZONTAL)
     3407        yscroll = magDisplay.CellToRect(next,1)[1]/G2frame.dataWindow.GetScrollPixelsPerUnit()[1]
     3408        G2frame.dataWindow.Scroll(xscroll,yscroll)
     3409       
    33713410    def RefreshMagCellsGrid(event):
    33723411        controls,bravais,cells,dminx,ssopt,magcells = G2frame.GPXtree.GetItemPyData(UnitCellsId)
     
    33943433                A = G2lat.cell2A(magcells[r]['Cell'][:6]) 
    33953434                G2frame.HKL = G2pwd.getHKLpeak(1.0,mSGData,A,Inst)
    3396                 G2plt.PlotPatterns(G2frame)
     3435                G2plt.PlotPatterns(G2frame,extraKeys=KeyList)
    33973436            elif c == 2:
    33983437                if MagCellsTable.GetValue(r,c):
     
    36613700            A = G2lat.cell2A(magcells[0]['Cell'][:6]) 
    36623701            G2frame.HKL = G2pwd.getHKLpeak(1.0,SGData,A,Inst)
    3663             G2plt.PlotPatterns(G2frame)
     3702            G2plt.PlotPatterns(G2frame,extraKeys=KeyList)
    36643703        data = [controls,bravais,cells,dmin,ssopt,magcells]
    36653704        G2frame.GPXtree.SetItemPyData(pUCid,data)
     
    39463985            G2frame.dataWindow.RunSubGroupsMag.Enable(True)
    39473986        G2frame.dataWindow.CopyCell.Enable(False)
    3948         Label = '\n Magnetic cells from Bilbao k-SUBGROUPSMAG for %s; kvec1: (%s), kvec2: (%s):'%(controls[13],''.join(controls[14][:3]),''.join(controls[14][3:]))
     3987        Label = '\n Magnetic cells from Bilbao k-SUBGROUPSMAG for %s; kvec1=(%s)'%(controls[13],''.join(controls[14][:3]))
     3988        kvec2 = ''.join(controls[14][3:])
     3989        if kvec2.strip():
     3990            Label += ', kvec2=(%s)' % kvec2
     3991        Label += ':'
    39493992        mainSizer.Add(wx.StaticText(parent=G2frame.dataWindow,label=Label),0,WACV)
    39503993        rowLabels = []
Note: See TracChangeset for help on using the changeset viewer.