Skip to content
This repository was archived by the owner on Dec 23, 2021. It is now read-only.

Added notification when filename is wrong. #63

Merged
merged 30 commits into from
Jul 22, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
80be2fe
Adding notification for the file name deployed to device
Jul 18, 2019
a3654e0
added popup for simulator
Jul 18, 2019
7ae7f2d
changed the message
Jul 19, 2019
0d98482
Update locales/en/out/constants.i18n.json
FMounz Jul 19, 2019
dfe1af6
changed constant
Jul 19, 2019
e28ff19
removed link from outputchannel
Jul 19, 2019
8d6af89
changed error debug
Jul 19, 2019
e6ff645
changed condition
Jul 19, 2019
43466dd
solved typo
Jul 19, 2019
da221ab
merge with dev
Jul 19, 2019
47b49b4
changed code
Jul 19, 2019
01c54f8
removed white line
Jul 19, 2019
0d53754
Update locales/en/out/constants.i18n.json
FMounz Jul 20, 2019
4dfea65
Update locales/en/out/constants.i18n.json
FMounz Jul 20, 2019
980cdb5
Update src/constants.ts
FMounz Jul 20, 2019
1026868
Update src/constants.ts
FMounz Jul 20, 2019
515f840
changes
Jul 20, 2019
16cb522
Merge branch 'users/t-chcido/filename-check' of https://github.com/mi…
Jul 20, 2019
0201ce3
Update locales/en/out/constants.i18n.json
FMounz Jul 20, 2019
333a11a
Update src/constants.ts
FMounz Jul 20, 2019
8bada49
added capital P to Python
Jul 20, 2019
1f2e781
changed python to Python
Jul 20, 2019
c8fcfa8
changes
Jul 20, 2019
4bfe5a0
Merge branch 'dev' into users/t-chcido/filename-check
Jul 20, 2019
ae33c00
used prettier
Jul 20, 2019
f8903ca
removed useless characters
FMounz Jul 21, 2019
8c1a558
removed spreding operator
Jul 21, 2019
4df6598
Merge branch 'dev' into users/t-chcido/filename-check
Jul 21, 2019
34d2207
merged with dev
Jul 21, 2019
1c9380c
deleted unused file
Jul 21, 2019
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 locales/en/out/constants.i18n.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
"dialogResponses.exampleCode": "Example Code on GitHub",
"dialogResponses.help": "I need help",
"dialogResponses.tutorials": "Tutorials on Adafruit",
" error.incorrectFileNameForDevice":"[ERROR] Can\\'t deploy to your Circuit Playground Express device, please rename your file to \"code.py\" or \"main.py\". \n",
"error.incorrectFileNameForDevicePopup":"Seems like you have a different file name than what the CPX requires, please rename it to \"code.py\" or \"main.py\".",
"error.incorrectFileNameForSimulatorPopup":"We want your code to work on your actual board as well. Make sure you name your file \"code.py\" or \"main.py\" to be able to run your code on an actual physical device.",
"error.invalidFileNameDebug":"The file you tried to debug isn\\'t named \"code.py\" or \"main.py\\. Rename your file if you want your code to work on your actual device.",
"error.noDevice": "No plugged in boards detected. Please double check if your board is connected and/or properly formatted",
"error.noFileToRun": "\n[ERROR] We can't find the .py file to run on simulator. Open up a new .py file, or browse through some examples\n",
"error.stderr": "\n[ERROR] {0} \n",
Expand All @@ -12,9 +16,10 @@
"info.deploySuccess": "\n[INFO] Code successfully deployed\n",
"info.extensionActivated": "Congratulations, your extension Adafruit_Simulator is now active!",
"info.firstTimeWebview": "To reopen the simulator click on the \"Open Simulator\" button on the upper right corner of the text editor, or select the command \"Open Simulator\" from command palette.",
"error.invalidFileExtensionDebug":"The file you tried to run isn\\'t a Python file.",
"info.newProject": "New to Python or Circuit Playground Express project? We are here to help!",
"info.runningCode": "Running user code",
"info.welcomeOutputTab": "Welcome to the Adafruit Simulator output tab !\n\n",
"label.webviewPanel": "Adafruit CPX",
"name": "Pacifica Simulator"
}
}
28 changes: 24 additions & 4 deletions src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,25 @@ const localize: nls.LocalizeFunc = nls.config({
export const CONSTANTS = {
DEBUG_CONFIGURATION_NAME: "Pacifica Simulator Debugger",
ERROR: {
INVALID_FILE_NAME_DEBUG: localize(
"error.invalidFileNameDebug",
'The file you tried to run isn\'t named "code.py" or "main.py". Rename your file if you wish to debug it.'
INCORRECT_FILE_NAME_FOR_DEVICE: localize(
"error.incorrectFileNameForDevice",
'[ERROR] Can\'t deploy to your Circuit Playground Express device, please rename your file to "code.py" or "main.py". \n'
),
INCORRECT_FILE_NAME_FOR_DEVICE_POPUP: localize(
"error.incorrectFileNameForDevicePopup",
'Seems like you have a different file name than what CPX requires, please rename it to "code.py" or "main.py".'
),
INVALID_FILE_EXTENSION_DEBUG: localize(
"error.invalidFileExtensionDebug",
"The file you tried to run isn't a Python file."
),
NO_DEVICE: localize(
"error.noDevice",
"No plugged in boards detected. Please double check if your board is connected and/or properly formatted"
),
NO_FILE_TO_RUN: localize(
"error.noFileToRun",
"\n[ERROR] We can't find the .py file to run. Open up a new .py file, or browse through some examples to start with: https://github.com/adafruit/Adafruit_CircuitPython_CircuitPlayground/tree/master/examples\n"
'[ERROR] We can\'t find the .py file to run. Open up a new .py file, or run the "New Project" command to get started and see useful links\n'
),
NO_PROGRAM_FOUND_DEBUG: localize(
"error.noProgramFoundDebug",
Expand Down Expand Up @@ -53,6 +61,7 @@ export const CONSTANTS = {
"info.extensionActivated",
"Congratulations, your extension Adafruit_Simulator is now active!"
),

FILE_SELECTED: (filePath: string) => {
return localize(
"info.fileSelected",
Expand All @@ -63,6 +72,14 @@ export const CONSTANTS = {
"info.firstTimeWebview",
'To reopen the simulator click on the "Open Simulator" button on the upper right corner of the text editor, or select the command "Open Simulator" from command palette.'
),
INCORRECT_FILE_NAME_FOR_SIMULATOR_POPUP: localize(
"info.incorrectFileNameForSimulatorPopup",
'We want your code to work on your actual board as well. Make sure you name your file "code.py" or "main.py" to be able to run your code on an actual physical device'
),
INVALID_FILE_NAME_DEBUG: localize(
"info.invalidFileNameDebug",
'The file you tried to debug isn\'t named "code.py" or "main.py". Rename your file if you want your code to work on your actual device.'
),
NEW_PROJECT: localize(
"info.newProject",
"New to Python or Circuit Playground Express project? We are here to help!"
Expand Down Expand Up @@ -143,6 +160,9 @@ export namespace DialogResponses {
export const EXAMPLE_CODE: MessageItem = {
title: localize("dialogResponses.exampleCode", "Example Code on GitHub")
};
export const MESSAGE_UNDERSTOOD: MessageItem = {
title: localize("dialogResponses.messageUnderstood", "Got It")
};
}

export const USER_CODE_NAMES = {
Expand Down
51 changes: 42 additions & 9 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ let currentFileAbsPath: string = "";
// Notification booleans
let firstTimeClosed: boolean = true;
let shouldShowNewProject: boolean = true;
let shouldShowInvalidFileNamePopup: boolean = true;
let telemetryAI: TelemetryAI;

function loadScript(context: vscode.ExtensionContext, scriptPath: string) {
Expand Down Expand Up @@ -83,14 +84,14 @@ export function activate(context: vscode.ExtensionContext) {
// Send input to the Python process
handleButtonPressTelemetry(message.text);
console.log("About to write");
console.log(messageJson + "\n");
console.log(messageJson + "\n");
if (childProcess) {
childProcess.stdin.write(messageJson + "\n");
childProcess.stdin.write(messageJson + "\n");
}
break;
case WebviewMessages.PLAY_SIMULATOR:
console.log("Play button");
console.log(messageJson + "\n");
console.log(messageJson + "\n");
if (message.text as boolean) {
runSimulatorCommand();
} else {
Expand All @@ -99,9 +100,9 @@ export function activate(context: vscode.ExtensionContext) {
break;
case WebviewMessages.SENSOR_CHANGED:
console.log("sensor changed");
console.log(messageJson + "\n");
console.log(messageJson + "\n");
if (childProcess) {
childProcess.stdin.write(messageJson + "\n");
childProcess.stdin.write(messageJson + "\n");
}
break;
case WebviewMessages.REFRESH_SIMULATOR:
Expand Down Expand Up @@ -158,9 +159,9 @@ export function activate(context: vscode.ExtensionContext) {
vscode.window
.showInformationMessage(
CONSTANTS.INFO.NEW_PROJECT,
DialogResponses.DONT_SHOW,
DialogResponses.EXAMPLE_CODE,
DialogResponses.TUTORIALS
DialogResponses.DONT_SHOW,
DialogResponses.EXAMPLE_CODE,
DialogResponses.TUTORIALS
)
.then((selection: vscode.MessageItem | undefined) => {
if (selection === DialogResponses.DONT_SHOW) {
Expand Down Expand Up @@ -246,6 +247,27 @@ export function activate(context: vscode.ExtensionContext) {
CONSTANTS.INFO.FILE_SELECTED(currentFileAbsPath)
);

if (
!utils.validCodeFileName(currentFileAbsPath) &&
shouldShowInvalidFileNamePopup
) {
// to the popup
vscode.window
.showInformationMessage(
CONSTANTS.INFO.INCORRECT_FILE_NAME_FOR_SIMULATOR_POPUP,
DialogResponses.DONT_SHOW,
DialogResponses.MESSAGE_UNDERSTOOD
)
.then((selection: vscode.MessageItem | undefined) => {
if (selection === DialogResponses.DONT_SHOW) {
shouldShowInvalidFileNamePopup = false;
telemetryAI.trackFeatureUsage(
TelemetryEventName.CLICK_DIALOG_DONT_SHOW
);
}
});
}

childProcess = cp.spawn("python", [
utils.getPathToScript(context, "out", "process_user_code.py"),
currentFileAbsPath
Expand Down Expand Up @@ -327,6 +349,17 @@ export function activate(context: vscode.ExtensionContext) {

if (currentFileAbsPath === "") {
logToOutputChannel(outChannel, CONSTANTS.ERROR.NO_FILE_TO_RUN, true);
} else if (!utils.validCodeFileName(currentFileAbsPath)) {
// Output panel
logToOutputChannel(
outChannel,
CONSTANTS.ERROR.INCORRECT_FILE_NAME_FOR_DEVICE,
true
);
// Popup
vscode.window.showErrorMessage(
CONSTANTS.ERROR.INCORRECT_FILE_NAME_FOR_DEVICE_POPUP
);
} else {
logToOutputChannel(
outChannel,
Expand Down Expand Up @@ -363,7 +396,7 @@ export function activate(context: vscode.ExtensionContext) {
vscode.window
.showErrorMessage(
CONSTANTS.ERROR.NO_DEVICE,
DialogResponses.HELP
DialogResponses.HELP
)
.then((selection: vscode.MessageItem | undefined) => {
if (selection === DialogResponses.HELP) {
Expand Down
21 changes: 17 additions & 4 deletions src/simulatorDebugConfigurationProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@

import * as vscode from "vscode";
import { validCodeFileName } from "./utils";
import { CONSTANTS } from "./constants";
import { CONSTANTS,DialogResponses } from "./constants";

let shouldShowInvalidFileNamePopup: boolean = true;

export class SimulatorDebugConfigurationProvider
implements vscode.DebugConfigurationProvider {
Expand All @@ -25,14 +27,25 @@ export class SimulatorDebugConfigurationProvider

// Check file type and name
if (
!(activeTextEditor.document.languageId === "python") ||
!validCodeFileName(currentFilePath)
!(activeTextEditor.document.languageId === "python")
) {
return vscode.window
.showErrorMessage(CONSTANTS.ERROR.INVALID_FILE_NAME_DEBUG)
.showErrorMessage(CONSTANTS.ERROR.INVALID_FILE_EXTENSION_DEBUG)
.then(() => {
return undefined; // Abort launch
});
}else if(!validCodeFileName(currentFilePath) && shouldShowInvalidFileNamePopup){
vscode.window
.showInformationMessage(CONSTANTS.INFO.INVALID_FILE_NAME_DEBUG,
...[
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if we're removing the spread operator elsewhere might as well do it here too?

DialogResponses.DONT_SHOW,
DialogResponses.MESSAGE_UNDERSTOOD
])
.then((selection: vscode.MessageItem | undefined) => {
if (selection === DialogResponses.DONT_SHOW) {
shouldShowInvalidFileNamePopup = false;
}
});
}
// Set process_user_code path as program
config.program = this.pathToScript;
Expand Down
1 change: 0 additions & 1 deletion src/view/components/toolbar/InputSlider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,6 @@ class InputSlider extends React.Component<ISliderProps, any, any> {
}

private writeMessage(event: React.ChangeEvent<HTMLInputElement>) {
parseInt(event.target.value, 10);
return this.props.type && this.state.value && event.target.value
? { temperature: parseInt(event.target.value, 10) }
: undefined;
Expand Down
4 changes: 3 additions & 1 deletion src/view/components/toolbar/TemperatureSensorBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@ class TemperatureSensorBar extends React.Component<any, ITemperatureUnit, any> {
<div className="temperatureSensorBar">
<div className="header">
<div className="title">
{`${TEMPERATURE_SENSOR_PROPERTIES.LABEL} ${CELSIUS_STATE.unitLabel}`}
{`${TEMPERATURE_SENSOR_PROPERTIES.LABEL} ${
CELSIUS_STATE.unitLabel
}`}
</div>
</div>
<InputSlider
Expand Down