Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/python/customgui_base.py

    r2799 r2697  
    11import os
    2 import weakref
    32import matplotlib, numpy
    43from asap.logging import asaplog, asaplog_post_dec
     
    1413class CustomToolbarCommon:
    1514    def __init__(self,parent):
    16         self.plotter = weakref.ref(parent)
     15        self.plotter = parent
    1716        #self.figmgr=self.plotter._plotter.figmgr
    18 
    19     def _get_plotter(self):
    20         # check for the validity of the plotter and
    21         # return the plotter class instance if its valid.
    22         if self.plotter() is None:
    23             raise RuntimeError, "Internal Error. The plotter has been destroyed."
    24         else:
    25             return self.plotter()
    2617
    2718    ### select the nearest spectrum in pick radius
     
    3829        if event.button != 1:
    3930            return
    40 
    41         # check for the validity of plotter and get the plotter
    42         theplotter = self._get_plotter()
    4331
    4432        xclick = event.xdata
     
    7462        del pind, inds, xlin, ylin
    7563        # Spectra are Picked
    76         theplot = theplotter._plotter
     64        theplot = self.plotter._plotter
    7765        thetoolbar = self.figmgr.toolbar
    7866        thecanvas = self.figmgr.canvas
     
    166154            return
    167155
    168         # check for the validity of plotter and get the plotter
    169         theplotter = self._get_plotter()
    170 
    171156        self._thisregion = {'axes': event.inaxes,'xs': event.x,
    172157                            'worldx': [event.xdata,event.xdata],
     
    175160        self.xdataold = event.xdata
    176161
    177         theplotter._plotter.register('button_press',None)
    178         theplotter._plotter.register('motion_notify', self._xspan_draw)
    179         theplotter._plotter.register('button_press', self._xspan_end)
     162        self.plotter._plotter.register('button_press',None)
     163        self.plotter._plotter.register('motion_notify', self._xspan_draw)
     164        self.plotter._plotter.register('button_press', self._xspan_end)
    180165
    181166    def _xspan_draw(self,event):
     
    218203            xdataend = self.xdataold
    219204
    220         # check for the validity of plotter and get the plotter
    221         theplotter = self._get_plotter()
    222 
    223205        self._thisregion['worldx'][1] = xdataend
    224206        # print statistics of spectra in subplot
     
    226208       
    227209        # release event
    228         theplotter._plotter.register('button_press',None)
    229         theplotter._plotter.register('motion_notify',None)
     210        self.plotter._plotter.register('button_press',None)
     211        self.plotter._plotter.register('motion_notify',None)
    230212        # Clear up region selection
    231213        self._thisregion = None
     
    233215        self.xold = None
    234216        # finally recover region selection event
    235         theplotter._plotter.register('button_press',self._single_mask)
     217        self.plotter._plotter.register('button_press',self._single_mask)
    236218
    237219    def _subplot_stats(self,selection):
     
    339321    ### actual plotting of the new page
    340322    def _new_page(self,goback=False):
    341         # check for the validity of plotter and get the plotter
    342         theplotter = self._get_plotter()
    343 
    344323        top = None
    345         header = theplotter._headtext
     324        header = self.plotter._headtext
    346325        reset = False
    347326        doheader = (isinstance(header['textobj'],list) and \
    348327                    len(header['textobj']) > 0)
    349328        if doheader:
    350             top = theplotter._plotter.figure.subplotpars.top
     329            top = self.plotter._plotter.figure.subplotpars.top
    351330            fontsize = header['textobj'][0].get_fontproperties().get_size()
    352         if theplotter._startrow <= 0:
     331        if self.plotter._startrow <= 0:
    353332            msg = "The page counter is reset due to chages of plot settings. "
    354333            msg += "Plotting from the first page."
     
    363342                if header.has_key('selstr'):
    364343                    selstr = header['selstr']
    365             theplotter._reset_header()
    366 
    367         theplotter._plotter.hold()
     344            self.plotter._reset_header()
     345
     346        self.plotter._plotter.hold()
    368347        if goback:
    369348            self._set_prevpage_counter()
    370         #theplotter._plotter.clear()
    371         theplotter._plot(theplotter._data)
     349        #self.plotter._plotter.clear()
     350        self.plotter._plot(self.plotter._data)
    372351        pagenum = self._get_pagenum()
    373352        self.set_pagecounter(pagenum)
     
    375354        #if header['textobj']:
    376355        if doheader and pagenum == 1:
    377             if top and top != theplotter._margins[3]:
     356            if top and top != self.plotter._margins[3]:
    378357                # work around for sdplot in CASA. complete checking in future?
    379                 theplotter._plotter.figure.subplots_adjust(top=top)
     358                self.plotter._plotter.figure.subplots_adjust(top=top)
    380359            if reset:
    381                 theplotter.print_header(plot=True,fontsize=fontsize,selstr=selstr, extrastr=extrastr)
     360                self.plotter.print_header(plot=True,fontsize=fontsize,selstr=selstr, extrastr=extrastr)
    382361            else:
    383                 theplotter._header_plot(header['string'],fontsize=fontsize)
    384         theplotter._plotter.release()
    385         theplotter._plotter.tidy()
    386         theplotter._plotter.show(hardrefresh=False)
     362                self.plotter._header_plot(header['string'],fontsize=fontsize)
     363        self.plotter._plotter.release()
     364        self.plotter._plotter.tidy()
     365        self.plotter._plotter.show(hardrefresh=False)
    387366        del top
    388367
    389368    ### calculate the panel ID and start row to plot the previous page
    390369    def _set_prevpage_counter(self):
    391         # check for the validity of plotter and get the plotter
    392         theplotter = self._get_plotter()
    393 
    394370        # set row and panel counters to those of the 1st panel of previous page
    395371        maxpanel = 16
    396372        # the ID of the last panel in current plot
    397         lastpanel = theplotter._ipanel
     373        lastpanel = self.plotter._ipanel
    398374        # the number of current subplots
    399         currpnum = len(theplotter._plotter.subplots)
     375        currpnum = len(self.plotter._plotter.subplots)
    400376        # the nuber of previous subplots
    401377        prevpnum = None
    402         if theplotter._rows and theplotter._cols:
     378        if self.plotter._rows and self.plotter._cols:
    403379            # when user set layout
    404             prevpnum = theplotter._rows*theplotter._cols
     380            prevpnum = self.plotter._rows*self.plotter._cols
    405381        else:
    406382            # no user specification
     
    409385        start_ipanel = max(lastpanel-currpnum-prevpnum+1, 0)
    410386        # set the pannel ID of the last panel of prev-prev page
    411         theplotter._ipanel = start_ipanel-1
    412         if theplotter._panelling == 'r':
    413             theplotter._startrow = start_ipanel
     387        self.plotter._ipanel = start_ipanel-1
     388        if self.plotter._panelling == 'r':
     389            self.plotter._startrow = start_ipanel
    414390        else:
    415391            # the start row number of the next panel
    416             theplotter._startrow = theplotter._panelrows[start_ipanel]
     392            self.plotter._startrow = self.plotter._panelrows[start_ipanel]
    417393        del lastpanel,currpnum,prevpnum,start_ipanel
    418394
     
    429405
    430406    def _get_pagenum(self):
    431         # check for the validity of plotter and get the plotter
    432         theplotter = self._get_plotter()
    433        
    434407        # get the ID of last panel in the current page
    435         idlastpanel = theplotter._ipanel
     408        idlastpanel = self.plotter._ipanel
    436409        # max panels in a page
    437         ppp = theplotter._plotter.rows*theplotter._plotter.cols
     410        ppp = self.plotter._plotter.rows*self.plotter._plotter.cols
    438411        return int(idlastpanel/ppp)+1
    439412
     
    710683class CustomFlagToolbarCommon:
    711684    def __init__(self,parent):
    712         self.plotter=weakref.ref(parent)
     685        self.plotter=parent
    713686        #self.figmgr=self.plotter._plotter.figmgr
    714687        self._selregions = {}
     
    718691        self.xdataold=None
    719692
    720     def _get_plotter(self):
    721         # check for the validity of the plotter and
    722         # return the plotter class instance if its valid.
    723         if self.plotter() is None:
    724             raise RuntimeError, "Internal Error. The plotter has been destroyed."
    725         else:
    726             return self.plotter()
    727 
    728693    ### select the nearest spectrum in pick radius
    729694    ###    and display spectral value on the toolbar.
     
    739704        if event.button != 1:
    740705            return
    741 
    742         # check for the validity of plotter and get the plotter
    743         theplotter = self._get_plotter()
    744706
    745707        xclick = event.xdata
     
    775737        del pind, inds, xlin, ylin
    776738        # Spectra are Picked
    777         theplot = theplotter._plotter
     739        theplot = self.plotter._plotter
    778740        thetoolbar = self.figmgr.toolbar
    779741        thecanvas = self.figmgr.canvas
     
    857819        if event.button != 1 or event.inaxes == None:
    858820            return
    859         # check for the validity of plotter and get the plotter
    860         theplotter = self._get_plotter()
    861821        # this row resolution assumes row panelling
    862822        irow = int(self._getrownum(event.inaxes))
     
    869829        self._thisregion = {'axes': event.inaxes,'xs': event.x,
    870830                            'worldx': [event.xdata,event.xdata]}
    871         theplotter._plotter.register('button_press',None)
     831        self.plotter._plotter.register('button_press',None)
    872832        self.xold = event.x
    873833        self.xdataold = event.xdata
    874         theplotter._plotter.register('motion_notify', self._xspan_draw)
    875         theplotter._plotter.register('button_press', self._xspan_end)
     834        self.plotter._plotter.register('motion_notify', self._xspan_draw)
     835        self.plotter._plotter.register('button_press', self._xspan_end)
    876836
    877837    def _xspan_draw(self,event):
     
    922882        self._thisregion['axes'].set_xlim(axlimx)
    923883       
    924         # check for the validity of plotter and get the plotter
    925         theplotter = self._get_plotter()
    926 
    927         theplotter._plotter.canvas.draw()
     884        self.plotter._plotter.canvas.draw()
    928885        self._polygons.append(pregion)
    929886        srow = self._getrownum(self._thisregion['axes'])
     
    938895
    939896        # release event
    940         theplotter._plotter.register('button_press',None)
    941         theplotter._plotter.register('motion_notify',None)
     897        self.plotter._plotter.register('button_press',None)
     898        self.plotter._plotter.register('motion_notify',None)
    942899        # Clear up region selection
    943900        self._thisregion = None
     
    945902        self.xold = None
    946903        # finally recover region selection event
    947         theplotter._plotter.register('button_press',self._add_region)
     904        self.plotter._plotter.register('button_press',self._add_region)
    948905
    949906    ### add panels to selections
     
    954911        if event.button != 1 or event.inaxes == None:
    955912            return
    956         # check for the validity of plotter and get the plotter
    957         theplotter = self._get_plotter()
    958 
    959913        selax = event.inaxes
    960914        # this row resolution assumes row panelling
     
    965919        shadow = Rectangle((0,0),1,1,facecolor='0.7',transform=selax.transAxes,visible=True)
    966920        self._polygons.append(selax.add_patch(shadow))
    967         #theplotter._plotter.show(False)
    968         theplotter._plotter.canvas.draw()
     921        #self.plotter._plotter.show(False)
     922        self.plotter._plotter.canvas.draw()
    969923        asaplog.push("row "+str(irow)+" is selected")
    970924        ## check for region selection of the spectra and overwrite it.
     
    1002956            asaplog.push("Invalid panel specification")
    1003957            asaplog.post('ERROR')
    1004 
    1005         # check for the validity of plotter and get the plotter
    1006         theplotter = self._get_plotter()
    1007 
    1008         strow = self._getrownum(theplotter._plotter.subplots[0]['axes'])
    1009         enrow = self._getrownum(theplotter._plotter.subplots[-1]['axes'])
     958        strow = self._getrownum(self.plotter._plotter.subplots[0]['axes'])
     959        enrow = self._getrownum(self.plotter._plotter.subplots[-1]['axes'])
    1010960        for irow in range(int(strow),int(enrow)+1):
    1011961            if regions.has_key(str(irow)):
    1012                 ax = theplotter._plotter.subplots[irow - int(strow)]['axes']
     962                ax = self.plotter._plotter.subplots[irow - int(strow)]['axes']
    1013963                mlist = regions.pop(str(irow))
    1014964                # WORKAROUND for the issue axvspan started to reset xlim.
     
    1020970                del ax,mlist,axlimx
    1021971            if irow in panels:
    1022                 ax = theplotter._plotter.subplots[irow - int(strow)]['axes']
     972                ax = self.plotter._plotter.subplots[irow - int(strow)]['axes']
    1023973                shadow = Rectangle((0,0),1,1,facecolor='0.7',
    1024974                                   transform=ax.transAxes,visible=True)
    1025975                self._polygons.append(ax.add_patch(shadow))
    1026976                del ax,shadow
    1027         theplotter._plotter.canvas.draw()
     977        self.plotter._plotter.canvas.draw()
    1028978        del regions,panels,strow,enrow
    1029979
     
    1033983            for shadow in self._polygons:
    1034984                shadow.remove()
    1035             if refresh:
    1036                 # check for the validity of plotter and get the plotter
    1037                 theplotter = self._get_plotter()
    1038                 theplotter._plotter.canvas.draw()
     985            if refresh: self.plotter._plotter.canvas.draw()
    1039986        self._polygons = []
    1040987
     
    10601007            asaplog.post('WARN')
    10611008            return
    1062 
    10631009        self._pause_buttons(operation="start",msg="Flagging data...")
    10641010        self._flag_operation(rows=self._selpanels,
     
    10691015        asaplog.push(sout)
    10701016        del sout
    1071         # check for the validity of plotter and get the plotter
    1072         theplotter = self._get_plotter()
    1073 
    1074         theplotter._ismodified = True
     1017        self.plotter._ismodified = True
    10751018        self._clearup_selections(refresh=False)
    10761019        self._plot_page(pagemode="current")
     
    10931036        asaplog.push(sout)
    10941037        del sout
    1095 
    1096         # check for the validity of plotter and get the plotter
    1097         theplotter = self._get_plotter()
    1098         theplotter._ismodified = True
     1038        self.plotter._ismodified = True
    10991039        self._clearup_selections(refresh=False)
    11001040        self._plot_page(pagemode="current")
     
    11041044    @asaplog_post_dec
    11051045    def _flag_operation(self,rows=None,regions=None,unflag=False):
    1106         # check for the validity of plotter and get the plotter
    1107         theplotter = self._get_plotter()
    1108 
    1109         scan = theplotter._data
     1046        scan = self.plotter._data
    11101047        if not scan:
    11111048            asaplog.post()
     
    11421079    @asaplog_post_dec
    11431080    def _selected_stats(self,rows=None,regions=None):
    1144         # check for the validity of plotter and get the plotter
    1145         theplotter = self._get_plotter()
    1146 
    1147         scan = theplotter._data
     1081        scan = self.plotter._data
    11481082        if not scan:
    11491083            asaplog.post()
     
    12301164    ### actual plotting of the new page
    12311165    def _plot_page(self,pagemode="next"):
    1232         # check for the validity of plotter and get the plotter
    1233         theplotter = self._get_plotter()
    1234         if theplotter._startrow <= 0:
     1166        if self.plotter._startrow <= 0:
    12351167            msg = "The page counter is reset due to chages of plot settings. "
    12361168            msg += "Plotting from the first page."
     
    12401172            goback = False
    12411173
    1242         theplotter._plotter.hold()
    1243         #theplotter._plotter.legend(1)
     1174        self.plotter._plotter.hold()
     1175        #self.plotter._plotter.legend(1)
    12441176        self._set_plot_counter(pagemode)
    1245         theplotter._plot(theplotter._data)
     1177        self.plotter._plot(self.plotter._data)
    12461178        self.set_pagecounter(self._get_pagenum())
    1247         theplotter._plotter.release()
    1248         theplotter._plotter.tidy()
    1249         theplotter._plotter.show(hardrefresh=False)
     1179        self.plotter._plotter.release()
     1180        self.plotter._plotter.tidy()
     1181        self.plotter._plotter.show(hardrefresh=False)
    12501182
    12511183    ### calculate the panel ID and start row to plot a page
     
    12621194            # nothing necessary to plot the next page
    12631195            return
    1264 
    1265         # check for the validity of plotter and get the plotter
    1266         theplotter = self._get_plotter()
    1267 
    12681196        # set row and panel counters to those of the 1st panel of previous page
    12691197        maxpanel = 25
    12701198        # the ID of the last panel in current plot
    1271         lastpanel = theplotter._ipanel
     1199        lastpanel = self.plotter._ipanel
    12721200        # the number of current subplots
    1273         currpnum = len(theplotter._plotter.subplots)
     1201        currpnum = len(self.plotter._plotter.subplots)
    12741202
    12751203        # the nuber of previous subplots
     
    12801208            ## previous page
    12811209            prevpnum = None
    1282             if theplotter._rows and theplotter._cols:
     1210            if self.plotter._rows and self.plotter._cols:
    12831211                # when user set layout
    1284                 prevpnum = theplotter._rows*theplotter._cols
     1212                prevpnum = self.plotter._rows*self.plotter._cols
    12851213            else:
    12861214                # no user specification
     
    12901218
    12911219        # set the pannel ID of the last panel of the prev(-prev) page
    1292         theplotter._ipanel = start_ipanel-1
    1293         if theplotter._panelling == 'r':
    1294             theplotter._startrow = start_ipanel
     1220        self.plotter._ipanel = start_ipanel-1
     1221        if self.plotter._panelling == 'r':
     1222            self.plotter._startrow = start_ipanel
    12951223        else:
    12961224            # the start row number of the next panel
    1297             theplotter._startrow = theplotter._panelrows[start_ipanel]
     1225            self.plotter._startrow = self.plotter._panelrows[start_ipanel]
    12981226        del lastpanel,currpnum,start_ipanel
    12991227
     
    13101238
    13111239    def _get_pagenum(self):
    1312         # check for the validity of plotter and get the plotter
    1313         theplotter = self._get_plotter()
    13141240        # get the ID of last panel in the current page
    1315         idlastpanel = theplotter._ipanel
     1241        idlastpanel = self.plotter._ipanel
    13161242        # max panels in a page
    1317         ppp = theplotter._plotter.rows*theplotter._plotter.cols
     1243        ppp = self.plotter._plotter.rows*self.plotter._plotter.cols
    13181244        return int(idlastpanel/ppp)+1
    13191245
Note: See TracChangeset for help on using the changeset viewer.