Skip to content

Commit

Permalink
preventEventPropagation
Browse files Browse the repository at this point in the history
  • Loading branch information
superstar54 committed Mar 1, 2024
1 parent dd5159c commit 2ff2980
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 4 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,11 @@ Press the transform shortcut, and move your mouse.
|----------|---------|
| Move | `g` |
| Rotate | `r` |
| Duplicate| `d` |


### Delete selected atoms
Press the ``x`` key to delete the selected atoms
Press the ``Delete`` key to delete the selected atoms


### Export edited atoms
Expand Down
8 changes: 5 additions & 3 deletions docs/source/edit.rst
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@


=======================
Edit the structure
Editing the structure
=======================

WEAS supports editing the atoms directly in the GUI and synchronizing with the structure of the Python object.
Expand All @@ -21,7 +21,7 @@ There are two methods for selecting atoms:



Move, Rotate selected atoms
Move, Rotate and Duplicate selected atoms
===========================

Press the transform shortcut, and move your mouse.
Expand All @@ -33,8 +33,10 @@ Press the transform shortcut, and move your mouse.
+-----------+----------+
| Rotate | ``r`` |
+-----------+----------+
| Duplicate | ``d`` |
+-----------+----------+


Delete selected atoms
=====================
Press the ``x`` key to delete the selected atoms
Press the ``Delete`` key to delete the selected atoms
16 changes: 16 additions & 0 deletions js/widget.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,16 @@ import "./widget.css";
function render({ model, el }) {
let avr; // Declare avr here
let viewerElement = document.createElement("div");
// Stop propagation of mouse and keyboard events from the viewer to jupyter notebook
// to avoid conflicts with the notebook's keyboard shortcuts
preventEventPropagation(viewerElement);
viewerElement.style.cssText = "position: relative; width: 600px; height: 400px;";
const viewerStyle = model.get("viewerStyle");
// set the style ortherwise use the default value
if (viewerStyle) {
viewerElement.style.width = viewerStyle.width;
viewerElement.style.height = viewerStyle.height;
}
el.appendChild(viewerElement);
// Function to render atoms
const renderAtoms = () => {
Expand Down Expand Up @@ -156,4 +165,11 @@ function createVolumeData(data, cell=[[1, 0, 0], [0, 1, 0], [0, 0, 1]]) {
return {dims, values, cell: cell, origin: [0, 0, 0]};
}

function preventEventPropagation(element) {
const stopPropagation = (e) => e.stopPropagation();
["click", "keydown", "keyup", "keypress"].forEach((eventType) => {
element.addEventListener(eventType, stopPropagation, false);
});
}

export default { render }
2 changes: 2 additions & 0 deletions src/weas_widget/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ class WeasWidget(anywidget.AnyWidget):
vectorField = tl.List().tag(sync=True)
showVectorField = tl.Bool(True).tag(sync=True)
guiConfig = tl.Dict({}).tag(sync=True)
# viewer
viewerStyle = tl.Dict({}).tag(sync=True)
# task
js_task = tl.Dict({}).tag(sync=True)
debug = tl.Bool(False).tag(sync=True)
Expand Down

0 comments on commit 2ff2980

Please sign in to comment.