Skip to content

Commit

Permalink
Fix versioning (#106)
Browse files Browse the repository at this point in the history
  • Loading branch information
almarklein authored Jan 15, 2025
1 parent d45ae67 commit d3e8b0d
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 41 deletions.
6 changes: 1 addition & 5 deletions js/lib/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
// Export widget models and views, and the npm package version number.

export { RemoteFrameBufferModel, RemoteFrameBufferView } from './widget';

// export {version} from '../package.json'; -> yarn gives warning:

export const version = '0.4.4'; // updated by release.py
export { RemoteFrameBufferModel, RemoteFrameBufferView, version } from './widget';
67 changes: 34 additions & 33 deletions js/lib/widget.js
Original file line number Diff line number Diff line change
@@ -1,34 +1,35 @@
import { DOMWidgetModel, DOMWidgetView } from '@jupyter-widgets/base';

/*
* For the kernel counterpart to this file, see widget.py
* For the base class, see https://github.com/jupyter-widgets/ipywidgets/blob/master/packages/base/src/widget.ts
*
* The server sends frames to the client, and the client sends back
* a confirmation when it has processed the frame.
*
* The client queues the frames it receives and processes them one-by-one
* at the browser's pace, using requestAnimationFrame. We send back a
* confirmation when the frame is processed (not when it is technically received).
* It is the responsibility of the server to not send too many frames beyond the
* last confirmed one.
*
* When setting the img.src attribute, the browser still needs to actually render
* the image. We wait for this before requesting a new animation. If we don't do
* this on FF, the animation is not smooth because the image "gets stuck".
*/

* For the kernel counterpart to this file, see widget.py
* For the base class, see https://github.com/jupyter-widgets/ipywidgets/blob/master/packages/base/src/widget.ts
*
* The server sends frames to the client, and the client sends back
* a confirmation when it has processed the frame.
*
* The client queues the frames it receives and processes them one-by-one
* at the browser's pace, using requestAnimationFrame. We send back a
* confirmation when the frame is processed (not when it is technically received).
* It is the responsibility of the server to not send too many frames beyond the
* last confirmed one.
*
* When setting the img.src attribute, the browser still needs to actually render
* the image. We wait for this before requesting a new animation. If we don't do
* this on FF, the animation is not smooth because the image "gets stuck".
*/

export const version = "0.4.4";

export class RemoteFrameBufferModel extends DOMWidgetModel {
defaults() {
return {
...super.defaults(),
...super.defaults(),
_model_name: 'RemoteFrameBufferModel',
_view_name: 'RemoteFrameBufferView',
_model_module: 'jupyter_rfb',
_view_module: 'jupyter_rfb',
_model_module_version: '0.1.0',
_view_module_version: '0.1.0',
_model_module_version: version,
_view_module_version: version,
// For the frames
frame_feedback: {},
// For the widget
Expand Down Expand Up @@ -64,7 +65,7 @@ export class RemoteFrameBufferModel extends DOMWidgetModel {
this._request_animation_frame();
}

async collect_view_img_elements () {
async collect_view_img_elements() {
// Here we collect img elements corresponding to the current views.
// We also set their onload methods which we use to schedule new draws.
// Plus we reset out visibility obserer.
Expand Down Expand Up @@ -98,7 +99,7 @@ export class RemoteFrameBufferModel extends DOMWidgetModel {
_intersection_callback(entries, observer) {
// This gets called when one of the views becomes visible/invisible.
// Note that entries only contains the *changed* elements.

// Set visibility of changed img elements.
for (let entry of entries) {
entry.target._is_visible = entry.isIntersecting;
Expand All @@ -109,7 +110,7 @@ export class RemoteFrameBufferModel extends DOMWidgetModel {
if (img._is_visible) { count += 1; }
}
// If the state changed, update our flag
let has_visible_views = count > 0;
let has_visible_views = count > 0;
if (has_visible_views != this.get("has_visible_views")) {
this.set('has_visible_views', has_visible_views);
this.save_changes();
Expand All @@ -124,7 +125,7 @@ export class RemoteFrameBufferModel extends DOMWidgetModel {
this.save_changes();
}

_request_animation_frame () {
_request_animation_frame() {
// Request an animation frame, but with a tiny delay, just to avoid
// straining the browser. This seems to actually make things more smooth.
if (!this._img_update_pending) {
Expand Down Expand Up @@ -216,8 +217,8 @@ export class RemoteFrameBufferView extends DOMWidgetView {
// Setting the this.el's size right now has no effect. We also set it in _check_size() below.
this.img.style.width = '100%';
this.img.style.height = '100%';
this.el.style.width = this.model.get('css_width');
this.el.style.height = this.model.get('css_height');
this.el.style.width = this.model.get('css_width');
this.el.style.height = this.model.get('css_height');
this.el.style.resize = this.model.get('resizable') ? 'both' : 'none';

// Keep track of size changes from the server
Expand Down Expand Up @@ -277,7 +278,7 @@ export class RemoteFrameBufferView extends DOMWidgetView {
// Also, only consume the wheel event when we have focus.
// On Firefox, e.buttons is always 0 for wheel events, so we use a cached value for the buttons.
this._wheel_state = { dx: 0, dy: 0, e: null, pending: false };
function send_wheel_event () {
function send_wheel_event() {
let e = that._wheel_state.e;
let rect = that.img.getBoundingClientRect();
let event = {
Expand All @@ -297,7 +298,7 @@ export class RemoteFrameBufferView extends DOMWidgetView {
}
this.img.addEventListener('wheel', function (e) {
if (window.document.activeElement !== that.focus_el) { return; }
let scales = [ 1 / window.devicePixelRatio, 16, 600 ]; // pixel, line, page
let scales = [1 / window.devicePixelRatio, 16, 600]; // pixel, line, page
let scale = scales[e.deltaMode];
that._wheel_state.dx += e.deltaX * scale;
that._wheel_state.dy += e.deltaY * scale;
Expand All @@ -310,7 +311,7 @@ export class RemoteFrameBufferView extends DOMWidgetView {
});

// Key events - approach inspired from ipyevents
function key_event_handler (e) {
function key_event_handler(e) {
// Failsafe in case the element is deleted or detached.
if (that.el.offsetParent === null) { return; }
let event = {
Expand Down Expand Up @@ -357,7 +358,7 @@ export class RemoteFrameBufferView extends DOMWidgetView {
}
}

send_throttled (msg, wait) {
send_throttled(msg, wait) {
// Like .send(), but throttled
let event_type = msg.event_type || '';
let func = this._throttlers[event_type];
Expand All @@ -378,13 +379,13 @@ var KEYMAP = {
};


function get_modifiers (e) {
function get_modifiers(e) {
let modifiers = ['Alt', 'Shift', 'Ctrl', 'Meta'].filter((n) => e[n.toLowerCase() + 'Key']);
return modifiers.map((m) => KEYMAP[m] || m);
}


function throttled (func, wait) {
function throttled(func, wait) {
var context, args, result;
var timeout = null;
var previous = 0;
Expand Down Expand Up @@ -412,7 +413,7 @@ function throttled (func, wait) {
}


function create_pointer_event (el, e, pointers, event_type) {
function create_pointer_event(el, e, pointers, event_type) {
let rect = el.getBoundingClientRect();
let offset = [rect.left, rect.top];
let main_x = Number(e.clientX - offset[0]);
Expand Down
1 change: 1 addition & 0 deletions jupyter_rfb/_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
# This is the reference version number, to be bumped before each release.
# The build system detects this definition when building a distribution.
__version__ = "0.4.4"
ref_version = __version__

# Allow using nearly the same code in different projects
project_name = "jupyter_rfb"
Expand Down
5 changes: 3 additions & 2 deletions jupyter_rfb/widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
from traitlets import Bool, Dict, Int, Unicode

from ._utils import array2compressed, RFBOutputContext, Snapshot
from ._version import ref_version


@ipywidgets.register
Expand Down Expand Up @@ -65,9 +66,9 @@ class RemoteFrameBuffer(ipywidgets.DOMWidget):
_model_module = Unicode("jupyter_rfb").tag(sync=True)

# Version of the front-end module containing widget view
_view_module_version = Unicode("^0.1.0").tag(sync=True)
_view_module_version = Unicode(f"^{ref_version}").tag(sync=True)
# Version of the front-end module containing widget model
_model_module_version = Unicode("^0.1.0").tag(sync=True)
_model_module_version = Unicode(f"^{ref_version}").tag(sync=True)

# Widget specific traits
frame_feedback = Dict({}).tag(sync=True)
Expand Down
2 changes: 1 addition & 1 deletion release.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def release(version):
os.path.join(ROOT_DIR, "pyproject.toml"),
os.path.join(ROOT_DIR, LIBNAME, "_version.py"),
os.path.join(ROOT_DIR, "js", "package.json"),
os.path.join(ROOT_DIR, "js", "lib", "index.js"),
os.path.join(ROOT_DIR, "js", "lib", "widget.js"),
]:
fname = os.path.basename(filename)
with open(filename, "rb") as f:
Expand Down

0 comments on commit d3e8b0d

Please sign in to comment.