source: branches/hpc34/python/customgui_tkagg.py@ 2631

Last change on this file since 2631 was 2416, checked in by Kana Sugimoto, 13 years ago

New Development: No

JIRA Issue: Yes (CAS-3749)

Ready for Test: Yes

Interface Changes: No

What Interface Changed:

Test Programs: an interactive test

  1. load casapy (or standalone asap)
  2. matplotlib.pyplot.show() ---> 2 plotters (ASAP plotter and matplotlib plotter) are displayed and casapy prompt is paused.
  3. close all plotter windows ---> casapy prompt should be back

Put in Release Notes: No

Module(s): sdplot, asap.plotter

Description:

Fixed a bug in asapplotter with Tk backend which caused scripts and python shells
freeze after the initial invocation of matplotlib.pyplot.show() (known as pl.show() on CASA).
plus minor fixes which handle backend dependencies.

File size: 26.2 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 Tkinter as Tk
10import tkMessageBox
11
12######################################
13## Add CASA custom toolbar ##
14######################################
15class CustomToolbarTkAgg(CustomToolbarCommon, Tk.Frame):
16 def __init__(self,parent):
17 from asap.asapplotter import asapplotter
18 if not isinstance(parent,asapplotter):
19 return False
20 if not parent._plotter:
21 return False
22 self._p = parent._plotter
23 self.figmgr = self._p.figmgr
24 self.canvas = self.figmgr.canvas
25 self.mode = ''
26 self.button = True
27 self.pagecount = None
28 CustomToolbarCommon.__init__(self,parent)
29 self.notewin = NotationWindowTkAgg(master=self.canvas)
30 self._add_custom_toolbar()
31
32 def _add_custom_toolbar(self):
33 Tk.Frame.__init__(self,master=self.figmgr.window)
34 #self.bSpec = self._NewButton(master=self,
35 # text='spec value',
36 # command=self.spec_show)
37 self.bNote = self._NewButton(master=self,
38 text='notation',
39 command=self.modify_note)
40
41 self.bStat = self._NewButton(master=self,
42 text='statistics',
43 command=self.stat_cal)
44 self.bQuit = self._NewButton(master=self,
45 text='Quit',
46 command=self.quit,
47 side=Tk.RIGHT)
48
49 # page change oparations
50 frPage = Tk.Frame(master=self,borderwidth=2,relief=Tk.GROOVE)
51 frPage.pack(ipadx=2,padx=10,side=Tk.RIGHT)
52 self.lPagetitle = Tk.Label(master=frPage,text='Page:',padx=5)
53 self.lPagetitle.pack(side=Tk.LEFT)
54 self.pagecount = Tk.StringVar(master=frPage)
55 self.lPagecount = Tk.Label(master=frPage,
56 textvariable=self.pagecount,
57 padx=5,bg='white')
58 self.lPagecount.pack(side=Tk.LEFT,padx=3)
59
60 self.bNext = self._NewButton(master=frPage,
61 text=' + ',
62 command=self.next_page)
63 self.bPrev = self._NewButton(master=frPage,
64 text=' - ',
65 command=self.prev_page)
66
67 if os.uname()[0] != 'Darwin':
68 self.bPrev.config(padx=5)
69 self.bNext.config(padx=5)
70
71 self.pack(side=Tk.BOTTOM,fill=Tk.BOTH)
72 self.pagecount.set(' '*4)
73
74 self.disable_button()
75 return #self
76
77 def _NewButton(self, master, text, command, side=Tk.LEFT):
78 if os.uname()[0] == 'Darwin':
79 b = Tk.Button(master=master, text=text, command=command)
80 else:
81 b = Tk.Button(master=master, text=text, padx=2, pady=2,
82 command=command)
83 b.pack(side=side)
84 return b
85
86 def show_pagenum(self,pagenum,formatstr):
87 self.pagecount.set(formatstr % (pagenum))
88
89 def spec_show(self):
90 if not self.figmgr.toolbar.mode == '' or not self.button: return
91 self.figmgr.toolbar.set_message('spec value: drag on a spec')
92 if self.mode == 'spec': return
93 #self.bStat.config(relief='raised')
94 #self.bSpec.config(relief='sunken')
95 #self.bNote.config(relief='raised')
96 self.mode = 'spec'
97 self.notewin.close_widgets()
98 self.__disconnect_event()
99 self._p.register('button_press',self._select_spectrum)
100
101 def stat_cal(self):
102 if not self.figmgr.toolbar.mode == '' or not self.button: return
103 self.figmgr.toolbar.set_message('statistics: select a region')
104 if self.mode == 'stat':
105 # go back to spec mode
106 self.bStat.config(relief='raised')
107 self.spec_show()
108 return
109 #self.bSpec.config(relief='raised')
110 self.bStat.config(relief='sunken')
111 self.bNote.config(relief='raised')
112 self.mode = 'stat'
113 self.notewin.close_widgets()
114 self.__disconnect_event()
115 self._p.register('button_press',self._single_mask)
116
117 def modify_note(self):
118 if not self.figmgr.toolbar.mode == '': return
119 self.figmgr.toolbar.set_message('text: select a position/text')
120 if self.mode == 'note':
121 self.bNote.config(relief='raised')
122 self.mode = 'none'
123 self.spec_show()
124 return
125 #self.bSpec.config(relief='raised')
126 self.bStat.config(relief='raised')
127 self.bNote.config(relief='sunken')
128 self.mode = 'note'
129 self.__disconnect_event()
130 self._p.register('button_press',self._mod_note)
131
132 def quit(self):
133 self.__disconnect_event()
134 #self.delete_bar()
135 self.disable_button()
136 self.figmgr.window.wm_withdraw()
137 self._p.quit()
138
139 def enable_button(self):
140 if self.button: return
141 #self.bSpec.config(state=Tk.NORMAL)
142 self.bStat.config(state=Tk.NORMAL)
143 self.button = True
144 self.spec_show()
145
146 def disable_button(self):
147 if not self.button: return
148 #self.bSpec.config(relief='raised', state=Tk.DISABLED)
149 self.bStat.config(relief='raised', state=Tk.DISABLED)
150 self.bNext.config(state=Tk.DISABLED)
151 self.bPrev.config(state=Tk.DISABLED)
152 self.button = False
153 self.mode = ''
154 self.__disconnect_event()
155
156 def enable_next(self):
157 self.bNext.config(state=Tk.NORMAL)
158
159 def disable_next(self):
160 self.bNext.config(state=Tk.DISABLED)
161
162 def enable_prev(self):
163 self.bPrev.config(state=Tk.NORMAL)
164
165 def disable_prev(self):
166 self.bPrev.config(state=Tk.DISABLED)
167
168 # pause buttons for slow operations
169 def _pause_buttons(self,operation="end",msg=""):
170 buttons = ["bStat","bNote","bQuit"]
171 if operation == "start":
172 state = Tk.DISABLED
173 else:
174 state = Tk.NORMAL
175 for btn in buttons:
176 getattr(self,btn).config(state=state)
177 self.figmgr.toolbar.set_message(msg)
178
179 def delete_bar(self):
180 self.__disconnect_event()
181 self.destroy()
182
183 def __disconnect_event(self):
184 self._p.register('button_press',None)
185 self._p.register('button_release',None)
186
187 def _draw_span(self,axes,x0,x1,**kwargs):
188 height = self._p.figure.bbox.height
189 y0 = height - axes.bbox.y0
190 y1 = height - axes.bbox.y1
191 return self._p.canvas._tkcanvas.create_rectangle(x0,y0,x1,y1,**kwargs)
192
193 def _remove_span(self,span):
194 self._p.canvas._tkcanvas.delete(span)
195
196
197
198######################################
199## Notation box window ##
200######################################
201class NotationWindowTkAgg(NotationWindowCommon):
202 """
203 Backend based class to create widgets to add, modify, or delete
204 note on the plot.
205
206 Note:
207 Press LEFT-mouse button on the plot to ADD a note on the canvas.
208 A notation window will be loaded for specifying note string and
209 anchor. The note will be anchored on a position in whether figure-
210 (0-1 relative in a figure), panel- (0-1 relative in a plot axes),
211 or data-coordinate (data value in a plot axes).
212 Press RIGHT-mouse button on a note to MODIFY/DELETE it. A cascade
213 menu will be displayed and you can select an operation.
214 """
215 def __init__(self,master=None):
216 self.parent = master._tkcanvas
217 NotationWindowCommon.__init__(self,master=master)
218 self.anchval = None
219 self.textwin = self._create_textwindow(master=None)
220 self.menu = self._create_modmenu(master=self.parent)
221
222 ### Notation window widget
223 def _create_textwindow(self,master=None):
224 """Create notation window widget and iconfy it"""
225 twin = Tk.Toplevel(padx=3,pady=3)
226 twin.title("Notation")
227 twin.resizable(width=True,height=True)
228 self.textbox = self._NotationBox(parent=twin)
229 self.radio = self._AnchorRadio(parent=twin)
230 self.actionbs = self._ActionButtons(parent=twin)
231
232 self.textbox.pack(side=Tk.TOP,fill=Tk.BOTH,expand=True)
233 self.actionbs.pack(side=Tk.BOTTOM)
234 self.radio.pack(side=Tk.BOTTOM)
235 #twin.deiconify()
236 #twin.minsize(width=twin.winfo_width(),height=twin.winfo_height())
237 #twin.lift()
238 twin.withdraw()
239 return twin
240
241 def _NotationBox(self,parent=None):
242 textbox = Tk.Text(master=parent,background='white',
243 height=2,width=20,cursor="xterm",
244 padx=2,pady=2,undo=True,maxundo=10,
245 relief='sunken',borderwidth=3,
246 state=Tk.NORMAL,takefocus=1)
247 return textbox
248
249 def _AnchorRadio(self,parent=None):
250 radio = Tk.LabelFrame(master=parent,text="anchor",
251 labelanchor="nw",padx=5,pady=3)
252 self.anchval = Tk.IntVar(master=radio,value=0)
253 self.rFig = self._NewRadioButton(radio,"figure",state=Tk.NORMAL,
254 variable=self.anchval,value=0,
255 side=Tk.LEFT)
256 self.rAxis = self._NewRadioButton(radio,"panel",state=Tk.DISABLED,
257 variable=self.anchval,value=1,
258 side=Tk.LEFT)
259 self.rData = self._NewRadioButton(radio,"data",state=Tk.DISABLED,
260 variable=self.anchval,value=2,
261 side=Tk.LEFT)
262 # set initial selection "figure"
263 self.anchval.set(0)
264 return radio
265
266 def _NewRadioButton(self,parent,text,state=Tk.NORMAL,variable=None,value=None,side=Tk.LEFT):
267 rb = Tk.Radiobutton(master=parent,text=text,state=state,
268 variable=variable,value=value)
269 rb.pack(side=side)
270 return rb
271
272 def _enable_radio(self):
273 """Enable 'panel' and 'data' radio button"""
274 self.rAxis.config(state=Tk.NORMAL)
275 self.rData.config(state=Tk.NORMAL)
276 #self.rFig.config(state=Tk.NORMAL)
277 self.rFig.select()
278
279 def _reset_radio(self):
280 """Disable 'panel' and 'data' radio button"""
281 self.rAxis.config(state=Tk.DISABLED)
282 self.rData.config(state=Tk.DISABLED)
283 self.rFig.config(state=Tk.NORMAL)
284 self.rFig.select()
285
286 def _select_radio(self,selection):
287 """Select a specified radio button"""
288 if not selection in self.anchors:
289 return
290 if selection == "data":
291 self.rData.select()
292 elif selection == "axes":
293 self.rAxis.select()
294 else:
295 self.rFig.select()
296
297 def _get_anchval(self):
298 """Returns a integer of a selected radio button"""
299 return self.anchval.get()
300
301 def _get_note(self):
302 """Returns a note string specified in the text box"""
303 return self.textbox.get("1.0",Tk.END)
304
305 def _clear_textbox(self):
306 """Clear the text box"""
307 self.textbox.delete("1.0",Tk.END)
308
309 def _set_note(self,note=None):
310 """Set a note string to the text box"""
311 self._clear_textbox()
312 if len(note) >0:
313 self.textbox.insert("1.0",note)
314
315 def _ActionButtons(self,parent=None):
316 actbuts = Tk.Frame(master=parent)
317 bCancel = self._NewButton(actbuts,"cancel",self._cancel_text,side=Tk.LEFT)
318 bPrint = self._NewButton(actbuts,"print", self._print_text,side=Tk.LEFT)
319 return actbuts
320
321 def _NewButton(self, parent, text, command, side=Tk.LEFT):
322 if(os.uname()[0] == 'Darwin'):
323 b = Tk.Button(master=parent, text=text, command=command)
324 else:
325 b = Tk.Button(master=parent, text=text, padx=2, pady=2, command=command)
326 b.pack(side=side)
327 return b
328
329 def _cancel_text(self):
330 """
331 Cancel adding/modifying a note and close notaion window.
332 called when 'cancel' is selected.
333 """
334 self.close_textwindow()
335
336 def _print_text(self):
337 """
338 Add/Modify a note. Called when 'print' is selected on the
339 notation window.
340 """
341 self.print_text()
342 self.close_textwindow()
343
344 def load_textwindow(self,event):
345 """
346 Load text window at a event position to add a note on a plot.
347 Parameter:
348 event: an even object to specify the position to load
349 text window.
350 """
351 self.close_modmenu()
352 if event.canvas._tkcanvas != self.parent:
353 raise RuntimeError, "Got invalid event!"
354
355 self.event = event
356 is_ax = (event.inaxes != None)
357 (xpix, ypix) = self._disppix2screen(event.x, event.y)
358 offset = 5
359 self.show_textwindow(xpix+offset,ypix+offset,enableaxes=is_ax)
360
361 def show_textwindow(self,xpix,ypix,basetext=None,enableaxes=False):
362 """
363 Load text window at a position of screen to add a note on a plot.
364 Parameters:
365 xpix, ypix: a pixel position from Upper-left corner
366 of the screen.
367 basetext: None (default) or any string.
368 A string to be printed on text box when loaded.
369 enable axes: False (default) or True.
370 If True, 'panel' & 'data' radio button is enabled.
371 """
372 if not self.textwin: return
373 self._reset_radio()
374 if enableaxes:
375 self._enable_radio()
376 self.textwin.deiconify()
377 (w,h) = self.textwin.minsize()
378 if w*h <= 1:
379 self.textwin.minsize(width=self.textwin.winfo_width(),
380 height=self.textwin.winfo_height())
381 (w,h) = self.textwin.minsize()
382 self.textwin.geometry("%sx%s+%s+%s"%(w,h,xpix,ypix))
383 self.textwin.lift()
384
385 def close_textwindow(self):
386 """Close text window."""
387 self.seltext = {}
388 self._reset_radio()
389 self._clear_textbox()
390 self.textwin.withdraw()
391
392
393 ### Modify/Delete menu widget
394 def _create_modmenu(self,master=None):
395 """Create modify/delete menu widget"""
396 if master:
397 self.parent = master
398 if not self.parent:
399 return False
400 menu = Tk.Menu(master=self.parent,tearoff=False)
401 menu.add_command(label="Modify",command=self._modify_note)
402 menu.add_command(label="Delete",command=self._delnote_dialog)
403 return menu
404
405 def load_modmenu(self,event):
406 """
407 Load cascade menu at a event position to modify or delete
408 selected text.
409 Parameter:
410 event: an even object to specify the position to load
411 text window.
412 """
413 self.close_textwindow()
414 self.seltext = self._get_selected_text(event)
415 if len(self.seltext) == 3:
416 tkcanvas = event.canvas._tkcanvas
417 xpos = tkcanvas.winfo_rootx() + int(event.x)
418 ypos = tkcanvas.winfo_rooty() \
419 + tkcanvas.winfo_height() - int(event.y)
420 self.menu.post(xpos,ypos)
421
422 def close_modmenu(self):
423 """Close cascade menu."""
424 self.seltext = {}
425 self.menu.unpost()
426
427 ### load text window for modification
428 def _modify_note(self):
429 """helper function to load text window to modify selected note"""
430 #print "Modify selected!!"
431 textobj = self.seltext['textobj']
432 (xtx, ytx) = textobj._get_xy_display()
433 is_ax = (self.seltext['anchor'] != 'figure')
434 if not is_ax:
435 # previous anchor is figure
436 pos = textobj.get_position()
437 is_ax = (self._get_axes_from_pos(pos,self.canvas) != None)
438
439 (xpix, ypix) = self._disppix2screen(xtx,ytx)
440 offset = int(textobj.get_size())*2
441 self.show_textwindow(xpix,ypix+offset,basetext=textobj.get_text(),\
442 enableaxes=is_ax)
443 self._select_radio(self.seltext['anchor'])
444 self._set_note(textobj.get_text())
445
446 ### close all widgets
447 def close_widgets(self):
448 """Close note window and menu"""
449 self.close_textwindow()
450 self.close_modmenu()
451
452 ### dialog to confirm deleting note
453 def _delnote_dialog(self):
454 """Load dialog to confirm deletion of the text"""
455 remind = "Delete text?\n '"+self.seltext['textobj'].get_text()+"'"
456 answer = tkMessageBox.askokcancel(parent=self.parent,title="Delete?",
457 message=remind,
458 default=tkMessageBox.CANCEL)
459 if answer:
460 self.delete_note()
461 else:
462 self.cancel_delete()
463
464 ### helper functions
465 def _disppix2screen(self,xpixd,ypixd):
466 """
467 helper function to calculate a pixel position form Upper-left
468 corner of the SCREEN from a pixel position (xpixd, ypixd)
469 from Lower-left of the CANVAS (which, e.g., event.x/y returns)
470
471 Returns:
472 (x, y): pixel position from Upper-left corner of the SCREEN.
473 """
474 xpixs = self.parent.winfo_rootx() + xpixd
475 ypixs = self.parent.winfo_rooty() + self.parent.winfo_height() \
476 - ypixd
477 return (int(xpixs), int(ypixs))
478
479
480
481
482
483
484###########################################
485## Add CASA custom Flag toolbar ##
486###########################################
487class CustomFlagToolbarTkAgg(CustomFlagToolbarCommon, Tk.Frame):
488 def __init__(self,parent):
489 from asap.asapplotter import asapplotter
490 if not isinstance(parent,asapplotter):
491 return False
492 if not parent._plotter:
493 return False
494 self._p = parent._plotter
495 self.figmgr = self._p.figmgr
496 self.canvas = self.figmgr.canvas
497 self.mode = ''
498 self.button = True
499 self.pagecount = None
500 CustomFlagToolbarCommon.__init__(self,parent)
501 self.notewin=NotationWindowTkAgg(master=self.canvas)
502 self._add_custom_toolbar()
503
504 def _add_custom_toolbar(self):
505 Tk.Frame.__init__(self,master=self.figmgr.window)
506 #self.bSpec = self._NewButton(master=self,
507 # text='spec value',
508 # command=self.spec_show)
509
510 self.bRegion = self._NewButton(master=self,
511 text='region',
512 command=self.select_region)
513 self.bPanel = self._NewButton(master=self,
514 text='panel',
515 command=self.select_panel)
516 self.bClear = self._NewButton(master=self,
517 text='clear',
518 command=self.cancel_select)
519 self.bFlag = self._NewButton(master=self,
520 text='flag',
521 command=self.flag)
522 self.bUnflag = self._NewButton(master=self,
523 text='unflag',
524 command=self.unflag)
525
526 self.bStat = self._NewButton(master=self,
527 text='statistics',
528 command=self.stat_cal)
529
530 self.bNote = self._NewButton(master=self,
531 text='notation',
532 command=self.modify_note)
533
534 self.bQuit = self._NewButton(master=self,
535 text='Quit',
536 #file="stock_close.ppm",
537 command=self.quit,
538 side=Tk.RIGHT)
539
540 # page change oparations
541 frPage = Tk.Frame(master=self,borderwidth=2,relief=Tk.GROOVE)
542 frPage.pack(ipadx=2,padx=10,side=Tk.RIGHT)
543 self.lPagetitle = Tk.Label(master=frPage,text='Page:',padx=5)
544 #width=8,anchor=Tk.E,padx=5)
545 self.lPagetitle.pack(side=Tk.LEFT)
546 self.pagecount = Tk.StringVar(master=frPage)
547 self.lPagecount = Tk.Label(master=frPage,
548 textvariable=self.pagecount,
549 padx=5,bg='white')
550 self.lPagecount.pack(side=Tk.LEFT,padx=3)
551
552 self.bNext=self._NewButton(master=frPage,
553 text=' + ',
554 #file="hand.ppm",
555 command=self.next_page)
556 self.bPrev=self._NewButton(master=frPage,
557 text=' - ',
558 command=self.prev_page)
559
560 if os.uname()[0] != 'Darwin':
561 self.bPrev.config(padx=5)
562 self.bNext.config(padx=5)
563
564 self.pack(side=Tk.BOTTOM,fill=Tk.BOTH)
565 self.pagecount.set(' '*4)
566
567 self.disable_button()
568 return #self
569
570 def _NewButton(self, master, text, command, side=Tk.LEFT,file=None):
571 img = None
572 if file:
573 file = os.path.join(matplotlib.rcParams['datapath'], 'images', file)
574 img = Tk.PhotoImage(master=master, file=file)
575
576 if os.uname()[0] == 'Darwin':
577 b = Tk.Button(master=master, text=text, image=img,
578 command=command)
579 if img: b.image = img
580 else:
581 b = Tk.Button(master=master, text=text, image=img, padx=2, pady=2,
582 command=command)
583 if img: b.image = img
584 b.pack(side=side)
585 return b
586
587 def show_pagenum(self,pagenum,formatstr):
588 self.pagecount.set(formatstr % (pagenum))
589
590 def spec_show(self):
591 if not self.figmgr.toolbar.mode == '' or not self.button: return
592 self.figmgr.toolbar.set_message('spec value: drag on a spec')
593 if self.mode == 'spec': return
594 self.mode = 'spec'
595 self.notewin.close_widgets()
596 self.__disconnect_event()
597 self._p.register('button_press',self._select_spectrum)
598
599 def modify_note(self):
600 if not self.figmgr.toolbar.mode == '': return
601 if self.mode == 'note':
602 self.bNote.config(relief='raised')
603 self.mode = 'none'
604 self.spec_show()
605 return
606 self.figmgr.toolbar.set_message('text: select a position/text')
607 self.bNote.config(relief='sunken')
608 self.bRegion.config(relief='raised')
609 self.bPanel.config(relief='raised')
610 self.mode = 'note'
611 self.__disconnect_event()
612 self._p.register('button_press',self._mod_note)
613
614 def select_region(self):
615 if not self.figmgr.toolbar.mode == '' or not self.button: return
616 if self.mode == 'region':
617 self.bRegion.config(relief='raised')
618 self.mode = 'none'
619 self.spec_show()
620 return
621 self.figmgr.toolbar.set_message('select regions: click at start and end channels')
622 self.bNote.config(relief='raised')
623 self.bRegion.config(relief='sunken')
624 self.bPanel.config(relief='raised')
625 self.mode = 'region'
626 self.notewin.close_widgets()
627 self.__disconnect_event()
628 self._p.register('button_press',self._add_region)
629
630 def select_panel(self):
631 if not self.figmgr.toolbar.mode == '' or not self.button: return
632 if self.mode == 'panel':
633 self.bPanel.config(relief='raised')
634 self.mode = 'none'
635 self.spec_show()
636 return
637 self.figmgr.toolbar.set_message('select spectra: click on subplots')
638 self.bNote.config(relief='raised')
639 self.bRegion.config(relief='raised')
640 self.bPanel.config(relief='sunken')
641 self.mode = 'panel'
642 self.notewin.close_widgets()
643 self.__disconnect_event()
644 self._p.register('button_press',self._add_panel)
645
646 def quit(self):
647 self.__disconnect_event()
648 self.disable_button()
649 self.figmgr.window.wm_withdraw()
650 self._p.quit()
651
652 def enable_button(self):
653 if self.button: return
654 self.bRegion.config(state=Tk.NORMAL)
655 self.bPanel.config(state=Tk.NORMAL)
656 self.bClear.config(state=Tk.NORMAL)
657 self.bFlag.config(state=Tk.NORMAL)
658 self.bUnflag.config(state=Tk.NORMAL)
659 self.bStat.config(state=Tk.NORMAL)
660 self.button = True
661 self.spec_show()
662
663 def disable_button(self):
664 ## disable buttons which don't work for plottp
665 if not self.button: return
666 self.bRegion.config(relief='raised')
667 self.bPanel.config(relief='raised')
668 self.bRegion.config(state=Tk.DISABLED)
669 self.bPanel.config(state=Tk.DISABLED)
670 self.bClear.config(state=Tk.DISABLED)
671 self.bFlag.config(state=Tk.DISABLED)
672 self.bUnflag.config(state=Tk.DISABLED)
673 self.bStat.config(state=Tk.DISABLED)
674 self.bNext.config(state=Tk.DISABLED)
675 self.bPrev.config(state=Tk.DISABLED)
676 self.button = False
677 self.mode = ''
678 self.notewin.close_widgets()
679 self.__disconnect_event()
680
681 def enable_next(self):
682 self.bNext.config(state=Tk.NORMAL)
683
684 def disable_next(self):
685 self.bNext.config(state=Tk.DISABLED)
686
687 def enable_prev(self):
688 self.bPrev.config(state=Tk.NORMAL)
689
690 def disable_prev(self):
691 self.bPrev.config(state=Tk.DISABLED)
692
693 # pause buttons for slow operations
694 def _pause_buttons(self,operation="end",msg=""):
695 buttons = ["bRegion","bPanel","bClear","bFlag","bUnflag","bStat",
696 "bNote","bQuit"]
697 if operation == "start":
698 state=Tk.DISABLED
699 else:
700 state=Tk.NORMAL
701 for btn in buttons:
702 getattr(self,btn).config(state=state)
703 self.figmgr.toolbar.set_message(msg)
704
705 def delete_bar(self):
706 self.__disconnect_event()
707 self.destroy()
708
709 def __disconnect_event(self):
710 self._p.register('button_press',None)
711 self._p.register('button_release',None)
712
713 def _draw_span(self,axes,x0,x1,**kwargs):
714 height = self._p.figure.bbox.height
715 y0 = height - axes.bbox.y0
716 y1 = height - axes.bbox.y1
717 return self._p.canvas._tkcanvas.create_rectangle(x0,y0,x1,y1,**kwargs)
718
719 def _remove_span(self,span):
720 self._p.canvas._tkcanvas.delete(span)
Note: See TracBrowser for help on using the repository browser.