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