[707] | 1 | """
|
---|
| 2 | ASAP plotting class based on matplotlib.
|
---|
| 3 | """
|
---|
| 4 |
|
---|
| 5 | from asap.asaplotbase import *
|
---|
| 6 | import Tkinter as Tk
|
---|
[1422] | 7 | import matplotlib
|
---|
[707] | 8 | from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg, \
|
---|
| 9 | FigureManagerTkAgg
|
---|
| 10 | # Force use of the newfangled toolbar.
|
---|
| 11 | matplotlib.rcParams['toolbar'] = 'toolbar2'
|
---|
[2416] | 12 | from matplotlib import _pylab_helpers
|
---|
[2451] | 13 | from asap.logging import asaplog, asaplog_post_dec
|
---|
[707] | 14 |
|
---|
| 15 | class asaplotgui(asaplotbase):
|
---|
| 16 | """
|
---|
| 17 | ASAP plotting class based on matplotlib.
|
---|
| 18 | """
|
---|
| 19 |
|
---|
[1563] | 20 | def __init__(self, rows=1, cols=0, title='', size=None, buffering=False):
|
---|
[1826] | 21 | """
|
---|
| 22 | Create a new instance of the ASAPlot plotting class.
|
---|
[707] | 23 |
|
---|
[1826] | 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 | """
|
---|
[707] | 27 | v = vars()
|
---|
| 28 | del v['self']
|
---|
[1153] | 29 |
|
---|
[707] | 30 | asaplotbase.__init__(self, **v)
|
---|
[2451] | 31 | #matplotlib.rcParams["interactive"] = True
|
---|
| 32 |
|
---|
[707] | 33 | self.window = Tk.Tk()
|
---|
[2416] | 34 | self.window.protocol("WM_DELETE_WINDOW", self.quit)
|
---|
[707] | 35 | self.canvas = FigureCanvasTkAgg(self.figure, master=self.window)
|
---|
| 36 | self.canvas.get_tk_widget().pack(side=Tk.TOP, fill=Tk.BOTH, expand=1)
|
---|
| 37 | # Simply instantiating this is enough to get a working toolbar.
|
---|
[2416] | 38 | self.figmgr = FigureManagerTkAgg(self.canvas, 0, self.window)
|
---|
| 39 | # Register this plot to matplotlib without activating it
|
---|
| 40 | #_pylab_helpers.Gcf.set_active(self.figmgr)
|
---|
| 41 | _pylab_helpers.Gcf.figs[self.figmgr.num] = self.figmgr
|
---|
[2170] | 42 | self._set_window_title('ASAP Plotter - Tk')
|
---|
[2451] | 43 | self.canvas.show()
|
---|
[707] | 44 |
|
---|
| 45 |
|
---|
| 46 | def map(self):
|
---|
[1826] | 47 | """
|
---|
| 48 | Reveal the ASAPlot graphics window and bring it to the top of the
|
---|
| 49 | window stack.
|
---|
| 50 | """
|
---|
[2451] | 51 | if self.is_dead:
|
---|
| 52 | raise RuntimeError( "No plotter to show. Not yet plotted or plotter is closed." )
|
---|
[1826] | 53 | self.window.wm_deiconify()
|
---|
| 54 | self.window.lift()
|
---|
[707] | 55 |
|
---|
| 56 | def quit(self):
|
---|
[1826] | 57 | """
|
---|
| 58 | Destroy the ASAPlot graphics window.
|
---|
| 59 | """
|
---|
[2149] | 60 | self.is_dead = True
|
---|
[2451] | 61 | if not self.figmgr:
|
---|
| 62 | return
|
---|
[2416] | 63 | #self.window.destroy()
|
---|
| 64 | _pylab_helpers.Gcf.destroy(self.figmgr.num)
|
---|
[2451] | 65 | del self.window, self.canvas, self.figmgr
|
---|
[2416] | 66 | self.window = None
|
---|
| 67 | self.canvas = None
|
---|
[2451] | 68 | self.figmgr = None
|
---|
[707] | 69 |
|
---|
[1153] | 70 | def show(self, hardrefresh=True):
|
---|
[1826] | 71 | """
|
---|
| 72 | Show graphics dependent on the current buffering state.
|
---|
| 73 | """
|
---|
[2451] | 74 | if self.is_dead:
|
---|
| 75 | raise RuntimeError( "No plotter to show (not yet plotted or closed)." )
|
---|
[1826] | 76 | if not self.buffering:
|
---|
[1153] | 77 | if hardrefresh:
|
---|
| 78 | asaplotbase.show(self)
|
---|
[1826] | 79 | self.window.wm_deiconify()
|
---|
| 80 | self.canvas.show()
|
---|
[707] | 81 |
|
---|
| 82 | def terminate(self):
|
---|
[1826] | 83 | """
|
---|
| 84 | Clear the figure.
|
---|
| 85 | """
|
---|
[2451] | 86 | if not self.window:
|
---|
| 87 | asaplog.push( "No plotter window to terminate." )
|
---|
| 88 | asaplog.post( "WARN" )
|
---|
| 89 | return
|
---|
[1826] | 90 | self.window.destroy()
|
---|
[707] | 91 |
|
---|
| 92 | def unmap(self):
|
---|
[1826] | 93 | """
|
---|
| 94 | Hide the ASAPlot graphics window.
|
---|
| 95 | """
|
---|
[2451] | 96 | if not self.window:
|
---|
| 97 | asaplog.push( "No plotter window to unmap." )
|
---|
| 98 | asaplog.post( "WARN" )
|
---|
| 99 | return
|
---|
[1826] | 100 | self.window.wm_withdraw()
|
---|
[2170] | 101 |
|
---|
| 102 | def _set_window_title(self,title):
|
---|
| 103 | # Set title to main window title bar
|
---|
| 104 | self.window.wm_title(title)
|
---|