From 73688343a076e492c50b70ce9b57741ab26e2045 Mon Sep 17 00:00:00 2001 From: M4x1m3 Date: Mon, 6 Jul 2020 11:56:11 +0200 Subject: [PATCH] [apps/code] Added File category to python toolbox --- apps/code/catalog.de.i18n | 16 ++++++++++++++++ apps/code/catalog.en.i18n | 16 ++++++++++++++++ apps/code/catalog.es.i18n | 16 ++++++++++++++++ apps/code/catalog.fr.i18n | 16 ++++++++++++++++ apps/code/catalog.hu.i18n | 16 ++++++++++++++++ apps/code/catalog.pt.i18n | 16 ++++++++++++++++ apps/code/catalog.universal.i18n | 32 ++++++++++++++++++++++++++++++++ apps/code/python_toolbox.cpp | 22 +++++++++++++++++++++- apps/code/toolbox.de.i18n | 1 + apps/code/toolbox.en.i18n | 1 + apps/code/toolbox.es.i18n | 1 + apps/code/toolbox.fr.i18n | 1 + apps/code/toolbox.hu.i18n | 1 + apps/code/toolbox.pt.i18n | 1 + python/port/mod/ion/file.cpp | 4 ++++ 15 files changed, 159 insertions(+), 1 deletion(-) diff --git a/apps/code/catalog.de.i18n b/apps/code/catalog.de.i18n index ba5d4676d..4bd73ab07 100644 --- a/apps/code/catalog.de.i18n +++ b/apps/code/catalog.de.i18n @@ -199,3 +199,19 @@ PythonTimeImport = "Import time module" PythonTimePrefix = "time module function prefix" PythonTimeSleep = "Warten Sie n Sekunden lang" PythonTimeMonotonic = "Monotone Zeit zurückgeben" +PythonFileOpen = "Öffnet eine Datei" +PythonFileSeekable = "Ist eine Datei durchsuchbar?" +PythonFileSeek = "Dateicursor verschieben" +PythonFileTell = "Cursorposition der Datei abrufen" +PythonFileClose = "Schließt eine Datei" +PythonFileClosed = "Wenn Datei geschlossen wurde" +PythonFileRead = "Bis zu size Bytes lesen" +PythonFileWrite = "Schreibe b in die Datei" +PythonFileReadline = "Lies eine Zeile" +PythonFileReadlines = "Liest eine Liste von Zeilen" +PythonFileTruncate = "Größe der Datei ändern" +PythonFileWritelines = "Schreibt eine Liste von Zeilen" +PythonFileName = "Dateiname" +PythonFileMode = "Dateiöffnungsmodus" +PythonFileReadable = "Ist die Datei lesbar?" +PythonFileWritable = "Ist die Datei beschreibbar?" diff --git a/apps/code/catalog.en.i18n b/apps/code/catalog.en.i18n index f833a5464..080d8462f 100644 --- a/apps/code/catalog.en.i18n +++ b/apps/code/catalog.en.i18n @@ -199,3 +199,19 @@ PythonTimeImport = "Import time module" PythonTimePrefix = "time module function prefix" PythonTimeSleep = "Wait for n second" PythonTimeMonotonic = "Return monotonic time" +PythonFileOpen = "Opens a file" +PythonFileSeekable = "Tells if seek can be used on a file" +PythonFileSeek = "Move file's cursor" +PythonFileTell = "Get file's cursor location" +PythonFileClose = "Closes a file" +PythonFileClosed = "True if file was closed" +PythonFileRead = "Read up to size bytes" +PythonFileWrite = "Write b into file" +PythonFileReadline = "Reads a line or up to size bytes" +PythonFileReadlines = "Reads a list of lines" +PythonFileTruncate = "Resize the file to size" +PythonFileWritelines = "Writes a list of lines" +PythonFileName = "Contains file's name" +PythonFileMode = "Contains file's open mode" +PythonFileReadable = "Tells if read can be used on a file" +PythonFileWritable = "Tells if write can be used on a file" diff --git a/apps/code/catalog.es.i18n b/apps/code/catalog.es.i18n index 0eefedac4..e0bc6c137 100644 --- a/apps/code/catalog.es.i18n +++ b/apps/code/catalog.es.i18n @@ -199,3 +199,19 @@ PythonTimeImport = "Import time module" PythonTimePrefix = "time module function prefix" PythonTimeSleep = "Esperar n segundos" PythonTimeMonotonic = "Tiempo monótono de retorno" +PythonFileOpen = "Opens a file" +PythonFileSeekable = "Tells if seek can be used on a file" +PythonFileSeek = "Move file's internal cursor" +PythonFileTell = "Get file's internal cursor location" +PythonFileClose = "Closes a file" +PythonFileClosed = "True if file was closed" +PythonFileRead = "Read up to size bytes" +PythonFileWrite = "Write b into file" +PythonFileReadline = "Reads a line or up to size bytes" +PythonFileReadlines = "Reads a list of lines" +PythonFileTruncate = "Resize the file to size" +PythonFileWritelines = "Writes a list of lines" +PythonFileName = "Contains file's name" +PythonFileMode = "Contains file's open mode" +PythonFileReadable = "Tells if read can be used on a file" +PythonFileWritable = "Tells if write can be used on a file" diff --git a/apps/code/catalog.fr.i18n b/apps/code/catalog.fr.i18n index 2a98a9105..2dfad76da 100644 --- a/apps/code/catalog.fr.i18n +++ b/apps/code/catalog.fr.i18n @@ -199,3 +199,19 @@ PythonTimeImport = "Importation du module temps" PythonTimePrefix = "Préfixe fonction du module temps" PythonTimeSleep = "Attendre n secondes" PythonTimeMonotonic = "Retourne le temps monotonic" +PythonFileOpen = "Ouvre un fichier" +PythonFileSeekable = "Indique si seek peut être utilisé" +PythonFileSeek = "Déplace le curseur interne" +PythonFileTell = "Donne la posititon du curseur" +PythonFileClose = "Ferme un fichier" +PythonFileClosed = "True si le fichier a été fermé" +PythonFileRead = "Lis jusqu'à size bytes" +PythonFileWrite = "Écris b dans le fichier" +PythonFileReadline = "Lis une ligne ou jusqu'à size bytes" +PythonFileReadlines = "Lis une liste de lignes" +PythonFileTruncate = "Redimensionne le fichier" +PythonFileWritelines = "Écris une liste de lignes" +PythonFileName = "Nom du fichier" +PythonFileMode = "Mode d'ouverture du fichier" +PythonFileReadable = "Indique si read peut être utilisé" +PythonFileWritable = "Indique si write peut être utilisé" diff --git a/apps/code/catalog.hu.i18n b/apps/code/catalog.hu.i18n index 862d85bd4..a82621ec8 100644 --- a/apps/code/catalog.hu.i18n +++ b/apps/code/catalog.hu.i18n @@ -199,3 +199,19 @@ PythonTimeImport = "Idömodul importálása" PythonTimePrefix = "idömodul funkció elötag" PythonTimeSleep = "Várj n másodpercet" PythonTimeMonotonic = "Vissza a monoton idö" +PythonFileOpen = "Fájl megnyitása" +PythonFileSeekable = "A fájl kereshető?" +PythonFileSeek = "A fájl kurzorának áthelyezése" +PythonFileTell = "A fájl kurzorának helye" +PythonFileClose = "Bezár egy fájlt" +PythonFileClosed = "Igaz, ha a fájl bezárt" +PythonFileRead = "Olvasson méretbájtig" +PythonFileWrite = "B beírása fájlba" +PythonFileReadline = "Olvas egy sort" +PythonFileReadlines = "Olvassa a sorok listáját" +PythonFileTruncate = "A fájl átméretezése méretre" +PythonFileWritelines = "Sorok listáját írja" +PythonFileName = "a fájl neve" +PythonFileMode = "a fájl nyitott módja" +PythonFileReadable = "A fájl olvasható?" +PythonFileWritable = "A fájl írható?" diff --git a/apps/code/catalog.pt.i18n b/apps/code/catalog.pt.i18n index 7294e19e0..97ef2861e 100644 --- a/apps/code/catalog.pt.i18n +++ b/apps/code/catalog.pt.i18n @@ -199,3 +199,19 @@ PythonTimeImport = "Import time module" PythonTimePrefix = "time module function prefix" PythonTimeSleep = "Aguardar n segundos" PythonTimeMonotonic = "Retornar tempo monotônico" +PythonFileOpen = "Opens a file" +PythonFileSeekable = "Tells if seek can be used on a file" +PythonFileSeek = "Move file's internal cursor" +PythonFileTell = "Get file's internal cursor location" +PythonFileClose = "Closes a file" +PythonFileClosed = "True if file was closed" +PythonFileRead = "Read up to size bytes" +PythonFileWrite = "Write b into file" +PythonFileReadline = "Reads a line or up to size bytes" +PythonFileReadlines = "Reads a list of lines" +PythonFileTruncate = "Resize the file to size" +PythonFileWritelines = "Writes a list of lines" +PythonFileName = "Contains file's name" +PythonFileMode = "Contains file's open mode" +PythonFileReadable = "Tells if read can be used on a file" +PythonFileWritable = "Tells if write can be used on a file" diff --git a/apps/code/catalog.universal.i18n b/apps/code/catalog.universal.i18n index c0fd92a28..bd028fe81 100644 --- a/apps/code/catalog.universal.i18n +++ b/apps/code/catalog.universal.i18n @@ -238,3 +238,35 @@ PythonTimeCommandImportFrom = "from time import *" PythonTimeCommandSleep = "sleep()" PythonTimeCommandSleepDemo = "sleep(n)" PythonTimeCommandMonotonic = "monotonic()" +PythonCommandFileOpen = "open(name, [mode])" +PythonCommandFileOpenWithoutArg = "open(\x11)" +PythonCommandFileSeek = "file.seek(offset, [whence])" +PythonCommandFileSeekWithoutArg = ".seek(\x11)" +PythonCommandFileTell = "file.tell()" +PythonCommandFileTellWithoutArg = ".tell()" +PythonCommandFileSeekable = "file.seekable()" +PythonCommandFileSeekableWithoutArg = ".seekable()" +PythonCommandFileClose = "file.close()" +PythonCommandFileCloseWithoutArg = ".close()" +PythonCommandFileClosed = "file.closed" +PythonCommandFileClosedWithoutArg = ".closed" +PythonCommandFileRead = "file.read([size])" +PythonCommandFileReadWithoutArg = ".read(\x11)" +PythonCommandFileWrite = "file.write(b)" +PythonCommandFileWriteWithoutArg = ".write(\x11)" +PythonCommandFileReadline = "file.readline([size])" +PythonCommandFileReadlineWithoutArg = ".readline(\x11)" +PythonCommandFileReadlines = "file.readlines([hint])" +PythonCommandFileReadlinesWithoutArg = ".readlines(\x11)" +PythonCommandFileTruncate = "file.truncate([size])" +PythonCommandFileTruncateWithoutArg = ".truncate(\x11)" +PythonCommandFileWritelines = "file.writelines(lines)" +PythonCommandFileWritelinesWithoutArg = ".writelines(\x11)" +PythonCommandFileName = "file.name" +PythonCommandFileNameWithoutArg = ".name" +PythonCommandFileMode = "file.mode" +PythonCommandFileModeWithoutArg = ".mode" +PythonCommandFileReadable = "file.readable()" +PythonCommandFileReadableWithoutArg = ".readable()" +PythonCommandFileWritable = "file.writable()" +PythonCommandFileWritableWithoutArg = ".writable()" diff --git a/apps/code/python_toolbox.cpp b/apps/code/python_toolbox.cpp index bdb79c4db..8ee79fbf1 100644 --- a/apps/code/python_toolbox.cpp +++ b/apps/code/python_toolbox.cpp @@ -422,11 +422,31 @@ const ToolboxMessageTree functionsChildren[] = { ToolboxMessageTree::Leaf(I18n::Message::PythonCommandReturn, I18n::Message::Default) }; +const ToolboxMessageTree fileChildren[] { + ToolboxMessageTree::Leaf(I18n::Message::PythonCommandFileOpen, I18n::Message::PythonFileOpen, false, I18n::Message::PythonCommandFileOpenWithoutArg), + ToolboxMessageTree::Leaf(I18n::Message::PythonCommandFileClose, I18n::Message::PythonFileClose, false, I18n::Message::PythonCommandFileCloseWithoutArg), + ToolboxMessageTree::Leaf(I18n::Message::PythonCommandFileClosed, I18n::Message::PythonFileClosed, false, I18n::Message::PythonCommandFileClosedWithoutArg), + ToolboxMessageTree::Leaf(I18n::Message::PythonCommandFileMode, I18n::Message::PythonFileMode, false, I18n::Message::PythonCommandFileModeWithoutArg), + ToolboxMessageTree::Leaf(I18n::Message::PythonCommandFileName, I18n::Message::PythonFileName, false, I18n::Message::PythonCommandFileNameWithoutArg), + ToolboxMessageTree::Leaf(I18n::Message::PythonCommandFileRead, I18n::Message::PythonFileRead, false, I18n::Message::PythonCommandFileReadWithoutArg), + ToolboxMessageTree::Leaf(I18n::Message::PythonCommandFileReadable, I18n::Message::PythonFileReadable, false, I18n::Message::PythonCommandFileReadableWithoutArg), + ToolboxMessageTree::Leaf(I18n::Message::PythonCommandFileReadline, I18n::Message::PythonFileReadline, false, I18n::Message::PythonCommandFileReadlineWithoutArg), + ToolboxMessageTree::Leaf(I18n::Message::PythonCommandFileReadlines, I18n::Message::PythonFileReadlines, false, I18n::Message::PythonCommandFileReadlinesWithoutArg), + ToolboxMessageTree::Leaf(I18n::Message::PythonCommandFileSeek, I18n::Message::PythonFileSeek, false, I18n::Message::PythonCommandFileSeekWithoutArg), + ToolboxMessageTree::Leaf(I18n::Message::PythonCommandFileSeekable, I18n::Message::PythonFileSeekable, false, I18n::Message::PythonCommandFileSeekableWithoutArg), + ToolboxMessageTree::Leaf(I18n::Message::PythonCommandFileTell, I18n::Message::PythonFileTell, false, I18n::Message::PythonCommandFileTellWithoutArg), + ToolboxMessageTree::Leaf(I18n::Message::PythonCommandFileTruncate, I18n::Message::PythonFileTruncate, false, I18n::Message::PythonCommandFileTruncateWithoutArg), + ToolboxMessageTree::Leaf(I18n::Message::PythonCommandFileWrite, I18n::Message::PythonFileWrite, false, I18n::Message::PythonCommandFileWriteWithoutArg), + ToolboxMessageTree::Leaf(I18n::Message::PythonCommandFileWritable, I18n::Message::PythonFileWritable, false, I18n::Message::PythonCommandFileWritableWithoutArg), + ToolboxMessageTree::Leaf(I18n::Message::PythonCommandFileWritelines, I18n::Message::PythonFileWritelines, false, I18n::Message::PythonCommandFileWritelinesWithoutArg), +}; + const ToolboxMessageTree menu[] = { ToolboxMessageTree::Node(I18n::Message::LoopsAndTests, loopsAndTestsChildren), ToolboxMessageTree::Node(I18n::Message::Modules, modulesChildren), ToolboxMessageTree::Node(I18n::Message::Catalog, catalogChildren), - ToolboxMessageTree::Node(I18n::Message::Functions, functionsChildren) + ToolboxMessageTree::Node(I18n::Message::Functions, functionsChildren), + ToolboxMessageTree::Node(I18n::Message::Files, fileChildren) }; const ToolboxMessageTree toolboxModel = ToolboxMessageTree::Node(I18n::Message::Toolbox, menu); diff --git a/apps/code/toolbox.de.i18n b/apps/code/toolbox.de.i18n index 41775c90c..fedc22d19 100644 --- a/apps/code/toolbox.de.i18n +++ b/apps/code/toolbox.de.i18n @@ -2,3 +2,4 @@ Functions = "Funktionen" Catalog = "Katalog" Modules = "Module" LoopsAndTests = "Schleifen und Tests" +Files = "Dateien" diff --git a/apps/code/toolbox.en.i18n b/apps/code/toolbox.en.i18n index 178d42b7b..40c50d42d 100644 --- a/apps/code/toolbox.en.i18n +++ b/apps/code/toolbox.en.i18n @@ -2,3 +2,4 @@ Functions = "Functions" Catalog = "Catalog" Modules = "Modules" LoopsAndTests = "Loops and tests" +Files = "Files" diff --git a/apps/code/toolbox.es.i18n b/apps/code/toolbox.es.i18n index 178d42b7b..40c50d42d 100644 --- a/apps/code/toolbox.es.i18n +++ b/apps/code/toolbox.es.i18n @@ -2,3 +2,4 @@ Functions = "Functions" Catalog = "Catalog" Modules = "Modules" LoopsAndTests = "Loops and tests" +Files = "Files" diff --git a/apps/code/toolbox.fr.i18n b/apps/code/toolbox.fr.i18n index 6442521cc..0b16add7c 100644 --- a/apps/code/toolbox.fr.i18n +++ b/apps/code/toolbox.fr.i18n @@ -2,3 +2,4 @@ Functions = "Fonctions" Catalog = "Catalogue" Modules = "Modules" LoopsAndTests = "Boucles et tests" +Files = "Fichiers" diff --git a/apps/code/toolbox.hu.i18n b/apps/code/toolbox.hu.i18n index 930be1430..8730fb185 100644 --- a/apps/code/toolbox.hu.i18n +++ b/apps/code/toolbox.hu.i18n @@ -2,3 +2,4 @@ Functions = "Funkciók" Catalog = "Katalógus" Modules = "Modulok" LoopsAndTests = "Hurkok és tesztek" +Files = "Fájlok" diff --git a/apps/code/toolbox.pt.i18n b/apps/code/toolbox.pt.i18n index 178d42b7b..40c50d42d 100644 --- a/apps/code/toolbox.pt.i18n +++ b/apps/code/toolbox.pt.i18n @@ -2,3 +2,4 @@ Functions = "Functions" Catalog = "Catalog" Modules = "Modules" LoopsAndTests = "Loops and tests" +Files = "Files" diff --git a/python/port/mod/ion/file.cpp b/python/port/mod/ion/file.cpp index 1cc8ff8de..df53bdc83 100644 --- a/python/port/mod/ion/file.cpp +++ b/python/port/mod/ion/file.cpp @@ -298,6 +298,10 @@ STATIC void file_attr(mp_obj_t self_in, qstr attribute, mp_obj_t *destination) { destination[0] = (mp_obj_t) MP_ROM_PTR(&file_readable_obj); destination[1] = self_in; break; + case MP_QSTR_writable: + destination[0] = (mp_obj_t) MP_ROM_PTR(&file_writable_obj); + destination[1] = self_in; + break; case MP_QSTR_read: destination[0] = (mp_obj_t) MP_ROM_PTR(&file_read_obj); destination[1] = self_in;