source: trunk/python/asaplotgui_qt4.py @ 2416

Last change on this file since 2416 was 2416, checked in by Kana Sugimoto, 12 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: 2.8 KB
RevLine 
[1640]1"""
2ASAP plotting class based on matplotlib.
3"""
4
5from asap.asaplotbase import *
6import PyQt4 as qt
7from matplotlib.backends.backend_qt4agg import FigureCanvasQTAgg, \
8        FigureManagerQTAgg
[2152]9from matplotlib import _pylab_helpers
[1640]10# Force use of the newfangled toolbar.
11import matplotlib
[2146]12#matplotlib.use("Qt4Agg")
[1640]13matplotlib.rcParams['toolbar'] = 'toolbar2'
14
15class asaplotgui(asaplotbase):
16    """
17    ASAP plotting class based on matplotlib.
18    """
19
[1757]20    def __init__(self, rows=1, cols=0, title='', size=None, buffering=False):
[1640]21        """
22        Create a new instance of the ASAPlot plotting class.
23
24        If rows < 1 then a separate call to set_panels() is required to define
25        the panel layout; refer to the doctext for set_panels().
26        """
27        v = vars()
28        del v['self']
29
30        asaplotbase.__init__(self, **v)
31
32        self.canvas = FigureCanvasQTAgg(self.figure)
33        # Simply instantiating this is enough to get a working toolbar.
[2416]34        self.figmgr = FigureManagerQTAgg(self.canvas, 0)
[1640]35        self.window = self.figmgr.window
[2170]36        self._set_window_title('ASAP Plotter - Qt4')
[2416]37        # Register this plot to matplotlib without activating it
38        #_pylab_helpers.Gcf.set_active(self.figmgr)
39        _pylab_helpers.Gcf.figs[self.figmgr.num] = self.figmgr
[1640]40
41        #############
42        ### DO WE HAVE TO DO SOMETHING FOR WINDOW CLOSE CALL?
43        #############
44        def dest_callback():
[2152]45            try:
46                self.is_dead = True
47            except NameError:
48                pass
[1640]49
50        qt.QtCore.QObject.connect(self.window, qt.QtCore.SIGNAL('destroyed()'),dest_callback)
51
52        self.events = {'button_press':None,
53                       'button_release':None,
54                       'motion_notify':None}
55
56        matplotlib.rcParams["interactive"] = True
57        self.buffering = buffering
58
[2146]59        self.unmap()
[1640]60        #self.canvas.show()
61
62    def map(self):
63        """
64        Reveal the ASAPlot graphics window and bring it to the top of the
65        window stack.
66        """
67        self.window.activateWindow()
68        #To raise this window to the top of the stacking order
69        self.window.raise_()
70        self.window.show()
71
72    def quit(self):
73        """
74        Destroy the ASAPlot graphics window.
75        """
[2149]76        self.is_dead = True
[2151]77        try: self.window.close()
78        except RuntimeError: pass # the window may already be closed by user
[1640]79
80    def show(self, hardrefresh=True):
81        """
82        Show graphics dependent on the current buffering state.
83        """
84        if not self.buffering:
85            if hardrefresh:
86                asaplotbase.show(self)
87            self.window.activateWindow()
[2148]88            self.canvas.draw()
89            #self.canvas.show()
[2146]90            self.window.show()
[1640]91
92    def terminate(self):
93        """
94        Clear the figure.
95        """
96        self.window.close()
97
98    def unmap(self):
99        """
100        Hide the ASAPlot graphics window.
101        """
102        self.window.hide()
[2170]103
104    def _set_window_title(self,title):
105        # Set title to main window title bar
106        self.window.setWindowTitle(title)
Note: See TracBrowser for help on using the repository browser.