From f466ac7314ea1c56b4ee7bad26116bc04c149e0d Mon Sep 17 00:00:00 2001 From: xnkevinnguyen Date: Sun, 29 Mar 2020 17:04:22 -0700 Subject: [PATCH 01/11] Add button refs to clue --- src/view/components/clue/ClueImage.tsx | 3 +- src/view/components/clue/Clue_svg.tsx | 81 +++++++---- .../components/microbit/MicrobitImage.tsx | 1 - src/view/components/microbit/Microbit_svg.tsx | 2 + src/view/styles/Clue.css | 135 ----------------- .../styles/{Microbit.css => SimulatorSvg.css} | 136 ++++++++++++++++++ 6 files changed, 189 insertions(+), 169 deletions(-) delete mode 100644 src/view/styles/Clue.css rename src/view/styles/{Microbit.css => SimulatorSvg.css} (62%) diff --git a/src/view/components/clue/ClueImage.tsx b/src/view/components/clue/ClueImage.tsx index a104108f0..25708da7f 100644 --- a/src/view/components/clue/ClueImage.tsx +++ b/src/view/components/clue/ClueImage.tsx @@ -5,7 +5,6 @@ import * as React from "react"; import { VIEW_STATE } from "../../constants"; import CONSTANTS, { BUTTON_STYLING_CLASSES } from "../../constants"; import { ViewStateContext } from "../../context"; -import "../../styles/Microbit.css"; import { ClueSvg, IRefObject } from "./Clue_svg"; interface EventTriggers { @@ -17,7 +16,7 @@ interface EventTriggers { interface IProps { eventTriggers: EventTriggers; displayMessage: string; - neopixel:number[] + neopixel: number[] } const BUTTON_CLASSNAME = { diff --git a/src/view/components/clue/Clue_svg.tsx b/src/view/components/clue/Clue_svg.tsx index 9b14a66b3..93135be3c 100644 --- a/src/view/components/clue/Clue_svg.tsx +++ b/src/view/components/clue/Clue_svg.tsx @@ -2,7 +2,7 @@ // Licensed under the MIT license. import * as React from "react"; -import "../../styles/Clue.css"; +import "../../styles/SimulatorSvg.css"; import { DEFAULT_CLUE_STATE } from "./ClueSimulator"; export interface IRefObject { [key: string]: React.RefObject; @@ -762,84 +762,103 @@ export class ClueSvg extends React.Component { transform="translate(-49.27 -48.48)" /> - + + + + { - + ); } private updateDisplay() { diff --git a/src/view/components/microbit/MicrobitImage.tsx b/src/view/components/microbit/MicrobitImage.tsx index a4df79750..1b1cb9af3 100644 --- a/src/view/components/microbit/MicrobitImage.tsx +++ b/src/view/components/microbit/MicrobitImage.tsx @@ -5,7 +5,6 @@ import * as React from "react"; import { VIEW_STATE } from "../../constants"; import CONSTANTS, { BUTTON_STYLING_CLASSES } from "../../constants"; import { ViewStateContext } from "../../context"; -import "../../styles/Microbit.css"; import { IRefObject, MicrobitSvg } from "./Microbit_svg"; interface EventTriggers { diff --git a/src/view/components/microbit/Microbit_svg.tsx b/src/view/components/microbit/Microbit_svg.tsx index 0c5447fbd..c3d95fdbb 100644 --- a/src/view/components/microbit/Microbit_svg.tsx +++ b/src/view/components/microbit/Microbit_svg.tsx @@ -4,6 +4,8 @@ // Adapted from : https://makecode.microbit.org/#editor import * as React from "react"; +import "../../styles/SimulatorSvg.css"; + export interface IRefObject { [key: string]: React.RefObject; } diff --git a/src/view/styles/Clue.css b/src/view/styles/Clue.css deleted file mode 100644 index c252fb62b..000000000 --- a/src/view/styles/Clue.css +++ /dev/null @@ -1,135 +0,0 @@ -.cls-1 { - fill: #097054; -} -.cls-1, -.cls-13, -.cls-14, -.cls-15, -.cls-23, -.cls-9 { - stroke: #000; -} -.cls-1, -.cls-11, -.cls-12, -.cls-13, -.cls-14, -.cls-15, -.cls-17, -.cls-22, -.cls-23, -.cls-3, -.cls-4, -.cls-5, -.cls-6, -.cls-9 { - stroke-miterlimit: 10; -} -.cls-1, -.cls-23 { - stroke-width: 1.99px; -} -.cls-18, -.cls-2 { - fill: #fff; -} -.cls-11, -.cls-12, -.cls-17, -.cls-23, -.cls-3, -.cls-4, -.cls-5, -.cls-6, -.cls-7, -.cls-8 { - fill: none; -} -.cls-11, -.cls-12, -.cls-17, -.cls-3, -.cls-4, -.cls-5, -.cls-6, -.cls-7, -.cls-8 { - stroke: #fff; -} -.cls-3 { - stroke-width: 2px; -} -.cls-12, -.cls-17, -.cls-4, -.cls-5, -.cls-6, -.cls-7, -.cls-8 { - stroke-linecap: round; -} -.cls-4, -.cls-7 { - stroke-width: 1.63px; -} -.cls-5 { - stroke-width: 1.41px; -} -.cls-6 { - stroke-width: 1.6px; -} -.cls-7, -.cls-8 { - stroke-linejoin: round; -} -.cls-8 { - stroke-width: 1.63px; -} -.cls-10, -.cls-15, -.cls-9 { - fill: #7e7272; -} -.cls-22, -.cls-9 { - stroke-width: 1.5px; -} -.cls-12 { - stroke-width: 1.71px; -} -.cls-13 { - fill: #6599ff; -} -.cls-13, -.cls-14, -.cls-15 { - stroke-width: 0.25px; -} -.cls-16 { - fill: #ffde00; -} -.cls-17 { - stroke-width: 2.02px; -} -.cls-18 { - font-size: 7px; - font-family: SegoeUI-Bold, Segoe UI; - font-weight: 700; - letter-spacing: -0.02em; -} -.cls-19 { - letter-spacing: -0.03em; -} -.cls-20 { - letter-spacing: -0.05em; -} -.cls-21 { - letter-spacing: 0em; -} -.cls-22 { - stroke: #7e7272; -} -.sim-text-outside { - font-size: 14px; - fill: var(--vscode-descriptionForeground); -} \ No newline at end of file diff --git a/src/view/styles/Microbit.css b/src/view/styles/SimulatorSvg.css similarity index 62% rename from src/view/styles/Microbit.css rename to src/view/styles/SimulatorSvg.css index f96655fa0..041f40ab5 100644 --- a/src/view/styles/Microbit.css +++ b/src/view/styles/SimulatorSvg.css @@ -38,6 +38,10 @@ sim-button { .sim-button-outer:active { fill: orange; } +.sim-button-outer{ + fill: #7e7272; + +} .sim-button-key-press { fill: orange; @@ -174,3 +178,135 @@ sim-button { -webkit-user-select: none; -ms-user-select: none; } +.sim-button{ + stroke:none +} +.sim-button:active{ + stroke:none +} +.cls-1 { + fill: #097054; +} +.cls-1, +.cls-14, +.cls-23, +.cls-9 { + stroke: #000; +} +.cls-1, +.cls-11, +.cls-12, +.cls-14, +.cls-17, +.cls-22, +.cls-23, +.cls-3, +.cls-4, +.cls-5, +.cls-6, +.cls-9 { + stroke-miterlimit: 10; +} +.cls-1, +.cls-23 { + stroke-width: 1.99px; +} +.cls-18, +.cls-2 { + fill: #fff; +} +.cls-11, +.cls-12, +.cls-17, +.cls-23, +.cls-3, +.cls-4, +.cls-5, +.cls-6, +.cls-7, +.cls-8 { + fill: none; +} +.cls-11, +.cls-12, +.cls-17, +.cls-3, +.cls-4, +.cls-5, +.cls-6, +.cls-7, +.cls-8 { + stroke: #fff; +} +.cls-3 { + stroke-width: 2px; +} +.cls-12, +.cls-17, +.cls-4, +.cls-5, +.cls-6, +.cls-7, +.cls-8 { + stroke-linecap: round; +} +.cls-4, +.cls-7 { + stroke-width: 1.63px; +} +.cls-5 { + stroke-width: 1.41px; +} +.cls-6 { + stroke-width: 1.6px; +} +.cls-7, +.cls-8 { + stroke-linejoin: round; +} +.cls-8 { + stroke-width: 1.63px; +} +.cls-10, +.cls-9 { + fill: #7e7272; +} +.cls-22, +.cls-9 { + stroke-width: 1.5px; +} +.cls-12 { + stroke-width: 1.71px; +} + +.cls-14 { + stroke-width: 0.25px; +} +.cls-16 { + fill: #ffde00; +} +.cls-17 { + stroke-width: 2.02px; +} +.cls-18 { + font-size: 7px; + font-family: SegoeUI-Bold, Segoe UI; + font-weight: 700; + letter-spacing: -0.02em; +} +.cls-19 { + letter-spacing: -0.03em; +} +.cls-20 { + letter-spacing: -0.05em; +} +.cls-21 { + letter-spacing: 0em; +} +.cls-22 { + stroke: #7e7272; +} +.sim-text-outside { + font-size: 14px; + fill: var(--vscode-descriptionForeground); +} From d412f0b0614ca81ddff22244e20ce5f32b3d7bc0 Mon Sep 17 00:00:00 2001 From: xnkevinnguyen Date: Sun, 29 Mar 2020 18:25:45 -0700 Subject: [PATCH 02/11] Add a+b buttons --- src/view/components/clue/Clue_svg.tsx | 53 ++++++++++++++++++++++++++- 1 file changed, 52 insertions(+), 1 deletion(-) diff --git a/src/view/components/clue/Clue_svg.tsx b/src/view/components/clue/Clue_svg.tsx index 93135be3c..fc5d26f83 100644 --- a/src/view/components/clue/Clue_svg.tsx +++ b/src/view/components/clue/Clue_svg.tsx @@ -858,7 +858,58 @@ export class ClueSvg extends React.Component { r="3.23" /> - + + + + + + + + + + A+B + Date: Mon, 30 Mar 2020 11:17:50 -0700 Subject: [PATCH 03/11] Add tests for clue --- src/view/components/clue/Clue.spec.tsx | 29 + .../clue/__snapshots__/Clue.spec.tsx.snap | 1160 ++++ src/view/components/cpx/Cpx.spec.tsx | 2 +- .../cpx/__snapshots__/Cpx.spec.tsx.snap | 4695 +++++++++++++++++ 4 files changed, 5885 insertions(+), 1 deletion(-) create mode 100644 src/view/components/clue/Clue.spec.tsx create mode 100644 src/view/components/clue/__snapshots__/Clue.spec.tsx.snap diff --git a/src/view/components/clue/Clue.spec.tsx b/src/view/components/clue/Clue.spec.tsx new file mode 100644 index 000000000..c69b4ebe7 --- /dev/null +++ b/src/view/components/clue/Clue.spec.tsx @@ -0,0 +1,29 @@ +import * as React from "react"; +import * as ReactDOM from "react-dom"; +import { IntlProvider } from "react-intl"; +import * as testRenderer from "react-test-renderer"; +import { Clue } from "./Clue"; + +describe("Clue component", () => { + it("should render correctly", () => { + const component = testRenderer + .create( + + + + ) + .toJSON(); + expect(component).toMatchSnapshot(); + }); + + it("should render without crashing", () => { + const div = document.createElement("div"); + ReactDOM.render( + + + , + div + ); + ReactDOM.unmountComponentAtNode(div); + }); +}); diff --git a/src/view/components/clue/__snapshots__/Clue.spec.tsx.snap b/src/view/components/clue/__snapshots__/Clue.spec.tsx.snap new file mode 100644 index 000000000..e64b0d068 --- /dev/null +++ b/src/view/components/clue/__snapshots__/Clue.spec.tsx.snap @@ -0,0 +1,1160 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`Clue component should render correctly 1`] = ` +Array [ +
+
+ The simulator will run the .py file you have focused on. +
+
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + A+B + + + + + + + + LIGHT + + + GESTURE + + + P + + R + + + O + + + XIMI + + + T + + + Y + + + + + + + + + + + + + + Neopixel + + + + +
+
+
+ + +
+
, +
+
+
+
+
, +] +`; diff --git a/src/view/components/cpx/Cpx.spec.tsx b/src/view/components/cpx/Cpx.spec.tsx index deb6da57d..24c53d551 100644 --- a/src/view/components/cpx/Cpx.spec.tsx +++ b/src/view/components/cpx/Cpx.spec.tsx @@ -4,7 +4,7 @@ import { IntlProvider } from "react-intl"; import * as testRenderer from "react-test-renderer"; import { Cpx } from "./Cpx"; -describe("Device component", () => { +describe("CPX component", () => { it("should render correctly", () => { const component = testRenderer .create( diff --git a/src/view/components/cpx/__snapshots__/Cpx.spec.tsx.snap b/src/view/components/cpx/__snapshots__/Cpx.spec.tsx.snap index 5120fb0a4..bf6def07c 100644 --- a/src/view/components/cpx/__snapshots__/Cpx.spec.tsx.snap +++ b/src/view/components/cpx/__snapshots__/Cpx.spec.tsx.snap @@ -1,5 +1,4700 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP +exports[`CPX component should render correctly 1`] = ` +Array [ +
+
+ The simulator will run the .py file you have focused on. +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+ + +
+
, +
+
+
+
+ +
+
+ +
+
+ +
+
+ +
+
+ +
+
+ +
+
+ +
+
+ +
+
+ +
+
+ +
+
+ +
+
+
+
, +] +`; + exports[`Device component should render correctly 1`] = ` Array [
Date: Mon, 30 Mar 2020 11:32:03 -0700 Subject: [PATCH 04/11] Filter messages for clue --- src/extension.ts | 3 --- src/view/components/clue/ClueSimulator.tsx | 19 ++++++++++++------- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/src/extension.ts b/src/extension.ts index d91b1a6de..ceaf839bc 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -3,16 +3,13 @@ import * as cp from "child_process"; import * as fs from "fs"; -import { registerDefaultFontFaces } from "office-ui-fabric-react"; import * as open from "open"; -import * as os from "os"; import * as path from "path"; import * as vscode from "vscode"; import { CONFIG, CONSTANTS, CPX_CONFIG_FILE, - DEFAULT_DEVICE, DialogResponses, GLOBAL_ENV_VARS, HELPER_FILES, diff --git a/src/view/components/clue/ClueSimulator.tsx b/src/view/components/clue/ClueSimulator.tsx index 7c2c3d932..083ecbbe9 100644 --- a/src/view/components/clue/ClueSimulator.tsx +++ b/src/view/components/clue/ClueSimulator.tsx @@ -5,6 +5,7 @@ import { CONSTANTS, WEBVIEW_MESSAGES, DEFAULT_IMG_CLUE, + DEVICE_LIST_KEY, } from "../../constants"; import PlayLogo from "../../svgs/play_svg"; import StopLogo from "../../svgs/stop_svg"; @@ -15,7 +16,7 @@ import { BUTTONS_KEYS, ClueImage } from "./ClueImage"; export const DEFAULT_CLUE_STATE: IClueState = { buttons: { button_a: false, button_b: false }, displayMessage: DEFAULT_IMG_CLUE, - neopixel: [0, 0, 0] + neopixel: [0, 0, 0], }; interface IState { @@ -30,7 +31,7 @@ interface IState { interface IClueState { buttons: { button_a: boolean; button_b: boolean }; displayMessage: string; - neopixel: number[] + neopixel: number[]; } export class ClueSimulator extends React.Component { private imageRef: React.RefObject = React.createRef(); @@ -48,7 +49,9 @@ export class ClueSimulator extends React.Component { } handleMessage = (event: any): void => { const message = event.data; - + if (message.active_device !== DEVICE_LIST_KEY.CLUE) { + return; + } switch (message.command) { case "reset-state": this.setState({ @@ -57,22 +60,24 @@ export class ClueSimulator extends React.Component { }); break; case "set-state": - console.log(`message received ${JSON.stringify(message.state)}`) + console.log( + `message received ${JSON.stringify(message.state)}` + ); if (message.state.display_base64) { this.setState({ clue: { ...this.state.clue, displayMessage: message.state.display_base64, }, - }) + }); } else if (message.state.pixels) { this.setState({ clue: { ...this.state.clue, neopixel: message.state.pixels, }, - }) - }; + }); + } break; case "activate-play": From b0d8daf3c60c59ca6a1384accb6dc4a387d1c44c Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 30 Mar 2020 22:26:11 -0700 Subject: [PATCH 05/11] first commit --- src/clue/adafruit_clue.py | 52 +++++++++++++++++++++++++++++++++++++-- 1 file changed, 50 insertions(+), 2 deletions(-) diff --git a/src/clue/adafruit_clue.py b/src/clue/adafruit_clue.py index bb4ef83b7..734a26939 100644 --- a/src/clue/adafruit_clue.py +++ b/src/clue/adafruit_clue.py @@ -199,15 +199,63 @@ class Clue: # pylint: disable=too-many-instance-attributes, too-many-public-met RAINBOW = (RED, ORANGE, YELLOW, GREEN, BLUE, PURPLE) def __init__(self): + self._a = False + self._b = False + self.__pressed_buttons = set() self._pixel = neopixel.NeoPixel( pin=CONSTANTS.CLUE_PIN, n=1, pixel_order=neopixel.RGB ) + @property + def button_a(self): + """``True`` when Button A is pressed. ``False`` if not. + This example prints when button A is pressed. + To use with the CLUE: + .. code-block:: python + from adafruit_clue import clue + while True: + if clue.button_a: + print("Button A pressed") + """ + return self._a + + @property + def button_b(self): + """``True`` when Button B is pressed. ``False`` if not. + This example prints when button B is pressed. + To use with the CLUE: + .. code-block:: python + from adafruit_clue import clue + while True: + if clue.button_b: + print("Button B pressed") + """ + return self._b + + def __press_button(self, button): + if button == "button_a": + self.__were_pressed.add("A") + self._a = True + elif button == "button_b": + self.__were_pressed.add("B") + self._b = True + + @property + def were_pressed(self): + """Returns a set of the buttons that have been pressed. + To use with the CLUE: + .. code-block:: python + from adafruit_clue import clue + while True: + print(clue.were_pressed) + """ + ret = self.__pressed_buttons.copy() + self.__pressed_buttons.clear() + return ret + @property def pixel(self): """The NeoPixel RGB LED. - .. image :: ../docs/_static/neopixel.jpg - :alt: NeoPixel This example turns the NeoPixel purple. To use with the CLUE: .. code-block:: python From 48bbcb27f333d85e89c285fc1b86daf8acef67e5 Mon Sep 17 00:00:00 2001 From: unknown Date: Tue, 31 Mar 2020 13:01:40 -0700 Subject: [PATCH 06/11] connect buttons to python side and add python-side button logic --- src/base_circuitpython/base_cp_constants.py | 2 ++ src/base_circuitpython/displayio/constants.py | 2 +- src/base_circuitpython/displayio/group.py | 3 +++ src/clue/adafruit_clue.py | 21 ++++++++++++++----- 4 files changed, 22 insertions(+), 6 deletions(-) diff --git a/src/base_circuitpython/base_cp_constants.py b/src/base_circuitpython/base_cp_constants.py index 53e627109..277b48c4d 100644 --- a/src/base_circuitpython/base_cp_constants.py +++ b/src/base_circuitpython/base_cp_constants.py @@ -6,3 +6,5 @@ IMG_DIR_NAME = "img" SCREEN_HEIGHT_WIDTH = 240 + +EXPECTED_INPUT_BUTTONS = ["button_a", "button_b"] \ No newline at end of file diff --git a/src/base_circuitpython/displayio/constants.py b/src/base_circuitpython/displayio/constants.py index e683684b9..06f6f43ec 100644 --- a/src/base_circuitpython/displayio/constants.py +++ b/src/base_circuitpython/displayio/constants.py @@ -8,4 +8,4 @@ SCREEN_HEIGHT_WIDTH = 240 CLUE = "CLUE" -BASE_64 = "display_base64" +BASE_64 = "display_base64" \ No newline at end of file diff --git a/src/base_circuitpython/displayio/group.py b/src/base_circuitpython/displayio/group.py index 2d3f3b8af..0eee8f96f 100644 --- a/src/base_circuitpython/displayio/group.py +++ b/src/base_circuitpython/displayio/group.py @@ -94,3 +94,6 @@ def __len__(self): return 0 else: return len(self.__contents) + + def pop(self, i=-1): + return self.__contents.pop(i) diff --git a/src/clue/adafruit_clue.py b/src/clue/adafruit_clue.py index 734a26939..35ce42099 100644 --- a/src/clue/adafruit_clue.py +++ b/src/clue/adafruit_clue.py @@ -232,13 +232,15 @@ def button_b(self): """ return self._b - def __press_button(self, button): + def __update_button(self, button, value): if button == "button_a": - self.__were_pressed.add("A") - self._a = True + if value: + self.__pressed_buttons.add("A") + self._a = value elif button == "button_b": - self.__were_pressed.add("B") - self._b = True + if value: + self.__pressed_buttons.add("B") + self._b = value @property def were_pressed(self): @@ -331,6 +333,15 @@ def simple_text_display( font=font, colors=colors, ) + + def update_state(self, new_state): + self.__update_buttons(new_state) + + # helpers + def __update_buttons(self, new_state): + # get button pushes + for button_name in CONSTANTS.EXPECTED_INPUT_BUTTONS: + self.__update_button(button_name, new_state.get(button_name)) clue = Clue() # pylint: disable=invalid-name From 750a42d65d901f8018dda16a9216a599c1f6b0fe Mon Sep 17 00:00:00 2001 From: unknown Date: Tue, 31 Mar 2020 13:07:30 -0700 Subject: [PATCH 07/11] formatted --- src/base_circuitpython/base_cp_constants.py | 2 +- src/base_circuitpython/displayio/constants.py | 2 +- src/clue/adafruit_clue.py | 2 +- src/view/components/clue/ClueImage.tsx | 2 +- src/view/components/clue/Clue_svg.tsx | 68 ++++++++++++------- src/view/styles/SimulatorSvg.css | 11 ++- 6 files changed, 53 insertions(+), 34 deletions(-) diff --git a/src/base_circuitpython/base_cp_constants.py b/src/base_circuitpython/base_cp_constants.py index 277b48c4d..67cea36e0 100644 --- a/src/base_circuitpython/base_cp_constants.py +++ b/src/base_circuitpython/base_cp_constants.py @@ -7,4 +7,4 @@ IMG_DIR_NAME = "img" SCREEN_HEIGHT_WIDTH = 240 -EXPECTED_INPUT_BUTTONS = ["button_a", "button_b"] \ No newline at end of file +EXPECTED_INPUT_BUTTONS = ["button_a", "button_b"] diff --git a/src/base_circuitpython/displayio/constants.py b/src/base_circuitpython/displayio/constants.py index 06f6f43ec..e683684b9 100644 --- a/src/base_circuitpython/displayio/constants.py +++ b/src/base_circuitpython/displayio/constants.py @@ -8,4 +8,4 @@ SCREEN_HEIGHT_WIDTH = 240 CLUE = "CLUE" -BASE_64 = "display_base64" \ No newline at end of file +BASE_64 = "display_base64" diff --git a/src/clue/adafruit_clue.py b/src/clue/adafruit_clue.py index 35ce42099..1a2f8cd72 100644 --- a/src/clue/adafruit_clue.py +++ b/src/clue/adafruit_clue.py @@ -333,7 +333,7 @@ def simple_text_display( font=font, colors=colors, ) - + def update_state(self, new_state): self.__update_buttons(new_state) diff --git a/src/view/components/clue/ClueImage.tsx b/src/view/components/clue/ClueImage.tsx index 25708da7f..402572c95 100644 --- a/src/view/components/clue/ClueImage.tsx +++ b/src/view/components/clue/ClueImage.tsx @@ -16,7 +16,7 @@ interface EventTriggers { interface IProps { eventTriggers: EventTriggers; displayMessage: string; - neopixel: number[] + neopixel: number[]; } const BUTTON_CLASSNAME = { diff --git a/src/view/components/clue/Clue_svg.tsx b/src/view/components/clue/Clue_svg.tsx index fc5d26f83..e606f3156 100644 --- a/src/view/components/clue/Clue_svg.tsx +++ b/src/view/components/clue/Clue_svg.tsx @@ -9,13 +9,15 @@ export interface IRefObject { } interface IProps { displayImage: string; - neopixel: number[] + neopixel: number[]; } -const LED_TINT_FACTOR = 0.5 +const LED_TINT_FACTOR = 0.5; export class ClueSvg extends React.Component { private svgRef: React.RefObject = React.createRef(); - private neopixel: React.RefObject = React.createRef() - private pixelStopGradient: React.RefObject = React.createRef() + private neopixel: React.RefObject = React.createRef(); + private pixelStopGradient: React.RefObject< + SVGStopElement + > = React.createRef(); private buttonRefs: IRefObject = { BTN_A: React.createRef(), @@ -36,12 +38,11 @@ export class ClueSvg extends React.Component { } componentDidMount() { this.updateDisplay(); - this.updateNeopixel() - + this.updateNeopixel(); } componentDidUpdate() { this.updateDisplay(); - this.updateNeopixel() + this.updateNeopixel(); } render() { @@ -56,11 +57,24 @@ export class ClueSvg extends React.Component { width="100%" height="100%" > - - - + + + - + + { A+B - + { Neopixel - + -
+
); } private updateDisplay() { @@ -1035,24 +1049,30 @@ export class ClueSvg extends React.Component { } } private updateNeopixel() { - const { neopixel } = this.props - const rgbColor = `rgb(${neopixel[0] + (255 - neopixel[0]) * LED_TINT_FACTOR}, - ${neopixel[1] + (255 - neopixel[1]) * LED_TINT_FACTOR},${neopixel[2] + (255 - neopixel[2]) * LED_TINT_FACTOR})` + const { neopixel } = this.props; + const rgbColor = `rgb(${neopixel[0] + + (255 - neopixel[0]) * LED_TINT_FACTOR}, + ${neopixel[1] + (255 - neopixel[1]) * LED_TINT_FACTOR},${neopixel[2] + + (255 - neopixel[2]) * LED_TINT_FACTOR})`; if (this.neopixel.current) { - this.neopixel.current.setAttribute('fill', rgbColor) + this.neopixel.current.setAttribute("fill", rgbColor); } if (this.pixelStopGradient.current) { if (neopixel === DEFAULT_CLUE_STATE.neopixel) { - console.log("remove opacity") + console.log("remove opacity"); - this.pixelStopGradient.current.setAttribute('stop-opacity', '0') + this.pixelStopGradient.current.setAttribute( + "stop-opacity", + "0" + ); } else { - this.pixelStopGradient.current.setAttribute('stop-opacity', '1') - + this.pixelStopGradient.current.setAttribute( + "stop-opacity", + "1" + ); } - this.pixelStopGradient.current.setAttribute('stop-color', rgbColor) + this.pixelStopGradient.current.setAttribute("stop-color", rgbColor); } - } } diff --git a/src/view/styles/SimulatorSvg.css b/src/view/styles/SimulatorSvg.css index 041f40ab5..1fb0fd426 100644 --- a/src/view/styles/SimulatorSvg.css +++ b/src/view/styles/SimulatorSvg.css @@ -38,9 +38,8 @@ sim-button { .sim-button-outer:active { fill: orange; } -.sim-button-outer{ +.sim-button-outer { fill: #7e7272; - } .sim-button-key-press { @@ -178,11 +177,11 @@ sim-button { -webkit-user-select: none; -ms-user-select: none; } -.sim-button{ - stroke:none +.sim-button { + stroke: none; } -.sim-button:active{ - stroke:none +.sim-button:active { + stroke: none; } .cls-1 { fill: #097054; From 9b507d75d3437c9b92d3ea97fbebb7d06afe763e Mon Sep 17 00:00:00 2001 From: unknown Date: Tue, 31 Mar 2020 14:30:45 -0700 Subject: [PATCH 08/11] added python tests for button --- src/clue/test/test_adafruit_clue.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/clue/test/test_adafruit_clue.py b/src/clue/test/test_adafruit_clue.py index 9f516eac7..afbaa02aa 100644 --- a/src/clue/test/test_adafruit_clue.py +++ b/src/clue/test/test_adafruit_clue.py @@ -53,3 +53,20 @@ def test_clue_display_text(self): clue_data.show() helper._Helper__test_image_equality(displayio.bmp_img, expected) + + def test_buttons(self): + BUTTON_A = "button_a" + BUTTON_B = "button_b" + + clue._Clue__update_button(BUTTON_A, True) + assert clue.button_a + clue._Clue_update_button(BUTTON_A, False) + assert not clue.button_a + + clue._Clue__update_button(BUTTON_B, True) + assert clue.button_b + clue._Clue_update_button(BUTTON_B, False) + assert not clue.button_b + + assert set(["A", "B"]) == clue.were_pressed + assert set() == clue.were_pressed From 227a28a836730a0d556fb4fa3c4f9b4641060499 Mon Sep 17 00:00:00 2001 From: xnkevinnguyen Date: Tue, 31 Mar 2020 14:44:08 -0700 Subject: [PATCH 09/11] Update tests --- .../clue/__snapshots__/Clue.spec.tsx.snap | 4 +- .../cpx/__snapshots__/Cpx.spec.tsx.snap | 4695 ----------------- 2 files changed, 2 insertions(+), 4697 deletions(-) diff --git a/src/view/components/clue/__snapshots__/Clue.spec.tsx.snap b/src/view/components/clue/__snapshots__/Clue.spec.tsx.snap index e64b0d068..099a3de7a 100644 --- a/src/view/components/clue/__snapshots__/Clue.spec.tsx.snap +++ b/src/view/components/clue/__snapshots__/Clue.spec.tsx.snap @@ -928,7 +928,7 @@ Array [ />
@@ -1064,7 +1064,7 @@ Array [ />
diff --git a/src/view/components/cpx/__snapshots__/Cpx.spec.tsx.snap b/src/view/components/cpx/__snapshots__/Cpx.spec.tsx.snap index bf6def07c..3a41b60f6 100644 --- a/src/view/components/cpx/__snapshots__/Cpx.spec.tsx.snap +++ b/src/view/components/cpx/__snapshots__/Cpx.spec.tsx.snap @@ -4694,4698 +4694,3 @@ Array [ , ] `; - -exports[`Device component should render correctly 1`] = ` -Array [ -
-
- The simulator will run the .py file you have focused on. -
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
-
- - -
-
, -
-
-
-
- -
-
- -
-
- -
-
- -
-
- -
-
- -
-
- -
-
- -
-
- -
-
- -
-
- -
-
-
-
, -] -`; From c34e81fab846f986565bc6ddb835daa61bfd1d68 Mon Sep 17 00:00:00 2001 From: unknown Date: Tue, 31 Mar 2020 15:15:49 -0700 Subject: [PATCH 10/11] Formatted --- src/clue/test/test_adafruit_clue.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/clue/test/test_adafruit_clue.py b/src/clue/test/test_adafruit_clue.py index afbaa02aa..73ff83bfa 100644 --- a/src/clue/test/test_adafruit_clue.py +++ b/src/clue/test/test_adafruit_clue.py @@ -53,7 +53,7 @@ def test_clue_display_text(self): clue_data.show() helper._Helper__test_image_equality(displayio.bmp_img, expected) - + def test_buttons(self): BUTTON_A = "button_a" BUTTON_B = "button_b" From b1079a7fef968f3e0d1f36a97c02ec2b3190904d Mon Sep 17 00:00:00 2001 From: unknown Date: Tue, 31 Mar 2020 15:22:02 -0700 Subject: [PATCH 11/11] fixed bug in python clue button tests --- src/clue/test/test_adafruit_clue.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/clue/test/test_adafruit_clue.py b/src/clue/test/test_adafruit_clue.py index 73ff83bfa..f634e5ae3 100644 --- a/src/clue/test/test_adafruit_clue.py +++ b/src/clue/test/test_adafruit_clue.py @@ -60,12 +60,12 @@ def test_buttons(self): clue._Clue__update_button(BUTTON_A, True) assert clue.button_a - clue._Clue_update_button(BUTTON_A, False) + clue._Clue__update_button(BUTTON_A, False) assert not clue.button_a clue._Clue__update_button(BUTTON_B, True) assert clue.button_b - clue._Clue_update_button(BUTTON_B, False) + clue._Clue__update_button(BUTTON_B, False) assert not clue.button_b assert set(["A", "B"]) == clue.were_pressed