Changeset 1826 for trunk/python/casatoolbar.py
- Timestamp:
- 08/03/10 11:41:13 (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/python/casatoolbar.py
r1819 r1826 10 10 11 11 ### select the nearest spectrum in pick radius 12 ### and display spectral value on the toolbar. 12 ### and display spectral value on the toolbar. 13 13 def _select_spectrum(self,event): 14 14 # Do not fire event when in zooming/panning mode 15 15 mode = self.figmgr.toolbar.mode 16 if not mode == '':17 18 # When selected point is out of panels16 if not mode == '': 17 return 18 # When selected point is out of panels 19 19 if event.inaxes == None: 20 20 return 21 21 # If not left button 22 22 if event.button != 1: 23 23 return 24 24 25 25 xclick=event.xdata … … 27 27 dist2=1000. 28 28 pickline=None 29 30 29 # If the pannel has picable objects 30 pflag=False 31 31 for lin in event.inaxes.lines: 32 if not lin.pickable(): continue 33 pflag=True 34 flag,pind = lin.contains(event) 35 if not flag: continue 36 # Get nearest point 37 inds = pind['ind'] 38 xlin = lin.get_xdata() 39 ylin = lin.get_ydata() 40 for i in inds: 41 d2=(xlin[i]-xclick)**2+(ylin[i]-yclick)**2 42 if dist2 >= d2: 43 dist2 = d2 44 pickline = lin 45 # No pickcable line in the pannel 46 if not pflag: return 47 # Pickable but too far from mouse position 48 elif pickline is None: 49 picked='No line selected.' 50 self.figmgr.toolbar.set_message(picked) 51 return 32 if not lin.pickable(): 33 continue 34 pflag=True 35 flag,pind = lin.contains(event) 36 if not flag: 37 continue 38 # Get nearest point 39 inds = pind['ind'] 40 xlin = lin.get_xdata() 41 ylin = lin.get_ydata() 42 for i in inds: 43 d2=(xlin[i]-xclick)**2+(ylin[i]-yclick)**2 44 if dist2 >= d2: 45 dist2 = d2 46 pickline = lin 47 # No pickcable line in the pannel 48 if not pflag: 49 return 50 # Pickable but too far from mouse position 51 elif pickline is None: 52 picked='No line selected.' 53 self.figmgr.toolbar.set_message(picked) 54 return 52 55 del pind, inds, xlin, ylin 53 56 # Spectra are Picked 54 57 theplot = self.plotter._plotter 55 56 57 58 59 58 thetoolbar = self.figmgr.toolbar 59 thecanvas = self.figmgr.canvas 60 # Disconnect the default motion notify event 61 # Notice! the other buttons are also diabled!!! 62 thecanvas.mpl_disconnect(thetoolbar._idDrag) 60 63 # Get picked spectrum 61 64 xdata = pickline.get_xdata() … … 64 67 titp=event.inaxes.title.get_text() 65 68 panel0=event.inaxes 66 67 68 69 picked="Selected: '"+titl+"' in panel '"+titp+"'." 70 thetoolbar.set_message(picked) 71 # Generate a navigation window 69 72 #naviwin=Navigationwindow(titp,titl) 70 73 #------------------------------------------------------# 71 74 # Show spectrum data at mouse position 72 75 def spec_data(event): 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 76 # Getting spectrum data of neiboring point 77 xclick=event.xdata 78 if event.inaxes != panel0: 79 return 80 ipoint=len(xdata)-1 81 for i in range(len(xdata)-1): 82 xl=xclick-xdata[i] 83 xr=xclick-xdata[i+1] 84 if xl*xr <= 0.: 85 ipoint = i 86 break 87 # Output spectral value on the navigation window 88 posi='[ %s, %s ]: x = %.2f value = %.2f'\ 89 %(titl,titp,xdata[ipoint],ydata[ipoint]) 90 #naviwin.posi.set(posi) 91 thetoolbar.set_message(posi) 89 92 #------------------------------------------------------# 90 93 # Disconnect from mouse events 91 94 def discon(event): 92 #naviwin.window.destroy() 93 theplot.register('motion_notify',None) 94 # Re-activate the default motion_notify_event 95 thetoolbar._idDrag=thecanvas.mpl_connect('motion_notify_event', thetoolbar.mouse_move) 96 theplot.register('button_release',None) 97 return 95 #naviwin.window.destroy() 96 theplot.register('motion_notify',None) 97 # Re-activate the default motion_notify_event 98 thetoolbar._idDrag=thecanvas.mpl_connect('motion_notify_event', 99 thetoolbar.mouse_move) 100 theplot.register('button_release',None) 101 return 98 102 #------------------------------------------------------# 99 103 # Show data value along with mouse movement 100 104 theplot.register('motion_notify',spec_data) 101 105 # Finish events when mouse button is released 102 106 theplot.register('button_release',discon) 103 107 104 108 105 ### Calculate statistics of the selected area. 109 ### Calculate statistics of the selected area. 106 110 def _single_mask(self,event): 107 111 # Do not fire event when in zooming/panning mode 108 if not self.figmgr.toolbar.mode == '': return 112 if not self.figmgr.toolbar.mode == '': 113 return 109 114 # When selected point is out of panels 110 115 if event.inaxes == None: 111 return 112 if event.button ==1: baseinv=True 113 elif event.button == 3: baseinv=False 114 else: return 115 116 def _calc_stats(): 117 msk=mymask.get_mask() 118 mymask.scan.stats(stat='max',mask=msk) 119 mymask.scan.stats(stat='min',mask=msk) 120 mymask.scan.stats(stat='sum',mask=msk) 121 mymask.scan.stats(stat='mean',mask=msk) 122 mymask.scan.stats(stat='median',mask=msk) 123 mymask.scan.stats(stat='rms',mask=msk) 124 mymask.scan.stats(stat='stddev',mask=msk) 125 126 # Interactive mask definition 116 return 117 if event.button ==1: 118 baseinv=True 119 elif event.button == 3: 120 baseinv=False 121 else: 122 return 123 124 def _calc_stats(): 125 msk=mymask.get_mask() 126 mymask.scan.stats(stat='max',mask=msk) 127 mymask.scan.stats(stat='min',mask=msk) 128 mymask.scan.stats(stat='sum',mask=msk) 129 mymask.scan.stats(stat='mean',mask=msk) 130 mymask.scan.stats(stat='median',mask=msk) 131 mymask.scan.stats(stat='rms',mask=msk) 132 mymask.scan.stats(stat='stddev',mask=msk) 133 134 # Interactive mask definition 127 135 from asap.interactivemask import interactivemask 128 129 130 131 132 133 134 135 136 136 mymask=interactivemask(plotter=self.plotter,scan=self.plotter._data) 137 # Create initial mask 138 mymask.set_basemask(invert=baseinv) 139 # Inherit event 140 mymask.set_startevent(event) 141 # Set callback func 142 mymask.set_callback(_calc_stats) 143 # Selected mask 144 mymask.select_mask(once=True,showmask=False) 137 145 138 146 ##################################### … … 140 148 ##################################### 141 149 ### TkAgg 142 if matplotlib.get_backend() == 'TkAgg': import Tkinter as Tk 150 if matplotlib.get_backend() == 'TkAgg': 151 import Tkinter as Tk 152 143 153 class CustomToolbarTkAgg(CustomToolbarCommon, Tk.Frame): 144 154 def __init__(self,parent): 145 155 from asap.asapplotter import asapplotter 146 if not isinstance(parent,asapplotter): return False 147 if not parent._plotter: return False 156 if not isinstance(parent,asapplotter): 157 return False 158 if not parent._plotter: 159 return False 148 160 self._p=parent._plotter 149 161 self.figmgr=self._p.figmgr … … 172 184 173 185 def _NewButton(self, master, text, command, side=Tk.LEFT): 174 if (os.uname()[0] == 'Darwin'):186 if os.uname()[0] == 'Darwin': 175 187 b = Tk.Button(master=master, text=text, command=command) 176 188 else: 177 b = Tk.Button(master=master, text=text, padx=2, pady=2, command=command) 189 b = Tk.Button(master=master, text=text, padx=2, pady=2, 190 command=command) 178 191 b.pack(side=side) 179 192 return b 180 193 181 194 def spec_show(self): 182 195 if not self.figmgr.toolbar.mode == '' or not self.button: return … … 212 225 self.button=True 213 226 self.spec_show() 214 227 215 228 def disable_button(self): 216 229 if not self.button: return 217 self.bStat.config(relief='raised', state=Tk.DISABLED)218 self.bSpec.config(relief='raised', state=Tk.DISABLED)230 self.bStat.config(relief='raised', state=Tk.DISABLED) 231 self.bSpec.config(relief='raised', state=Tk.DISABLED) 219 232 self.button=False 220 233 self.mode=''
Note: See TracChangeset
for help on using the changeset viewer.