Changes in trunk/python/customgui_base.py [2697:2799]
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/python/customgui_base.py
r2697 r2799 1 1 import os 2 import weakref 2 3 import matplotlib, numpy 3 4 from asap.logging import asaplog, asaplog_post_dec … … 13 14 class CustomToolbarCommon: 14 15 def __init__(self,parent): 15 self.plotter = parent16 self.plotter = weakref.ref(parent) 16 17 #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() 17 26 18 27 ### select the nearest spectrum in pick radius … … 29 38 if event.button != 1: 30 39 return 40 41 # check for the validity of plotter and get the plotter 42 theplotter = self._get_plotter() 31 43 32 44 xclick = event.xdata … … 62 74 del pind, inds, xlin, ylin 63 75 # Spectra are Picked 64 theplot = self.plotter._plotter76 theplot = theplotter._plotter 65 77 thetoolbar = self.figmgr.toolbar 66 78 thecanvas = self.figmgr.canvas … … 154 166 return 155 167 168 # check for the validity of plotter and get the plotter 169 theplotter = self._get_plotter() 170 156 171 self._thisregion = {'axes': event.inaxes,'xs': event.x, 157 172 'worldx': [event.xdata,event.xdata], … … 160 175 self.xdataold = event.xdata 161 176 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)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) 165 180 166 181 def _xspan_draw(self,event): … … 203 218 xdataend = self.xdataold 204 219 220 # check for the validity of plotter and get the plotter 221 theplotter = self._get_plotter() 222 205 223 self._thisregion['worldx'][1] = xdataend 206 224 # print statistics of spectra in subplot … … 208 226 209 227 # release event 210 self.plotter._plotter.register('button_press',None)211 self.plotter._plotter.register('motion_notify',None)228 theplotter._plotter.register('button_press',None) 229 theplotter._plotter.register('motion_notify',None) 212 230 # Clear up region selection 213 231 self._thisregion = None … … 215 233 self.xold = None 216 234 # finally recover region selection event 217 self.plotter._plotter.register('button_press',self._single_mask)235 theplotter._plotter.register('button_press',self._single_mask) 218 236 219 237 def _subplot_stats(self,selection): … … 321 339 ### actual plotting of the new page 322 340 def _new_page(self,goback=False): 341 # check for the validity of plotter and get the plotter 342 theplotter = self._get_plotter() 343 323 344 top = None 324 header = self.plotter._headtext345 header = theplotter._headtext 325 346 reset = False 326 347 doheader = (isinstance(header['textobj'],list) and \ 327 348 len(header['textobj']) > 0) 328 349 if doheader: 329 top = self.plotter._plotter.figure.subplotpars.top350 top = theplotter._plotter.figure.subplotpars.top 330 351 fontsize = header['textobj'][0].get_fontproperties().get_size() 331 if self.plotter._startrow <= 0:352 if theplotter._startrow <= 0: 332 353 msg = "The page counter is reset due to chages of plot settings. " 333 354 msg += "Plotting from the first page." … … 342 363 if header.has_key('selstr'): 343 364 selstr = header['selstr'] 344 self.plotter._reset_header()345 346 self.plotter._plotter.hold()365 theplotter._reset_header() 366 367 theplotter._plotter.hold() 347 368 if goback: 348 369 self._set_prevpage_counter() 349 # self.plotter._plotter.clear()350 self.plotter._plot(self.plotter._data)370 #theplotter._plotter.clear() 371 theplotter._plot(theplotter._data) 351 372 pagenum = self._get_pagenum() 352 373 self.set_pagecounter(pagenum) … … 354 375 #if header['textobj']: 355 376 if doheader and pagenum == 1: 356 if top and top != self.plotter._margins[3]:377 if top and top != theplotter._margins[3]: 357 378 # work around for sdplot in CASA. complete checking in future? 358 self.plotter._plotter.figure.subplots_adjust(top=top)379 theplotter._plotter.figure.subplots_adjust(top=top) 359 380 if reset: 360 self.plotter.print_header(plot=True,fontsize=fontsize,selstr=selstr, extrastr=extrastr)381 theplotter.print_header(plot=True,fontsize=fontsize,selstr=selstr, extrastr=extrastr) 361 382 else: 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)383 theplotter._header_plot(header['string'],fontsize=fontsize) 384 theplotter._plotter.release() 385 theplotter._plotter.tidy() 386 theplotter._plotter.show(hardrefresh=False) 366 387 del top 367 388 368 389 ### calculate the panel ID and start row to plot the previous page 369 390 def _set_prevpage_counter(self): 391 # check for the validity of plotter and get the plotter 392 theplotter = self._get_plotter() 393 370 394 # set row and panel counters to those of the 1st panel of previous page 371 395 maxpanel = 16 372 396 # the ID of the last panel in current plot 373 lastpanel = self.plotter._ipanel397 lastpanel = theplotter._ipanel 374 398 # the number of current subplots 375 currpnum = len( self.plotter._plotter.subplots)399 currpnum = len(theplotter._plotter.subplots) 376 400 # the nuber of previous subplots 377 401 prevpnum = None 378 if self.plotter._rows and self.plotter._cols:402 if theplotter._rows and theplotter._cols: 379 403 # when user set layout 380 prevpnum = self.plotter._rows*self.plotter._cols404 prevpnum = theplotter._rows*theplotter._cols 381 405 else: 382 406 # no user specification … … 385 409 start_ipanel = max(lastpanel-currpnum-prevpnum+1, 0) 386 410 # set the pannel ID of the last panel of prev-prev page 387 self.plotter._ipanel = start_ipanel-1388 if self.plotter._panelling == 'r':389 self.plotter._startrow = start_ipanel411 theplotter._ipanel = start_ipanel-1 412 if theplotter._panelling == 'r': 413 theplotter._startrow = start_ipanel 390 414 else: 391 415 # the start row number of the next panel 392 self.plotter._startrow = self.plotter._panelrows[start_ipanel]416 theplotter._startrow = theplotter._panelrows[start_ipanel] 393 417 del lastpanel,currpnum,prevpnum,start_ipanel 394 418 … … 405 429 406 430 def _get_pagenum(self): 431 # check for the validity of plotter and get the plotter 432 theplotter = self._get_plotter() 433 407 434 # get the ID of last panel in the current page 408 idlastpanel = self.plotter._ipanel435 idlastpanel = theplotter._ipanel 409 436 # max panels in a page 410 ppp = self.plotter._plotter.rows*self.plotter._plotter.cols437 ppp = theplotter._plotter.rows*theplotter._plotter.cols 411 438 return int(idlastpanel/ppp)+1 412 439 … … 683 710 class CustomFlagToolbarCommon: 684 711 def __init__(self,parent): 685 self.plotter= parent712 self.plotter=weakref.ref(parent) 686 713 #self.figmgr=self.plotter._plotter.figmgr 687 714 self._selregions = {} … … 691 718 self.xdataold=None 692 719 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 693 728 ### select the nearest spectrum in pick radius 694 729 ### and display spectral value on the toolbar. … … 704 739 if event.button != 1: 705 740 return 741 742 # check for the validity of plotter and get the plotter 743 theplotter = self._get_plotter() 706 744 707 745 xclick = event.xdata … … 737 775 del pind, inds, xlin, ylin 738 776 # Spectra are Picked 739 theplot = self.plotter._plotter777 theplot = theplotter._plotter 740 778 thetoolbar = self.figmgr.toolbar 741 779 thecanvas = self.figmgr.canvas … … 819 857 if event.button != 1 or event.inaxes == None: 820 858 return 859 # check for the validity of plotter and get the plotter 860 theplotter = self._get_plotter() 821 861 # this row resolution assumes row panelling 822 862 irow = int(self._getrownum(event.inaxes)) … … 829 869 self._thisregion = {'axes': event.inaxes,'xs': event.x, 830 870 'worldx': [event.xdata,event.xdata]} 831 self.plotter._plotter.register('button_press',None)871 theplotter._plotter.register('button_press',None) 832 872 self.xold = event.x 833 873 self.xdataold = event.xdata 834 self.plotter._plotter.register('motion_notify', self._xspan_draw)835 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) 836 876 837 877 def _xspan_draw(self,event): … … 882 922 self._thisregion['axes'].set_xlim(axlimx) 883 923 884 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() 885 928 self._polygons.append(pregion) 886 929 srow = self._getrownum(self._thisregion['axes']) … … 895 938 896 939 # release event 897 self.plotter._plotter.register('button_press',None)898 self.plotter._plotter.register('motion_notify',None)940 theplotter._plotter.register('button_press',None) 941 theplotter._plotter.register('motion_notify',None) 899 942 # Clear up region selection 900 943 self._thisregion = None … … 902 945 self.xold = None 903 946 # finally recover region selection event 904 self.plotter._plotter.register('button_press',self._add_region)947 theplotter._plotter.register('button_press',self._add_region) 905 948 906 949 ### add panels to selections … … 911 954 if event.button != 1 or event.inaxes == None: 912 955 return 956 # check for the validity of plotter and get the plotter 957 theplotter = self._get_plotter() 958 913 959 selax = event.inaxes 914 960 # this row resolution assumes row panelling … … 919 965 shadow = Rectangle((0,0),1,1,facecolor='0.7',transform=selax.transAxes,visible=True) 920 966 self._polygons.append(selax.add_patch(shadow)) 921 # self.plotter._plotter.show(False)922 self.plotter._plotter.canvas.draw()967 #theplotter._plotter.show(False) 968 theplotter._plotter.canvas.draw() 923 969 asaplog.push("row "+str(irow)+" is selected") 924 970 ## check for region selection of the spectra and overwrite it. … … 956 1002 asaplog.push("Invalid panel specification") 957 1003 asaplog.post('ERROR') 958 strow = self._getrownum(self.plotter._plotter.subplots[0]['axes']) 959 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']) 960 1010 for irow in range(int(strow),int(enrow)+1): 961 1011 if regions.has_key(str(irow)): 962 ax = self.plotter._plotter.subplots[irow - int(strow)]['axes']1012 ax = theplotter._plotter.subplots[irow - int(strow)]['axes'] 963 1013 mlist = regions.pop(str(irow)) 964 1014 # WORKAROUND for the issue axvspan started to reset xlim. … … 970 1020 del ax,mlist,axlimx 971 1021 if irow in panels: 972 ax = self.plotter._plotter.subplots[irow - int(strow)]['axes']1022 ax = theplotter._plotter.subplots[irow - int(strow)]['axes'] 973 1023 shadow = Rectangle((0,0),1,1,facecolor='0.7', 974 1024 transform=ax.transAxes,visible=True) 975 1025 self._polygons.append(ax.add_patch(shadow)) 976 1026 del ax,shadow 977 self.plotter._plotter.canvas.draw()1027 theplotter._plotter.canvas.draw() 978 1028 del regions,panels,strow,enrow 979 1029 … … 983 1033 for shadow in self._polygons: 984 1034 shadow.remove() 985 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() 986 1039 self._polygons = [] 987 1040 … … 1007 1060 asaplog.post('WARN') 1008 1061 return 1062 1009 1063 self._pause_buttons(operation="start",msg="Flagging data...") 1010 1064 self._flag_operation(rows=self._selpanels, … … 1015 1069 asaplog.push(sout) 1016 1070 del sout 1017 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 1018 1075 self._clearup_selections(refresh=False) 1019 1076 self._plot_page(pagemode="current") … … 1036 1093 asaplog.push(sout) 1037 1094 del sout 1038 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 1039 1099 self._clearup_selections(refresh=False) 1040 1100 self._plot_page(pagemode="current") … … 1044 1104 @asaplog_post_dec 1045 1105 def _flag_operation(self,rows=None,regions=None,unflag=False): 1046 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 1047 1110 if not scan: 1048 1111 asaplog.post() … … 1079 1142 @asaplog_post_dec 1080 1143 def _selected_stats(self,rows=None,regions=None): 1081 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 1082 1148 if not scan: 1083 1149 asaplog.post() … … 1164 1230 ### actual plotting of the new page 1165 1231 def _plot_page(self,pagemode="next"): 1166 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: 1167 1235 msg = "The page counter is reset due to chages of plot settings. " 1168 1236 msg += "Plotting from the first page." … … 1172 1240 goback = False 1173 1241 1174 self.plotter._plotter.hold()1175 # self.plotter._plotter.legend(1)1242 theplotter._plotter.hold() 1243 #theplotter._plotter.legend(1) 1176 1244 self._set_plot_counter(pagemode) 1177 self.plotter._plot(self.plotter._data)1245 theplotter._plot(theplotter._data) 1178 1246 self.set_pagecounter(self._get_pagenum()) 1179 self.plotter._plotter.release()1180 self.plotter._plotter.tidy()1181 self.plotter._plotter.show(hardrefresh=False)1247 theplotter._plotter.release() 1248 theplotter._plotter.tidy() 1249 theplotter._plotter.show(hardrefresh=False) 1182 1250 1183 1251 ### calculate the panel ID and start row to plot a page … … 1194 1262 # nothing necessary to plot the next page 1195 1263 return 1264 1265 # check for the validity of plotter and get the plotter 1266 theplotter = self._get_plotter() 1267 1196 1268 # set row and panel counters to those of the 1st panel of previous page 1197 1269 maxpanel = 25 1198 1270 # the ID of the last panel in current plot 1199 lastpanel = self.plotter._ipanel1271 lastpanel = theplotter._ipanel 1200 1272 # the number of current subplots 1201 currpnum = len( self.plotter._plotter.subplots)1273 currpnum = len(theplotter._plotter.subplots) 1202 1274 1203 1275 # the nuber of previous subplots … … 1208 1280 ## previous page 1209 1281 prevpnum = None 1210 if self.plotter._rows and self.plotter._cols:1282 if theplotter._rows and theplotter._cols: 1211 1283 # when user set layout 1212 prevpnum = self.plotter._rows*self.plotter._cols1284 prevpnum = theplotter._rows*theplotter._cols 1213 1285 else: 1214 1286 # no user specification … … 1218 1290 1219 1291 # set the pannel ID of the last panel of the prev(-prev) page 1220 self.plotter._ipanel = start_ipanel-11221 if self.plotter._panelling == 'r':1222 self.plotter._startrow = start_ipanel1292 theplotter._ipanel = start_ipanel-1 1293 if theplotter._panelling == 'r': 1294 theplotter._startrow = start_ipanel 1223 1295 else: 1224 1296 # the start row number of the next panel 1225 self.plotter._startrow = self.plotter._panelrows[start_ipanel]1297 theplotter._startrow = theplotter._panelrows[start_ipanel] 1226 1298 del lastpanel,currpnum,start_ipanel 1227 1299 … … 1238 1310 1239 1311 def _get_pagenum(self): 1312 # check for the validity of plotter and get the plotter 1313 theplotter = self._get_plotter() 1240 1314 # get the ID of last panel in the current page 1241 idlastpanel = self.plotter._ipanel1315 idlastpanel = theplotter._ipanel 1242 1316 # max panels in a page 1243 ppp = self.plotter._plotter.rows*self.plotter._plotter.cols1317 ppp = theplotter._plotter.rows*theplotter._plotter.cols 1244 1318 return int(idlastpanel/ppp)+1 1245 1319
Note:
See TracChangeset
for help on using the changeset viewer.