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