source: branches/hpc34/python/asaplotgui.py@ 2582

Last change on this file since 2582 was 2516, checked in by Malte Marquarding, 13 years ago

Another occurence of teh atexit gcf failure

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 3.3 KB
Line 
1"""
2ASAP plotting class based on matplotlib.
3"""
4
5from asap.asaplotbase import *
6import Tkinter as Tk
7import matplotlib
8from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg, \
9 FigureManagerTkAgg
10# Force use of the newfangled toolbar.
11matplotlib.rcParams['toolbar'] = 'toolbar2'
12from matplotlib import _pylab_helpers
13from asap.logging import asaplog, asaplog_post_dec
14
15class 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 #matplotlib.rcParams["interactive"] = True
32
33 _pylab_helpers.Gcf.destroy(0)
34 self.window = Tk.Tk()
35 self.window.protocol("WM_DELETE_WINDOW", self.quit)
36 self.canvas = FigureCanvasTkAgg(self.figure, master=self.window)
37 self.canvas.get_tk_widget().pack(side=Tk.TOP, fill=Tk.BOTH, expand=1)
38 # Simply instantiating this is enough to get a working toolbar.
39 self.figmgr = FigureManagerTkAgg(self.canvas, 0, self.window)
40 self.figmgr._cidgcf = None
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 self.canvas.show()
46
47
48 def map(self):
49 """
50 Reveal the ASAPlot graphics window and bring it to the top of the
51 window stack.
52 """
53 if self.is_dead:
54 raise RuntimeError( "No plotter to show. Not yet plotted or plotter is closed." )
55 self.window.wm_deiconify()
56 self.window.lift()
57
58 def quit(self):
59 """
60 Destroy the ASAPlot graphics window.
61 """
62 self.is_dead = True
63 if not self.figmgr:
64 return
65 #self.window.destroy()
66 _pylab_helpers.Gcf.destroy(self.figmgr.num)
67 del self.window, self.canvas, self.figmgr
68 self.window = None
69 self.canvas = None
70 self.figmgr = None
71
72 def show(self, hardrefresh=True):
73 """
74 Show graphics dependent on the current buffering state.
75 """
76 if self.is_dead:
77 raise RuntimeError( "No plotter to show (not yet plotted or closed)." )
78 if not self.buffering:
79 if hardrefresh:
80 asaplotbase.show(self)
81 self.window.wm_deiconify()
82 self.canvas.show()
83
84 def terminate(self):
85 """
86 Clear the figure.
87 """
88 if not self.window:
89 asaplog.push( "No plotter window to terminate." )
90 asaplog.post( "WARN" )
91 return
92 self.window.destroy()
93
94 def unmap(self):
95 """
96 Hide the ASAPlot graphics window.
97 """
98 if not self.window:
99 asaplog.push( "No plotter window to unmap." )
100 asaplog.post( "WARN" )
101 return
102 self.window.wm_withdraw()
103
104 def _set_window_title(self,title):
105 # Set title to main window title bar
106 self.window.wm_title(title)
Note: See TracBrowser for help on using the repository browser.