Changeset 1981


Ignore:
Timestamp:
01/28/11 17:34:32 (13 years ago)
Author:
Kana Sugimoto
Message:

New Development: Yes

JIRA Issue: Yes (CAS-1822/ASAP-204)

Ready for Test: Yes

Interface Changes: Yes

What Interface Changed: Added "-" page button and page counter to the ASAP plotter

Test Programs: plot spectra and press Page: "+" and "-" button to go

back and forth between the pages

Put in Release Notes: Yes

Module(s): asapplotter and sdplot (CASA)

Description:

Added "-" page button and page counter to the ASAP plotter.
Renamed "+ page" button to "+" button.
You can plot multi-page plots and move back and forth between pages.

Location:
trunk/python
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/python/asapplotter.py

    r1949 r1981  
    5252        self._panellayout = self.set_panellayout(refresh=False)
    5353        self._offset = None
    54         self._rowcount = 0
    55         self._panelcnt = 0
     54        self._startrow = 0
     55        self._ipanel = -1
     56        self._panelrows = []
    5657
    5758    def _translate(self, instr):
     
    9697            are consistent e.g. all 'channel' or all 'velocity' etc.
    9798        """
    98         self._rowcount = self._panelcnt = 0
     99        self._startrow = 0
     100        self._ipanel = -1
    99101        if self._plotter.is_dead:
    100102            if hasattr(self._plotter.figmgr,'casabar'):
     
    102104            self._plotter = self._newplotter()
    103105            self._plotter.figmgr.casabar=self._newcasabar()
     106        if self._plotter.figmgr.casabar:
     107            self._plotter.figmgr.casabar.set_pagenum(1)
     108        self._panelrows = []
    104109        self._plotter.hold()
    105110        #self._plotter.clear()
     
    361366            if md == 'r':
    362367                self._stacking = '_r'
     368            # you need to reset counters for multi page plotting
     369            self._reset_counters()
    363370            return True
    364371        return False
     
    396403            if md == 'r':
    397404                self._panelling = '_r'
     405            # you need to reset counters for multi page plotting
     406            self._reset_counters()
    398407            return True
    399408        return False
     409
     410    def _reset_counters(self):
     411        self._startrow = 0
     412        self._ipanel = -1
     413        self._panelrows = []
    400414
    401415    def set_range(self,xstart=None,xend=None,ystart=None,yend=None,refresh=True, offset=None):
     
    853867            asaplog.post('WARN')
    854868            nstack = min(nstack,maxstack)
    855         n = min(n,maxpanel)
     869        #n = min(n,maxpanel)
     870        n = min(n-self._ipanel-1,maxpanel)
    856871           
    857872        if n > 1:
     
    871886            self._plotter.set_panels(layout=self._panellayout)
    872887        #r = 0
    873         r = self._rowcount
     888        r = self._startrow
    874889        nr = scan.nrow()
    875890        a0,b0 = -1,-1
    876891        allxlim = []
    877892        allylim = []
    878         newpanel=True
     893        #newpanel=True
     894        newpanel=False
    879895        panelcount,stackcount = 0,0
     896        # If this is not the first page
     897        if r > 0:
     898            # panelling value of the prev page
     899            a0 = d[self._panelling](r-1)
     900            # set the initial stackcount large not to plot
     901            # the start row automatically
     902            stackcount = nstack
     903
    880904        while r < nr:
    881905            a = d[self._panelling](r)
     
    906930                stackcount = 0
    907931                panelcount += 1
     932                # save the start row to plot this panel for future revisit.
     933                if self._panelling != 'r' and \
     934                       len(self._panelrows) < self._ipanel+1+panelcount:
     935                    self._panelrows += [r]
     936                   
    908937            #if (b > b0 or newpanel) and stackcount < nstack:
    909938            if stackcount < nstack and (newpanel or (a == a0 and b > b0)):
     
    954983                    allylim += ylim
    955984                stackcount += 1
     985                a0=a
     986                b0=b
    956987                # last in colour stack -> autoscale x
    957988                if stackcount == nstack and len(allxlim) > 0:
     
    962993
    963994            newpanel = False
    964             a0=a
    965             b0=b
     995            #a0=a
     996            #b0=b
    966997            # ignore following rows
    967             if (panelcount == n) and (stackcount == nstack):
     998            if (panelcount == n and stackcount == nstack) or (r == nr-1):
    968999                # last panel -> autoscale y if ganged
    9691000                if rcParams['plotter.ganged'] and len(allylim) > 0:
     
    9721003                break
    9731004            r+=1 # next row
    974         ###-S
    975         self._rowcount = r+1
    976         self._panelcnt += panelcount
     1005
     1006        # save the current counter for multi-page plotting
     1007        self._startrow = r+1
     1008        self._ipanel += panelcount
    9771009        if self._plotter.figmgr.casabar:
    978             if self._panelcnt >= nptot-1:
     1010            if self._ipanel >= nptot-1:
    9791011                self._plotter.figmgr.casabar.disable_next()
    9801012            else:
    9811013                self._plotter.figmgr.casabar.enable_next()
    982             #if self._panelcnt - panelcount > 0:
    983             #    self._plotter.figmgr.casabar.enable_prev()
    984             #else:
    985             #    self._plotter.figmgr.casabar.disable_prev()
    986         ###-E
     1014            if self._ipanel + 1 - panelcount > 0:
     1015                self._plotter.figmgr.casabar.enable_prev()
     1016            else:
     1017                self._plotter.figmgr.casabar.disable_prev()
     1018
    9871019        #reset the selector to the scantable's original
    9881020        scan.set_selection(savesel)
  • trunk/python/casatoolbar.py

    r1979 r1981  
    11import os
    2 import matplotlib
     2import matplotlib, numpy
     3from asap.logging import asaplog, asaplog_post_dec
    34
    45######################################
     
    168169
    169170    def _new_page(self,next=True):
     171        if self.plotter._startrow <= 0:
     172            msg = "The page counter is reset due to chages of plot settings. "
     173            msg += "Plotting from the first page."
     174            asaplog.push(msg)
     175            asaplog.post('WARN')
     176            next = True
     177           
    170178        self.plotter._plotter.hold()
     179        if not next:
     180            self._set_prevpage_counter()
    171181        #self.plotter._plotter.clear()
     182        self.set_pagenum(self._get_pagenum())
    172183        self.plotter._plot(self.plotter._data)
    173184        self.plotter._plotter.release()
     
    175186        self.plotter._plotter.show(hardrefresh=False)
    176187
     188    def _set_prevpage_counter(self):
     189        # set row and panel counters to those of the 1st panel of previous page
     190        maxpanel = 16
     191        # the ID of the last panel in current plot
     192        lastpanel = self.plotter._ipanel
     193        # the number of current subplots
     194        currpnum = len(self.plotter._plotter.subplots)
     195        # the nuber of previous subplots
     196        prevpnum = None
     197        if self.plotter._rows and self.plotter._cols:
     198            # when user set layout
     199            prevpnum = self.plotter._rows*self.plotter._cols
     200        else:
     201            # no user specification
     202            prevpnum = maxpanel
     203           
     204        start_ipanel = max(lastpanel-currpnum-prevpnum+1, 0)
     205        # set the pannel ID of the last panel of prev-prev page
     206        self.plotter._ipanel = start_ipanel-1
     207        if self.plotter._panelling == 'r':
     208            self.plotter._startrow = start_ipanel
     209        else:
     210            # the start row number of the next panel
     211            self.plotter._startrow = self.plotter._panelrows[start_ipanel]
     212        del lastpanel,currpnum,prevpnum,start_ipanel
     213
     214    def _get_pagenum(self):
     215        maxpanel = 16
     216        nextp = self.plotter._ipanel+1
     217        if self.plotter._rows and self.plotter._cols:
     218            ppp = self.plotter._rows*self.plotter._cols
     219        else:
     220            ppp = maxpanel
     221        return int(nextp/ppp)+1
    177222
    178223#####################################
     
    191236        if not parent._plotter:
    192237            return False
    193         self._p=parent._plotter
    194         self.figmgr=self._p.figmgr
    195         self.canvas=self.figmgr.canvas
    196         self.mode=''
    197         self.button=True
     238        self._p = parent._plotter
     239        self.figmgr = self._p.figmgr
     240        self.canvas = self.figmgr.canvas
     241        self.mode = ''
     242        self.button = True
     243        self.pagenum = None
    198244        self._add_custom_toolbar()
    199245        self.notewin=NotationWindowTkAgg(master=self.canvas)
     
    205251        #                           text='spec value',
    206252        #                           command=self.spec_show)
     253        self.bNote=self._NewButton(master=self,
     254                                   text='notation',
     255                                   command=self.modify_note)
     256
    207257        self.bStat=self._NewButton(master=self,
    208258                                   text='statistics',
    209259                                   command=self.stat_cal)
    210         self.bNote=self._NewButton(master=self,
    211                                    text='notation',
    212                                    command=self.modify_note)
    213         #self.bPrev=self._NewButton(master=self,
    214         #                           text='- page',
    215         #                           command=self.prev_page)
     260        # page change oparations
     261        self.lPagetitle = Tk.Label(master=self,text='   Page:',padx=5)
     262        self.lPagetitle.pack(side=Tk.LEFT)
     263        self.pagenum = Tk.StringVar(master=self)
     264        self.lPage = Tk.Label(master=self,textvariable=self.pagenum,
     265                              padx=5,bg='white')
     266        self.lPage.pack(side=Tk.LEFT,padx=3)
     267       
    216268        self.bNext=self._NewButton(master=self,
    217                                    text='+ page',
     269                                   text=' + ',
    218270                                   command=self.next_page)
     271        self.bPrev=self._NewButton(master=self,
     272                                   text=' - ',
     273                                   command=self.prev_page)
     274
    219275        if os.uname()[0] != 'Darwin':
    220             #self.bPrev.config(padx=5)
     276            self.bPrev.config(padx=5)
    221277            self.bNext.config(padx=5)
    222278        self.bQuit=self._NewButton(master=self,
     
    225281                                   side=Tk.RIGHT)
    226282        self.pack(side=Tk.BOTTOM,fill=Tk.BOTH)
     283        self.pagenum.set('    ')
    227284
    228285        self.disable_button()
     
    289346        self._new_page(next=True)
    290347
     348    def set_pagenum(self,page):
     349        nwidth = int(numpy.ceil(numpy.log10(max(page,1))))+1
     350        nwidth = max(nwidth,4)
     351        formatstr = '%'+str(nwidth)+'d'
     352        self.pagenum.set(formatstr % (page))
     353
    291354    def quit(self):
    292355        self.__disconnect_event()
     
    304367    def disable_button(self):
    305368        if not self.button: return
     369        #self.bSpec.config(relief='raised', state=Tk.DISABLED)
    306370        self.bStat.config(relief='raised', state=Tk.DISABLED)
    307         #self.bSpec.config(relief='raised', state=Tk.DISABLED)
     371        #self.bNext.config(state=Tk.DISABLED)
    308372        #self.bPrev.config(state=Tk.DISABLED)
    309         #self.bNext.config(state=Tk.DISABLED)
    310373        self.button=False
    311374        self.mode=''
     
    319382
    320383    def enable_prev(self):
    321         #self.bPrev.config(state=Tk.NORMAL)
    322         pass
     384        self.bPrev.config(state=Tk.NORMAL)
    323385
    324386    def disable_prev(self):
    325         #self.bPrev.config(state=Tk.DISABLED)
    326         pass
     387        self.bPrev.config(state=Tk.DISABLED)
    327388
    328389    def delete_bar(self):
     
    331392
    332393    def __disconnect_event(self):
    333         #idP=self.figmgr.toolbar._idPress
    334         #idR=self.figmgr.toolbar._idRelease
    335         #if idP is not None:
    336         #    self.canvas.mpl_disconnect(idP)
    337         #    self.figmgr.toolbar._idPress=None
    338         #if idR is not None:
    339         #    self.canvas.mpl_disconnect(idR)
    340         #    self.figmgr.toolbar._idRelease=None
    341394        self._p.register('button_press',None)
    342395        self._p.register('button_release',None)
Note: See TracChangeset for help on using the changeset viewer.