3
3
4
4
import * as outputBase from '@jupyter-widgets/output' ;
5
5
6
+ import {
7
+ DOMWidgetView , JupyterPhosphorWidget
8
+ } from '@jupyter-widgets/base' ;
9
+
6
10
import {
7
11
IDisposable
8
12
} from '@phosphor/disposable' ;
9
13
14
+ import {
15
+ Message
16
+ } from '@phosphor/messaging' ;
17
+
10
18
import {
11
19
Panel , Widget
12
20
} from '@phosphor/widgets' ;
@@ -100,13 +108,51 @@ class OutputModel extends outputBase.OutputModel {
100
108
private _outputs : OutputAreaModel ;
101
109
}
102
110
111
+ export
112
+ class JupyterPhosphorPanelWidget extends Panel {
113
+ constructor ( options : JupyterPhosphorWidget . IOptions & Panel . IOptions ) {
114
+ let view = options . view ;
115
+ delete options . view ;
116
+ super ( options ) ;
117
+ this . _view = view ;
118
+ }
119
+
120
+ /**
121
+ * Process the phosphor message.
122
+ *
123
+ * Any custom phosphor widget used inside a Jupyter widget should override
124
+ * the processMessage function like this.
125
+ */
126
+ processMessage ( msg : Message ) {
127
+ super . processMessage ( msg ) ;
128
+ this . _view . processPhosphorMessage ( msg ) ;
129
+ }
130
+
131
+ /**
132
+ * Dispose the widget.
133
+ *
134
+ * This causes the view to be destroyed as well with 'remove'
135
+ */
136
+ dispose ( ) {
137
+ if ( this . isDisposed ) {
138
+ return ;
139
+ }
140
+ super . dispose ( ) ;
141
+ if ( this . _view ) {
142
+ this . _view . remove ( ) ;
143
+ }
144
+ this . _view = null ;
145
+ }
146
+
147
+ private _view : DOMWidgetView ;
148
+ }
103
149
104
150
export
105
151
class OutputView extends outputBase . OutputView {
106
152
107
153
_createElement ( tagName : string ) {
108
- this . pWidget = new Panel ( ) ;
109
- return this . pWidget . node ;
154
+ this . pWidget = new JupyterPhosphorPanelWidget ( { view : this } ) ;
155
+ return this . pWidget . node ;
110
156
}
111
157
112
158
_setElement ( el : HTMLElement ) {
@@ -123,6 +169,7 @@ class OutputView extends outputBase.OutputView {
123
169
* Called when view is rendered.
124
170
*/
125
171
render ( ) {
172
+ super . render ( ) ;
126
173
this . _outputView = new OutputArea ( {
127
174
rendermime : this . model . widget_manager . rendermime ,
128
175
contentFactory : OutputArea . defaultContentFactory ,
@@ -139,16 +186,6 @@ class OutputView extends outputBase.OutputView {
139
186
this . update ( ) ; // Set defaults.
140
187
}
141
188
142
- /**
143
- * Update the contents of this view
144
- *
145
- * Called when the model is changed. The model may have been
146
- * changed by another view or by a state update from the back-end.
147
- */
148
- update ( ) {
149
- return super . update ( ) ;
150
- }
151
-
152
189
remove ( ) {
153
190
this . _outputView . dispose ( ) ;
154
191
return super . remove ( ) ;
0 commit comments