[707] | 1 | """
|
---|
| 2 | ASAP plotting class based on matplotlib.
|
---|
| 3 | """
|
---|
| 4 |
|
---|
| 5 | from asap.asaplotbase import *
|
---|
| 6 | import Tkinter as Tk
|
---|
[1603] | 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'
|
---|
| 12 |
|
---|
| 13 | class asaplotgui(asaplotbase):
|
---|
| 14 | """
|
---|
| 15 | ASAP plotting class based on matplotlib.
|
---|
| 16 | """
|
---|
| 17 |
|
---|
| 18 | def __init__(self, rows=1, cols=0, title='', size=(8,6), buffering=False):
|
---|
| 19 | """
|
---|
| 20 | Create a new instance of the ASAPlot plotting class.
|
---|
| 21 |
|
---|
| 22 | If rows < 1 then a separate call to set_panels() is required to define
|
---|
| 23 | the panel layout; refer to the doctext for set_panels().
|
---|
| 24 | """
|
---|
| 25 | v = vars()
|
---|
| 26 | del v['self']
|
---|
[1153] | 27 |
|
---|
[707] | 28 | asaplotbase.__init__(self, **v)
|
---|
| 29 | self.window = Tk.Tk()
|
---|
| 30 | def dest_callback():
|
---|
| 31 | self.is_dead = True
|
---|
| 32 | self.window.destroy()
|
---|
| 33 |
|
---|
| 34 | self.window.protocol("WM_DELETE_WINDOW", dest_callback)
|
---|
| 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.
|
---|
| 38 | self.figmgr = FigureManagerTkAgg(self.canvas, 1, self.window)
|
---|
[1153] | 39 | self.window.wm_title('ASAP Plotter - Tk')
|
---|
[707] | 40 |
|
---|
| 41 | self.events = {'button_press':None,
|
---|
| 42 | 'button_release':None,
|
---|
| 43 | 'motion_notify':None}
|
---|
| 44 |
|
---|
[1153] | 45 | matplotlib.rcParams["interactive"] = True
|
---|
| 46 | #self.buffering = buffering
|
---|
[707] | 47 |
|
---|
| 48 | self.canvas.show()
|
---|
| 49 |
|
---|
| 50 | def map(self):
|
---|
| 51 | """
|
---|
| 52 | Reveal the ASAPlot graphics window and bring it to the top of the
|
---|
| 53 | window stack.
|
---|
| 54 | """
|
---|
| 55 | self.window.wm_deiconify()
|
---|
| 56 | self.window.lift()
|
---|
| 57 |
|
---|
| 58 | def quit(self):
|
---|
| 59 | """
|
---|
| 60 | Destroy the ASAPlot graphics window.
|
---|
| 61 | """
|
---|
| 62 | self.window.destroy()
|
---|
| 63 |
|
---|
[1153] | 64 | def show(self, hardrefresh=True):
|
---|
[707] | 65 | """
|
---|
| 66 | Show graphics dependent on the current buffering state.
|
---|
| 67 | """
|
---|
| 68 | if not self.buffering:
|
---|
[1153] | 69 | if hardrefresh:
|
---|
| 70 | asaplotbase.show(self)
|
---|
[707] | 71 | self.window.wm_deiconify()
|
---|
[1153] | 72 | self.canvas.show()
|
---|
[707] | 73 |
|
---|
| 74 | def terminate(self):
|
---|
| 75 | """
|
---|
| 76 | Clear the figure.
|
---|
| 77 | """
|
---|
| 78 | self.window.destroy()
|
---|
| 79 |
|
---|
| 80 | def unmap(self):
|
---|
| 81 | """
|
---|
| 82 | Hide the ASAPlot graphics window.
|
---|
| 83 | """
|
---|
| 84 | self.window.wm_withdraw()
|
---|