wigglystuff 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- wigglystuff-0.1.0/LICENSE +21 -0
- wigglystuff-0.1.0/PKG-INFO +73 -0
- wigglystuff-0.1.0/setup.cfg +4 -0
- wigglystuff-0.1.0/setup.py +36 -0
- wigglystuff-0.1.0/wigglystuff/__init__.py +15 -0
- wigglystuff-0.1.0/wigglystuff/static/2dslider.js +71 -0
- wigglystuff-0.1.0/wigglystuff.egg-info/PKG-INFO +73 -0
- wigglystuff-0.1.0/wigglystuff.egg-info/SOURCES.txt +9 -0
- wigglystuff-0.1.0/wigglystuff.egg-info/dependency_links.txt +1 -0
- wigglystuff-0.1.0/wigglystuff.egg-info/requires.txt +3 -0
- wigglystuff-0.1.0/wigglystuff.egg-info/top_level.txt +1 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2022 Vincent D. Warmerdam
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: wigglystuff
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Collection of Jupyter Widgets
|
|
5
|
+
Author: Vincent D. Warmerdam
|
|
6
|
+
Classifier: Intended Audience :: Developers
|
|
7
|
+
Classifier: Intended Audience :: Science/Research
|
|
8
|
+
Classifier: Programming Language :: Python :: 3
|
|
9
|
+
Classifier: Programming Language :: Python :: 3.8
|
|
10
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
11
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
12
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
14
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
15
|
+
Classifier: Topic :: Scientific/Engineering
|
|
16
|
+
Description-Content-Type: text/markdown
|
|
17
|
+
License-File: LICENSE
|
|
18
|
+
|
|
19
|
+
# wigglystuff
|
|
20
|
+
|
|
21
|
+
<img src="imgs/stuff.png" width=125 height=125 align="right" style="z-index: 9999;">
|
|
22
|
+
|
|
23
|
+
> "A collection of expressive Jupyter widgets."
|
|
24
|
+
|
|
25
|
+
The project uses [anywidget](https://anywidget.dev/) under the hood so our tools should work in Jupyter, VSCode and Colab. That also means that you get a proper widget that can interact with [ipywidgets](https://ipywidgets.readthedocs.io/en/stable/) natively.
|
|
26
|
+
|
|
27
|
+
## Installation
|
|
28
|
+
|
|
29
|
+
Installation occurs via pip.
|
|
30
|
+
|
|
31
|
+
```
|
|
32
|
+
python -m pip install wigglystuff
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
## Usage
|
|
36
|
+
|
|
37
|
+
### `Slider2D`
|
|
38
|
+
|
|
39
|
+
```python
|
|
40
|
+
from wigglystuff import Slider2D
|
|
41
|
+
|
|
42
|
+
widget = Slider2D()
|
|
43
|
+
widget
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+

|
|
47
|
+
|
|
48
|
+
This widget allows you to grab the `widget.x` and `widget.y` properties to get the current position of the slider. But you can also use the `widget.observe` method to listen to changes in the widget.
|
|
49
|
+
|
|
50
|
+
<details>
|
|
51
|
+
<summary><b>Example of <code>widget.observe</code></b></summary>
|
|
52
|
+
|
|
53
|
+
```python
|
|
54
|
+
import ipywidgets
|
|
55
|
+
from wigglystuff import Slider2D
|
|
56
|
+
|
|
57
|
+
widget = Slider2D()
|
|
58
|
+
output = ipywidgets.Output()
|
|
59
|
+
state = [[0.0, 0.0]]
|
|
60
|
+
|
|
61
|
+
@output.capture(clear_output=True)
|
|
62
|
+
def on_change(change):
|
|
63
|
+
if abs(widget.x - state[-1][0]) > 0.01:
|
|
64
|
+
if abs(widget.y - state[-1][1]) > 0.01:
|
|
65
|
+
state.append([widget.x, widget.y])
|
|
66
|
+
for elem in state[-5:]:
|
|
67
|
+
print(elem)
|
|
68
|
+
|
|
69
|
+
widget.observe(on_change)
|
|
70
|
+
on_change(None)
|
|
71
|
+
ipywidgets.HBox([widget, output])
|
|
72
|
+
```
|
|
73
|
+
</details>
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import os
|
|
2
|
+
from setuptools import setup, find_packages
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
base_packages = [
|
|
6
|
+
"jupyterlab>=4.0.0", "anywidget>=0.9.2", "ipython>=7.16.1"
|
|
7
|
+
]
|
|
8
|
+
|
|
9
|
+
def read(fname):
|
|
10
|
+
return open(os.path.join(os.path.dirname(__file__), fname)).read()
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
setup(
|
|
14
|
+
name="wigglystuff",
|
|
15
|
+
version="0.1.0",
|
|
16
|
+
description="Collection of Jupyter Widgets",
|
|
17
|
+
author="Vincent D. Warmerdam",
|
|
18
|
+
packages=find_packages(exclude=["notebooks"]),
|
|
19
|
+
package_data={"wigglystuff": ["static/*.js", "static/*.css"]},
|
|
20
|
+
long_description=read("readme.md"),
|
|
21
|
+
long_description_content_type="text/markdown",
|
|
22
|
+
install_requires=base_packages,
|
|
23
|
+
classifiers=[
|
|
24
|
+
"Intended Audience :: Developers",
|
|
25
|
+
"Intended Audience :: Science/Research",
|
|
26
|
+
"Programming Language :: Python :: 3",
|
|
27
|
+
"Programming Language :: Python :: 3.8",
|
|
28
|
+
"Programming Language :: Python :: 3.9",
|
|
29
|
+
"Programming Language :: Python :: 3.10",
|
|
30
|
+
"Programming Language :: Python :: 3.11",
|
|
31
|
+
"Programming Language :: Python :: 3.12",
|
|
32
|
+
"License :: OSI Approved :: MIT License",
|
|
33
|
+
"Topic :: Scientific/Engineering",
|
|
34
|
+
],
|
|
35
|
+
license_files=["LICENSE"],
|
|
36
|
+
)
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
from pathlib import Path
|
|
2
|
+
import anywidget
|
|
3
|
+
import traitlets
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
class Slider2D(anywidget.AnyWidget):
|
|
7
|
+
"""
|
|
8
|
+
A scatter drawing widget that automatically can update a pandas/polars dataframe
|
|
9
|
+
as your draw data.
|
|
10
|
+
"""
|
|
11
|
+
_esm = Path(__file__).parent / 'static' / '2dslider.js'
|
|
12
|
+
x = traitlets.Float(0.0).tag(sync=True)
|
|
13
|
+
y = traitlets.Float(0.0).tag(sync=True)
|
|
14
|
+
width = traitlets.Int(400).tag(sync=True)
|
|
15
|
+
height = traitlets.Int(400).tag(sync=True)
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
function render({ model, el }) {
|
|
2
|
+
const canvas = document.createElement("canvas");
|
|
3
|
+
canvas.setAttribute("id", "sliderCanvas");
|
|
4
|
+
canvas.setAttribute("width", model.get("width").toString());
|
|
5
|
+
canvas.setAttribute("height", model.get("height").toString());
|
|
6
|
+
canvas.setAttribute("style", "border: 1px solid #ccc; background: #eee;");
|
|
7
|
+
|
|
8
|
+
const sliderValuesDiv = document.createElement("div");
|
|
9
|
+
sliderValuesDiv.setAttribute("id", "sliderValues");
|
|
10
|
+
|
|
11
|
+
el.appendChild(canvas);
|
|
12
|
+
el.appendChild(sliderValuesDiv);
|
|
13
|
+
|
|
14
|
+
const ctx = canvas.getContext('2d');
|
|
15
|
+
|
|
16
|
+
const centerX = canvas.width / 2;
|
|
17
|
+
const centerY = canvas.height / 2;
|
|
18
|
+
const radius = Math.min(centerX, centerY) - 20;
|
|
19
|
+
|
|
20
|
+
let isDragging = false;
|
|
21
|
+
let currentX = 0;
|
|
22
|
+
let currentY = 0;
|
|
23
|
+
|
|
24
|
+
function drawSlider() {
|
|
25
|
+
ctx.clearRect(0, 0, canvas.width, canvas.height);
|
|
26
|
+
|
|
27
|
+
ctx.beginPath();
|
|
28
|
+
ctx.arc(centerX + currentX, centerY + currentY, 10, 0, 2 * Math.PI);
|
|
29
|
+
ctx.fillStyle = '#eee';
|
|
30
|
+
ctx.strokeStyle = "#666";
|
|
31
|
+
ctx.lineWidth = 2;
|
|
32
|
+
ctx.fill();
|
|
33
|
+
ctx.stroke();
|
|
34
|
+
|
|
35
|
+
const normalizedX = currentX / radius;
|
|
36
|
+
const normalizedY = currentY / radius;
|
|
37
|
+
sliderValuesDiv.textContent = `X: ${normalizedX.toFixed(2)}, Y: ${normalizedY.toFixed(2)}`;
|
|
38
|
+
model.set('x', normalizedX);
|
|
39
|
+
model.set('y', normalizedY);
|
|
40
|
+
model.save_changes();
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function handleMouseDown(event) {
|
|
44
|
+
isDragging = true;
|
|
45
|
+
currentX = event.offsetX - centerX;
|
|
46
|
+
currentY = event.offsetY - centerY;
|
|
47
|
+
drawSlider();
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
function handleMouseMove(event) {
|
|
51
|
+
if (isDragging) {
|
|
52
|
+
currentX = event.offsetX - centerX;
|
|
53
|
+
currentY = event.offsetY - centerY;
|
|
54
|
+
currentX = Math.max(-radius, Math.min(radius, currentX));
|
|
55
|
+
currentY = Math.max(-radius, Math.min(radius, currentY));
|
|
56
|
+
drawSlider();
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
function handleMouseUp() {
|
|
61
|
+
isDragging = false;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
canvas.addEventListener('mousedown', handleMouseDown);
|
|
65
|
+
canvas.addEventListener('mousemove', handleMouseMove);
|
|
66
|
+
canvas.addEventListener('mouseup', handleMouseUp);
|
|
67
|
+
|
|
68
|
+
drawSlider();
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export default { render };
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: wigglystuff
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Collection of Jupyter Widgets
|
|
5
|
+
Author: Vincent D. Warmerdam
|
|
6
|
+
Classifier: Intended Audience :: Developers
|
|
7
|
+
Classifier: Intended Audience :: Science/Research
|
|
8
|
+
Classifier: Programming Language :: Python :: 3
|
|
9
|
+
Classifier: Programming Language :: Python :: 3.8
|
|
10
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
11
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
12
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
14
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
15
|
+
Classifier: Topic :: Scientific/Engineering
|
|
16
|
+
Description-Content-Type: text/markdown
|
|
17
|
+
License-File: LICENSE
|
|
18
|
+
|
|
19
|
+
# wigglystuff
|
|
20
|
+
|
|
21
|
+
<img src="imgs/stuff.png" width=125 height=125 align="right" style="z-index: 9999;">
|
|
22
|
+
|
|
23
|
+
> "A collection of expressive Jupyter widgets."
|
|
24
|
+
|
|
25
|
+
The project uses [anywidget](https://anywidget.dev/) under the hood so our tools should work in Jupyter, VSCode and Colab. That also means that you get a proper widget that can interact with [ipywidgets](https://ipywidgets.readthedocs.io/en/stable/) natively.
|
|
26
|
+
|
|
27
|
+
## Installation
|
|
28
|
+
|
|
29
|
+
Installation occurs via pip.
|
|
30
|
+
|
|
31
|
+
```
|
|
32
|
+
python -m pip install wigglystuff
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
## Usage
|
|
36
|
+
|
|
37
|
+
### `Slider2D`
|
|
38
|
+
|
|
39
|
+
```python
|
|
40
|
+
from wigglystuff import Slider2D
|
|
41
|
+
|
|
42
|
+
widget = Slider2D()
|
|
43
|
+
widget
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+

|
|
47
|
+
|
|
48
|
+
This widget allows you to grab the `widget.x` and `widget.y` properties to get the current position of the slider. But you can also use the `widget.observe` method to listen to changes in the widget.
|
|
49
|
+
|
|
50
|
+
<details>
|
|
51
|
+
<summary><b>Example of <code>widget.observe</code></b></summary>
|
|
52
|
+
|
|
53
|
+
```python
|
|
54
|
+
import ipywidgets
|
|
55
|
+
from wigglystuff import Slider2D
|
|
56
|
+
|
|
57
|
+
widget = Slider2D()
|
|
58
|
+
output = ipywidgets.Output()
|
|
59
|
+
state = [[0.0, 0.0]]
|
|
60
|
+
|
|
61
|
+
@output.capture(clear_output=True)
|
|
62
|
+
def on_change(change):
|
|
63
|
+
if abs(widget.x - state[-1][0]) > 0.01:
|
|
64
|
+
if abs(widget.y - state[-1][1]) > 0.01:
|
|
65
|
+
state.append([widget.x, widget.y])
|
|
66
|
+
for elem in state[-5:]:
|
|
67
|
+
print(elem)
|
|
68
|
+
|
|
69
|
+
widget.observe(on_change)
|
|
70
|
+
on_change(None)
|
|
71
|
+
ipywidgets.HBox([widget, output])
|
|
72
|
+
```
|
|
73
|
+
</details>
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
wigglystuff
|