Skip to content
This repository was archived by the owner on Jun 7, 2023. It is now read-only.

Commit 4fa97db

Browse files
committed
Add: Cellbotics
1 parent 74c3f55 commit 4fa97db

21 files changed

Lines changed: 1979 additions & 3 deletions

runestone/activecode/js/skulpt-stdlib.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

runestone/activecode/js/skulpt.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
-2 Bytes
Binary file not shown.

runestone/activecode/js/skulpt.min.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

runestone/cellbotics/__init__.py

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
# .. Copyright (C) 2021 Bryan A. Jones.
2+
#
3+
# *********************************************************
4+
# |docname| - A Runestone extension supporting cellbotics
5+
# *********************************************************
6+
# This extension provides one new directive, ``ble-pair-button``, to add the Bluetooth Low Energy "Pair" button and status display to a page where users will be using the Cellbotics Python module and associated BLE functionality. The extension also includes all the supporting JavaScript files needed for the Cellbotics Python module.
7+
#
8+
#
9+
# Imports
10+
# =======
11+
# These are listed in the order prescribed by `PEP 8
12+
# <http://www.python.org/dev/peps/pep-0008/#imports>`_.
13+
#
14+
# Standard library
15+
# ----------------
16+
# None.
17+
#
18+
# Third-party imports
19+
# -------------------
20+
from docutils import nodes
21+
from docutils.parsers.rst import Directive
22+
23+
# Local imports
24+
# -------------
25+
# None
26+
27+
28+
# Code
29+
# ====
30+
class BlePairNode(nodes.General, nodes.Element):
31+
pass
32+
33+
34+
def visit_ble_pair_node(self, node):
35+
self.body.append(
36+
'<div data-component="ble">\n'
37+
' <script>runestone_import("ble");</script>\n'
38+
' <button id="ble_pair_button" type="button" disabled>Pair</button>\n'
39+
' <span id="ble_pair_status"></span>\n'
40+
'</div>\n'
41+
)
42+
43+
44+
def depart_ble_pair_node(self, node):
45+
pass
46+
47+
48+
class BlePairDirective(Directive):
49+
has_content = False
50+
required_arguments = 0
51+
optional_arguments = 0
52+
option_spec = {}
53+
54+
def run(self):
55+
return [BlePairNode()]
56+
57+
58+
def setup(app):
59+
# Add the Pair button directive.
60+
app.add_node(BlePairNode, html=(visit_ble_pair_node, depart_ble_pair_node))
61+
app.add_directive('ble-pair-button', BlePairDirective)
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
// .. Copyright (C) 2012-2020 Bryan A. Jones.
2+
//
3+
// This file is part of the CellBotics system.
4+
//
5+
// The CellBotics system is free software: you can redistribute it and/or
6+
// modify it under the terms of the GNU General Public License as
7+
// published by the Free Software Foundation, either version 3 of the
8+
// License, or (at your option) any later version.
9+
//
10+
// The CellBotics system is distributed in the hope that it will be
11+
// useful, but WITHOUT ANY WARRANTY; without even the implied warranty
12+
// of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13+
// General Public License for more details.
14+
//
15+
// You should have received a copy of the GNU General Public License
16+
// along with the CellBotics system. If not, see
17+
// <http://www.gnu.org/licenses/>.
18+
//
19+
// *********************************************************
20+
// |docname| - Automatically bind methods to their instances
21+
// *********************************************************
22+
23+
"use strict";
24+
25+
26+
// The following two functions were taken from https://github.com/sindresorhus/auto-bind/blob/master/index.js and lightly modified. They provide an easy way to bind all callable methods to their instance. See `Binding Methods to Class Instance Objects <https://ponyfoo.com/articles/binding-methods-to-class-instance-objects>`_ for more discussion on this crazy JavaScript necessity.
27+
//
28+
// Gets all non-builtin properties up the prototype chain
29+
const getAllProperties = object => {
30+
const properties = new Set();
31+
32+
do {
33+
for (const key of Reflect.ownKeys(object)) {
34+
properties.add([object, key]);
35+
}
36+
} while ((object = Reflect.getPrototypeOf(object)) && object !== Object.prototype);
37+
38+
return properties;
39+
};
40+
41+
42+
// Invoke this in the constructor of an object.
43+
export function auto_bind(self) {
44+
for (const [object, key] of getAllProperties(self.constructor.prototype)) {
45+
if (key === 'constructor') {
46+
continue;
47+
}
48+
49+
const descriptor = Reflect.getOwnPropertyDescriptor(object, key);
50+
if (descriptor && typeof descriptor.value === 'function') {
51+
self[key] = self[key].bind(self);
52+
}
53+
}
54+
}

0 commit comments

Comments
 (0)