source: trunk/python/customgui_qt4agg.py@ 2723

Last change on this file since 2723 was 2603, checked in by Kana Sugimoto, 12 years ago

New Development: No

JIRA Issue: No (bug fixes and a minor improvement)

Ready for Test: Yes

Interface Changes: No

What Interface Changed:

Test Programs: interactive test needed.

Put in Release Notes: No

Module(s): asapplotter, flagplotter, and sdplot (CASA)

Description:

Fixed bugs in asapplotter and flagplotter which prevented users from exiting
from notation mode, when the other buttons in the additional toolbar is not active.
Consintently use 'self._data' in asapplotter.plotgrid() instead of 'scan'.


File size: 29.7 KB
Line 
1import os
2import matplotlib, numpy
3from asap.logging import asaplog, asaplog_post_dec
4from matplotlib.patches import Rectangle
5from asap.parameters import rcParams
6from asap._asap import stmath
7from asap.customgui_base import *
8
9import PyQt4 as qt
10
11######################################
12## Add CASA custom toolbar ##
13######################################
14class CustomToolbarQT4Agg(CustomToolbarCommon, qt.QtGui.QToolBar):
15 def __init__(self,parent):
16 from asap.asapplotter import asapplotter
17 if not isinstance(parent,asapplotter):
18 return False
19 if not parent._plotter:
20 return False
21 self._p = parent._plotter
22 self.figmgr = self._p.figmgr
23 self.canvas = self.figmgr.canvas
24 self.mode = ''
25 self.button = True
26 self.pagecount = None
27 CustomToolbarCommon.__init__(self,parent)
28 self.notewin = NotationWindowQT4Agg(master=self.canvas)
29 self._add_custom_toolbar()
30
31 def _add_custom_toolbar(self):
32 qt.QtGui.QToolBar.__init__(self,parent=self.figmgr.window)
33 self.figmgr.window.addToolBar(qt.QtCore.Qt.BottomToolBarArea,self)
34 self.bNote = self._NewButton(master=self,
35 text='notation',
36 command=self.modify_note,
37 balloon="add note on plot")
38 self.bNote.setCheckable(True)
39
40 self.bStat = self._NewButton(master=self,
41 text='statistics',
42 command=self.stat_cal,
43 balloon="calculate statistics")
44 self.bStat.setCheckable(True)
45
46 # page change oparations
47 frPage = qt.QtGui.QWidget(parent=self,flags=qt.QtCore.Qt.Tool)
48 loPage = qt.QtGui.QHBoxLayout(self)
49 loPage.addStretch(1)
50 self.lPagetitle = qt.QtGui.QLabel('Page:',parent=frPage)
51 self.lPagetitle.setMargin(5)
52 loPage.addWidget(self.lPagetitle)
53 self.pagecount = qt.QtGui.QLabel(parent=frPage)
54 self.pagecount.setStyleSheet("background-color: white")
55 self.pagecount.setMargin(3)
56 self.pagecount.setText(' 1')
57 loPage.addWidget(self.pagecount)
58
59 self.bNext = self._NewButton(master=frPage,
60 text=' + ',
61 command=self.next_page,
62 addit=False,
63 balloon="plot next page")
64 loPage.addWidget(self.bNext)
65 self.bPrev = self._NewButton(master=frPage,
66 text=' - ',
67 command=self.prev_page,addit=False,
68 balloon="plot previous page")
69 loPage.addWidget(self.bPrev)
70 frPage.setLayout(loPage)
71 self.addWidget(frPage)
72
73 self.bQuit = self._NewButton(master=self,
74 text='Quit',
75 command=self.quit,
76 balloon="Close window")
77
78 self.pagecount.setText(' '*4)
79
80 self.disable_button()
81 return
82
83 def _NewButton(self, master, text, command, balloon=None,addit=True):
84 b = qt.QtGui.QPushButton(text,parent=master)
85 if balloon: b.setToolTip(balloon)
86 if addit: master.addWidget(b)
87 master.connect(b,qt.QtCore.SIGNAL('clicked()'),command)
88 return b
89
90 def show_pagenum(self,pagenum,formatstr):
91 self.pagecount.setText(formatstr % (pagenum))
92
93 def spec_show(self):
94 if not self.figmgr.toolbar.mode == '' or not self.button: return
95 self.figmgr.toolbar.set_message("spec value: drag on a spec")
96 if self.mode == 'spec': return
97 self.mode = 'spec'
98 self.notewin.close_widgets()
99 self.__disconnect_event()
100 self._p.register('button_press',self._select_spectrum)
101
102 def stat_cal(self):
103 if not self.figmgr.toolbar.mode == '' or not self.button:
104 # Get back button status BEFORE clicked
105 self.bStat.setChecked(not self.bStat.isChecked())
106 return
107 if self.mode == 'stat':
108 # go back to spec mode
109 self.bStat.setChecked(False)
110 self.bStat.setToolTip("calculate statistics")
111 self.spec_show()
112 return
113 self.figmgr.toolbar.set_message("statistics: click at start and end channels")
114 self.bStat.setChecked(True)
115 self.bStat.setToolTip("Back to spec value mode")
116 self.bNote.setChecked(False)
117 self.bNote.setToolTip("add note on plot")
118 self.mode = 'stat'
119 self.notewin.close_widgets()
120 self.__disconnect_event()
121 self._p.register('button_press',self._single_mask)
122
123 def modify_note(self):
124 if not self.figmgr.toolbar.mode == '':
125 # Get back button status BEFORE clicked
126 self.bNote.setChecked(not self.bNote.isChecked())
127 return
128 if self.mode == 'note':
129 self.bNote.setChecked(False)
130 self.bNote.setToolTip("add note on plot")
131 self.mode = 'none'
132 self.spec_show()
133 if not self.button:
134 self.notewin.close_widgets()
135 self.__disconnect_event()
136 return
137 self.figmgr.toolbar.set_message("text: select a position/text")
138 self.bStat.setChecked(False)
139 self.bStat.setToolTip("calculate statistics")
140 self.bNote.setChecked(True)
141 self.bNote.setToolTip("Back to spec value mode")
142 self.mode = 'note'
143 self.__disconnect_event()
144 self._p.register('button_press',self._mod_note)
145
146 def quit(self):
147 self.__disconnect_event()
148 self.disable_button()
149 self._p.quit()
150
151 def enable_button(self):
152 if self.button: return
153 self.bStat.setEnabled(True)
154 self.button = True
155 self.spec_show()
156
157 def disable_button(self):
158 if not self.button: return
159 self.bStat.setChecked(False)
160 self.bStat.setDisabled(True)
161 self.button = False
162 self.mode = ''
163 self.__disconnect_event()
164
165 def enable_next(self):
166 self.bNext.setEnabled(True)
167
168 def disable_next(self):
169 self.bNext.setDisabled(True)
170
171 def enable_prev(self):
172 self.bPrev.setEnabled(True)
173
174 def disable_prev(self):
175 self.bPrev.setDisabled(True)
176
177 # pause buttons for slow operations
178 def _pause_buttons(self,operation="end",msg=""):
179 buttons = ["bStat","bNote","bQuit"]
180 if operation == "start":
181 enable = False
182 else:
183 enable = True
184 for btn in buttons:
185 getattr(self,btn).setEnabled(enable)
186 self.figmgr.toolbar.set_message(msg)
187
188 def delete_bar(self):
189 self.__disconnect_event()
190 self.destroy()
191
192 def __disconnect_event(self):
193 self._p.register('button_press',None)
194 self._p.register('button_release',None)
195
196 def _draw_span(self,axes,x0,x1,**kwargs):
197 height = self._p.figure.bbox.height
198 y1 = height - axes.bbox.y1
199 h = axes.bbox.height
200 w = abs(x1 - x0)
201 rect = [ int(val) for val in min(x0,x1), y1, w, h ]
202 self._p.canvas.drawRectangle( rect )
203 # nothing is returned by drawRectangle
204 return None
205
206 def _remove_span(self,span):
207 # Nothing to do with remove. just refresh (call only once)
208 self.canvas.draw()
209
210
211
212######################################
213## Notation box window ##
214######################################
215class NotationWindowQT4Agg(NotationWindowCommon):
216 """
217 Backend based class to create widgets to add, modify, or delete
218 note on the plot.
219
220 Note:
221 Press LEFT-mouse button on the plot to ADD a note on the canvas.
222 A notation window will be loaded for specifying note string and
223 anchor. The note will be anchored on a position in whether figure-
224 (0-1 relative in a figure), panel- (0-1 relative in a plot axes),
225 or data-coordinate (data value in a plot axes).
226 Press RIGHT-mouse button on a note to MODIFY/DELETE it. A cascade
227 menu will be displayed and you can select an operation.
228 """
229 def __init__(self,master=None):
230 self.parent = master
231 NotationWindowCommon.__init__(self,master=master)
232 self.anchval = None
233 self.textwin = self._create_textwindow(master=None)
234 self.menu = self._create_modmenu(master=self.parent)
235
236 ### Notation window widget
237 def _create_textwindow(self,master=None):
238 """Create notation window widget and iconfy it"""
239 #twin = qt.QtGui.QWidget(parent=master, flags=qt.QtCore.Qt.Popup)
240 twin = qt.QtGui.QWidget(parent=master, flags=qt.QtCore.Qt.Dialog)
241 twin.setWindowTitle("Notation")
242 self.textbox = self._NotationBox(parent=twin)
243 radiobox = self._AnchorRadio(parent=twin)
244 self.actionbs = self._ActionButtons(parent=twin)
245 vbox = qt.QtGui.QVBoxLayout(twin)
246 vbox.addWidget(self.textbox)
247 vbox.addWidget(radiobox)
248 vbox.addLayout(self.actionbs)
249 twin.setLayout(vbox)
250 #twin.setCentralWidget(self.textbox)
251 twin.hide()
252 return twin
253
254 def _NotationBox(self,parent=None):
255 textbox = qt.QtGui.QPlainTextEdit(parent=parent)
256 textbox.setStyleSheet("background-color: white")
257 fmetric = qt.QtGui.QFontMetrics(textbox.currentCharFormat().font())
258 textbox.resize(fmetric.width("A")*20+fmetric.leading()*2,
259 fmetric.height()*2+fmetric.ascent()+fmetric.descent())
260 del fmetric
261 textbox.setMinimumSize(textbox.size())
262 textbox.setUndoRedoEnabled(True)
263 textbox.setMidLineWidth(3)
264 textbox.setFrameShadow(qt.QtGui.QFrame.Sunken)
265 textbox.setCursor(qt.QtCore.Qt.IBeamCursor)
266 textbox.setFocus()
267 return textbox
268
269 def _AnchorRadio(self,parent=None):
270 # Returns a QGoupBox object which includes radio butons to
271 # select an anchor
272 anchbox = qt.QtGui.QGroupBox("anchor",parent=parent)
273 self.radio = qt.QtGui.QButtonGroup(parent=anchbox)
274 self.rFig = self._NewRadioButton(anchbox,"figure",\
275 bgr=self.radio,value=0,\
276 balloon="a fixed position in figure")
277 self.rAxis = self._NewRadioButton(anchbox,"panel",\
278 bgr=self.radio,value=1,\
279 balloon="a fixed realtive position in subplot")
280 self.rData = self._NewRadioButton(anchbox,"data",\
281 bgr=self.radio,value=2,\
282 balloon="a fixed data position in subplot")
283 hbox = qt.QtGui.QHBoxLayout(anchbox)
284 hbox.addWidget(self.rFig)
285 hbox.addWidget(self.rAxis)
286 hbox.addWidget(self.rData)
287 anchbox.setLayout(hbox)
288 # set initial selection "figure"
289 self.rFig.setChecked(True)
290 self.radio.setExclusive(True)
291 self.anchval = self.radio.checkedId()
292 return anchbox
293
294 def _NewRadioButton(self,parent,text,balloon=None,bgr=None,value=None):
295 rb= qt.QtGui.QRadioButton(text,parent=parent)
296 if bgr:
297 if value is not None:
298 bgr.addButton(rb,value)
299 else:
300 bgr.addButton(rb)
301 if balloon: rb.setToolTip(balloon)
302 return rb
303
304 def _enable_radio(self):
305 """Enable 'panel' and 'data' radio button"""
306 self.rAxis.setEnabled(True)
307 self.rData.setEnabled(True)
308 # select Figure as the default value
309 self.rFig.setChecked(True)
310 self.anchval = self.radio.checkedId()
311
312 def _reset_radio(self):
313 """Disable 'panel' and 'data' radio button"""
314 self.rAxis.setDisabled(True)
315 self.rData.setDisabled(True)
316 self.rFig.setEnabled(True)
317 # select Figure as the default value
318 self.rFig.setChecked(True)
319 self.anchval = self.radio.checkedId()
320
321 def _select_radio(self,selection):
322 """Select a specified radio button"""
323 if not selection in self.anchors:
324 return
325 if selection == "data":
326 self.rData.setChecked(True)
327 elif selection == "axes":
328 self.rAxis.setChecked(True)
329 else:
330 self.rFig.setChecked(True)
331 self.anchval = self.radio.checkedId()
332
333 def _get_anchval(self):
334 """Returns a integer of a selected radio button"""
335 self.anchval = self.radio.checkedId()
336 return self.anchval
337
338 def _get_note(self):
339 """Returns a note string specified in the text box"""
340 return str(self.textbox.toPlainText())
341
342 def _clear_textbox(self):
343 """Clear the text box"""
344 self.textbox.clear()
345
346 def _set_note(self,note=None):
347 """Set a note string to the text box"""
348 self._clear_textbox()
349 if len(note) >0:
350 self.textbox.setPlainText(note)
351
352 def _ActionButtons(self,parent=None):
353 # Returns a layout object which includes "cancel" and "print" buttons
354 actbuts = qt.QtGui.QHBoxLayout()
355 bCancel = self._NewButton(parent,"cancel",self._cancel_text,\
356 addit=False,\
357 balloon="cancel printing/modifying")
358 bPrint = self._NewButton(parent,"print", self._print_text,\
359 addit=False,\
360 balloon="print text on plot")
361 actbuts.addWidget(bCancel)
362 actbuts.addWidget(bPrint)
363 return actbuts
364
365 def _NewButton(self, parent, text, command, balloon=None, addit=True):
366 b = qt.QtGui.QPushButton(text,parent=parent)
367 if balloon: b.setToolTip(balloon)
368 if addit: parent.addWidget(b)
369 parent.connect(b,qt.QtCore.SIGNAL('clicked()'),command)
370 return b
371
372 def _cancel_text(self):
373 """
374 Cancel adding/modifying a note and close notaion window.
375 called when 'cancel' is selected.
376 """
377 self.close_textwindow()
378
379 def _print_text(self):
380 """
381 Add/Modify a note. Called when 'print' is selected on the
382 notation window.
383 """
384 self.print_text()
385 self.close_textwindow()
386
387 def load_textwindow(self,event):
388 """
389 Load text window at a event position to add a note on a plot.
390 Parameter:
391 event: an even object to specify the position to load
392 text window.
393 """
394 self.close_modmenu()
395 if event.canvas != self.parent:
396 raise RuntimeError, "Got invalid event!"
397
398 self.event = event
399 is_ax = (event.inaxes != None)
400 (xpix, ypix) = self._disppix2screen(event.x, event.y)
401 offset = 5
402 self.show_textwindow(xpix+offset,ypix+offset,enableaxes=is_ax)
403
404 def show_textwindow(self,xpix,ypix,basetext=None,enableaxes=False):
405 """
406 Load text window at a position of screen to add a note on a plot.
407 Parameters:
408 xpix, ypix: a pixel position from Upper-left corner
409 of the screen.
410 basetext: None (default) or any string.
411 A string to be printed on text box when loaded.
412 enableaxes: False (default) or True.
413 If True, 'panel' & 'data' radio button is enabled.
414 """
415 if not self.textwin: return
416 self._reset_radio()
417 if enableaxes:
418 self._enable_radio()
419 self.textwin.activateWindow()
420 h = self.textwin.minimumHeight()
421 w = self.textwin.minimumWidth()
422 self.textwin.resize(w,h)
423 self.textwin.move(xpix,ypix)
424 self.textbox.setFocus()
425 self.textwin.raise_()
426 self.textwin.show()
427 if w*h <= 1: # Initial load
428 self.textwin.setMinimumSize(self.textwin.size())
429
430 def close_textwindow(self):
431 """Close text window."""
432 self.seltext = {}
433 self._reset_radio()
434 self._clear_textbox()
435 self.textwin.hide()
436
437
438 ### Modify/Delete menu widget
439 def _create_modmenu(self,master=None):
440 """Create modify/delete menu widget"""
441 if master:
442 self.parent = master
443 if not self.parent:
444 return False
445 menu = qt.QtGui.QMenu(parent=self.parent)
446 menu.setTearOffEnabled(False)
447 menu.addAction("Modify",self._modify_note)
448 menu.addAction("Delete",self._delnote_dialog)
449 return menu
450
451 def load_modmenu(self,event):
452 """
453 Load cascade menu at a event position to modify or delete
454 selected text.
455 Parameter:
456 event: an even object to specify the position to load
457 text window.
458 """
459 self.close_textwindow()
460 self.seltext = self._get_selected_text(event)
461 if len(self.seltext) == 3:
462 canvas = event.canvas
463 corig = canvas.mapToGlobal(qt.QtCore.QPoint(0,0))
464 xpixs = corig.x() + int(event.x)
465 ypixs = corig.y() + canvas.height() - int(event.y)
466 self.menu.activateWindow()
467 self.menu.move(xpixs,ypixs)
468 self.menu.show()
469
470 def close_modmenu(self):
471 """Close cascade menu."""
472 self.seltext = {}
473 self.menu.hide()
474
475 ### load text window for modification
476 def _modify_note(self):
477 """helper function to load text window to modify selected note"""
478 textobj = self.seltext['textobj']
479 (xtx, ytx) = textobj._get_xy_display()
480 is_ax = (self.seltext['anchor'] != 'figure')
481 if not is_ax:
482 # previous anchor is figure
483 pos = textobj.get_position()
484 is_ax = (self._get_axes_from_pos(pos,self.canvas) != None)
485
486 (xpix, ypix) = self._disppix2screen(xtx,ytx)
487 offset = int(textobj.get_size())*2
488 self.show_textwindow(xpix,ypix+offset,basetext=textobj.get_text(),\
489 enableaxes=is_ax)
490 self._select_radio(self.seltext['anchor'])
491 self._set_note(textobj.get_text())
492
493 ### close all widgets
494 def close_widgets(self):
495 """Close note window and menu"""
496 self.close_textwindow()
497 self.close_modmenu()
498
499 ### dialog to confirm deleting note
500 def _delnote_dialog(self):
501 """Load dialog to confirm deletion of the text"""
502 remind = "Delete text?\n '"+self.seltext['textobj'].get_text()+"'"
503 from PyQt4.QtGui import QMessageBox as mbox
504 answer = mbox.question(self.parent,"Delete?",remind,
505 buttons = mbox.Ok | mbox.Cancel,
506 defaultButton=mbox.Cancel)
507 if answer == mbox.Ok:
508 self.delete_note()
509 else:
510 self.cancel_delete()
511
512 ### helper functions
513 def _disppix2screen(self,xpixd,ypixd):
514 """
515 helper function to calculate a pixel position form Upper-left
516 corner of the SCREEN from a pixel position (xpixd, ypixd)
517 from Lower-left of the CANVAS (which, e.g., event.x/y returns)
518
519 Returns:
520 (x, y): pixel position from Upper-left corner of the SCREEN.
521 """
522 corig = self.parent.mapToGlobal(qt.QtCore.QPoint(0,0))
523 xpixs = corig.x() + xpixd
524 ypixs = corig.y() + self.parent.height() - ypixd
525 return (int(xpixs), int(ypixs))
526
527
528
529
530
531
532###########################################
533## Add CASA custom Flag toolbar ##
534###########################################
535class CustomFlagToolbarQT4Agg(CustomFlagToolbarCommon, qt.QtGui.QToolBar):
536 def __init__(self,parent):
537 from asap.asapplotter import asapplotter
538 if not isinstance(parent,asapplotter):
539 return False
540 if not parent._plotter:
541 return False
542 self._p = parent._plotter
543 self.figmgr = self._p.figmgr
544 self.canvas = self.figmgr.canvas
545 self.mode = ''
546 self.button = True
547 self.pagecount = None
548 CustomFlagToolbarCommon.__init__(self,parent)
549 self.notewin=NotationWindowQT4Agg(master=self.canvas)
550 self._add_custom_toolbar()
551
552 def _add_custom_toolbar(self):
553 qt.QtGui.QToolBar.__init__(self,parent=self.figmgr.window)
554 self.figmgr.window.addToolBar(qt.QtCore.Qt.BottomToolBarArea,self)
555 self.bRegion = self._NewButton(master=self,
556 text='region',
557 command=self.select_region,
558 balloon="select channel regions")
559 self.bRegion.setCheckable(True)
560
561 self.bPanel = self._NewButton(master=self,
562 text='panel',
563 command=self.select_panel,
564 balloon="select a whole spectrum")
565 self.bPanel.setCheckable(True)
566
567 self.bClear = self._NewButton(master=self,
568 text='clear',
569 command=self.cancel_select,
570 balloon="clear selections")
571
572 self.bFlag = self._NewButton(master=self,
573 text='flag',
574 command=self.flag,
575 balloon="flag selections")
576
577 self.bUnflag = self._NewButton(master=self,
578 text='unflag',
579 command=self.unflag,
580 balloon="unflag selections")
581
582 self.bStat = self._NewButton(master=self,
583 text='statistics',
584 command=self.stat_cal,
585 balloon="print statistics of selections")
586
587 self.bNote = self._NewButton(master=self,
588 text='notation',
589 command=self.modify_note,
590 balloon="add note on plot")
591 self.bNote.setCheckable(True)
592
593 # page change oparations
594 frPage = qt.QtGui.QWidget(parent=self,flags=qt.QtCore.Qt.Tool)
595 loPage = qt.QtGui.QHBoxLayout(self)
596 loPage.addStretch(1)
597 self.lPagetitle = qt.QtGui.QLabel('Page:',parent=frPage)
598 self.lPagetitle.setMargin(5)
599 loPage.addWidget(self.lPagetitle)
600 self.pagecount = qt.QtGui.QLabel(parent=frPage)
601 self.pagecount.setStyleSheet("background-color: white")
602 self.pagecount.setMargin(3)
603 self.pagecount.setText(' 1')
604 loPage.addWidget(self.pagecount)
605
606 self.bNext = self._NewButton(master=frPage,
607 text='+',
608 #imagename="hand.ppm",
609 command=self.next_page,
610 addit=False,
611 balloon="plot next page")
612 loPage.addWidget(self.bNext)
613 self.bPrev = self._NewButton(master=frPage,
614 text='-',
615 command=self.prev_page,
616 addit=False,
617 balloon="plot previous page")
618 loPage.addWidget(self.bPrev)
619 frPage.setLayout(loPage)
620 self.addWidget(frPage)
621
622 self.bQuit = self._NewButton(master=self,
623 text='Quit',
624 #imagename="stock_close.ppm",
625 command=self.quit,
626 balloon="Close window")
627
628 self.pagecount.setText(' '*4)
629 self.disable_button()
630 return
631
632 def _NewButton(self, master, text, command, balloon=None,addit=True,imagename=None):
633 img = None
634 if imagename:
635 imagename = os.path.join(matplotlib.rcParams['datapath'], 'images', imagename)
636# img = Tk.PhotoImage(master=master, file=imagename)
637
638 b = qt.QtGui.QPushButton(text,parent=master)
639 if balloon: b.setToolTip(balloon)
640 if addit: master.addWidget(b)
641 master.connect(b,qt.QtCore.SIGNAL('clicked()'),command)
642# if img: b.image = img
643 return b
644
645 def show_pagenum(self,pagenum,formatstr):
646 self.pagecount.setText(formatstr % (pagenum))
647
648 def spec_show(self):
649 if not self.figmgr.toolbar.mode == '' or not self.button: return
650 self.figmgr.toolbar.set_message('spec value: drag on a spec')
651 if self.mode == 'spec': return
652 self.mode = 'spec'
653 self.notewin.close_widgets()
654 self.__disconnect_event()
655 self._p.register('button_press',self._select_spectrum)
656
657 def modify_note(self):
658 if not self.figmgr.toolbar.mode == '':
659 # Get back button status BEFORE clicked
660 self.bNote.setChecked(not self.bNote.isChecked())
661 return
662 if self.mode == 'note':
663 self.bNote.setChecked(False)
664 self.bNote.setToolTip("add note on plot")
665 self.mode = 'none'
666 self.spec_show()
667 if not self.button:
668 self.notewin.close_widgets()
669 self.__disconnect_event()
670 return
671 self.figmgr.toolbar.set_message('text: select a position/text')
672 self.bNote.setChecked(True)
673 self.bNote.setToolTip("Back to spec value mode")
674 self.bRegion.setChecked(False)
675 self.bRegion.setToolTip("select channel regions")
676 self.bPanel.setChecked(False)
677 self.bPanel.setToolTip("select a whole spectrum")
678 self.mode = 'note'
679 self.__disconnect_event()
680 self._p.register('button_press',self._mod_note)
681
682 def select_region(self):
683 if not self.figmgr.toolbar.mode == '' or not self.button:
684 # Get back button status BEFORE clicked
685 self.bRegion.setChecked(not self.bRegion.isChecked())
686 if self.mode == 'region':
687 self.bRegion.setChecked(False)
688 self.bRegion.setToolTip("select channel regions")
689 self.mode = 'none'
690 self.spec_show()
691 return
692 self.figmgr.toolbar.set_message('select regions: click at start and end channels')
693 self.bNote.setChecked(False)
694 self.bNote.setToolTip("add note on plot")
695 self.bRegion.setChecked(True)
696 self.bRegion.setToolTip("Back to spec value mode")
697 self.bPanel.setChecked(False)
698 self.bPanel.setToolTip("select a whole spectrum")
699 self.mode = 'region'
700 self.notewin.close_widgets()
701 self.__disconnect_event()
702 self._p.register('button_press',self._add_region)
703
704 def select_panel(self):
705 if not self.figmgr.toolbar.mode == '' or not self.button:
706 # Get back button status BEFORE clicked
707 self.bPanel.setChecked(not self.bPanel.isChecked())
708 return
709 if self.mode == 'panel':
710 self.bPanel.setChecked(False)
711 self.bPanel.setToolTip("select subplots")
712 self.mode = 'none'
713 self.spec_show()
714 return
715 self.figmgr.toolbar.set_message('select spectra: click on subplots')
716 self.bNote.setChecked(False)
717 self.bNote.setToolTip("add note on plot")
718 self.bRegion.setChecked(False)
719 self.bRegion.setToolTip("select channel regions")
720 self.bPanel.setChecked(True)
721 self.bPanel.setToolTip("Back to spec value mode")
722 self.mode = 'panel'
723 self.notewin.close_widgets()
724 self.__disconnect_event()
725 self._p.register('button_press',self._add_panel)
726
727 def quit(self):
728 self.__disconnect_event()
729 self.disable_button()
730 self._p.unmap()
731
732 def enable_button(self):
733 if self.button: return
734 self.bRegion.setEnabled(True)
735 self.bPanel.setEnabled(True)
736 self.bClear.setEnabled(True)
737 self.bFlag.setEnabled(True)
738 self.bUnflag.setEnabled(True)
739 self.bStat.setEnabled(True)
740 self.button = True
741 self.spec_show()
742
743 def disable_button(self):
744 ## disable buttons which don't work for plottp
745 if not self.button: return
746 self.bRegion.setChecked(False)
747 self.bRegion.setToolTip("select channel regions")
748 self.bPanel.setChecked(False)
749 self.bPanel.setToolTip("select subplots")
750
751 self.bRegion.setDisabled(True)
752 self.bPanel.setDisabled(True)
753 self.bClear.setDisabled(True)
754 self.bFlag.setDisabled(True)
755 self.bUnflag.setDisabled(True)
756 self.bStat.setDisabled(True)
757 self.bNext.setDisabled(True)
758 self.bPrev.setDisabled(True)
759 self.button = False
760 self.mode = ''
761 self.notewin.close_widgets()
762 self.__disconnect_event()
763
764 def enable_next(self):
765 self.bNext.setEnabled(True)
766
767 def disable_next(self):
768 self.bNext.setDisabled(True)
769
770 def enable_prev(self):
771 self.bPrev.setEnabled(True)
772
773 def disable_prev(self):
774 self.bPrev.setDisabled(True)
775
776 # pause buttons for slow operations
777 def _pause_buttons(self,operation="end",msg=""):
778 buttons = ["bRegion","bPanel","bClear","bFlag","bUnflag","bStat",
779 "bNote","bQuit"]
780 if operation == "start":
781 enable = False
782 else:
783 enable = True
784 for btn in buttons:
785 getattr(self,btn).setEnabled(enable)
786 self.figmgr.toolbar.set_message(msg)
787
788 def delete_bar(self):
789 self.__disconnect_event()
790 self.destroy()
791
792 def __disconnect_event(self):
793 self._p.register('button_press',None)
794 self._p.register('button_release',None)
795
796 def _draw_span(self,axes,x0,x1,**kwargs):
797 height = self._p.figure.bbox.height
798 y1 = height - axes.bbox.y1
799 h = axes.bbox.height
800 w = abs(x1 - x0)
801 rect = [ int(val) for val in min(x0,x1), y1, w, h ]
802 self._p.canvas.drawRectangle( rect )
803 # nothing is returned by drawRectangle
804 return None
805
806 def _remove_span(self,span):
807 # Nothing to do with remove.
808 pass
Note: See TracBrowser for help on using the repository browser.