Ignore:
Timestamp:
08/03/10 11:41:13 (14 years ago)
Author:
Malte Marquarding
Message:

Tidy up of imports (now imported from asap.). Also fixed some whitespace/tab issues

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/python/casatoolbar.py

    r1819 r1826  
    1010
    1111    ### select the nearest spectrum in pick radius
    12     ###    and display spectral value on the toolbar. 
     12    ###    and display spectral value on the toolbar.
    1313    def _select_spectrum(self,event):
    1414        # Do not fire event when in zooming/panning mode
    1515        mode = self.figmgr.toolbar.mode
    16         if not mode =='':
    17                 return
    18         # When selected point is out of panels
     16        if not mode == '':
     17            return
     18            # When selected point is out of panels
    1919        if event.inaxes == None:
    20                 return
     20            return
    2121        # If not left button
    2222        if event.button != 1:
    23                 return
     23            return
    2424
    2525        xclick=event.xdata
     
    2727        dist2=1000.
    2828        pickline=None
    29         # If the pannel has picable objects
    30         pflag=False
     29        # If the pannel has picable objects
     30        pflag=False
    3131        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
    5255        del pind, inds, xlin, ylin
    53         # Spectra are Picked
     56        # Spectra are Picked
    5457        theplot = self.plotter._plotter
    55         thetoolbar = self.figmgr.toolbar
    56         thecanvas = self.figmgr.canvas
    57         # Disconnect the default motion notify event
    58         # Notice! the other buttons are also diabled!!!
    59         thecanvas.mpl_disconnect(thetoolbar._idDrag)
     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)
    6063        # Get picked spectrum
    6164        xdata = pickline.get_xdata()
     
    6467        titp=event.inaxes.title.get_text()
    6568        panel0=event.inaxes
    66         picked="Selected: '"+titl+"' in panel '"+titp+"'."
    67         thetoolbar.set_message(picked)
    68         # Generate a navigation window
     69        picked="Selected: '"+titl+"' in panel '"+titp+"'."
     70        thetoolbar.set_message(picked)
     71        # Generate a navigation window
    6972        #naviwin=Navigationwindow(titp,titl)
    7073        #------------------------------------------------------#
    7174        # Show spectrum data at mouse position
    7275        def spec_data(event):
    73                 # Getting spectrum data of neiboring point
    74                 xclick=event.xdata
    75                 if event.inaxes != panel0:
    76                         return
    77                 ipoint=len(xdata)-1
    78                 for i in range(len(xdata)-1):
    79                         xl=xclick-xdata[i]
    80                         xr=xclick-xdata[i+1]
    81                         if xl*xr <= 0.:
    82                                 ipoint = i
    83                                 break
    84                 # Output spectral value on the navigation window
    85                 posi='[ %s, %s ]:  x = %.2f   value = %.2f'\
    86                       %(titl,titp,xdata[ipoint],ydata[ipoint])
    87                 #naviwin.posi.set(posi)
    88                 thetoolbar.set_message(posi)
     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)
    8992        #------------------------------------------------------#
    9093        # Disconnect from mouse events
    9194        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
    98102        #------------------------------------------------------#
    99103        # Show data value along with mouse movement
    100         theplot.register('motion_notify',spec_data)
     104        theplot.register('motion_notify',spec_data)
    101105        # Finish events when mouse button is released
    102106        theplot.register('button_release',discon)
    103107
    104108
    105     ### Calculate statistics of the selected area. 
     109    ### Calculate statistics of the selected area.
    106110    def _single_mask(self,event):
    107111        # 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
    109114        # When selected point is out of panels
    110115        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
    127135        from asap.interactivemask import interactivemask
    128         mymask=interactivemask(plotter=self.plotter,scan=self.plotter._data)
    129         # Create initial mask
    130         mymask.set_basemask(invert=baseinv)
    131         # Inherit event
    132         mymask.set_startevent(event)
    133         # Set callback func
    134         mymask.set_callback(_calc_stats)
    135         # Selected mask
    136         mymask.select_mask(once=True,showmask=False)
     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)
    137145
    138146#####################################
     
    140148#####################################
    141149### TkAgg
    142 if matplotlib.get_backend() == 'TkAgg': import Tkinter as Tk
     150if matplotlib.get_backend() == 'TkAgg':
     151    import Tkinter as Tk
     152
    143153class CustomToolbarTkAgg(CustomToolbarCommon, Tk.Frame):
    144154    def __init__(self,parent):
    145155        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
    148160        self._p=parent._plotter
    149161        self.figmgr=self._p.figmgr
     
    172184
    173185    def _NewButton(self, master, text, command, side=Tk.LEFT):
    174         if(os.uname()[0] == 'Darwin'):
     186        if os.uname()[0] == 'Darwin':
    175187            b = Tk.Button(master=master, text=text, command=command)
    176188        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)
    178191        b.pack(side=side)
    179192        return b
    180        
     193
    181194    def spec_show(self):
    182195        if not self.figmgr.toolbar.mode == '' or not self.button: return
     
    212225        self.button=True
    213226        self.spec_show()
    214        
     227
    215228    def disable_button(self):
    216229        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)
    219232        self.button=False
    220233        self.mode=''
Note: See TracChangeset for help on using the changeset viewer.