Changeset 1128


Ignore:
Timestamp:
Oct 29, 2013 12:03:49 PM (10 years ago)
Author:
vondreele
Message:

mask picking redone; all now made by key, mouse or submenu
some update of G2obj stuff

Location:
trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/GSASII.py

    r1125 r1128  
    14081408        self.Sngl = 0
    14091409        self.ifGetRing = False
    1410         self.setPoly = False
    1411         self.setFrame = False
    1412         self.setSpot = False
    1413         self.setArc = False
    1414         self.setRing = False
     1410        self.MaskKey = ''           #trigger for making image masks
    14151411        arg = sys.argv
    14161412        if len(arg) > 1:
  • trunk/GSASIIgrid.py

    r1127 r1128  
    9595] = [wx.NewId() for item in range(8)]
    9696
    97 [ wxID_MASKCOPY, wxID_MASKSAVE, wxID_MASKLOAD,
     97[ wxID_MASKCOPY, wxID_MASKSAVE, wxID_MASKLOAD,wxID_NEWMASKSPOT,wxID_NEWMASKARC,wxID_NEWMASKRING,
    9898  wxID_NEWMASKFRAME, wxID_NEWMASKPOLY,
    99 ] = [wx.NewId() for item in range(5)]
     99] = [wx.NewId() for item in range(8)]
    100100
    101101
     
    22142214        self.MaskEdit.Append(help='Load mask from file',
    22152215            id=wxID_MASKLOAD, kind=wx.ITEM_NORMAL,text='Load mask')
    2216         submenu.Append(help='Create a Frame mask with mouse input',
     2216        submenu.Append(help='Create an arc mask with mouse input',
     2217            id=wxID_NEWMASKARC, kind=wx.ITEM_NORMAL,text='Arc mask')
     2218        submenu.Append(help='Create a frame mask with mouse input',
    22172219            id=wxID_NEWMASKFRAME, kind=wx.ITEM_NORMAL,text='Frame mask')
    22182220        submenu.Append(help='Create a polygon mask with mouse input',
    22192221            id=wxID_NEWMASKPOLY, kind=wx.ITEM_NORMAL,text='Polygon mask')
     2222        submenu.Append(help='Create a ring mask with mouse input',
     2223            id=wxID_NEWMASKRING, kind=wx.ITEM_NORMAL,text='Ring mask')
     2224        submenu.Append(help='Create a spot mask with mouse input',
     2225            id=wxID_NEWMASKSPOT, kind=wx.ITEM_NORMAL,text='Spot mask')
    22202226        self.PostfillDataMenu()
    22212227           
  • trunk/GSASIIimgGUI.py

    r1124 r1128  
    990990        finally:
    991991            dlg.Destroy()
     992           
     993    def OnNewSpotMask(event):
     994        'Start a new spot mask'
     995        G2frame.MaskKey = 's'
     996        G2plt.OnStartMask(G2frame)
     997       
     998    def OnNewArcMask(event):
     999        'Start a new arc mask'
     1000        G2frame.MaskKey = 'a'
     1001        G2plt.OnStartMask(G2frame)
     1002       
     1003    def OnNewRingMask(event):
     1004        'Start a new ring mask'
     1005        G2frame.MaskKey = 'r'
     1006        G2plt.OnStartMask(G2frame)
     1007       
     1008    def OnNewPolyMask(event):
     1009        'Start a new polygon mask'
     1010        G2frame.MaskKey = 'p'
     1011        G2plt.OnStartMask(G2frame)
     1012       
    9921013    def OnNewFrameMask(event):
    9931014        'Start a new Frame mask'
    994         G2plt.OnStartMask(G2frame,'f')
    995     def OnNewPolyMask(event):
    996         'Start a new polygon mask'
    997         G2plt.OnStartMask(G2frame,'p')
    998        
     1015        G2frame.MaskKey = 'f'
     1016        G2plt.OnStartMask(G2frame)
     1017               
    9991018    if G2frame.dataDisplay:
    10001019        G2frame.dataDisplay.Destroy()
     
    10031022    G2frame.dataFrame.Bind(wx.EVT_MENU, OnLoadMask, id=G2gd.wxID_MASKLOAD)
    10041023    G2frame.dataFrame.Bind(wx.EVT_MENU, OnSaveMask, id=G2gd.wxID_MASKSAVE)
     1024    G2frame.dataFrame.Bind(wx.EVT_MENU, OnNewSpotMask, id=G2gd.wxID_NEWMASKSPOT)
     1025    G2frame.dataFrame.Bind(wx.EVT_MENU, OnNewArcMask, id=G2gd.wxID_NEWMASKARC)
     1026    G2frame.dataFrame.Bind(wx.EVT_MENU, OnNewRingMask, id=G2gd.wxID_NEWMASKRING)
     1027    G2frame.dataFrame.Bind(wx.EVT_MENU, OnNewPolyMask, id=G2gd.wxID_NEWMASKPOLY)
    10051028    G2frame.dataFrame.Bind(wx.EVT_MENU, OnNewFrameMask, id=G2gd.wxID_NEWMASKFRAME)
    1006     G2frame.dataFrame.Bind(wx.EVT_MENU, OnNewPolyMask, id=G2gd.wxID_NEWMASKPOLY)
    10071029    if not G2frame.dataFrame.GetStatusBar():
    10081030        Status = G2frame.dataFrame.CreateStatusBar()
    1009     if G2frame.setFrame:
    1010         G2frame.dataFrame.GetStatusBar().SetStatusText("Adding frame mask")
    1011     elif G2frame.setPoly:
    1012         G2frame.dataFrame.GetStatusBar().SetStatusText("Adding polygon mask")
     1031    if G2frame.MaskKey == 'f':
     1032        G2frame.dataFrame.GetStatusBar().SetStatusText('Frame mask active - LB pick next point, RB close polygon')
     1033    elif G2frame.MaskKey == 'p':
     1034        G2frame.dataFrame.GetStatusBar().SetStatusText('Polygon mask active - LB pick next point, RB close polygon')
     1035    elif G2frame.MaskKey == 's':
     1036        G2frame.dataFrame.GetStatusBar().SetStatusText('Spot mask active - LB pick spot location')
     1037    elif G2frame.MaskKey == 'a':
     1038        G2frame.dataFrame.GetStatusBar().SetStatusText('Arc mask active - LB pick arc location')
     1039    elif G2frame.MaskKey == 'r':
     1040        G2frame.dataFrame.GetStatusBar().SetStatusText('Ring mask active - LB pick ring location')
    10131041    else:
    10141042        G2frame.dataFrame.GetStatusBar().SetStatusText("To add mask: On 2D Powder Image, key a:arc, r:ring, s:spot, p:polygon, f:frame")
     
    10611089            wx.ALIGN_CENTER_VERTICAL)
    10621090        littleSizer.Add((5,0),0)
    1063         for x,y,d in spots:
    1064             spotText = wx.TextCtrl(parent=G2frame.dataDisplay,value=("%.2f,%.2f" % (x,y)),
    1065                 style=wx.TE_READONLY)
    1066             spotText.SetBackgroundColour(VERY_LIGHT_GREY)
    1067             littleSizer.Add(spotText,0,wx.ALIGN_CENTER_VERTICAL)
    1068             spotText.Bind(wx.EVT_ENTER_WINDOW,OnTextMsg)
    1069             spotDiameter = wx.TextCtrl(parent=G2frame.dataDisplay,value=("%.2f" % (d)),
    1070                 style=wx.TE_PROCESS_ENTER)
    1071             littleSizer.Add(spotDiameter,0,wx.ALIGN_CENTER_VERTICAL)
    1072             spotDiameter.Bind(wx.EVT_TEXT_ENTER,OnSpotDiameter)
    1073             spotDiameter.Bind(wx.EVT_KILL_FOCUS,OnSpotDiameter)
    1074             spotIds.append(spotDiameter.GetId())
    1075             spotDelete = wx.CheckBox(parent=G2frame.dataDisplay,label='delete?')
    1076             spotDelete.Bind(wx.EVT_CHECKBOX,OnDeleteSpot)
    1077             delSpotId.append(spotDelete)
    1078             littleSizer.Add(spotDelete,0,wx.ALIGN_CENTER_VERTICAL)
     1091        for spot in spots:
     1092            if spot:
     1093                x,y,d = spot
     1094                spotText = wx.TextCtrl(parent=G2frame.dataDisplay,value=("%.2f,%.2f" % (x,y)),
     1095                    style=wx.TE_READONLY)
     1096                spotText.SetBackgroundColour(VERY_LIGHT_GREY)
     1097                littleSizer.Add(spotText,0,wx.ALIGN_CENTER_VERTICAL)
     1098                spotText.Bind(wx.EVT_ENTER_WINDOW,OnTextMsg)
     1099                spotDiameter = wx.TextCtrl(parent=G2frame.dataDisplay,value=("%.2f" % (d)),
     1100                    style=wx.TE_PROCESS_ENTER)
     1101                littleSizer.Add(spotDiameter,0,wx.ALIGN_CENTER_VERTICAL)
     1102                spotDiameter.Bind(wx.EVT_TEXT_ENTER,OnSpotDiameter)
     1103                spotDiameter.Bind(wx.EVT_KILL_FOCUS,OnSpotDiameter)
     1104                spotIds.append(spotDiameter.GetId())
     1105                spotDelete = wx.CheckBox(parent=G2frame.dataDisplay,label='delete?')
     1106                spotDelete.Bind(wx.EVT_CHECKBOX,OnDeleteSpot)
     1107                delSpotId.append(spotDelete)
     1108                littleSizer.Add(spotDelete,0,wx.ALIGN_CENTER_VERTICAL)
    10791109        mainSizer.Add(littleSizer,0,)
    10801110    ringIds = []
     
    10911121            wx.ALIGN_CENTER_VERTICAL)
    10921122        littleSizer.Add((5,0),0)
    1093         for tth,thick in rings:
    1094             ringText = wx.TextCtrl(parent=G2frame.dataDisplay,value=("%.3f" % (tth)),
    1095                 style=wx.TE_READONLY)
    1096             ringText.SetBackgroundColour(VERY_LIGHT_GREY)
    1097             ringText.Bind(wx.EVT_ENTER_WINDOW,OnTextMsg)
    1098             littleSizer.Add(ringText,0,wx.ALIGN_CENTER_VERTICAL)
    1099             ringThick = wx.TextCtrl(parent=G2frame.dataDisplay,value=("%.3f" % (thick)),
    1100                 style=wx.TE_PROCESS_ENTER)
    1101             littleSizer.Add(ringThick,0,wx.ALIGN_CENTER_VERTICAL)
    1102             ringThick.Bind(wx.EVT_TEXT_ENTER,OnRingThickness)
    1103             ringThick.Bind(wx.EVT_KILL_FOCUS,OnRingThickness)
    1104             ringIds.append(ringThick.GetId())
    1105             ringDelete = wx.CheckBox(parent=G2frame.dataDisplay,label='delete?')
    1106             ringDelete.Bind(wx.EVT_CHECKBOX,OnDeleteRing)
    1107             delRingId.append(ringDelete)
    1108             littleSizer.Add(ringDelete,0,wx.ALIGN_CENTER_VERTICAL)
     1123        for ring in rings:
     1124            if ring:
     1125                tth,thick = ring
     1126                ringText = wx.TextCtrl(parent=G2frame.dataDisplay,value=("%.3f" % (tth)),
     1127                    style=wx.TE_READONLY)
     1128                ringText.SetBackgroundColour(VERY_LIGHT_GREY)
     1129                ringText.Bind(wx.EVT_ENTER_WINDOW,OnTextMsg)
     1130                littleSizer.Add(ringText,0,wx.ALIGN_CENTER_VERTICAL)
     1131                ringThick = wx.TextCtrl(parent=G2frame.dataDisplay,value=("%.3f" % (thick)),
     1132                    style=wx.TE_PROCESS_ENTER)
     1133                littleSizer.Add(ringThick,0,wx.ALIGN_CENTER_VERTICAL)
     1134                ringThick.Bind(wx.EVT_TEXT_ENTER,OnRingThickness)
     1135                ringThick.Bind(wx.EVT_KILL_FOCUS,OnRingThickness)
     1136                ringIds.append(ringThick.GetId())
     1137                ringDelete = wx.CheckBox(parent=G2frame.dataDisplay,label='delete?')
     1138                ringDelete.Bind(wx.EVT_CHECKBOX,OnDeleteRing)
     1139                delRingId.append(ringDelete)
     1140                littleSizer.Add(ringDelete,0,wx.ALIGN_CENTER_VERTICAL)
    11091141        mainSizer.Add(littleSizer,0,)
    11101142    arcIds = []
     
    11241156            wx.ALIGN_CENTER_VERTICAL)
    11251157        littleSizer.Add((5,0),0)
    1126         for tth,azimuth,thick in arcs:
    1127             arcText = wx.TextCtrl(parent=G2frame.dataDisplay,value=("%.3f" % (tth)),
    1128                 style=wx.TE_READONLY)
    1129             arcText.SetBackgroundColour(VERY_LIGHT_GREY)
    1130             arcText.Bind(wx.EVT_ENTER_WINDOW,OnTextMsg)
    1131             littleSizer.Add(arcText,0,wx.ALIGN_CENTER_VERTICAL)
    1132             azmText = wx.TextCtrl(parent=G2frame.dataDisplay,value=("%d,%d" % (azimuth[0],azimuth[1])),
    1133                 style=wx.TE_READONLY)
    1134             azmText.SetBackgroundColour(VERY_LIGHT_GREY)
    1135             azmText.Bind(wx.EVT_ENTER_WINDOW,OnTextMsg)
    1136             littleSizer.Add(azmText,0,wx.ALIGN_CENTER_VERTICAL)
    1137             arcThick = wx.TextCtrl(parent=G2frame.dataDisplay,value=("%.3f" % (thick)),
    1138                 style=wx.TE_PROCESS_ENTER)
    1139             littleSizer.Add(arcThick,0,wx.ALIGN_CENTER_VERTICAL)
    1140             arcThick.Bind(wx.EVT_TEXT_ENTER,OnArcThickness)
    1141             arcThick.Bind(wx.EVT_KILL_FOCUS,OnArcThickness)
    1142             arcIds.append(arcThick.GetId())
    1143             arcDelete = wx.CheckBox(parent=G2frame.dataDisplay,label='delete?')
    1144             arcDelete.Bind(wx.EVT_CHECKBOX,OnDeleteArc)
    1145             delArcId.append(arcDelete)
    1146             littleSizer.Add(arcDelete,0,wx.ALIGN_CENTER_VERTICAL)
     1158        for arc in arcs:
     1159            if arc:
     1160                tth,azimuth,thick = arc
     1161                arcText = wx.TextCtrl(parent=G2frame.dataDisplay,value=("%.3f" % (tth)),
     1162                    style=wx.TE_READONLY)
     1163                arcText.SetBackgroundColour(VERY_LIGHT_GREY)
     1164                arcText.Bind(wx.EVT_ENTER_WINDOW,OnTextMsg)
     1165                littleSizer.Add(arcText,0,wx.ALIGN_CENTER_VERTICAL)
     1166                azmText = wx.TextCtrl(parent=G2frame.dataDisplay,value=("%d,%d" % (azimuth[0],azimuth[1])),
     1167                    style=wx.TE_READONLY)
     1168                azmText.SetBackgroundColour(VERY_LIGHT_GREY)
     1169                azmText.Bind(wx.EVT_ENTER_WINDOW,OnTextMsg)
     1170                littleSizer.Add(azmText,0,wx.ALIGN_CENTER_VERTICAL)
     1171                arcThick = wx.TextCtrl(parent=G2frame.dataDisplay,value=("%.3f" % (thick)),
     1172                    style=wx.TE_PROCESS_ENTER)
     1173                littleSizer.Add(arcThick,0,wx.ALIGN_CENTER_VERTICAL)
     1174                arcThick.Bind(wx.EVT_TEXT_ENTER,OnArcThickness)
     1175                arcThick.Bind(wx.EVT_KILL_FOCUS,OnArcThickness)
     1176                arcIds.append(arcThick.GetId())
     1177                arcDelete = wx.CheckBox(parent=G2frame.dataDisplay,label='delete?')
     1178                arcDelete.Bind(wx.EVT_CHECKBOX,OnDeleteArc)
     1179                delArcId.append(arcDelete)
     1180                littleSizer.Add(arcDelete,0,wx.ALIGN_CENTER_VERTICAL)
    11471181        mainSizer.Add(littleSizer,0,)
    11481182    polyIds = []
  • trunk/GSASIIobj.py

    r1127 r1128  
    148148  \         F000N            neutron F(000) intensity (float)
    149149  \         Mydir            directory of current .gpx file (str)
    150   \         MCSA controls    ?
    151   \         Cell             List with 7 items: cell refinement flag (bool)
     150  \         MCSA controls    Monte Carlo-Simulated Annealing controls (dict)
     151  \         Cell             List with 8 items: cell refinement flag (bool)
    152152                             a, b, c, (Angstrom, float)
    153153                             alpha, beta & gamma (degrees, float)
    154   \         Type             for now 'nuclear' (str)
     154                             volume (A^3, float)
     155  \         Type             'nuclear' or 'macromolecular' for now (str)
    155156  \         Map              dict of map parameters
    156157  \         SH Texture       dict of spherical harmonic preferred orientation
     
    164165  \         Pawley neg wt    Restraint value for negative Pawley intensities
    165166                             (float)
    166   \         Flip             Charge flip controls dict?
    167   \         Data plot type   ?
     167  \         Flip             dict of Charge flip controls
     168  \         Data plot type   data plot type ('Mustrain', 'Size' or
     169                             'Preferred orientation') for powder data (str)
    168170  \         Mass             Mass of unit cell contents in g/mol
    169171  \         POhkl            March-Dollase preferred orientation direction
    170   \         Z                ?
    171   \         vdWRadii         ?
     172  \         Z                dict of atomic numbers for each atom type
     173  \         vdWRadii         dict of van der Waals radii for each atom type
    172174  \         Color            Colors for atoms (list of (r,b,g) triplets)
    173175  \         AtomTypes        List of atom types
     
    198200\           ballScale        Size of spheres in ball-and-stick display (float)
    199201\           bondList         dict with bonds
    200 \           contourLevel     ? (float)
     202\           contourLevel     map contour level in e/A^3 (float)
    201203\           showABC          Flag to show view point triplet (bool). True=show.
    202204\           viewDir          cartesian viewing direction (np.array with three
     
    210212\           sizeH            Size ratio for H atoms (float)
    211213\           bondRadius       Size of binds in A (float)
    212 \           atomPtrs         ? (list)
     214\           atomPtrs         positions of x, type, site sym, ADP flag in Draw Atoms (list)
    213215\           viewPoint        list of lists. First item in list is [x,y,z]
    214216                             in fractional coordinates for the center of
    215                              the plot. Second item ?.
     217                             the plot. Second item list of previous & current
     218                             atom number viewed (may be [0,0])
    216219\           showHydrogen     Flag to control plotting of H atoms.
    217220\           unitCellBox      Flag to control display of the unit cell.
     
    227230                             are located that are within r(Ra+Rb) and (Ra+Rb)/r
    228231                             where Ra and Rb are the atomic radii.
    229 \           oldxy            ? (list with two floats)
     232\           oldxy            previous view point (list with two floats)
    230233\           cameraPos        Viewing position in A for plot (float)
    231 \           depthFog         ? (bool)
     234\           depthFog         True if use depthFog on plot - set currently as False (bool)
    232235RBModels        \            Rigid body assignments (note Rigid body definitions
    233236                             are stored in their own main top-level tree entry.)
     
    238241                             parameters for items such as scale factors,
    239242                             size and strain parameters. (dict)
    240 MCSA            \            Monte-Carlo simulated annealing parameters
     243MCSA            \            Monte-Carlo simulated annealing parameters (dict)
     244\           
    241245==========  ===============  ====================================================
    242246
     
    304308``phasedict['Atoms']``. Also needed to read atom information
    305309are four pointers, ``cx,ct,cs,cia = phasedict['General']['AtomPtrs']``,
    306 which define locations in the atom record, as shown below.
     310which define locations in the atom record, as shown below. Items shown are
     311always present; additional ones for macromolecular phases are marked 'mm'
    307312
    308313.. tabularcolumns:: |l|p{4.5in}|
     
    313318cx,cx+1,cx+2      the x,y and z coordinates
    314319cx+3              fractional occupancy (also cs-1)
     320ct-4              (mm) residue number (str)
     321ct-3              (mm) residue name (e.g. ALA) (str)
     322ct-2              (mm) chain label (str)
    315323ct-1              atom label
    316324ct                atom type
  • trunk/GSASIIplot.py

    r1124 r1128  
    20832083        PlotIntegration(G2frame,newPlot,event)
    20842084
    2085 def OnStartMask(G2frame,eventkey):
     2085def OnStartMask(G2frame):
    20862086    '''Initiate the start of a Frame or Polygon map
    20872087
     
    20922092    Masks = G2frame.PatternTree.GetItemPyData(
    20932093        G2gd.GetPatternTreeItemId(G2frame,G2frame.Image, 'Masks'))
    2094     if eventkey == 'f':
    2095         G2frame.setFrame = True
     2094    if G2frame.MaskKey == 'f':
    20962095        Masks['Frames'] = []
    2097         G2frame.G2plotNB.status.SetFields(['','Frame mask active - LB pick next point, RB close polygon'])
    2098     elif eventkey == 'p':
    2099         G2frame.setPoly = True
     2096    elif G2frame.MaskKey == 'p':
    21002097        Masks['Polygons'].append([])
    2101         G2frame.G2plotNB.status.SetFields(['','Polygon mask active - LB pick next point, RB close polygon'])
     2098    elif G2frame.MaskKey == 's':
     2099        Masks['Points'].append([])
     2100    elif G2frame.MaskKey == 'a':
     2101        Masks['Arcs'].append([])
     2102    elif G2frame.MaskKey == 'r':
     2103        Masks['Rings'].append([])
    21022104    G2imG.UpdateMasks(G2frame,Masks)
    21032105    PlotImage(G2frame,newImage=True)
     
    21532155                tth,azm,dsp = G2img.GetTthAzmDsp(xpos,ypos,Data)
    21542156                Q = 2.*math.pi/dsp
    2155                 if G2frame.setPoly or G2frame.setFrame:
     2157                if G2frame.MaskKey in ['p','f']:
    21562158                    G2frame.G2plotNB.status.SetFields(['','Polygon/frame mask pick - LB next point, RB close polygon'])
    21572159                else:
     
    21652167            return
    21662168        if PickName == 'Masks':
    2167             Xpos = event.xdata
    2168             if not Xpos:            #got point out of frame
    2169                 return
    2170             Ypos = event.ydata
    2171             if event.key == 's':
    2172                 Masks['Points'].append([Xpos,Ypos,1.])
    2173             elif event.key == 'r':
    2174                 tth = G2img.GetTth(Xpos,Ypos,Data)
    2175                 Masks['Rings'].append([tth,0.1])
    2176             elif event.key == 'a':
    2177                 tth,azm = G2img.GetTthAzm(Xpos,Ypos,Data)
    2178                 azm = int(azm)               
    2179                 Masks['Arcs'].append([tth,[azm-5,azm+5],0.1])
    2180             elif event.key == 'p':
    2181                 OnStartMask(G2frame,event.key)
    2182                 #G2frame.setPoly = True
    2183                 #Masks['Polygons'].append([])
    2184                 #G2frame.G2plotNB.status.SetFields(['','Polygon mask active - LB pick next point, RB close polygon'])
    2185             elif event.key == 'f':
    2186                 OnStartMask(G2frame,event.key)
    2187                 #G2frame.setFrame = True
    2188                 #Masks['Frames'] = []
    2189                 #G2frame.G2plotNB.status.SetFields(['','Frame mask active - LB pick next point, RB close polygon'])
    2190             G2imG.UpdateMasks(G2frame,Masks)
     2169            if event.key in ['p','f','s','a','r']:
     2170                G2frame.MaskKey = event.key
     2171                OnStartMask(G2frame)
     2172               
    21912173        elif PickName == 'Image Controls':
    21922174            if event.key == 'c':
     
    22222204        if G2frame.PatternTree.GetItemText(G2frame.PickId) not in ['Image Controls','Masks']:
    22232205            return
    2224         if G2frame.setPoly:
    2225             polygon = Masks['Polygons'][-1]
    2226             xpos,ypos = event.mouseevent.xdata,event.mouseevent.ydata
    2227             if xpos and ypos:                       #point inside image
    2228                 if len(polygon) > 2 and event.mouseevent.button == 3:
    2229                     x0,y0 = polygon[0]
    2230                     polygon.append([x0,y0])
    2231                     G2frame.setPoly = False
    2232                     G2frame.G2plotNB.status.SetFields(['','Polygon closed - RB drag a vertex to change shape'])
    2233                 else:
    2234                     G2frame.G2plotNB.status.SetFields(['','New polygon point: %.1f,%.1f'%(xpos,ypos)])
    2235                     polygon.append([xpos,ypos])
    2236                 G2imG.UpdateMasks(G2frame,Masks)
    2237         elif G2frame.setFrame:
    2238             frame = Masks['Frames']
    2239             xpos,ypos = event.mouseevent.xdata,event.mouseevent.ydata
    2240             if xpos and ypos:                       #point inside image
    2241                 if len(frame) > 2 and event.mouseevent.button == 3:
    2242                     x0,y0 = frame[0]
    2243                     frame.append([x0,y0])
    2244                     G2frame.setFrame = False
    2245                     G2frame.G2plotNB.status.SetFields(['','Frame closed - RB drag a vertex to change shape'])
    2246                 else:
    2247                     G2frame.G2plotNB.status.SetFields(['','New frame point: %.1f,%.1f'%(xpos,ypos)])
    2248                     frame.append([xpos,ypos])
    2249                 G2imG.UpdateMasks(G2frame,Masks)
    2250         else:
    2251             if G2frame.itemPicked is not None: return
    2252             G2frame.itemPicked = event.artist
    2253             G2frame.mousePicked = event.mouseevent
     2206        if G2frame.itemPicked is not None: return
     2207        G2frame.itemPicked = event.artist
     2208        G2frame.mousePicked = event.mouseevent
    22542209       
    22552210    def OnImRelease(event):
     
    22652220        pixLimit = Data['pixLimit']
    22662221        if G2frame.itemPicked is None and PickName == 'Image Controls' and len(G2frame.ImageZ):
    2267 #            sizexy = Data['size']
    22682222            Xpos = event.xdata
    22692223            if not (Xpos and G2frame.ifGetRing):                   #got point out of frame
     
    22942248                PlotImage(G2frame,newImage=False)
    22952249            return
     2250        elif G2frame.MaskKey and PickName == 'Masks':
     2251            Xpos,Ypos = [event.xdata,event.ydata]
     2252            if not Xpos or not Ypos or Page.toolbar._active:  #got point out of frame or zoom/pan selected
     2253                return
     2254            if G2frame.MaskKey == 's' and event.button == 1:
     2255                Masks['Points'][-1] = [Xpos,Ypos,1.]
     2256                G2frame.MaskKey = ''               
     2257            elif G2frame.MaskKey == 'r' and event.button == 1:
     2258                tth = G2img.GetTth(Xpos,Ypos,Data)
     2259                Masks['Rings'][-1] = [tth,0.1]
     2260                G2frame.MaskKey = ''               
     2261            elif G2frame.MaskKey == 'a' and event.button == 1:
     2262                tth,azm = G2img.GetTthAzm(Xpos,Ypos,Data)
     2263                azm = int(azm)               
     2264                Masks['Arcs'][-1] = [tth,[azm-5,azm+5],0.1]
     2265                G2frame.MaskKey = ''               
     2266            elif G2frame.MaskKey =='p':
     2267                polygon = Masks['Polygons'][-1]
     2268                if len(polygon) > 2 and event.mouseevent.button == 3:
     2269                    x0,y0 = polygon[0]
     2270                    polygon.append([x0,y0])
     2271                    G2frame.MaskKey = ''
     2272                    G2frame.G2plotNB.status.SetFields(['','Polygon closed - RB drag a vertex to change shape'])
     2273                else:
     2274                    G2frame.G2plotNB.status.SetFields(['','New polygon point: %.1f,%.1f'%(Xpos,Ypos)])
     2275                    polygon.append([Xpos,Ypos])
     2276            elif G2frame.MaskKey =='f':
     2277                frame = Masks['Frames']
     2278                if len(frame) > 2 and event.mouseevent.button == 3:
     2279                    x0,y0 = frame[0]
     2280                    frame.append([x0,y0])
     2281                    G2frame.MaskKey = ''
     2282                    G2frame.G2plotNB.status.SetFields(['','Frame closed - RB drag a vertex to change shape'])
     2283                else:
     2284                    G2frame.G2plotNB.status.SetFields(['','New frame point: %.1f,%.1f'%(Xpos,Ypos)])
     2285                    frame.append([Xpos,Ypos])
     2286            G2imG.UpdateMasks(G2frame,Masks)
     2287            PlotImage(G2frame,newImage=False)
    22962288        else:
    2297             xpos = event.xdata
    2298             if xpos:                                        #avoid out of frame mouse position
    2299                 ypos = event.ydata
    2300                 if G2frame.ifGetRing:                          #delete a calibration ring pick
    2301                     xypos = [xpos,ypos]
    2302                     rings = Data['ring']
    2303                     for ring in rings:
    2304                         if np.allclose(ring,xypos,.01,0):
    2305                             rings.remove(ring)                                                                       
    2306                 else:
    2307                     tth,azm,dsp = G2img.GetTthAzmDsp(xpos,ypos,Data)
    2308                     itemPicked = str(G2frame.itemPicked)
    2309                     if 'Line2D' in itemPicked and PickName == 'Image Controls':
    2310                         if 'line1' in itemPicked:
    2311                             Data['IOtth'][0] = max(tth,0.001)
    2312                         elif 'line2' in itemPicked:
    2313                             Data['IOtth'][1] = tth
    2314                         elif 'line3' in itemPicked:
    2315                             Data['LRazimuth'][0] = int(azm)
    2316                             if Data['fullIntegrate']:
    2317                                 Data['LRazimuth'][1] = Data['LRazimuth'][0]+360
    2318                         elif 'line4' in itemPicked and not Data['fullIntegrate']:
    2319                             Data['LRazimuth'][1] = int(azm)
    2320                            
    2321                         if Data['LRazimuth'][0] > Data['LRazimuth'][1]:
    2322                             Data['LRazimuth'][0] -= 360
    2323                            
    2324                         azLim = np.array(Data['LRazimuth'])   
    2325                         if np.any(azLim>360):
    2326                             azLim -= 360
    2327                             Data['LRazimuth'] = list(azLim)
    2328                            
    2329                         if  Data['IOtth'][0] > Data['IOtth'][1]:
    2330                             Data['IOtth'][0],Data['IOtth'][1] = Data['IOtth'][1],Data['IOtth'][0]
    2331                            
    2332                         G2frame.InnerTth.SetValue("%8.2f" % (Data['IOtth'][0]))
    2333                         G2frame.OuterTth.SetValue("%8.2f" % (Data['IOtth'][1]))
    2334                         G2frame.Lazim.SetValue("%6d" % (Data['LRazimuth'][0]))
    2335                         G2frame.Razim.SetValue("%6d" % (Data['LRazimuth'][1]))
    2336                     elif 'Circle' in itemPicked and PickName == 'Masks':
    2337                         spots = Masks['Points']
    2338                         newPos = itemPicked.split(')')[0].split('(')[2].split(',')
    2339                         newPos = np.array([float(newPos[0]),float(newPos[1])])
    2340                         for spot in spots:
    2341                             if np.allclose(np.array([spot[:2]]),newPos):
    2342                                 spot[:2] = xpos,ypos
    2343                         G2imG.UpdateMasks(G2frame,Masks)
    2344                     elif 'Line2D' in itemPicked and PickName == 'Masks':
    2345                         Obj = G2frame.itemPicked.findobj()
    2346                         rings = Masks['Rings']
    2347                         arcs = Masks['Arcs']
    2348                         polygons = Masks['Polygons']
    2349                         frame = Masks['Frames']
    2350                         for ring in G2frame.ringList:
    2351                             if Obj == ring[0]:
    2352                                 rN = ring[1]
    2353                                 if ring[2] == 'o':
    2354                                     rings[rN][0] = G2img.GetTth(xpos,ypos,Data)-rings[rN][1]/2.
    2355                                 else:
    2356                                     rings[rN][0] = G2img.GetTth(xpos,ypos,Data)+rings[rN][1]/2.
    2357                         for arc in G2frame.arcList:
    2358                             if Obj == arc[0]:
    2359                                 aN = arc[1]
    2360                                 if arc[2] == 'o':
    2361                                     arcs[aN][0] = G2img.GetTth(xpos,ypos,Data)-arcs[aN][2]/2
    2362                                 elif arc[2] == 'i':
    2363                                     arcs[aN][0] = G2img.GetTth(xpos,ypos,Data)+arcs[aN][2]/2
    2364                                 elif arc[2] == 'l':
    2365                                     arcs[aN][1][0] = int(G2img.GetAzm(xpos,ypos,Data))
    2366                                 else:
    2367                                     arcs[aN][1][1] = int(G2img.GetAzm(xpos,ypos,Data))
    2368                         for poly in G2frame.polyList:
    2369                             if Obj == poly[0]:
    2370                                 ind = G2frame.itemPicked.contains(G2frame.mousePicked)[1]['ind'][0]
    2371                                 oldPos = np.array([G2frame.mousePicked.xdata,G2frame.mousePicked.ydata])
    2372                                 pN = poly[1]
    2373                                 for i,xy in enumerate(polygons[pN]):
    2374                                     if np.allclose(np.array([xy]),oldPos,atol=1.0):
    2375                                         polygons[pN][i] = xpos,ypos
    2376                         if frame:
     2289            Xpos,Ypos = [event.xdata,event.ydata]
     2290            if not Xpos or not Ypos or Page.toolbar._active:  #got point out of frame or zoom/pan selected
     2291                return
     2292            if G2frame.ifGetRing:                          #delete a calibration ring pick
     2293                xypos = [Xpos,Ypos]
     2294                rings = Data['ring']
     2295                for ring in rings:
     2296                    if np.allclose(ring,xypos,.01,0):
     2297                        rings.remove(ring)
     2298            else:
     2299                tth,azm,dsp = G2img.GetTthAzmDsp(Xpos,Ypos,Data)
     2300                itemPicked = str(G2frame.itemPicked)
     2301                if 'Line2D' in itemPicked and PickName == 'Image Controls':
     2302                    if 'line1' in itemPicked:
     2303                        Data['IOtth'][0] = max(tth,0.001)
     2304                    elif 'line2' in itemPicked:
     2305                        Data['IOtth'][1] = tth
     2306                    elif 'line3' in itemPicked:
     2307                        Data['LRazimuth'][0] = int(azm)
     2308                        if Data['fullIntegrate']:
     2309                            Data['LRazimuth'][1] = Data['LRazimuth'][0]+360
     2310                    elif 'line4' in itemPicked and not Data['fullIntegrate']:
     2311                        Data['LRazimuth'][1] = int(azm)
     2312                       
     2313                    if Data['LRazimuth'][0] > Data['LRazimuth'][1]:
     2314                        Data['LRazimuth'][0] -= 360
     2315                       
     2316                    azLim = np.array(Data['LRazimuth'])   
     2317                    if np.any(azLim>360):
     2318                        azLim -= 360
     2319                        Data['LRazimuth'] = list(azLim)
     2320                       
     2321                    if  Data['IOtth'][0] > Data['IOtth'][1]:
     2322                        Data['IOtth'][0],Data['IOtth'][1] = Data['IOtth'][1],Data['IOtth'][0]
     2323                       
     2324                    G2frame.InnerTth.SetValue("%8.2f" % (Data['IOtth'][0]))
     2325                    G2frame.OuterTth.SetValue("%8.2f" % (Data['IOtth'][1]))
     2326                    G2frame.Lazim.SetValue("%6d" % (Data['LRazimuth'][0]))
     2327                    G2frame.Razim.SetValue("%6d" % (Data['LRazimuth'][1]))
     2328                elif 'Circle' in itemPicked and PickName == 'Masks':
     2329                    spots = Masks['Points']
     2330                    newPos = itemPicked.split(')')[0].split('(')[2].split(',')
     2331                    newPos = np.array([float(newPos[0]),float(newPos[1])])
     2332                    for spot in spots:
     2333                        if np.allclose(np.array([spot[:2]]),newPos):
     2334                            spot[:2] = Xpos,Ypos
     2335                    G2imG.UpdateMasks(G2frame,Masks)
     2336                elif 'Line2D' in itemPicked and PickName == 'Masks':
     2337                    Obj = G2frame.itemPicked.findobj()
     2338                    rings = Masks['Rings']
     2339                    arcs = Masks['Arcs']
     2340                    polygons = Masks['Polygons']
     2341                    frame = Masks['Frames']
     2342                    for ring in G2frame.ringList:
     2343                        if Obj == ring[0]:
     2344                            rN = ring[1]
     2345                            if ring[2] == 'o':
     2346                                rings[rN][0] = G2img.GetTth(Xpos,Ypos,Data)-rings[rN][1]/2.
     2347                            else:
     2348                                rings[rN][0] = G2img.GetTth(Xpos,Ypos,Data)+rings[rN][1]/2.
     2349                    for arc in G2frame.arcList:
     2350                        if Obj == arc[0]:
     2351                            aN = arc[1]
     2352                            if arc[2] == 'o':
     2353                                arcs[aN][0] = G2img.GetTth(Xpos,Ypos,Data)-arcs[aN][2]/2
     2354                            elif arc[2] == 'i':
     2355                                arcs[aN][0] = G2img.GetTth(Xpos,Ypos,Data)+arcs[aN][2]/2
     2356                            elif arc[2] == 'l':
     2357                                arcs[aN][1][0] = int(G2img.GetAzm(Xpos,Ypos,Data))
     2358                            else:
     2359                                arcs[aN][1][1] = int(G2img.GetAzm(Xpos,Ypos,Data))
     2360                    for poly in G2frame.polyList:
     2361                        if Obj == poly[0]:
     2362                            ind = G2frame.itemPicked.contains(G2frame.mousePicked)[1]['ind'][0]
    23772363                            oldPos = np.array([G2frame.mousePicked.xdata,G2frame.mousePicked.ydata])
    2378                             for i,xy in enumerate(frame):
     2364                            pN = poly[1]
     2365                            for i,xy in enumerate(polygons[pN]):
    23792366                                if np.allclose(np.array([xy]),oldPos,atol=1.0):
    2380                                     frame[i] = xpos,ypos
    2381                         G2imG.UpdateMasks(G2frame,Masks)
    2382 #                    else:                  #keep for future debugging
    2383 #                        print str(G2frame.itemPicked),event.xdata,event.ydata,event.button
    2384                 PlotImage(G2frame,newImage=True)
     2367                                    polygons[pN][i] = Xpos,Ypos
     2368                    if frame:
     2369                        oldPos = np.array([G2frame.mousePicked.xdata,G2frame.mousePicked.ydata])
     2370                        for i,xy in enumerate(frame):
     2371                            if np.allclose(np.array([xy]),oldPos,atol=1.0):
     2372                                frame[i] = Xpos,Ypos
     2373                    G2imG.UpdateMasks(G2frame,Masks)
     2374#                else:                  #keep for future debugging
     2375#                    print str(G2frame.itemPicked),event.xdata,event.ydata,event.button
     2376            PlotImage(G2frame,newImage=True)
    23852377            G2frame.itemPicked = None
    23862378           
     
    24172409                Page.Choice[1] = 'l: log(I) off'
    24182410            Page.keyPress = OnImPlotKeyPress
     2411        elif G2frame.PatternTree.GetItemText(G2frame.PickId) in ['Masks',]:
     2412            Page.Choice = (' key press','s: spot mask','a: arc mask','r: ring mask',
     2413                'p: polygon mask','f: frame mask',)
     2414            Page.keyPress = OnImPlotKeyPress
    24192415    except TypeError:
    24202416        pass
     
    24632459            Img = Plot.imshow(A,aspect='equal',cmap=acolor,
    24642460                interpolation='nearest',vmin=Imin,vmax=Imax,extent=[0,Xmax,Ymax,0])
    2465             if G2frame.setPoly or G2frame.setFrame:
    2466                 Img.set_picker(True)
    24672461   
    24682462        Plot.plot(xcent,ycent,'x')
     
    25342528            Masks['Frames'] = []
    25352529        frame = Masks['Frames']
    2536         for x,y,d in spots:
    2537             Plot.add_artist(Circle((x,y),radius=d/2,fc='none',ec='r',picker=3))
     2530        for spot in spots:
     2531            if spot:
     2532                x,y,d = spot
     2533                Plot.add_artist(Circle((x,y),radius=d/2,fc='none',ec='r',picker=3))
    25382534        G2frame.ringList = []
    2539         for iring,(tth,thick) in enumerate(rings):
    2540             wave = Data['wavelength']
    2541             x1,y1 = np.hsplit(np.array(G2img.makeIdealRing(G2img.GetEllipse(Dsp(tth+thick/2.,wave),Data))),2)
    2542             x2,y2 = np.hsplit(np.array(G2img.makeIdealRing(G2img.GetEllipse(Dsp(tth-thick/2.,wave),Data))),2)
    2543             G2frame.ringList.append([Plot.plot(x1,y1,'r',picker=3),iring,'o'])           
    2544             G2frame.ringList.append([Plot.plot(x2,y2,'r',picker=3),iring,'i'])
     2535        for iring,ring in enumerate(rings):
     2536            if ring:
     2537                tth,thick = ring
     2538                wave = Data['wavelength']
     2539                x1,y1 = np.hsplit(np.array(G2img.makeIdealRing(G2img.GetEllipse(Dsp(tth+thick/2.,wave),Data))),2)
     2540                x2,y2 = np.hsplit(np.array(G2img.makeIdealRing(G2img.GetEllipse(Dsp(tth-thick/2.,wave),Data))),2)
     2541                G2frame.ringList.append([Plot.plot(x1,y1,'r',picker=3),iring,'o'])           
     2542                G2frame.ringList.append([Plot.plot(x2,y2,'r',picker=3),iring,'i'])
    25452543        G2frame.arcList = []
    2546         for iarc,(tth,azm,thick) in enumerate(arcs):           
    2547             wave = Data['wavelength']
    2548             x1,y1 = np.hsplit(np.array(G2img.makeIdealRing(G2img.GetEllipse(Dsp(tth+thick/2.,wave),Data),azm)),2)
    2549             x2,y2 = np.hsplit(np.array(G2img.makeIdealRing(G2img.GetEllipse(Dsp(max(0.01,tth-thick/2.),wave),Data),azm)),2)
    2550             G2frame.arcList.append([Plot.plot(x1,y1,'r',picker=3),iarc,'o'])           
    2551             G2frame.arcList.append([Plot.plot(x2,y2,'r',picker=3),iarc,'i'])
    2552             G2frame.arcList.append([Plot.plot([x1[0],x2[0]],[y1[0],y2[0]],'r',picker=3),iarc,'l'])
    2553             G2frame.arcList.append([Plot.plot([x1[-1],x2[-1]],[y1[-1],y2[-1]],'r',picker=3),iarc,'u'])
     2544        for iarc,arc in enumerate(arcs):
     2545            if arc:
     2546                tth,azm,thick = arc           
     2547                wave = Data['wavelength']
     2548                x1,y1 = np.hsplit(np.array(G2img.makeIdealRing(G2img.GetEllipse(Dsp(tth+thick/2.,wave),Data),azm)),2)
     2549                x2,y2 = np.hsplit(np.array(G2img.makeIdealRing(G2img.GetEllipse(Dsp(max(0.01,tth-thick/2.),wave),Data),azm)),2)
     2550                G2frame.arcList.append([Plot.plot(x1,y1,'r',picker=3),iarc,'o'])           
     2551                G2frame.arcList.append([Plot.plot(x2,y2,'r',picker=3),iarc,'i'])
     2552                G2frame.arcList.append([Plot.plot([x1[0],x2[0]],[y1[0],y2[0]],'r',picker=3),iarc,'l'])
     2553                G2frame.arcList.append([Plot.plot([x1[-1],x2[-1]],[y1[-1],y2[-1]],'r',picker=3),iarc,'u'])
    25542554        G2frame.polyList = []
    25552555        for ipoly,polygon in enumerate(polygons):
    2556             x,y = np.hsplit(np.array(polygon),2)
    2557             G2frame.polyList.append([Plot.plot(x,y,'r+',picker=10),ipoly])
    2558             Plot.plot(x,y,'r')           
     2556            if polygon:
     2557                x,y = np.hsplit(np.array(polygon),2)
     2558                G2frame.polyList.append([Plot.plot(x,y,'r+',picker=10),ipoly])
     2559                Plot.plot(x,y,'r')           
    25592560        G2frame.frameList = []
    25602561        if frame:
Note: See TracChangeset for help on using the changeset viewer.