Skip to content

Instantly share code, notes, and snippets.

@epifanio
Created February 13, 2014 19:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save epifanio/8981624 to your computer and use it in GitHub Desktop.
Save epifanio/8981624 to your computer and use it in GitHub Desktop.
View creation failed
Backbone.Model.extend.constructor {widget_manager: WidgetManager, _buffered_state_diff: Object, pending_msgs: 0, msg_throttle: 3, msg_buffer: null…}
widgetmanager.js:83
Exception in Comm callback
TypeError {stack: "TypeError: Cannot read property '$el' of null↵ …min.js?v=ccd0edd113b78697e04fb5c1b519a5cd:4:5488)", message: "Cannot read property '$el' of null"}
TypeError: Cannot read property '$el' of null
at WidgetManager._handle_display_view (http://127.0.0.1:8888/static/notebook/js/widgetmanager.js:97:58)
at WidgetManager.display_view (http://127.0.0.1:8888/static/notebook/js/widgetmanager.js:87:26)
at Backbone.Model.extend._handle_comm_msg (http://127.0.0.1:8888/static/notebook/js/widgets/widget.js:86:41)
at x.isFunction.i (http://127.0.0.1:8888/static/components/jquery/jquery.min.js?v=ccd0edd113b78697e04fb5c1b519a5cd:4:5488)
at Comm._maybe_callback (http://127.0.0.1:8888/static/services/kernels/js/comm.js?v=f6acfac4110c05a2d4985876fb49765a:177:17)
at Comm.handle_msg (http://127.0.0.1:8888/static/services/kernels/js/comm.js?v=f6acfac4110c05a2d4985876fb49765a:185:14)
at CommManager.comm_msg (http://127.0.0.1:8888/static/services/kernels/js/comm.js?v=f6acfac4110c05a2d4985876fb49765a:116:18)
at x.isFunction.i (http://127.0.0.1:8888/static/components/jquery/jquery.min.js?v=ccd0edd113b78697e04fb5c1b519a5cd:4:5488)
at Kernel._handle_iopub_message (http://127.0.0.1:8888/static/services/kernels/js/kernel.js?v=f6186ba2f4410fa59763d501b96e03c4:580:13)
at WebSocket.x.isFunction.i (http://127.0.0.1:8888/static/components/jquery/jquery.min.js?v=ccd0edd113b78697e04fb5c1b519a5cd:4:5488)
Object {parent_header: Object, msg_type: "comm_msg", msg_id: "9eef36bd-f2a5-4c63-9930-6bc4182c2a3c", content: Object, header: Object…}
comm.js?v=f6acfac4110c05a2d4985876fb49765a:179
//----------------------------------------------------------------------------
// Copyright (C) 2013 The IPython Development Team
//
// Distributed under the terms of the BSD License. The full license is in
// the file COPYING, distributed as part of this software.
//----------------------------------------------------------------------------
//============================================================================
// ButtonWidget
//============================================================================
/**
* @module IPython
* @namespace IPython
**/
define(["notebook/js/widgets/widget"], function(WidgetManager){
var MappView = IPython.DOMWidgetView.extend({
render : function(){
// Called when view is rendered.
this.setElement($("<button />")
.addClass('btn'));
this.update(); // Set defaults.
},
update : function(){
// Update the contents of this view
//
// Called when the model is changed. The model may have been
// changed by another view or by a state update from the back-end.
var description = this.model.get('description');
if (description.length === 0) {
this.$el.text(' '); // Preserve button height
} else {
this.$el.text(description);
}
if (this.model.get('disabled')) {
this.$el.attr('disabled','disabled');
} else {
this.$el.removeAttr('disabled');
}
return MappView.__super__.update.apply(this);
},
events: {
// Dictionary of events and their handlers.
'click': '_handle_click',
},
_handle_click: function(){
// Handles when the button is clicked.
this.send({event: 'click'});
},
});
WidgetManager.register_widget_view('MappView', MappView);
});
"""MappWidget class.
Represents a button in the frontend using a widget. Allows user to listen for
click events on the button and trigger backend code when the clicks are fired.
"""
#-----------------------------------------------------------------------------
# Copyright (c) 2013, the IPython Development Team.
#
# Distributed under the terms of the Modified BSD License.
#
# The full license is in the file COPYING.txt, distributed with this software.
#-----------------------------------------------------------------------------
#-----------------------------------------------------------------------------
# Imports
#-----------------------------------------------------------------------------
from .widget import DOMWidget, CallbackDispatcher
from IPython.utils.traitlets import Unicode, Bool
#-----------------------------------------------------------------------------
# Classes
#-----------------------------------------------------------------------------
class MappWidget(DOMWidget):
_view_name = Unicode('MappView', sync=True)
# Keys
description = Unicode('', help="Description of the button (label).", sync=True)
disabled = Bool(False, help="Enable or disable user changes.", sync=True)
def __init__(self, **kwargs):
"""Constructor"""
super(MappWidget, self).__init__(**kwargs)
self._click_handlers = CallbackDispatcher()
self.on_msg(self._handle_button_msg)
def on_click(self, callback, remove=False):
"""Register a callback to execute when the button is clicked.
The callback will be called with one argument,
the clicked button widget instance.
Parameters
----------
remove : bool (optional)
Set to true to remove the callback from the list of callbacks."""
self._click_handlers.register_callback(callback, remove=remove)
def _handle_button_msg(self, _, content):
"""Handle a msg from the front-end.
Parameters
----------
content: dict
Content of the msg."""
if content.get('event', '') == 'click':
self._click_handlers(self)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment