| 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
|
|---|
| 9 | # Force use of the newfangled toolbar.
|
|---|
| 10 | import matplotlib
|
|---|
| 11 | #matplotlib.use("Qt4Agg")
|
|---|
| 12 | matplotlib.rcParams['toolbar'] = 'toolbar2'
|
|---|
| 13 |
|
|---|
| 14 | class 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 |
|
|---|
| 31 | self.canvas = FigureCanvasQTAgg(self.figure)
|
|---|
| 32 | # Simply instantiating this is enough to get a working toolbar.
|
|---|
| 33 | self.figmgr = FigureManagerQTAgg(self.canvas, 1)
|
|---|
| 34 | self.window = self.figmgr.window
|
|---|
| 35 | self.window.setWindowTitle('ASAP Plotter - Qt4')
|
|---|
| 36 |
|
|---|
| 37 | #############
|
|---|
| 38 | ### DO WE HAVE TO DO SOMETHING FOR WINDOW CLOSE CALL?
|
|---|
| 39 | #############
|
|---|
| 40 | def dest_callback():
|
|---|
| 41 | self.is_dead = True
|
|---|
| 42 |
|
|---|
| 43 | qt.QtCore.QObject.connect(self.window, qt.QtCore.SIGNAL('destroyed()'),dest_callback)
|
|---|
| 44 |
|
|---|
| 45 | self.events = {'button_press':None,
|
|---|
| 46 | 'button_release':None,
|
|---|
| 47 | 'motion_notify':None}
|
|---|
| 48 |
|
|---|
| 49 | matplotlib.rcParams["interactive"] = True
|
|---|
| 50 | self.buffering = buffering
|
|---|
| 51 |
|
|---|
| 52 | self.unmap()
|
|---|
| 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.activateWindow()
|
|---|
| 61 | #To raise this window to the top of the stacking order
|
|---|
| 62 | self.window.raise_()
|
|---|
| 63 | self.window.show()
|
|---|
| 64 |
|
|---|
| 65 | def quit(self):
|
|---|
| 66 | """
|
|---|
| 67 | Destroy the ASAPlot graphics window.
|
|---|
| 68 | """
|
|---|
| 69 | self.is_dead = True
|
|---|
| 70 | try: self.window.close()
|
|---|
| 71 | except RuntimeError: pass # the window may already be closed by user
|
|---|
| 72 |
|
|---|
| 73 | def show(self, hardrefresh=True):
|
|---|
| 74 | """
|
|---|
| 75 | Show graphics dependent on the current buffering state.
|
|---|
| 76 | """
|
|---|
| 77 | if not self.buffering:
|
|---|
| 78 | if hardrefresh:
|
|---|
| 79 | asaplotbase.show(self)
|
|---|
| 80 | self.window.activateWindow()
|
|---|
| 81 | self.canvas.draw()
|
|---|
| 82 | #self.canvas.show()
|
|---|
| 83 | self.window.show()
|
|---|
| 84 |
|
|---|
| 85 | def terminate(self):
|
|---|
| 86 | """
|
|---|
| 87 | Clear the figure.
|
|---|
| 88 | """
|
|---|
| 89 | self.window.close()
|
|---|
| 90 |
|
|---|
| 91 | def unmap(self):
|
|---|
| 92 | """
|
|---|
| 93 | Hide the ASAPlot graphics window.
|
|---|
| 94 | """
|
|---|
| 95 | self.window.hide()
|
|---|