Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow setting the cursor #84

Merged
merged 2 commits into from
Nov 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion js/lib/widget.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ export class RemoteFrameBufferModel extends DOMWidgetModel {
css_width: '500px',
css_height: '300px',
resizable: true,
has_visible_views: false
has_visible_views: false,
cursor: 'default'
};
}
initialize() {
Expand Down Expand Up @@ -204,6 +205,10 @@ export class RemoteFrameBufferView extends DOMWidgetView {
this.el.appendChild(this.img);
this.model.collect_view_img_elements();

// Cursor
this.el.style.cursor = this.model.get('cursor');
this.model.on('change:cursor', function () { this.el.style.cursor = this.model.get('cursor'); }, this);

// Set of throttler functions to send events at a friendly pace
this._throttlers = {};

Expand Down
3 changes: 3 additions & 0 deletions jupyter_rfb/widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ class RemoteFrameBuffer(ipywidgets.DOMWidget):
* *max_buffered_frames*: the number of frames that is allowed to be "in-flight",
i.e. sent, but not yet confirmed by the client. Default 2. Higher values
may result in a higher FPS at the cost of introducing lag.
* *cursor*: the cursor style, ex: "crosshair", "grab". Valid cursors:
https://developer.mozilla.org/en-US/docs/Web/CSS/cursor#keyword

"""

Expand Down Expand Up @@ -75,6 +77,7 @@ class RemoteFrameBuffer(ipywidgets.DOMWidget):
css_width = Unicode("500px").tag(sync=True)
css_height = Unicode("300px").tag(sync=True)
resizable = Bool(True).tag(sync=True)
cursor = Unicode("default").tag(sync=True)

def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
Expand Down
3 changes: 2 additions & 1 deletion tests/test_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from pytest import raises
from jupyter_rfb import RemoteFrameBuffer
from jupyter_rfb._utils import Snapshot
from traitlets import TraitError


class MyRFB(RemoteFrameBuffer):
Expand Down Expand Up @@ -211,7 +212,7 @@ def test_widget_traits():
assert w.max_buffered_frames == 2
w.max_buffered_frames = 99
w.max_buffered_frames = 1
with raises(Exception): # TraitError -> min 1
with raises(TraitError): # TraitError -> min 1
w.max_buffered_frames = 0

assert w.css_width.endswith("px")
Expand Down