source: trunk/python/asaplotgui.py@ 2431

Last change on this file since 2431 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.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 2.8 KB
RevLine 
[707]1"""
2ASAP plotting class based on matplotlib.
3"""
4
5from asap.asaplotbase import *
6import Tkinter as Tk
[1422]7import matplotlib
[707]8from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg, \
9 FigureManagerTkAgg
10# Force use of the newfangled toolbar.
11matplotlib.rcParams['toolbar'] = 'toolbar2'
[2416]12from matplotlib import _pylab_helpers
[707]13
14class asaplotgui(asaplotbase):
15 """
16 ASAP plotting class based on matplotlib.
17 """
18
[1563]19 def __init__(self, rows=1, cols=0, title='', size=None, buffering=False):
[1826]20 """
21 Create a new instance of the ASAPlot plotting class.
[707]22
[1826]23 If rows < 1 then a separate call to set_panels() is required to define
24 the panel layout; refer to the doctext for set_panels().
25 """
[707]26 v = vars()
27 del v['self']
[1153]28
[707]29 asaplotbase.__init__(self, **v)
30 self.window = Tk.Tk()
[2416]31 #def dest_callback():
32 # print "dest_callback"
33 # self.is_dead = True
34 # self.window.destroy()
[707]35
[2416]36 self.window.protocol("WM_DELETE_WINDOW", self.quit)
[707]37 self.canvas = FigureCanvasTkAgg(self.figure, master=self.window)
38 self.canvas.get_tk_widget().pack(side=Tk.TOP, fill=Tk.BOTH, expand=1)
39 # Simply instantiating this is enough to get a working toolbar.
[2416]40 self.figmgr = FigureManagerTkAgg(self.canvas, 0, self.window)
41 # Register this plot to matplotlib without activating it
42 #_pylab_helpers.Gcf.set_active(self.figmgr)
43 _pylab_helpers.Gcf.figs[self.figmgr.num] = self.figmgr
[2170]44 self._set_window_title('ASAP Plotter - Tk')
[707]45
46 self.events = {'button_press':None,
47 'button_release':None,
48 'motion_notify':None}
49
[1153]50 matplotlib.rcParams["interactive"] = True
51 #self.buffering = buffering
[707]52
53 self.canvas.show()
54
55 def map(self):
[1826]56 """
57 Reveal the ASAPlot graphics window and bring it to the top of the
58 window stack.
59 """
60 self.window.wm_deiconify()
61 self.window.lift()
[707]62
63 def quit(self):
[1826]64 """
65 Destroy the ASAPlot graphics window.
66 """
[2149]67 self.is_dead = True
[2416]68 #self.window.destroy()
69 _pylab_helpers.Gcf.destroy(self.figmgr.num)
70 del self.window, self.canvas
71 self.window = None
72 self.canvas = None
73
[707]74
[1153]75 def show(self, hardrefresh=True):
[1826]76 """
77 Show graphics dependent on the current buffering state.
78 """
79 if not self.buffering:
[1153]80 if hardrefresh:
81 asaplotbase.show(self)
[1826]82 self.window.wm_deiconify()
83 self.canvas.show()
[707]84
85 def terminate(self):
[1826]86 """
87 Clear the figure.
88 """
89 self.window.destroy()
[707]90
91 def unmap(self):
[1826]92 """
93 Hide the ASAPlot graphics window.
94 """
95 self.window.wm_withdraw()
[2170]96
97 def _set_window_title(self,title):
98 # Set title to main window title bar
99 self.window.wm_title(title)
Note: See TracBrowser for help on using the repository browser.