Changeset 2799


Ignore:
Timestamp:
03/18/13 16:42:12 (11 years ago)
Author:
Kana Sugimoto
Message:

New Development: No (a bug fix)

JIRA Issue: Yes (CAS-4859)

Ready for Test: Yes

Interface Changes: No

What Interface Changed:

Test Programs:

Put in Release Notes: No

Module(s): asap.asapplotter and sdplot

Description:

Fixed a bug in the usage of weakref.


File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/python/customgui_base.py

    r2796 r2799  
    1717        #self.figmgr=self.plotter._plotter.figmgr
    1818
     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()
     26
    1927    ### select the nearest spectrum in pick radius
    2028    ###    and display spectral value on the toolbar.
     
    3038        if event.button != 1:
    3139            return
     40
     41        # check for the validity of plotter and get the plotter
     42        theplotter = self._get_plotter()
    3243
    3344        xclick = event.xdata
     
    6374        del pind, inds, xlin, ylin
    6475        # Spectra are Picked
    65         theplot = self.plotter._plotter
     76        theplot = theplotter._plotter
    6677        thetoolbar = self.figmgr.toolbar
    6778        thecanvas = self.figmgr.canvas
     
    155166            return
    156167
     168        # check for the validity of plotter and get the plotter
     169        theplotter = self._get_plotter()
     170
    157171        self._thisregion = {'axes': event.inaxes,'xs': event.x,
    158172                            'worldx': [event.xdata,event.xdata],
     
    161175        self.xdataold = event.xdata
    162176
    163         self.plotter._plotter.register('button_press',None)
    164         self.plotter._plotter.register('motion_notify', self._xspan_draw)
    165         self.plotter._plotter.register('button_press', self._xspan_end)
     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)
    166180
    167181    def _xspan_draw(self,event):
     
    204218            xdataend = self.xdataold
    205219
     220        # check for the validity of plotter and get the plotter
     221        theplotter = self._get_plotter()
     222
    206223        self._thisregion['worldx'][1] = xdataend
    207224        # print statistics of spectra in subplot
     
    209226       
    210227        # release event
    211         self.plotter._plotter.register('button_press',None)
    212         self.plotter._plotter.register('motion_notify',None)
     228        theplotter._plotter.register('button_press',None)
     229        theplotter._plotter.register('motion_notify',None)
    213230        # Clear up region selection
    214231        self._thisregion = None
     
    216233        self.xold = None
    217234        # finally recover region selection event
    218         self.plotter._plotter.register('button_press',self._single_mask)
     235        theplotter._plotter.register('button_press',self._single_mask)
    219236
    220237    def _subplot_stats(self,selection):
     
    322339    ### actual plotting of the new page
    323340    def _new_page(self,goback=False):
     341        # check for the validity of plotter and get the plotter
     342        theplotter = self._get_plotter()
     343
    324344        top = None
    325         header = self.plotter._headtext
     345        header = theplotter._headtext
    326346        reset = False
    327347        doheader = (isinstance(header['textobj'],list) and \
    328348                    len(header['textobj']) > 0)
    329349        if doheader:
    330             top = self.plotter._plotter.figure.subplotpars.top
     350            top = theplotter._plotter.figure.subplotpars.top
    331351            fontsize = header['textobj'][0].get_fontproperties().get_size()
    332         if self.plotter._startrow <= 0:
     352        if theplotter._startrow <= 0:
    333353            msg = "The page counter is reset due to chages of plot settings. "
    334354            msg += "Plotting from the first page."
     
    343363                if header.has_key('selstr'):
    344364                    selstr = header['selstr']
    345             self.plotter._reset_header()
    346 
    347         self.plotter._plotter.hold()
     365            theplotter._reset_header()
     366
     367        theplotter._plotter.hold()
    348368        if goback:
    349369            self._set_prevpage_counter()
    350         #self.plotter._plotter.clear()
    351         self.plotter._plot(self.plotter._data)
     370        #theplotter._plotter.clear()
     371        theplotter._plot(theplotter._data)
    352372        pagenum = self._get_pagenum()
    353373        self.set_pagecounter(pagenum)
     
    355375        #if header['textobj']:
    356376        if doheader and pagenum == 1:
    357             if top and top != self.plotter._margins[3]:
     377            if top and top != theplotter._margins[3]:
    358378                # work around for sdplot in CASA. complete checking in future?
    359                 self.plotter._plotter.figure.subplots_adjust(top=top)
     379                theplotter._plotter.figure.subplots_adjust(top=top)
    360380            if reset:
    361                 self.plotter.print_header(plot=True,fontsize=fontsize,selstr=selstr, extrastr=extrastr)
     381                theplotter.print_header(plot=True,fontsize=fontsize,selstr=selstr, extrastr=extrastr)
    362382            else:
    363                 self.plotter._header_plot(header['string'],fontsize=fontsize)
    364         self.plotter._plotter.release()
    365         self.plotter._plotter.tidy()
    366         self.plotter._plotter.show(hardrefresh=False)
     383                theplotter._header_plot(header['string'],fontsize=fontsize)
     384        theplotter._plotter.release()
     385        theplotter._plotter.tidy()
     386        theplotter._plotter.show(hardrefresh=False)
    367387        del top
    368388
    369389    ### calculate the panel ID and start row to plot the previous page
    370390    def _set_prevpage_counter(self):
     391        # check for the validity of plotter and get the plotter
     392        theplotter = self._get_plotter()
     393
    371394        # set row and panel counters to those of the 1st panel of previous page
    372395        maxpanel = 16
    373396        # the ID of the last panel in current plot
    374         lastpanel = self.plotter._ipanel
     397        lastpanel = theplotter._ipanel
    375398        # the number of current subplots
    376         currpnum = len(self.plotter._plotter.subplots)
     399        currpnum = len(theplotter._plotter.subplots)
    377400        # the nuber of previous subplots
    378401        prevpnum = None
    379         if self.plotter._rows and self.plotter._cols:
     402        if theplotter._rows and theplotter._cols:
    380403            # when user set layout
    381             prevpnum = self.plotter._rows*self.plotter._cols
     404            prevpnum = theplotter._rows*theplotter._cols
    382405        else:
    383406            # no user specification
     
    386409        start_ipanel = max(lastpanel-currpnum-prevpnum+1, 0)
    387410        # set the pannel ID of the last panel of prev-prev page
    388         self.plotter._ipanel = start_ipanel-1
    389         if self.plotter._panelling == 'r':
    390             self.plotter._startrow = start_ipanel
     411        theplotter._ipanel = start_ipanel-1
     412        if theplotter._panelling == 'r':
     413            theplotter._startrow = start_ipanel
    391414        else:
    392415            # the start row number of the next panel
    393             self.plotter._startrow = self.plotter._panelrows[start_ipanel]
     416            theplotter._startrow = theplotter._panelrows[start_ipanel]
    394417        del lastpanel,currpnum,prevpnum,start_ipanel
    395418
     
    406429
    407430    def _get_pagenum(self):
     431        # check for the validity of plotter and get the plotter
     432        theplotter = self._get_plotter()
     433       
    408434        # get the ID of last panel in the current page
    409         idlastpanel = self.plotter._ipanel
     435        idlastpanel = theplotter._ipanel
    410436        # max panels in a page
    411         ppp = self.plotter._plotter.rows*self.plotter._plotter.cols
     437        ppp = theplotter._plotter.rows*theplotter._plotter.cols
    412438        return int(idlastpanel/ppp)+1
    413439
     
    692718        self.xdataold=None
    693719
     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
    694728    ### select the nearest spectrum in pick radius
    695729    ###    and display spectral value on the toolbar.
     
    705739        if event.button != 1:
    706740            return
     741
     742        # check for the validity of plotter and get the plotter
     743        theplotter = self._get_plotter()
    707744
    708745        xclick = event.xdata
     
    738775        del pind, inds, xlin, ylin
    739776        # Spectra are Picked
    740         theplot = self.plotter._plotter
     777        theplot = theplotter._plotter
    741778        thetoolbar = self.figmgr.toolbar
    742779        thecanvas = self.figmgr.canvas
     
    820857        if event.button != 1 or event.inaxes == None:
    821858            return
     859        # check for the validity of plotter and get the plotter
     860        theplotter = self._get_plotter()
    822861        # this row resolution assumes row panelling
    823862        irow = int(self._getrownum(event.inaxes))
     
    830869        self._thisregion = {'axes': event.inaxes,'xs': event.x,
    831870                            'worldx': [event.xdata,event.xdata]}
    832         self.plotter._plotter.register('button_press',None)
     871        theplotter._plotter.register('button_press',None)
    833872        self.xold = event.x
    834873        self.xdataold = event.xdata
    835         self.plotter._plotter.register('motion_notify', self._xspan_draw)
    836         self.plotter._plotter.register('button_press', self._xspan_end)
     874        theplotter._plotter.register('motion_notify', self._xspan_draw)
     875        theplotter._plotter.register('button_press', self._xspan_end)
    837876
    838877    def _xspan_draw(self,event):
     
    883922        self._thisregion['axes'].set_xlim(axlimx)
    884923       
    885         self.plotter._plotter.canvas.draw()
     924        # check for the validity of plotter and get the plotter
     925        theplotter = self._get_plotter()
     926
     927        theplotter._plotter.canvas.draw()
    886928        self._polygons.append(pregion)
    887929        srow = self._getrownum(self._thisregion['axes'])
     
    896938
    897939        # release event
    898         self.plotter._plotter.register('button_press',None)
    899         self.plotter._plotter.register('motion_notify',None)
     940        theplotter._plotter.register('button_press',None)
     941        theplotter._plotter.register('motion_notify',None)
    900942        # Clear up region selection
    901943        self._thisregion = None
     
    903945        self.xold = None
    904946        # finally recover region selection event
    905         self.plotter._plotter.register('button_press',self._add_region)
     947        theplotter._plotter.register('button_press',self._add_region)
    906948
    907949    ### add panels to selections
     
    912954        if event.button != 1 or event.inaxes == None:
    913955            return
     956        # check for the validity of plotter and get the plotter
     957        theplotter = self._get_plotter()
     958
    914959        selax = event.inaxes
    915960        # this row resolution assumes row panelling
     
    920965        shadow = Rectangle((0,0),1,1,facecolor='0.7',transform=selax.transAxes,visible=True)
    921966        self._polygons.append(selax.add_patch(shadow))
    922         #self.plotter._plotter.show(False)
    923         self.plotter._plotter.canvas.draw()
     967        #theplotter._plotter.show(False)
     968        theplotter._plotter.canvas.draw()
    924969        asaplog.push("row "+str(irow)+" is selected")
    925970        ## check for region selection of the spectra and overwrite it.
     
    9571002            asaplog.push("Invalid panel specification")
    9581003            asaplog.post('ERROR')
    959         strow = self._getrownum(self.plotter._plotter.subplots[0]['axes'])
    960         enrow = self._getrownum(self.plotter._plotter.subplots[-1]['axes'])
     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'])
    9611010        for irow in range(int(strow),int(enrow)+1):
    9621011            if regions.has_key(str(irow)):
    963                 ax = self.plotter._plotter.subplots[irow - int(strow)]['axes']
     1012                ax = theplotter._plotter.subplots[irow - int(strow)]['axes']
    9641013                mlist = regions.pop(str(irow))
    9651014                # WORKAROUND for the issue axvspan started to reset xlim.
     
    9711020                del ax,mlist,axlimx
    9721021            if irow in panels:
    973                 ax = self.plotter._plotter.subplots[irow - int(strow)]['axes']
     1022                ax = theplotter._plotter.subplots[irow - int(strow)]['axes']
    9741023                shadow = Rectangle((0,0),1,1,facecolor='0.7',
    9751024                                   transform=ax.transAxes,visible=True)
    9761025                self._polygons.append(ax.add_patch(shadow))
    9771026                del ax,shadow
    978         self.plotter._plotter.canvas.draw()
     1027        theplotter._plotter.canvas.draw()
    9791028        del regions,panels,strow,enrow
    9801029
     
    9841033            for shadow in self._polygons:
    9851034                shadow.remove()
    986             if refresh: self.plotter._plotter.canvas.draw()
     1035            if refresh:
     1036                # check for the validity of plotter and get the plotter
     1037                theplotter = self._get_plotter()
     1038                theplotter._plotter.canvas.draw()
    9871039        self._polygons = []
    9881040
     
    10081060            asaplog.post('WARN')
    10091061            return
     1062
    10101063        self._pause_buttons(operation="start",msg="Flagging data...")
    10111064        self._flag_operation(rows=self._selpanels,
     
    10161069        asaplog.push(sout)
    10171070        del sout
    1018         self.plotter._ismodified = True
     1071        # check for the validity of plotter and get the plotter
     1072        theplotter = self._get_plotter()
     1073
     1074        theplotter._ismodified = True
    10191075        self._clearup_selections(refresh=False)
    10201076        self._plot_page(pagemode="current")
     
    10371093        asaplog.push(sout)
    10381094        del sout
    1039         self.plotter._ismodified = True
     1095
     1096        # check for the validity of plotter and get the plotter
     1097        theplotter = self._get_plotter()
     1098        theplotter._ismodified = True
    10401099        self._clearup_selections(refresh=False)
    10411100        self._plot_page(pagemode="current")
     
    10451104    @asaplog_post_dec
    10461105    def _flag_operation(self,rows=None,regions=None,unflag=False):
    1047         scan = self.plotter._data
     1106        # check for the validity of plotter and get the plotter
     1107        theplotter = self._get_plotter()
     1108
     1109        scan = theplotter._data
    10481110        if not scan:
    10491111            asaplog.post()
     
    10801142    @asaplog_post_dec
    10811143    def _selected_stats(self,rows=None,regions=None):
    1082         scan = self.plotter._data
     1144        # check for the validity of plotter and get the plotter
     1145        theplotter = self._get_plotter()
     1146
     1147        scan = theplotter._data
    10831148        if not scan:
    10841149            asaplog.post()
     
    11651230    ### actual plotting of the new page
    11661231    def _plot_page(self,pagemode="next"):
    1167         if self.plotter._startrow <= 0:
     1232        # check for the validity of plotter and get the plotter
     1233        theplotter = self._get_plotter()
     1234        if theplotter._startrow <= 0:
    11681235            msg = "The page counter is reset due to chages of plot settings. "
    11691236            msg += "Plotting from the first page."
     
    11731240            goback = False
    11741241
    1175         self.plotter._plotter.hold()
    1176         #self.plotter._plotter.legend(1)
     1242        theplotter._plotter.hold()
     1243        #theplotter._plotter.legend(1)
    11771244        self._set_plot_counter(pagemode)
    1178         self.plotter._plot(self.plotter._data)
     1245        theplotter._plot(theplotter._data)
    11791246        self.set_pagecounter(self._get_pagenum())
    1180         self.plotter._plotter.release()
    1181         self.plotter._plotter.tidy()
    1182         self.plotter._plotter.show(hardrefresh=False)
     1247        theplotter._plotter.release()
     1248        theplotter._plotter.tidy()
     1249        theplotter._plotter.show(hardrefresh=False)
    11831250
    11841251    ### calculate the panel ID and start row to plot a page
     
    11951262            # nothing necessary to plot the next page
    11961263            return
     1264
     1265        # check for the validity of plotter and get the plotter
     1266        theplotter = self._get_plotter()
     1267
    11971268        # set row and panel counters to those of the 1st panel of previous page
    11981269        maxpanel = 25
    11991270        # the ID of the last panel in current plot
    1200         lastpanel = self.plotter._ipanel
     1271        lastpanel = theplotter._ipanel
    12011272        # the number of current subplots
    1202         currpnum = len(self.plotter._plotter.subplots)
     1273        currpnum = len(theplotter._plotter.subplots)
    12031274
    12041275        # the nuber of previous subplots
     
    12091280            ## previous page
    12101281            prevpnum = None
    1211             if self.plotter._rows and self.plotter._cols:
     1282            if theplotter._rows and theplotter._cols:
    12121283                # when user set layout
    1213                 prevpnum = self.plotter._rows*self.plotter._cols
     1284                prevpnum = theplotter._rows*theplotter._cols
    12141285            else:
    12151286                # no user specification
     
    12191290
    12201291        # set the pannel ID of the last panel of the prev(-prev) page
    1221         self.plotter._ipanel = start_ipanel-1
    1222         if self.plotter._panelling == 'r':
    1223             self.plotter._startrow = start_ipanel
     1292        theplotter._ipanel = start_ipanel-1
     1293        if theplotter._panelling == 'r':
     1294            theplotter._startrow = start_ipanel
    12241295        else:
    12251296            # the start row number of the next panel
    1226             self.plotter._startrow = self.plotter._panelrows[start_ipanel]
     1297            theplotter._startrow = theplotter._panelrows[start_ipanel]
    12271298        del lastpanel,currpnum,start_ipanel
    12281299
     
    12391310
    12401311    def _get_pagenum(self):
     1312        # check for the validity of plotter and get the plotter
     1313        theplotter = self._get_plotter()
    12411314        # get the ID of last panel in the current page
    1242         idlastpanel = self.plotter._ipanel
     1315        idlastpanel = theplotter._ipanel
    12431316        # max panels in a page
    1244         ppp = self.plotter._plotter.rows*self.plotter._plotter.cols
     1317        ppp = theplotter._plotter.rows*theplotter._plotter.cols
    12451318        return int(idlastpanel/ppp)+1
    12461319
Note: See TracChangeset for help on using the changeset viewer.