[1640] | 1 | """
|
---|
| 2 | ASAP plotting class based on matplotlib.
|
---|
| 3 | """
|
---|
| 4 |
|
---|
| 5 | from asap.asaplotbase import *
|
---|
| 6 | import PyQt4 as qt
|
---|
| 7 | from matplotlib.backends.backend_qt4agg import FigureCanvasQTAgg, \
|
---|
| 8 | FigureManagerQTAgg
|
---|
[2152] | 9 | from matplotlib import _pylab_helpers
|
---|
[1640] | 10 | # Force use of the newfangled toolbar.
|
---|
| 11 | import matplotlib
|
---|
[2146] | 12 | #matplotlib.use("Qt4Agg")
|
---|
[1640] | 13 | matplotlib.rcParams['toolbar'] = 'toolbar2'
|
---|
| 14 |
|
---|
| 15 | class 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.
|
---|
| 34 | self.figmgr = FigureManagerQTAgg(self.canvas, 1)
|
---|
| 35 | self.window = self.figmgr.window
|
---|
[2170] | 36 | self._set_window_title('ASAP Plotter - Qt4')
|
---|
[2152] | 37 | # register this plot to matplotlib
|
---|
| 38 | _pylab_helpers.Gcf.set_active(self.figmgr)
|
---|
[1640] | 39 |
|
---|
| 40 | #############
|
---|
| 41 | ### DO WE HAVE TO DO SOMETHING FOR WINDOW CLOSE CALL?
|
---|
| 42 | #############
|
---|
| 43 | def dest_callback():
|
---|
[2152] | 44 | try:
|
---|
| 45 | self.is_dead = True
|
---|
| 46 | except NameError:
|
---|
| 47 | pass
|
---|
[1640] | 48 |
|
---|
| 49 | qt.QtCore.QObject.connect(self.window, qt.QtCore.SIGNAL('destroyed()'),dest_callback)
|
---|
| 50 |
|
---|
| 51 | self.events = {'button_press':None,
|
---|
| 52 | 'button_release':None,
|
---|
| 53 | 'motion_notify':None}
|
---|
| 54 |
|
---|
| 55 | matplotlib.rcParams["interactive"] = True
|
---|
| 56 | self.buffering = buffering
|
---|
| 57 |
|
---|
[2146] | 58 | self.unmap()
|
---|
[1640] | 59 | #self.canvas.show()
|
---|
| 60 |
|
---|
| 61 | def map(self):
|
---|
| 62 | """
|
---|
| 63 | Reveal the ASAPlot graphics window and bring it to the top of the
|
---|
| 64 | window stack.
|
---|
| 65 | """
|
---|
| 66 | self.window.activateWindow()
|
---|
| 67 | #To raise this window to the top of the stacking order
|
---|
| 68 | self.window.raise_()
|
---|
| 69 | self.window.show()
|
---|
| 70 |
|
---|
| 71 | def quit(self):
|
---|
| 72 | """
|
---|
| 73 | Destroy the ASAPlot graphics window.
|
---|
| 74 | """
|
---|
[2149] | 75 | self.is_dead = True
|
---|
[2151] | 76 | try: self.window.close()
|
---|
| 77 | except RuntimeError: pass # the window may already be closed by user
|
---|
[1640] | 78 |
|
---|
| 79 | def show(self, hardrefresh=True):
|
---|
| 80 | """
|
---|
| 81 | Show graphics dependent on the current buffering state.
|
---|
| 82 | """
|
---|
| 83 | if not self.buffering:
|
---|
| 84 | if hardrefresh:
|
---|
| 85 | asaplotbase.show(self)
|
---|
| 86 | self.window.activateWindow()
|
---|
[2148] | 87 | self.canvas.draw()
|
---|
| 88 | #self.canvas.show()
|
---|
[2146] | 89 | self.window.show()
|
---|
[1640] | 90 |
|
---|
| 91 | def terminate(self):
|
---|
| 92 | """
|
---|
| 93 | Clear the figure.
|
---|
| 94 | """
|
---|
| 95 | self.window.close()
|
---|
| 96 |
|
---|
| 97 | def unmap(self):
|
---|
| 98 | """
|
---|
| 99 | Hide the ASAPlot graphics window.
|
---|
| 100 | """
|
---|
| 101 | self.window.hide()
|
---|
[2170] | 102 |
|
---|
| 103 | def _set_window_title(self,title):
|
---|
| 104 | # Set title to main window title bar
|
---|
| 105 | self.window.setWindowTitle(title)
|
---|