|
24 | 24 | from matplotlib.backend_bases import \
|
25 | 25 | RendererBase, GraphicsContextBase, FigureManagerBase, FigureCanvasBase,\
|
26 | 26 | NavigationToolbar2, cursors
|
| 27 | +from matplotlib.backend_bases import ShowBase |
| 28 | + |
| 29 | + |
27 | 30 | from matplotlib.figure import Figure
|
28 | 31 | from matplotlib._pylab_helpers import Gcf
|
29 | 32 | import matplotlib.backends.windowing as windowing
|
30 | 33 | from matplotlib.widgets import SubplotTool
|
31 | 34 |
|
32 |
| - |
33 |
| -import thread,time |
34 |
| - |
35 |
| -Fl_running=thread.allocate_lock() |
36 |
| -def Fltk_run_interactive(): |
37 |
| - global Fl_running |
38 |
| - if Fl_running.acquire(0): |
39 |
| - while True: |
40 |
| - Fltk.Fl.check() |
41 |
| - time.sleep(0.005) |
42 |
| - else: |
43 |
| - print "fl loop already running" |
44 |
| - |
45 | 35 | # the true dots per inch on the screen; should be display dependent
|
46 | 36 | # see http://groups.google.com/groups?q=screen+dpi+x11&hl=en&lr=&ie=UTF-8&oe=UTF-8&safe=off&selm=7077.26e81ad5%40swift.cs.tcd.ie&rnum=5 for some info about screen dpi
|
47 | 37 | PIXELS_PER_INCH = 75
|
@@ -75,29 +65,12 @@ def draw_if_interactive():
|
75 | 65 | if figManager is not None:
|
76 | 66 | figManager.canvas.draw()
|
77 | 67 |
|
| 68 | +class Show(ShowBase): |
| 69 | + def mainloop(self): |
| 70 | + Fltk.Fl.run() |
78 | 71 |
|
79 |
| -def ishow(): |
80 |
| - """ |
81 |
| - Show all the figures and enter the fltk mainloop in another thread |
82 |
| - This allows to keep hand in interractive python session |
83 |
| - Warning: does not work under windows |
84 |
| - This should be the last line of your script |
85 |
| - """ |
86 |
| - for manager in Gcf.get_all_fig_managers(): |
87 |
| - manager.show() |
88 |
| - if show._needmain: |
89 |
| - thread.start_new_thread(Fltk_run_interactive,()) |
90 |
| - show._needmain = False |
| 72 | +show = Show() |
91 | 73 |
|
92 |
| -def show(): |
93 |
| - """ |
94 |
| - Show all the figures and enter the fltk mainloop |
95 |
| -
|
96 |
| - This should be the last line of your script |
97 |
| - """ |
98 |
| - for manager in Gcf.get_all_fig_managers(): |
99 |
| - manager.show() |
100 |
| - Fltk.Fl.run() |
101 | 74 |
|
102 | 75 | def new_figure_manager(num, *args, **kwargs):
|
103 | 76 | """
|
@@ -249,8 +222,9 @@ def stop_event_loop(self):
|
249 | 222 | FigureCanvasBase.stop_event_loop_default(self)
|
250 | 223 | stop_event_loop.__doc__=FigureCanvasBase.stop_event_loop_default.__doc__
|
251 | 224 |
|
252 |
| -def destroy_figure(ptr,figman): |
| 225 | +def destroy_figure(ptr, figman): |
253 | 226 | figman.window.hide()
|
| 227 | + Fltk.Fl.wait(0) # This is needed to make the last figure vanish. |
254 | 228 | Gcf.destroy(figman._num)
|
255 | 229 |
|
256 | 230 | class FigureManagerFltkAgg(FigureManagerBase):
|
@@ -301,6 +275,11 @@ def show(self):
|
301 | 275 | self.canvas.draw()
|
302 | 276 | self.window.redraw()
|
303 | 277 |
|
| 278 | + def destroy(self): |
| 279 | + self.window.hide() |
| 280 | + Fltk.Fl.wait(0) # This is needed to make the last figure vanish. |
| 281 | + Gcf.destroy(self._num) |
| 282 | + |
304 | 283 | def set_window_title(self, title):
|
305 | 284 | self.window_title=title
|
306 | 285 | self.window.label(title)
|
|
0 commit comments