-
Notifications
You must be signed in to change notification settings - Fork 134
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
12,861 additions
and
10,391 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
{ | ||
"name": "nglview-js-widgets", | ||
"version": "2.6.2", | ||
"version": "2.6.5", | ||
"description": "nglview-js-widgets", | ||
"author": "Hai Nguyen <[email protected]>, Alexander Rose <[email protected]>", | ||
"license": "MIT", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
var widgets = require("@jupyter-widgets/base") | ||
var NGL = require("ngl") | ||
|
||
|
||
var BaseView = widgets.DOMWidgetView.extend({ | ||
|
||
render: function(){ | ||
this.handleMessage(); | ||
this.displayed.then(() =>{ | ||
this.model.set("_ready", true) | ||
this.touch() | ||
}) | ||
}, | ||
|
||
executeCode: function(code){ | ||
eval(code); | ||
}, | ||
|
||
handleMessage: function(){ | ||
this.model.on("msg:custom", function(msg){ | ||
this.on_msg(msg) | ||
}.bind(this)) | ||
}, | ||
|
||
on_msg: function(msg){ | ||
if (msg.type == 'callMethod'){ | ||
this[msg.methodName].apply(this, msg.args, msg.kwargs) | ||
} | ||
} | ||
}) | ||
|
||
module.exports = { | ||
"BaseView": BaseView | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
var _ = require('underscore') | ||
var NGL = require("ngl") | ||
var BaseView = require("./base").BaseView | ||
var widgets = require("@jupyter-widgets/base") | ||
|
||
|
||
var ColormakerRegistryModel = widgets.DOMWidgetModel.extend({ | ||
defaults: function(){ | ||
return _.extend(widgets.DOMWidgetModel.prototype.defaults(), { | ||
_model_name: 'ColormakerRegistryModel', | ||
_model_module: 'nglview-js-widgets', | ||
_model_module_version: require("../package.json").version, | ||
_view_name: "ColormakerRegistryView", | ||
_view_module: "nglview-js-widgets", | ||
_view_module_version: require("../package.json").version, | ||
}); | ||
} | ||
}) | ||
|
||
|
||
var ColormakerRegistryView = BaseView.extend({ | ||
addSelectionScheme: function(label, args){ | ||
var id = NGL.ColormakerRegistry.addSelectionScheme(args, label) | ||
this._updateId(id, label) | ||
}, | ||
|
||
addSelectionSchemeOriginal: function(label, args){ | ||
var id = NGL.ColormakerRegistry.addSelectionScheme(args, label); | ||
var scheme = NGL.ColormakerRegistry.userSchemes[id]; | ||
NGL.ColormakerRegistry.removeScheme(id); | ||
// hard code the scheme ID | ||
NGL.ColormakerRegistry.add(label, scheme); | ||
}, | ||
|
||
addScheme: function(label, func_str){ | ||
var func = Function("return " + func_str)() | ||
console.log(func) | ||
var id = NGL.ColormakerRegistry.addScheme(function(params){ | ||
this.atomColor = func | ||
}) | ||
this._updateId(id, label) | ||
}, | ||
|
||
_updateId: function(oldId, newId){ | ||
var scheme = NGL.ColormakerRegistry.userSchemes[oldId] | ||
console.log(oldId, scheme) | ||
NGL.ColormakerRegistry.add(newId, scheme) | ||
NGL.ColormakerRegistry.removeScheme(oldId) | ||
}, | ||
|
||
removeScheme: function(schemeId){ | ||
NGL.ColormakerRegistry.removeScheme(schemeId) | ||
}, | ||
}) | ||
|
||
|
||
module.exports = { | ||
ColormakerRegistryView: ColormakerRegistryView, | ||
ColormakerRegistryModel: ColormakerRegistryModel | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
__frontend_version__ = '2.6.2' | ||
__frontend_version__ = '2.6.5' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
from ipywidgets import DOMWidget | ||
from traitlets import Bool, List | ||
|
||
|
||
class BaseWidget(DOMWidget): | ||
_msg_q = [] | ||
_msg_ar = List().tag(sync=True) | ||
_ready = Bool(False).tag(sync=True) | ||
|
||
def _js(self, code): | ||
self._call("executeCode", code) | ||
|
||
def _call(self, method_name, *args, **kwargs): | ||
msg = {"type": "callMethod", | ||
"methodName": method_name, | ||
"args": args, "kwargs": kwargs} | ||
if not self._ready: | ||
# fire later | ||
self._msg_q.append(msg) | ||
else: | ||
self.send(msg) | ||
msg_ar = self._msg_ar[:] | ||
msg_ar.append(msg) | ||
self._msg_ar = msg_ar # trigger sync |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.