source: trunk/python/asaplotgui.py@ 2445

Last change on this file since 2445 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
Line 
1"""
2ASAP plotting class based on matplotlib.
3"""
4
5from asap.asaplotbase import *
6import Tkinter as Tk
7import matplotlib
8from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg, \
9 FigureManagerTkAgg
10# Force use of the newfangled toolbar.
11matplotlib.rcParams['toolbar'] = 'toolbar2'
12from matplotlib import _pylab_helpers
13
14class asaplotgui(asaplotbase):
15 """
16 ASAP plotting class based on matplotlib.
17 """
18
19 def __init__(self, rows=1, cols=0, title='', size=None, buffering=False):
20 """
21 Create a new instance of the ASAPlot plotting class.
22
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 """
26 v = vars()
27 del v['self']
28
29 asaplotbase.__init__(self, **v)
30 self.window = Tk.Tk()
31 #def dest_callback():
32 # print "dest_callback"
33 # self.is_dead = True
34 # self.window.destroy()
35
36 self.window.protocol("WM_DELETE_WINDOW", self.quit)
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.
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
44 self._set_window_title('ASAP Plotter - Tk')
45
46 self.events = {'button_press':None,
47 'button_release':None,
48 'motion_notify':None}
49
50 matplotlib.rcParams["interactive"] = True
51 #self.buffering = buffering
52
53 self.canvas.show()
54
55 def map(self):
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()
62
63 def quit(self):
64 """
65 Destroy the ASAPlot graphics window.
66 """
67 self.is_dead = True
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
74
75 def show(self, hardrefresh=True):
76 """
77 Show graphics dependent on the current buffering state.
78 """
79 if not self.buffering:
80 if hardrefresh:
81 asaplotbase.show(self)
82 self.window.wm_deiconify()
83 self.canvas.show()
84
85 def terminate(self):
86 """
87 Clear the figure.
88 """
89 self.window.destroy()
90
91 def unmap(self):
92 """
93 Hide the ASAPlot graphics window.
94 """
95 self.window.wm_withdraw()
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.