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 | from matplotlib import _pylab_helpers |
---|
10 | # Force use of the newfangled toolbar. |
---|
11 | import matplotlib |
---|
12 | #matplotlib.use("Qt4Agg") |
---|
13 | matplotlib.rcParams['toolbar'] = 'toolbar2' |
---|
14 | |
---|
15 | class asaplotgui(asaplotbase): |
---|
16 | """ |
---|
17 | ASAP plotting class based on matplotlib. |
---|
18 | """ |
---|
19 | |
---|
20 | def __init__(self, rows=1, cols=0, title='', size=None, buffering=False): |
---|
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._set_window_title('ASAP Plotter - Qt4') |
---|
37 | # register this plot to matplotlib |
---|
38 | _pylab_helpers.Gcf.set_active(self.figmgr) |
---|
39 | |
---|
40 | ############# |
---|
41 | ### DO WE HAVE TO DO SOMETHING FOR WINDOW CLOSE CALL? |
---|
42 | ############# |
---|
43 | def dest_callback(): |
---|
44 | try: |
---|
45 | self.is_dead = True |
---|
46 | except NameError: |
---|
47 | pass |
---|
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 | |
---|
58 | self.unmap() |
---|
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 | """ |
---|
75 | self.is_dead = True |
---|
76 | try: self.window.close() |
---|
77 | except RuntimeError: pass # the window may already be closed by user |
---|
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() |
---|
87 | self.canvas.draw() |
---|
88 | #self.canvas.show() |
---|
89 | self.window.show() |
---|
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() |
---|
102 | |
---|
103 | def _set_window_title(self,title): |
---|
104 | # Set title to main window title bar |
---|
105 | self.window.setWindowTitle(title) |
---|