pybricksMicropython/lib: add module

This creates a new module for dealing with stuff specific to Pybricks
MicroPython.
This commit is contained in:
David Lechner
2022-03-11 15:41:16 -06:00
parent 38b9bb6656
commit e36a30de4c
8 changed files with 142 additions and 73 deletions
+2 -1
View File
@@ -4,6 +4,7 @@
import React, { useContext } from 'react';
import { useDispatch } from 'react-redux';
import * as notificationActions from '../notifications/actions';
import { pythonFileExtension } from '../pybricksMicropython/lib';
import OpenFileButton, { OpenFileButtonProps } from '../toolbar/OpenFileButton';
import { TooltipId } from '../toolbar/i18n';
import { EditorContext } from './Editor';
@@ -18,7 +19,7 @@ const OpenButton: React.FunctionComponent<OpenButtonProps> = (props) => {
return (
<OpenFileButton
fileExtension=".py"
fileExtension={pythonFileExtension}
tooltip={TooltipId.Open}
icon={openIcon}
enabled={editor !== null}
+3 -2
View File
@@ -3,6 +3,7 @@
import FileSaver from 'file-saver';
import { call, getContext, put, takeEvery } from 'typed-redux-saga/macro';
import { pythonFileExtension, pythonFileMimeType } from '../pybricksMicropython/lib';
import { ensureError } from '../utils';
import { EditorType } from './Editor';
import { didFailToSaveAs, didSaveAs, open, saveAs } from './actions';
@@ -37,7 +38,7 @@ function* handleSaveAs(): Generator {
}
const data = editor.getValue();
const blob = new Blob([data], { type: 'text/x-python;charset=utf-8' });
const blob = new Blob([data], { type: `${pythonFileMimeType};charset=utf-8` });
if (window.showSaveFilePicker) {
// This uses https://wicg.github.io/file-system-access which is not
@@ -48,7 +49,7 @@ function* handleSaveAs(): Generator {
suggestedName: 'main.py',
types: [
{
accept: { 'text/x-python': '.py' },
accept: { [pythonFileMimeType]: pythonFileExtension },
// TODO: translate description
description: 'Python Files',
},