source: trunk/python/flagtoolbar.py@ 2015

Last change on this file since 2015 was 2000, checked in by Kana Sugimoto, 14 years ago

New Development: No

JIRA Issue: Yes (CAS-1306/ASAP-205)

Ready for Test: Yes

Interface Changes: No

What Interface Changed: Please list interface changes

Test Programs: run flagplotter

Put in Release Notes: No

Module(s): flagtoolbar & flagplotter

Description:

Region selection and operation information will be printed on the logger
instead of the terminal.
Removed _statistics function in CustomFlagToolbarCommon and merged it to stat_cal function.


File size: 29.3 KB
RevLine 
[1996]1import os
2import matplotlib, numpy
3from matplotlib.patches import Rectangle
4from asap.parameters import rcParams
5from asap.logging import asaplog, asaplog_post_dec
6from asap import scantable
7from asap._asap import stmath
8
9###########################################
10## Add CASA custom Flag toolbar ##
11###########################################
12class CustomFlagToolbarCommon:
13 def __init__(self,parent):
14 self.plotter=parent
15 #self.figmgr=self.plotter._plotter.figmgr
16 self._selregions = {}
17 self._selpanels = []
18 self._polygons = []
19 self._thisregion = None
20 self.xdataold=None
21
22 ### select the nearest spectrum in pick radius
23 ### and display spectral value on the toolbar.
24 def _select_spectrum(self,event):
25 # Do not fire event when in zooming/panning mode
26 mode = self.figmgr.toolbar.mode
27 if not mode == '':
28 return
29 # When selected point is out of panels
30 if event.inaxes == None:
31 return
32 # If not left button
33 if event.button != 1:
34 return
35
36 xclick=event.xdata
37 yclick=event.ydata
38 dist2=1000.
39 pickline=None
40 # If the pannel has picable objects
41 pflag=False
42 for lin in event.inaxes.lines:
43 if not lin.pickable():
44 continue
45 pflag=True
46 flag,pind = lin.contains(event)
47 if not flag:
48 continue
49 # Get nearest point
50 inds = pind['ind']
51 xlin = lin.get_xdata()
52 ylin = lin.get_ydata()
53 for i in inds:
54 d2=(xlin[i]-xclick)**2+(ylin[i]-yclick)**2
55 if dist2 >= d2:
56 dist2 = d2
57 pickline = lin
58 # No pickcable line in the pannel
59 if not pflag:
60 return
61 # Pickable but too far from mouse position
62 elif pickline is None:
63 picked='No line selected.'
64 self.figmgr.toolbar.set_message(picked)
65 return
66 del pind, inds, xlin, ylin
67 # Spectra are Picked
68 theplot = self.plotter._plotter
69 thetoolbar = self.figmgr.toolbar
70 thecanvas = self.figmgr.canvas
71 # Disconnect the default motion notify event
72 # Notice! the other buttons are also diabled!!!
73 thecanvas.mpl_disconnect(thetoolbar._idDrag)
74 # Get picked spectrum
75 xdata = pickline.get_xdata()
76 ydata = pickline.get_ydata()
77 titl=pickline.get_label()
78 titp=event.inaxes.title.get_text()
79 panel0=event.inaxes
80 picked="Selected: '"+titl+"' in panel '"+titp+"'."
81 thetoolbar.set_message(picked)
82 # Generate a navigation window
83 #naviwin=Navigationwindow(titp,titl)
84 #------------------------------------------------------#
85 # Show spectrum data at mouse position
86 def spec_data(event):
87 # Getting spectrum data of neiboring point
88 xclick=event.xdata
89 if event.inaxes != panel0:
90 return
91 ipoint=len(xdata)-1
92 for i in range(len(xdata)-1):
93 xl=xclick-xdata[i]
94 xr=xclick-xdata[i+1]
95 if xl*xr <= 0.:
96 ipoint = i
97 break
98 # Output spectral value on the navigation window
99 posi='[ %s, %s ]: x = %.2f value = %.2f'\
100 %(titl,titp,xdata[ipoint],ydata[ipoint])
101 #naviwin.posi.set(posi)
102 thetoolbar.set_message(posi)
103 #------------------------------------------------------#
104 # Disconnect from mouse events
105 def discon(event):
106 #naviwin.window.destroy()
107 theplot.register('motion_notify',None)
108 # Re-activate the default motion_notify_event
109 thetoolbar._idDrag=thecanvas.mpl_connect('motion_notify_event',
110 thetoolbar.mouse_move)
111 theplot.register('button_release',None)
112 return
113 #------------------------------------------------------#
114 # Show data value along with mouse movement
115 theplot.register('motion_notify',spec_data)
116 # Finish events when mouse button is released
117 theplot.register('button_release',discon)
118
119
120 ### Notation
121 def _mod_note(self,event):
122 # Do not fire event when in zooming/panning mode
123 if not self.figmgr.toolbar.mode == '':
124 return
125 if event.button ==1:
126 self.notewin.load_textwindow(event)
127 elif event.button == 3 and self._note_picked(event):
128 self.notewin.load_modmenu(event)
129 return
130
131 def _note_picked(self,event):
132 # just briefly check if any texts are picked
133 for textobj in self.canvas.figure.texts:
134 if textobj.contains(event)[0]:
135 return True
136 for ax in self.canvas.figure.axes:
137 for textobj in ax.texts:
138 if textobj.contains(event)[0]:
139 return True
140 #print "No text picked"
141 return False
142
143 ### Region/Panel selection & oparations
144 ### add regions to selections
145 @asaplog_post_dec
146 def _add_region(self,event):
147 if not self.figmgr.toolbar.mode == '':
148 return
149 if event.button != 1 or event.inaxes == None:
150 return
151 # this row resolution assumes row panelling
152 irow = int(self._getrownum(event.inaxes))
153 if irow in self._selpanels:
154 msg = "The whole spectrum is already selected"
155 asaplog.post()
156 asaplog.push(msg)
157 asaplog.post('WARN')
158 return
[2000]159 #print "add the region to selections"
[1996]160 self._thisregion = {'axes': event.inaxes,'xs': event.xdata,
161 'worldx': [event.xdata,event.xdata]}
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)
165
166 def _xspan_draw(self,event):
167 if event.inaxes == self._thisregion['axes']:
168 xnow = event.xdata
169 self.xdataold = xnow
170 else:
171 xnow = self.xdataold
172 try: self.lastspan
173 except AttributeError: pass
174 else: self.lastspan.remove()
175
176 self.lastspan = self._thisregion['axes'].axvspan(self._thisregion['xs'],xnow,facecolor='0.7')
[1999]177 #self.plotter._plotter.show(False)
178 self.plotter._plotter.canvas.draw()
[1996]179 del xnow
180
181 def _xspan_end(self,event):
182 if not self.figmgr.toolbar.mode == '':
183 return
184 if event.button != 1:
185 return
186
187 try: self.lastspan
188 except AttributeError: pass
189 else:
190 self.lastspan.remove()
191 del self.lastspan
192 if event.inaxes == self._thisregion['axes']:
193 xdataend = event.xdata
194 else:
195 xdataend=self.xdataold
196
197 self._thisregion['worldx'][1] = xdataend
198 lregion = self._thisregion['worldx']
199 pregion = self._thisregion['axes'].axvspan(lregion[0],lregion[1],
200 facecolor='0.7')
[1999]201 #self.plotter._plotter.show(False)
202 self.plotter._plotter.canvas.draw()
[1996]203 self._polygons.append(pregion)
204 srow = self._getrownum(self._thisregion['axes'])
205 irow = int(srow)
206 if not self._selregions.has_key(srow):
207 self._selregions[srow] = []
208 self._selregions[srow].append(lregion)
209 del lregion, pregion, xdataend
[2000]210 sout = "selected region: "+str(self._thisregion['worldx'])+\
211 "(@row "+str(self._getrownum(self._thisregion['axes']))+")"
212 asaplog.push(sout)
[1996]213
214 # release event
215 self.plotter._plotter.register('button_press',None)
216 self.plotter._plotter.register('motion_notify',None)
217 # Clear up region selection
218 self._thisregion = None
219 self.xdataold = None
220 # finally recover region selection event
221 self.plotter._plotter.register('button_press',self._add_region)
222
223 ### add panels to selections
224 @asaplog_post_dec
225 def _add_panel(self,event):
226 if not self.figmgr.toolbar.mode == '':
227 return
228 if event.button != 1 or event.inaxes == None:
229 return
230 selax = event.inaxes
231 # this row resolution assumes row panelling
232 srow = self._getrownum(selax)
233 irow = int(srow)
234 if srow:
235 self._selpanels.append(irow)
236 shadow = Rectangle((0,0),1,1,facecolor='0.7',transform=selax.transAxes,visible=True)
237 self._polygons.append(selax.add_patch(shadow))
[1999]238 #self.plotter._plotter.show(False)
239 self.plotter._plotter.canvas.draw()
[2000]240 asaplog.push("row "+str(irow)+" is selected")
241 #print "selected rows =",self._selpanels
[1996]242 ## check for region selection of the spectra and overwrite it.
243 ##!!!! currently disabled for consistency with flag tools !!!!
244 #if self._selregions.has_key(srow):
245 # self._selregions.pop(srow)
246 # msg = "The whole spectrum is selected for row="+srow+". Region selection will be overwritten."
247 # asaplog.push(msg)
248
249 def _getrownum(self,axis):
250 ### returns the row number of selected spectrum as a string ###
251 plabel = axis.get_title()
252 if plabel.startswith("row "):
253 return plabel.strip("row ")
254 return None
255
256 def _any_selection(self):
257 ### returns if users have selected any spectrum or region ###
258 if len(self._selpanels) or len(self._selregions):
259 return True
260 return False
261
262 def _plot_selections(self,regions=None,panels=None):
263 ### mark panels/spectra selections in the page
264 if not self._any_selection() and not (regions or panels):
265 return
266 regions = regions or self._selregions.copy() or {}
267 panels = panels or self._selpanels or []
268 if not isinstance(regions,dict):
269 asaplog.post()
270 asaplog.push("Invalid region specification")
271 asaplog.post('ERROR')
272 if not isinstance(panels,list):
273 asaplog.post()
274 asaplog.push("Invalid panel specification")
275 asaplog.post('ERROR')
276 strow = self._getrownum(self.plotter._plotter.subplots[0]['axes'])
277 enrow = self._getrownum(self.plotter._plotter.subplots[-1]['axes'])
278 for irow in range(int(strow),int(enrow)+1):
279 if regions.has_key(str(irow)):
280 ax = self.plotter._plotter.subplots[irow - int(strow)]['axes']
281 mlist = regions.pop(str(irow))
282 for i in range(len(mlist)):
283 self._polygons.append(ax.axvspan(mlist[i][0],mlist[i][1],
284 facecolor='0.7'))
285 del ax,mlist
286 if irow in panels:
287 ax = self.plotter._plotter.subplots[irow - int(strow)]['axes']
288 shadow = Rectangle((0,0),1,1,facecolor='0.7',
289 transform=ax.transAxes,visible=True)
290 self._polygons.append(ax.add_patch(shadow))
291 del ax,shadow
[1999]292 #self.plotter._plotter.show(False)
293 self.plotter._plotter.canvas.draw()
[1996]294 del regions,panels,strow,enrow
295
296 def _clear_selection_plot(self):
297 ### clear up polygons which mark selected spectra and regions ###
[1998]298 if len(self._polygons) > 0:
[1996]299 for shadow in self._polygons:
300 shadow.remove()
[1998]301 self.plotter._plotter.canvas.draw()
[1996]302 self._polygons = []
303
304 def _clearup_selections(self):
305 # clear-up selection and polygons
306 self._selpanels = []
307 self._selregions = {}
308 self._clear_selection_plot()
309
310 ### clear up selections
311 def cancel_select(self):
312 self.figmgr.toolbar.set_message('selections canceled')
313 # clear-up selection and polygons
314 self._clearup_selections()
315
316 ### flag selected spectra/regions
317 @asaplog_post_dec
318 def flag(self):
319 if not self._any_selection():
320 msg = "No selection to be Flagged"
321 asaplog.post()
322 asaplog.push(msg)
323 asaplog.post('WARN')
324 return
325 self._flag_operation(rows=self._selpanels,
326 regions=self._selregions,unflag=False)
[2000]327 sout = "Flagged:\n"
328 sout += " rows = "+str(self._selpanels)+"\n"
329 sout += " regions: "+str(self._selregions)
330 asaplog.push(sout)
331 del sout
[1996]332 self._clearup_selections()
333 self._plot_page(pagemode="current")
334
335 ### unflag selected spectra/regions
336 @asaplog_post_dec
337 def unflag(self):
338 if not self._any_selection():
339 msg = "No selection to be Flagged"
340 asaplog.push(msg)
341 asaplog.post('WARN')
342 return
343 self._flag_operation(rows=self._selpanels,
344 regions=self._selregions,unflag=True)
[2000]345 sout = "Unflagged:\n"
346 sout += " rows = "+str(self._selpanels)+"\n"
347 sout += " regions: "+str(self._selregions)
348 asaplog.push(sout)
349 del sout
[1996]350 self._clearup_selections()
351 self._plot_page(pagemode="current")
352
353 ### actual flag operation
354 @asaplog_post_dec
355 def _flag_operation(self,rows=None,regions=None,unflag=False):
356 scan = self.plotter._data
357 if not scan:
358 asaplog.post()
359 asaplog.push("Invalid scantable")
360 asaplog.post("ERROR")
361 if isinstance(rows,list) and len(rows) > 0:
362 scan.flag_row(rows=rows,unflag=unflag)
363 if isinstance(regions,dict) and len(regions) > 0:
364 for srow, masklist in regions.iteritems():
365 if not isinstance(masklist,list) or len(masklist) ==0:
366 msg = "Ignoring invalid region selection for row = "+srow
367 asaplog.post()
368 asaplog.push(msg)
369 asaplog.post("WARN")
370 continue
371 irow = int(srow)
372 mask = scan.create_mask(masklist,invert=False,row=irow)
373 scan.flag(row=irow,mask=mask,unflag=unflag)
374 del irow, mask
375 del srow, masklist
376 del scan
377
378 ### show statistics of selected spectra/regions
[2000]379 @asaplog_post_dec
[1996]380 def stat_cal(self):
[2000]381 if not self._any_selection():
382 msg = "No selection to be calculated"
383 asaplog.push(msg)
384 asaplog.post('WARN')
385 return
386 #print "Calculate statistics of selected region and spectra"
387 self._selected_stats(rows=self._selpanels,regions=self._selregions)
388 #print "Statistics: "
389 #print "- rows: ",self._selpanels
390 #print "- regions:\n ",self._selregions
391 self._clearup_selections()
[1996]392
[2000]393 @asaplog_post_dec
394 def _selected_stats(self,rows=None,regions=None):
395 scan = self.plotter._data
396 if not scan:
397 asaplog.post()
398 asaplog.push("Invalid scantable")
399 asaplog.post("ERROR")
400 mathobj = stmath( rcParams['insitu'] )
401 statval={}
402 statstr = ['max', 'min', 'mean', 'median', 'sum', 'stddev', 'rms']
403 if isinstance(rows,list) and len(rows) > 0:
404 for irow in rows:
405 for stat in statstr:
406 #statval[stat] = scan.stats(stat=stat,row=irow)[0]
407 statval[stat] = mathobj._statsrow(scan,[],stat,irow)[0]
408 self._print_stats(scan,irow,statval,statstr=statstr)
409 del irow
410 if isinstance(regions,dict) and len(regions) > 0:
411 for srow, masklist in regions.iteritems():
412 if not isinstance(masklist,list) or len(masklist) ==0:
413 msg = "Ignoring invalid region selection for row = "+srow
414 asaplog.post()
415 asaplog.push(msg)
416 asaplog.post("WARN")
417 continue
418 irow = int(srow)
419 mask = scan.create_mask(masklist,invert=False,row=irow)
420 for stat in statstr:
421 #statval[stat] = scan.stats(stat=stat,row=irow,mask = mask)[0]
422 statval[stat] = mathobj._statsrow(scan,mask,stat,irow)[0]
423 self._print_stats(scan,irow,statval,statstr=statstr,mask=masklist)
424 del irow, mask
425 del srow, masklist
426 del scan, statval, mathobj
427
428 @asaplog_post_dec
429 def _print_stats(self,scan,row,stats,statstr=None,mask=None):
430 if not isinstance(scan, scantable):
431 asaplog.post()
432 asaplog.push("Invalid scantable")
433 asaplog.post("ERROR")
434 if row < 0 or row > scan.nrow():
435 asaplog.post()
436 asaplog.push("Invalid row number")
437 asaplog.post("ERROR")
438 if not isinstance(stats,dict) or len(stats) == 0:
439 asaplog.post()
440 asaplog.push("Invalid statistic value")
441 asaplog.post("ERROR")
442 maskstr = "All"
443 if mask:
444 maskstr = str(mask)
445 ssep = "-"*70+"\n"
446 sout = ssep
447 sout += ("Row=%d Scan=%d IF=%d Pol=%d Time=%s mask=%s" % \
448 (row, scan.getscan(row), scan.getif(row), scan.getpol(row), scan.get_time(row),maskstr))
449 sout += "\n"
450 statvals = []
451 if not len(statstr):
452 statstr = stats.keys()
453 for key in statstr:
454 sout += key.ljust(10)
455 statvals.append(stats.pop(key))
456 sout += "\n"
457 sout += ("%f "*len(statstr) % tuple(statvals))
458 sout += "\n"+ssep
459 asaplog.push(sout)
460 del sout, ssep, maskstr, statvals, key, scan, row, stats, statstr, mask
461
[1996]462 ### Page chages
463 ### go to the previous page
464 def prev_page(self):
465 self.figmgr.toolbar.set_message('plotting the previous page')
466 self._clear_selection_plot()
467 self._plot_page(pagemode="prev")
468 self._plot_selections()
469
470 ### go to the next page
471 def next_page(self):
472 self.figmgr.toolbar.set_message('plotting the next page')
473 self._clear_selection_plot()
474 self._plot_page(pagemode="next")
475 self._plot_selections()
476
477 ### actual plotting of the new page
478 def _plot_page(self,pagemode="next"):
479 if self.plotter._startrow <= 0:
480 msg = "The page counter is reset due to chages of plot settings. "
481 msg += "Plotting from the first page."
482 asaplog.post()
483 asaplog.push(msg)
484 asaplog.post('WARN')
485 goback = False
486
487 self.plotter._plotter.hold()
488 self.plotter._plotter.legend(1)
489 #if goback:
490 # self._set_prevpage_counter()
491 self._set_plot_counter(pagemode)
492 #self.plotter._plotter.clear()
493 self.plotter._plot(self.plotter._data)
494 self.set_pagecounter(self._get_pagenum())
495 self.plotter._plotter.release()
496 self.plotter._plotter.tidy()
497 self.plotter._plotter.show(hardrefresh=False)
498
499 ### calculate the panel ID and start row to plot a page
500 #def _set_prevpage_counter(self):
501 def _set_plot_counter(self, pagemode):
502 ## page operation should be either "previous", "current", or "next"
503 availpage = ["p","c","n"]
504 pageop = pagemode[0].lower()
505 if not (pageop in availpage):
506 asaplog.post()
[2000]507 asaplog.push("Invalid page operation")
508 asaplog.post("ERROR")
[1996]509 if pageop == "n":
510 # nothing necessary to plot the next page
511 return
512 # set row and panel counters to those of the 1st panel of previous page
513 maxpanel = 16
514 # the ID of the last panel in current plot
515 lastpanel = self.plotter._ipanel
516 # the number of current subplots
517 currpnum = len(self.plotter._plotter.subplots)
518
519 # the nuber of previous subplots
520 start_ipanel = None
521 if pageop == "c":
522 start_ipanel = max(lastpanel-currpnum+1, 0)
523 else:
524 ## previous page
525 prevpnum = None
526 if self.plotter._rows and self.plotter._cols:
527 # when user set layout
528 prevpnum = self.plotter._rows*self.plotter._cols
529 else:
530 # no user specification
531 prevpnum = maxpanel
532 start_ipanel = max(lastpanel-currpnum-prevpnum+1, 0)
533 del prevpnum
534
535 # set the pannel ID of the last panel of the prev(-prev) page
536 self.plotter._ipanel = start_ipanel-1
537 if self.plotter._panelling == 'r':
538 self.plotter._startrow = start_ipanel
539 else:
540 # the start row number of the next panel
541 self.plotter._startrow = self.plotter._panelrows[start_ipanel]
542 del lastpanel,currpnum,start_ipanel
543
544 ### refresh the page counter
545 def set_pagecounter(self,page):
546 nwidth = int(numpy.ceil(numpy.log10(max(page,1))))+1
547 nwidth = max(nwidth,4)
548 formatstr = '%'+str(nwidth)+'d'
549 self.show_pagenum(page,formatstr)
550
551 def show_pagenum(self,pagenum,formatstr):
552 # passed to backend dependent class
553 pass
554
555 def _get_pagenum(self):
556 maxpanel = 16
557 # get the ID of last panel in the current page
558 idlastpanel = self.plotter._ipanel
559 if self.plotter._rows and self.plotter._cols:
560 ppp = self.plotter._rows*self.plotter._cols
561 else:
562 ppp = maxpanel
563 return int(idlastpanel/ppp)+1
564
565#####################################
566## Backend dependent Classes ##
567#####################################
568### TkAgg
569if matplotlib.get_backend() == 'TkAgg':
570 import Tkinter as Tk
571 from notationwindow import NotationWindowTkAgg
572
573class CustomFlagToolbarTkAgg(CustomFlagToolbarCommon, Tk.Frame):
574 def __init__(self,parent):
575 from asap.asapplotter import asapplotter
576 if not isinstance(parent,asapplotter):
577 return False
578 if not parent._plotter:
579 return False
580 self._p = parent._plotter
581 self.figmgr = self._p.figmgr
582 self.canvas = self.figmgr.canvas
583 self.mode = ''
584 self.button = True
585 self.pagecount = None
586 CustomFlagToolbarCommon.__init__(self,parent)
587 self.notewin=NotationWindowTkAgg(master=self.canvas)
588 self._add_custom_toolbar()
589
590 def _add_custom_toolbar(self):
591 Tk.Frame.__init__(self,master=self.figmgr.window)
592 #self.bSpec=self._NewButton(master=self,
593 # text='spec value',
594 # command=self.spec_show)
595
596 self.bRegion=self._NewButton(master=self,
597 text='region',
598 command=self.select_region)
599 self.bPanel=self._NewButton(master=self,
600 text='panel',
601 command=self.select_panel)
602 self.bClear=self._NewButton(master=self,
603 text='clear',
604 command=self.cancel_select)
605 self.bFlag=self._NewButton(master=self,
606 text='flag',
607 command=self.flag)
608 self.bUnflag=self._NewButton(master=self,
609 text='unflag',
610 command=self.unflag)
611
612 self.bStat=self._NewButton(master=self,
613 text='statistics',
614 command=self.stat_cal)
615
616 self.bNote=self._NewButton(master=self,
617 text='notation',
618 command=self.modify_note)
619
620 self.bQuit=self._NewButton(master=self,
621 text='Quit',
622 #file="stock_close.ppm",
623 command=self.quit,
624 side=Tk.RIGHT)
625
626 # page change oparations
627 frPage = Tk.Frame(master=self,borderwidth=2,relief=Tk.GROOVE)
628 frPage.pack(ipadx=2,padx=10,side=Tk.RIGHT)
629 self.lPagetitle = Tk.Label(master=frPage,text='Page:',padx=5)
630 #width=8,anchor=Tk.E,padx=5)
631 self.lPagetitle.pack(side=Tk.LEFT)
632 self.pagecount = Tk.StringVar(master=frPage)
633 self.lPagecount = Tk.Label(master=frPage,
634 textvariable=self.pagecount,
635 padx=5,bg='white')
636 self.lPagecount.pack(side=Tk.LEFT,padx=3)
637
638 self.bNext=self._NewButton(master=frPage,
639 text=' + ',
640 #file="hand.ppm",
641 command=self.next_page)
642 self.bPrev=self._NewButton(master=frPage,
643 text=' - ',
644 command=self.prev_page)
645
646 if os.uname()[0] != 'Darwin':
647 self.bPrev.config(padx=5)
648 self.bNext.config(padx=5)
649
650 self.pack(side=Tk.BOTTOM,fill=Tk.BOTH)
651 self.pagecount.set(' '*4)
652
653 self.disable_button()
654 return #self
655
656 def _NewButton(self, master, text, command, side=Tk.LEFT,file=None):
657 img = None
658 if file:
659 file = os.path.join(matplotlib.rcParams['datapath'], 'images', file)
660 img = Tk.PhotoImage(master=master, file=file)
661
662 if os.uname()[0] == 'Darwin':
663 b = Tk.Button(master=master, text=text, image=img,
664 command=command)
665 if img: b.image = img
666 else:
667 b = Tk.Button(master=master, text=text, image=img, padx=2, pady=2,
668 command=command)
669 if img: b.image = img
670 b.pack(side=side)
671 return b
672
673 def show_pagenum(self,pagenum,formatstr):
674 self.pagecount.set(formatstr % (pagenum))
675
676 def spec_show(self):
677 if not self.figmgr.toolbar.mode == '' or not self.button: return
678 self.figmgr.toolbar.set_message('spec value: drag on a spec')
679 if self.mode == 'spec': return
680 self.mode='spec'
681 self.notewin.close_widgets()
682 self.__disconnect_event()
683 self._p.register('button_press',self._select_spectrum)
684
685 def modify_note(self):
686 if not self.figmgr.toolbar.mode == '': return
687 self.figmgr.toolbar.set_message('text: select a position/text')
688 if self.mode == 'note':
689 self.bNote.config(relief='raised')
690 self.mode='none'
691 self.spec_show()
692 return
693 self.bNote.config(relief='sunken')
694 self.bRegion.config(relief='raised')
695 self.bPanel.config(relief='raised')
696 self.mode='note'
697 self.__disconnect_event()
698 self._p.register('button_press',self._mod_note)
699
700 def select_region(self):
701 if not self.figmgr.toolbar.mode == '' or not self.button: return
702 self.figmgr.toolbar.set_message('select rectangle regions')
703 if self.mode == 'region':
704 self.bRegion.config(relief='raised')
705 self.mode='none'
706 self.spec_show()
707 return
708 self.bNote.config(relief='raised')
709 self.bRegion.config(relief='sunken')
710 self.bPanel.config(relief='raised')
711 self.mode='region'
712 self.notewin.close_widgets()
713 self.__disconnect_event()
714 self._p.register('button_press',self._add_region)
715
716 def select_panel(self):
717 if not self.figmgr.toolbar.mode == '' or not self.button: return
718 self.figmgr.toolbar.set_message('select panels')
719 if self.mode == 'panel':
720 self.bPanel.config(relief='raised')
721 self.mode='none'
722 self.spec_show()
723 return
724 self.bNote.config(relief='raised')
725 self.bRegion.config(relief='raised')
726 self.bPanel.config(relief='sunken')
727 self.mode='panel'
728 self.notewin.close_widgets()
729 self.__disconnect_event()
730 self._p.register('button_press',self._add_panel)
731
732 def quit(self):
733 self.__disconnect_event()
734 #self.delete_bar()
735 self.disable_button()
736 self.figmgr.window.wm_withdraw()
737
738 def enable_button(self):
739 if self.button: return
740 self.bRegion.config(state=Tk.NORMAL)
741 self.bPanel.config(state=Tk.NORMAL)
742 self.bClear.config(state=Tk.NORMAL)
743 self.bFlag.config(state=Tk.NORMAL)
744 self.bUnflag.config(state=Tk.NORMAL)
745 self.bStat.config(state=Tk.NORMAL)
746 self.button=True
747 self.spec_show()
748
749 def disable_button(self):
750 ## disable buttons which don't work for plottp
751 if not self.button: return
752 self.bRegion.config(relief='raised', state=Tk.DISABLED)
753 self.bPanel.config(relief='raised', state=Tk.DISABLED)
754 self.bClear.config(state=Tk.DISABLED)
755 self.bFlag.config(state=Tk.DISABLED)
756 self.bUnflag.config(state=Tk.DISABLED)
757 self.bStat.config(state=Tk.DISABLED)
758 self.bNext.config(state=Tk.DISABLED)
759 self.bPrev.config(state=Tk.DISABLED)
760 self.button=False
761 self.mode=''
762 self.notewin.close_widgets()
763 self.__disconnect_event()
764
765 def enable_next(self):
766 self.bNext.config(state=Tk.NORMAL)
767
768 def disable_next(self):
769 self.bNext.config(state=Tk.DISABLED)
770
771 def enable_prev(self):
772 self.bPrev.config(state=Tk.NORMAL)
773
774 def disable_prev(self):
775 self.bPrev.config(state=Tk.DISABLED)
776
777 def delete_bar(self):
778 self.__disconnect_event()
779 self.destroy()
780
781 def __disconnect_event(self):
782 self._p.register('button_press',None)
783 self._p.register('button_release',None)
Note: See TracBrowser for help on using the repository browser.