16
16
17
17
18
18
class Show (ShowBase ):
19
- def __call__ (self , block = None ):
20
- import matplotlib ._pylab_helpers as pylab_helpers
21
-
19
+ def display_js (self ):
22
20
# XXX How to do this just once? It has to deal with multiple
23
21
# browser instances using the same kernel.
24
22
display (Javascript (FigureManagerNbAgg .get_javascript ()))
25
23
24
+ def __call__ (self , block = None ):
25
+ from matplotlib import is_interactive
26
+ import matplotlib ._pylab_helpers as pylab_helpers
27
+
26
28
queue = pylab_helpers .Gcf ._activeQue
27
29
for manager in queue [:]:
28
- manager .show ()
29
- # If we are not interactive, disable the figure from the active queue,
30
- # but don't destroy it.
31
- queue .remove (manager )
30
+ if not manager .shown :
31
+ self .display_js ()
32
+
33
+ manager .show ()
34
+ # If we are not interactive, disable the figure from
35
+ # the active queue, but don't destroy it.
36
+ if not is_interactive ():
37
+ queue .remove (manager )
38
+ manager .canvas .draw_idle ()
39
+
32
40
33
41
show = Show ()
34
42
35
43
36
44
def draw_if_interactive ():
37
- # TODO: Sort out the expected interactive interface & make it easy for
38
- # somebody to "re-show" a specific figure.
39
- pass
40
- # from matplotlib import is_interactive
41
- # import matplotlib._pylab_helpers as pylab_helpers
42
- #
43
- # if is_interactive():
44
- # figManager = pylab_helpers.Gcf.get_active()
45
- # if figManager is not None:
46
- # figManager.show()
45
+ from matplotlib import is_interactive
46
+ import matplotlib ._pylab_helpers as pylab_helpers
47
+
48
+ if is_interactive ():
49
+ manager = pylab_helpers .Gcf .get_active ()
50
+ if manager is not None :
51
+ if not manager .shown :
52
+ manager .show ()
53
+ manager .canvas .draw_idle ()
47
54
48
55
49
56
def connection_info ():
@@ -54,13 +61,13 @@ def connection_info():
54
61
"""
55
62
# TODO: Make this useful!
56
63
import matplotlib ._pylab_helpers as pylab_helpers
64
+ result = []
57
65
for manager in pylab_helpers .Gcf .get_all_fig_managers ():
58
66
fig = manager .canvas .figure
59
- print fig .get_label () or "Figure {0}" .format (manager .num ),
60
- print [socket .supports_binary for socket in manager .web_sockets ],
61
- print manager .web_sockets
62
-
63
- print 'Figures pending show: ' , len (pylab_helpers .Gcf ._activeQue )
67
+ result .append ('{} - {}' .format (fig .get_label () or "Figure {0}" .format (manager .num ),
68
+ manager .web_sockets ))
69
+ result .append ('Figures pending show: ' + str (len (pylab_helpers .Gcf ._activeQue )))
70
+ return '\n ' .join (result )
64
71
65
72
66
73
class NavigationIPy (NavigationToolbar2WebAgg ):
@@ -86,13 +93,17 @@ class FigureManagerNbAgg(FigureManagerWebAgg):
86
93
ToolbarCls = NavigationIPy
87
94
88
95
def __init__ (self , canvas , num ):
89
- self ._shown = False
96
+ self .shown = False
90
97
FigureManagerWebAgg .__init__ (self , canvas , num )
91
98
92
99
def show (self ):
93
- if not self ._shown :
100
+ if not self .shown :
94
101
self ._create_comm ()
95
- self ._shown = True
102
+ self .shown = True
103
+
104
+ def reshow (self ):
105
+ self .shown = False
106
+ self .show ()
96
107
97
108
@property
98
109
def connected (self ):
0 commit comments