Skip to content

Commit 7050568

Browse files
committed
Little tweaks
1 parent 3952594 commit 7050568

2 files changed

Lines changed: 20 additions & 8 deletions

File tree

ActiveHTMLWidget/widget.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ class HTMLElement(DOMWidget):
2020
tagName = Unicode('div').tag(sync=True)
2121
classList = List().tag(sync=True)
2222
styleDict = Dict().tag(sync=True)
23+
unsyncedProps = List().tag(sync=True)
2324
elementAttributes = Dict().tag(sync=True, **widget_serialization)
2425
innerHTML = Unicode('').tag(sync=True)
2526
textContent = Unicode('').tag(sync=True)
@@ -75,15 +76,15 @@ def __repr__(self):
7576

7677
_here = __file__
7778
@classmethod
78-
def jupyterlab_install(self, overwrite=False):
79+
def jupyterlab_install(self, exec_prefix=None, overwrite=False):
7980
"""
8081
Attempts to do a basic installation for JupterLab
8182
:return:
8283
:rtype:
8384
"""
8485
import sys, shutil, os, tempfile as tf
8586

86-
prefix = sys.exec_prefix
87+
prefix = sys.exec_prefix if exec_prefix is None else exec_prefix
8788
pkg_root = os.path.dirname(os.path.abspath(self._here))
8889
pkg_name = os.path.basename(pkg_root)
8990
src = os.path.join(pkg_root, 'labextension')
@@ -110,15 +111,15 @@ def jupyterlab_install(self, overwrite=False):
110111
if copied:
111112
return HTML("<h4>Extension installed to {}. You will need to reload the page to get the widgets to display.</h1>".format(target))
112113
@classmethod
113-
def jupyternb_install(self, overwrite=False):
114+
def jupyternb_install(self, exec_prefix=None, overwrite=False):
114115
"""
115116
Attempts to do a basic installation for JupterLab
116117
:return:
117118
:rtype:
118119
"""
119120
import sys, shutil, os, tempfile as tf
120121

121-
prefix = sys.exec_prefix
122+
prefix = sys.exec_prefix if exec_prefix is None else exec_prefix
122123
pkg_root = os.path.dirname(os.path.abspath(self._here))
123124
pkg_name = os.path.basename(pkg_root)
124125
src = os.path.join(pkg_root, 'nbextension')

src/widget.ts

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,13 @@ class LayoutManagerWidget extends Widget {
5656
}
5757
processMessage(msg: Message) {
5858
super.processMessage(msg);
59-
this._view.processPhosphorMessage(msg);
59+
try {
60+
//@ts-ignore
61+
this._view.processPhosphorMessage(msg);
62+
} catch {
63+
//@ts-ignore
64+
this._view.processLuminoMessage(msg);
65+
}
6066
}
6167
get widgets(): ReadonlyArray<Widget> {
6268
return (this.layout as PanelLayout).widgets;
@@ -111,6 +117,7 @@ export class ActiveHTMLModel extends DOMWidgetModel {
111117
_bodyType: "",
112118
_debugPrint:false,
113119
styleDict: {},
120+
unsyncedProperties: [],
114121
elementAttributes: {},
115122
id: "",
116123
value: "",
@@ -351,6 +358,7 @@ export class ActiveHTMLView extends DOMWidgetView {
351358
setStyle(style: WidgetModel, oldStyle?: WidgetModel) {} // null override
352359
setStyles(): Promise<any> {
353360
let elementStyles = this.model.get("styleDict") as Record<string, string>;
361+
let unsyncedProperties = this.model.get("unsyncedProperties");
354362
let keys = Object.keys(elementStyles);
355363
if (keys.length === 0) {
356364
this._currentStyles.clear();
@@ -363,7 +371,7 @@ export class ActiveHTMLView extends DOMWidgetView {
363371
return ActiveHTMLView._each(
364372
keys,
365373
(prop:string) => {
366-
if (elementStyles.hasOwnProperty(prop)) {
374+
if (elementStyles.hasOwnProperty(prop) && !unsyncedProperties.includes(prop)) {
367375
// console.log(">>>", prop, elementStyles[prop], typeof prop);
368376
this.el.style.setProperty(prop, elementStyles[prop]);
369377
// console.log("<<<", prop, this.el.style.getPropertyValue(prop));
@@ -375,7 +383,7 @@ export class ActiveHTMLView extends DOMWidgetView {
375383
}
376384
updateStyles(): Promise<any> {
377385
return this.setStyles().then(
378-
()=>this.removeStyles
386+
()=>this.removeStyles()
379387
)
380388
}
381389

@@ -642,9 +650,12 @@ export class ActiveHTMLView extends DOMWidgetView {
642650
}
643651
updateAttributes():Promise<any> {
644652
let attrs = this.model.get('elementAttributes') as Record<string, any>;
653+
let unsyncedProperties = this.model.get('unsyncedProperties');
645654
let debug = this.model.get("_debugPrint");
646655
if (debug) { console.log(this.el, "Element Properties:", attrs); }
647-
return ActiveHTMLView._each(Object.keys(attrs), (prop:string)=>this._updateAttribute(prop, attrs))
656+
return ActiveHTMLView._each(Object.keys(attrs),
657+
(prop:string)=>(!unsyncedProperties.includes(prop) && this._updateAttribute(prop, attrs))
658+
)
648659
}
649660
notifyAttrUpdate(prop:string):Promise<any> {
650661
let key = "view-change:"+prop;

0 commit comments

Comments
 (0)