| 1 | """
|
|---|
| 2 | ASAP plotting class based on matplotlib.
|
|---|
| 3 | """
|
|---|
| 4 |
|
|---|
| 5 | from asap.asaplotbase import *
|
|---|
| 6 | import Tkinter as Tk
|
|---|
| 7 | import matplotlib
|
|---|
| 8 | from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg, \
|
|---|
| 9 | FigureManagerTkAgg
|
|---|
| 10 | # Force use of the newfangled toolbar.
|
|---|
| 11 | matplotlib.rcParams['toolbar'] = 'toolbar2'
|
|---|
| 12 | from matplotlib import _pylab_helpers
|
|---|
| 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 | self.window = Tk.Tk()
|
|---|
| 31 | #def dest_callback():
|
|---|
| 32 | # print "dest_callback"
|
|---|
| 33 | # self.is_dead = True
|
|---|
| 34 | # self.window.destroy()
|
|---|
| 35 |
|
|---|
| 36 | self.window.protocol("WM_DELETE_WINDOW", self.quit)
|
|---|
| 37 | self.canvas = FigureCanvasTkAgg(self.figure, master=self.window)
|
|---|
| 38 | self.canvas.get_tk_widget().pack(side=Tk.TOP, fill=Tk.BOTH, expand=1)
|
|---|
| 39 | # Simply instantiating this is enough to get a working toolbar.
|
|---|
| 40 | self.figmgr = FigureManagerTkAgg(self.canvas, 0, self.window)
|
|---|
| 41 | # Register this plot to matplotlib without activating it
|
|---|
| 42 | #_pylab_helpers.Gcf.set_active(self.figmgr)
|
|---|
| 43 | _pylab_helpers.Gcf.figs[self.figmgr.num] = self.figmgr
|
|---|
| 44 | self._set_window_title('ASAP Plotter - Tk')
|
|---|
| 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.wm_deiconify()
|
|---|
| 61 | self.window.lift()
|
|---|
| 62 |
|
|---|
| 63 | def quit(self):
|
|---|
| 64 | """
|
|---|
| 65 | Destroy the ASAPlot graphics window.
|
|---|
| 66 | """
|
|---|
| 67 | self.is_dead = True
|
|---|
| 68 | #self.window.destroy()
|
|---|
| 69 | _pylab_helpers.Gcf.destroy(self.figmgr.num)
|
|---|
| 70 | del self.window, self.canvas
|
|---|
| 71 | self.window = None
|
|---|
| 72 | self.canvas = None
|
|---|
| 73 |
|
|---|
| 74 |
|
|---|
| 75 | def show(self, hardrefresh=True):
|
|---|
| 76 | """
|
|---|
| 77 | Show graphics dependent on the current buffering state.
|
|---|
| 78 | """
|
|---|
| 79 | if not self.buffering:
|
|---|
| 80 | if hardrefresh:
|
|---|
| 81 | asaplotbase.show(self)
|
|---|
| 82 | self.window.wm_deiconify()
|
|---|
| 83 | self.canvas.show()
|
|---|
| 84 |
|
|---|
| 85 | def terminate(self):
|
|---|
| 86 | """
|
|---|
| 87 | Clear the figure.
|
|---|
| 88 | """
|
|---|
| 89 | self.window.destroy()
|
|---|
| 90 |
|
|---|
| 91 | def unmap(self):
|
|---|
| 92 | """
|
|---|
| 93 | Hide the ASAPlot graphics window.
|
|---|
| 94 | """
|
|---|
| 95 | self.window.wm_withdraw()
|
|---|
| 96 |
|
|---|
| 97 | def _set_window_title(self,title):
|
|---|
| 98 | # Set title to main window title bar
|
|---|
| 99 | self.window.wm_title(title)
|
|---|