[1089] | 1 | """
|
---|
| 2 | ASAP plotting class based on matplotlib.
|
---|
| 3 | """
|
---|
| 4 |
|
---|
| 5 | from asap.asaplotbase import *
|
---|
| 6 | # Force use of the newfangled toolbar.
|
---|
| 7 | import gtk
|
---|
| 8 | import matplotlib
|
---|
| 9 | from matplotlib.backends.backend_gtkagg import FigureCanvasGTKAgg as FigureCanvas
|
---|
[1153] | 10 | from matplotlib.backends.backend_gtkagg import FigureManagerGTKAgg
|
---|
[1089] | 11 | matplotlib.use("GTkAgg")
|
---|
| 12 | matplotlib.rcParams['toolbar'] = 'toolbar2'
|
---|
[1153] | 13 | from matplotlib.backends.backend_gtk import NavigationToolbar2GTK as NavigationToolbar
|
---|
[2451] | 14 | from matplotlib import _pylab_helpers
|
---|
[1089] | 15 |
|
---|
| 16 | class asaplotgui(asaplotbase):
|
---|
| 17 | """
|
---|
| 18 | ASAP plotting class based on matplotlib.
|
---|
| 19 | """
|
---|
| 20 |
|
---|
[1563] | 21 | def __init__(self, rows=1, cols=0, title='', size=None, buffering=False):
|
---|
[1089] | 22 | """
|
---|
| 23 | Create a new instance of the ASAPlot plotting class.
|
---|
| 24 |
|
---|
| 25 | If rows < 1 then a separate call to set_panels() is required to define
|
---|
| 26 | the panel layout; refer to the doctext for set_panels().
|
---|
| 27 | """
|
---|
| 28 | v = vars()
|
---|
| 29 | del v['self']
|
---|
| 30 |
|
---|
| 31 | asaplotbase.__init__(self, **v)
|
---|
[2451] | 32 | matplotlib.rcParams['interactive'] = True
|
---|
[1153] | 33 | matplotlib.interactive = True
|
---|
[2451] | 34 |
|
---|
| 35 | _pylab_helpers.Gcf.destroy(0)
|
---|
[1153] | 36 | self.canvas = FigureCanvas(self.figure)
|
---|
| 37 | # Simply instantiating this is enough to get a working toolbar.
|
---|
| 38 | self.figmgr = FigureManagerGTKAgg(self.canvas, 1)
|
---|
[1089] | 39 | def dest_callback(val):
|
---|
| 40 | self.is_dead = True
|
---|
[1153] | 41 | self.figmgr.window.destroy()
|
---|
| 42 | self.window = self.figmgr.window
|
---|
[1089] | 43 | self.window.connect("destroy", dest_callback )
|
---|
[1153] | 44 | self.window.set_title('ASAP Plotter - GTK')
|
---|
| 45 | #self.canvas.set_size_request(800,600)
|
---|
[2451] | 46 | _pylab_helpers.Gcf.figs[self.figmgr.num] = self.figmgr
|
---|
[1089] | 47 |
|
---|
[1153] | 48 | #self.canvas.show()
|
---|
[1089] | 49 |
|
---|
| 50 | def map(self):
|
---|
| 51 | """
|
---|
| 52 | Reveal the ASAPlot graphics window and bring it to the top of the
|
---|
| 53 | window stack.
|
---|
| 54 | """
|
---|
[2451] | 55 | if self.is_dead:
|
---|
| 56 | raise RuntimeError( "No plotter to show. Not yet plotted or plotter is closed." )
|
---|
[1089] | 57 | self.window.deiconify()
|
---|
| 58 | #self.window.lift()
|
---|
| 59 |
|
---|
| 60 | def quit(self):
|
---|
| 61 | """
|
---|
| 62 | Destroy the ASAPlot graphics window.
|
---|
| 63 | """
|
---|
[2451] | 64 | self.is_dead = True
|
---|
| 65 | if not self.figmgr:
|
---|
| 66 | return
|
---|
| 67 | #self.window.destroy()
|
---|
| 68 | _pylab_helpers.Gcf.destroy(self.figmgr.num)
|
---|
| 69 | del self.window, self.canvas, self.figmgr
|
---|
| 70 | self.window = None
|
---|
| 71 | self.canvas = None
|
---|
| 72 | self.figmgr = None
|
---|
[1089] | 73 |
|
---|
[1153] | 74 | def show(self, hardrefresh=True):
|
---|
[1089] | 75 | """
|
---|
| 76 | Show graphics dependent on the current buffering state.
|
---|
| 77 | """
|
---|
[2451] | 78 | if self.is_dead:
|
---|
| 79 | raise RuntimeError( "No plotter to show (not yet plotted or closed)." )
|
---|
[1089] | 80 | if not self.buffering:
|
---|
[1153] | 81 | if hardrefresh:
|
---|
| 82 | asaplotbase.show(self, hardrefresh)
|
---|
[1089] | 83 | self.window.deiconify()
|
---|
| 84 | self.canvas.draw()
|
---|
| 85 | self.window.show_all()
|
---|
| 86 |
|
---|
| 87 | def terminate(self):
|
---|
| 88 | """
|
---|
| 89 | Clear the figure.
|
---|
| 90 | """
|
---|
[2451] | 91 | if not self.window:
|
---|
| 92 | asaplog.push( "No plotter window to terminate." )
|
---|
| 93 | asaplog.post( "WARN" )
|
---|
| 94 | return
|
---|
[1089] | 95 | self.window.destroy()
|
---|
| 96 |
|
---|
| 97 | def unmap(self):
|
---|
| 98 | """
|
---|
| 99 | Hide the ASAPlot graphics window.
|
---|
| 100 | """
|
---|
[2451] | 101 | if not self.window:
|
---|
| 102 | asaplog.push( "No plotter window to unmap." )
|
---|
| 103 | asaplog.post( "WARN" )
|
---|
| 104 | return
|
---|
[1089] | 105 | self.window.wm_withdraw()
|
---|