source: trunk/python/asaplotgui_qt4.py@ 2497

Last change on this file since 2497 was 2451, 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: unit tests of sdplot

Put in Release Notes: No

Module(s): sdplot, sdfit, sdstat, sdflag, sdcal, sdreduce

Description:

Made asapplotter not to generate plotter window at start-up, but the window is
only generated at the first invokation of plotting operation.


File size: 3.5 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)
[2451]31 matplotlib.rcParams["interactive"] = True
[1640]32
[2451]33 _pylab_helpers.Gcf.destroy(0)
[1640]34 self.canvas = FigureCanvasQTAgg(self.figure)
35 # Simply instantiating this is enough to get a working toolbar.
[2416]36 self.figmgr = FigureManagerQTAgg(self.canvas, 0)
[1640]37 self.window = self.figmgr.window
[2170]38 self._set_window_title('ASAP Plotter - Qt4')
[2416]39 # Register this plot to matplotlib without activating it
40 #_pylab_helpers.Gcf.set_active(self.figmgr)
41 _pylab_helpers.Gcf.figs[self.figmgr.num] = self.figmgr
[1640]42
43 #############
44 ### DO WE HAVE TO DO SOMETHING FOR WINDOW CLOSE CALL?
45 #############
46 def dest_callback():
[2152]47 try:
48 self.is_dead = True
49 except NameError:
50 pass
[1640]51
52 qt.QtCore.QObject.connect(self.window, qt.QtCore.SIGNAL('destroyed()'),dest_callback)
53
[2146]54 self.unmap()
[1640]55 #self.canvas.show()
56
57 def map(self):
58 """
59 Reveal the ASAPlot graphics window and bring it to the top of the
60 window stack.
61 """
[2451]62 if self.is_dead:
63 raise RuntimeError( "No plotter to show. Not yet plotted or plotter is closed." )
[1640]64 self.window.activateWindow()
65 #To raise this window to the top of the stacking order
66 self.window.raise_()
67 self.window.show()
68
69 def quit(self):
70 """
71 Destroy the ASAPlot graphics window.
72 """
[2149]73 self.is_dead = True
[2451]74 if not self.figmgr:
75 return
76 try:
77 #self.window.close()
78 # TODO destroy casabar
79 _pylab_helpers.Gcf.destroy(self.figmgr.num)
80 del self.window, self.canvas, self.figmgr
81 self.window = None
82 self.canvas = None
83 self.figmgr = None
[2151]84 except RuntimeError: pass # the window may already be closed by user
[1640]85
86 def show(self, hardrefresh=True):
87 """
88 Show graphics dependent on the current buffering state.
89 """
[2451]90 if self.is_dead:
91 raise RuntimeError( "No plotter to show (not yet plotted or closed)." )
[1640]92 if not self.buffering:
93 if hardrefresh:
94 asaplotbase.show(self)
95 self.window.activateWindow()
[2148]96 self.canvas.draw()
97 #self.canvas.show()
[2146]98 self.window.show()
[1640]99
100 def terminate(self):
101 """
102 Clear the figure.
103 """
[2451]104 if not self.window:
105 asaplog.push( "No plotter window to terminate." )
106 asaplog.post( "WARN" )
107 return
[1640]108 self.window.close()
109
110 def unmap(self):
111 """
112 Hide the ASAPlot graphics window.
113 """
[2451]114 if not self.window:
115 asaplog.push( "No plotter window to unmap." )
116 asaplog.post( "WARN" )
117 return
[1640]118 self.window.hide()
[2170]119
120 def _set_window_title(self,title):
121 # Set title to main window title bar
122 self.window.setWindowTitle(title)
Note: See TracBrowser for help on using the repository browser.