[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 |
---|
| 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 | 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 |
---|
| 36 | self.window.setWindowTitle('ASAP Plotter - Qt4') |
---|
| 37 | |
---|
| 38 | ############# |
---|
| 39 | ### DO WE HAVE TO DO SOMETHING FOR WINDOW CLOSE CALL? |
---|
| 40 | ############# |
---|
| 41 | def dest_callback(): |
---|
| 42 | self.is_dead = True |
---|
| 43 | |
---|
| 44 | qt.QtCore.QObject.connect(self.window, qt.QtCore.SIGNAL('destroyed()'),dest_callback) |
---|
| 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.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.window.close() |
---|
| 70 | |
---|
| 71 | def show(self, hardrefresh=True): |
---|
| 72 | """ |
---|
| 73 | Show graphics dependent on the current buffering state. |
---|
| 74 | """ |
---|
| 75 | if not self.buffering: |
---|
| 76 | if hardrefresh: |
---|
| 77 | asaplotbase.show(self) |
---|
| 78 | self.window.activateWindow() |
---|
| 79 | self.canvas.show() |
---|
| 80 | #self.window.show() |
---|
| 81 | |
---|
| 82 | def terminate(self): |
---|
| 83 | """ |
---|
| 84 | Clear the figure. |
---|
| 85 | """ |
---|
| 86 | self.window.close() |
---|
| 87 | |
---|
| 88 | def unmap(self): |
---|
| 89 | """ |
---|
| 90 | Hide the ASAPlot graphics window. |
---|
| 91 | """ |
---|
| 92 | self.window.hide() |
---|