[python/kandinsky] Added get_palette() function

This commit is contained in:
Laury
2021-08-31 16:17:36 +02:00
parent fb4fc4862d
commit 210a83b04d
14 changed files with 64 additions and 31 deletions

View File

@@ -63,6 +63,7 @@ PythonFloor = "Floor"
PythonFmod = "a modulo b" PythonFmod = "a modulo b"
PythonFrExp = "Mantissa and exponent of x: (m,e)" PythonFrExp = "Mantissa and exponent of x: (m,e)"
PythonGamma = "Gamma function" PythonGamma = "Gamma function"
PythonGetPalette = "Themenpalette erhalten"
PythonGetPixel = "Return pixel (x,y) color" PythonGetPixel = "Return pixel (x,y) color"
PythonGetrandbits = "Integer with k random bits" PythonGetrandbits = "Integer with k random bits"
PythonGrid = "Toggle the visibility of the grid" PythonGrid = "Toggle the visibility of the grid"
@@ -101,36 +102,36 @@ PythonMathFunction = "math module function prefix"
PythonMatplotlibPyplotFunction = "matplotlib.pyplot module prefix" PythonMatplotlibPyplotFunction = "matplotlib.pyplot module prefix"
PythonMax = "Maximum" PythonMax = "Maximum"
PythonMin = "Minimum" PythonMin = "Minimum"
PythonModf = "Fractional and integer parts of x" PythonModf = "Bruch- und Ganzzahl-Anteile von x"
PythonMonotonic = "Value of a monotonic clock" PythonMonotonic = "Wert einer monotonen Uhr"
PythonOct = "Convert integer to octal" PythonOct = "Ganzzahl in Oktal umwandeln"
PythonPhase = "Phase of z" PythonPhase = "Phase von z"
PythonPlot = "Plot y versus x as lines" PythonPlot = "Plotten von y gegen x als Linien"
PythonPolar = "z in polar coordinates" PythonPolar = "z in Polarkoordinaten"
PythonPop = "Remove and return the last item" PythonPop = "Letztes Element abnehmen"
PythonPower = "x raised to the power y" PythonPower = "x erhöht mit der Potenz y"
PythonPrint = "Print object" PythonPrint = "Objekt drucken"
PythonRadians = "Convert x from degrees to radians" PythonRadians = "x von Grad in Bogenmaß umrechnen"
PythonRandint = "Random integer in [a,b]" PythonRandint = "Zufällige Ganzzahl in [a,b]"
PythonRandom = "Floating point number in [0,1[" PythonRandom = "Fließkommazahl in [0,1]"
PythonRandomFunction = "random module function prefix" PythonRandomFunction = "Random-Modul Funktionspräfix"
PythonRandrange = "Random number in range(start,stop)" PythonRandrange = "Zufallszahl im Bereich(start,stop)"
PythonRangeStartStop = "List from start to stop-1" PythonRangeStartStop = "Liste von Start bis Stop-1"
PythonRangeStop = "List from 0 to stop-1" PythonRangeStop = "Liste von 0 bis Stop-1"
PythonRect = "Convert to cartesian coordinates" PythonRect = "In kartesische Koordinaten"
PythonRemove = "Remove the first occurrence of x" PythonRemove = "Entferne das erste Vorkommen von x"
PythonReverse = "Reverse the elements of the list" PythonReverse = "Kehrt die Elemente der Liste um"
PythonRound = "Round to n digits" PythonRound = "Runden auf n Stellen"
PythonScatter = "Draw a scatter plot of y versus x" PythonScatter = "Streudiagramm von y gg. x zeichnen"
PythonSeed = "Initialize random number generator" PythonSeed = "Zufallszahlengenerator initiieren"
PythonSetPixel = "Color pixel (x,y)" PythonSetPixel = "Pixel (x,y) einfärben"
PythonShow = "Display the figure" PythonShow = "Figur anzeigen"
PythonSin = "Sine" PythonSin = "Sinus"
PythonSinh = "Hyperbolic sine" PythonSinh = "Hyperbolischer Sinus"
PythonSleep = "Suspend the execution for t seconds" PythonSleep = "Ausführung aussetzen für t Sekunden"
PythonSort = "Sort the list" PythonSort = "Die Liste sortieren"
PythonSqrt = "Wurzel" PythonSqrt = "Quadratwurzel"
PythonSum = "Sum the items of a list" PythonSum = "Summe der Elemente einer Liste"
PythonTan = "Tangens" PythonTan = "Tangens"
PythonTanh = "Hyperbolic tangent" PythonTanh = "Hyperbolic tangent"
PythonText = "Display a text at (x,y) coordinates" PythonText = "Display a text at (x,y) coordinates"

View File

@@ -62,6 +62,7 @@ PythonFloor = "Floor"
PythonFmod = "a modulo b" PythonFmod = "a modulo b"
PythonFrExp = "Mantissa and exponent of x: (m,e)" PythonFrExp = "Mantissa and exponent of x: (m,e)"
PythonGamma = "Gamma function" PythonGamma = "Gamma function"
PythonGetPalette = "Get theme palette"
PythonGetPixel = "Return pixel (x,y) color" PythonGetPixel = "Return pixel (x,y) color"
PythonGetrandbits = "Integer with k random bits" PythonGetrandbits = "Integer with k random bits"
PythonGrid = "Toggle the visibility of the grid" PythonGrid = "Toggle the visibility of the grid"

View File

@@ -62,6 +62,7 @@ PythonFloor = "Floor"
PythonFmod = "a modulo b" PythonFmod = "a modulo b"
PythonFrExp = "Mantissa and exponent of x: (m,e)" PythonFrExp = "Mantissa and exponent of x: (m,e)"
PythonGamma = "Gamma function" PythonGamma = "Gamma function"
PythonGetPalette = "Get theme palette"
PythonGetPixel = "Return pixel (x,y) color" PythonGetPixel = "Return pixel (x,y) color"
PythonGetrandbits = "Integer with k random bits" PythonGetrandbits = "Integer with k random bits"
PythonGrid = "Toggle the visibility of the grid" PythonGrid = "Toggle the visibility of the grid"

View File

@@ -62,6 +62,7 @@ PythonFloor = "Partie entière"
PythonFmod = "a modulo b" PythonFmod = "a modulo b"
PythonFrExp = "Mantisse et exposant de x : (m,e)" PythonFrExp = "Mantisse et exposant de x : (m,e)"
PythonGamma = "Fonction gamma" PythonGamma = "Fonction gamma"
PythonGetPalette = "Obtient la palette du thème"
PythonGetPixel = "Renvoie la couleur du pixel (x,y)" PythonGetPixel = "Renvoie la couleur du pixel (x,y)"
PythonGetrandbits = "Nombre aléatoire sur k bits" PythonGetrandbits = "Nombre aléatoire sur k bits"
PythonGrid = "Affiche ou masque la grille" PythonGrid = "Affiche ou masque la grille"

View File

@@ -62,6 +62,7 @@ PythonFloor = "Egész része"
PythonFmod = "a modulo b" PythonFmod = "a modulo b"
PythonFrExp = "X mantissája és kiállítója" PythonFrExp = "X mantissája és kiállítója"
PythonGamma = "Gamma funkció" PythonGamma = "Gamma funkció"
PythonGetPalette = "Téma paletta beszerzése"
PythonGetPixel = "Visszatéríti (x,y) színét" PythonGetPixel = "Visszatéríti (x,y) színét"
PythonGetrandbits = "Váletlenszám visszatérítése k biten" PythonGetrandbits = "Váletlenszám visszatérítése k biten"
PythonGrid = "Rács megjelenítése/elrejtése" PythonGrid = "Rács megjelenítése/elrejtése"

View File

@@ -62,6 +62,7 @@ PythonFloor = "Parte intera"
PythonFmod = "a modulo b" PythonFmod = "a modulo b"
PythonFrExp = "Mantissa ed esponente di x : (m,e)" PythonFrExp = "Mantissa ed esponente di x : (m,e)"
PythonGamma = "Funzione gamma" PythonGamma = "Funzione gamma"
PythonGetPalette = "Ottieni la tavolozza del tema"
PythonGetPixel = "Restituisce colore del pixel(x,y)" PythonGetPixel = "Restituisce colore del pixel(x,y)"
PythonGetrandbits = "Numero aleatorio con k bit" PythonGetrandbits = "Numero aleatorio con k bit"
PythonGrid = "Attiva la visibilità della griglia" PythonGrid = "Attiva la visibilità della griglia"

View File

@@ -62,6 +62,7 @@ PythonFloor = "Vloer"
PythonFmod = "a modulo b" PythonFmod = "a modulo b"
PythonFrExp = "Mantisse en exponent van x: (m,e)" PythonFrExp = "Mantisse en exponent van x: (m,e)"
PythonGamma = "Gammafunctie" PythonGamma = "Gammafunctie"
PythonGetPalette = "Thema palet krijgen"
PythonGetPixel = "Geef pixel (x,y) kleur (rgb)" PythonGetPixel = "Geef pixel (x,y) kleur (rgb)"
PythonGetrandbits = "Integer met k willekeurige bits" PythonGetrandbits = "Integer met k willekeurige bits"
PythonGrid = "Verander zichtbaarheid raster" PythonGrid = "Verander zichtbaarheid raster"

View File

@@ -62,6 +62,7 @@ PythonFloor = "Parte inteira"
PythonFmod = "a módulo b" PythonFmod = "a módulo b"
PythonFrExp = "Coeficiente e expoente de x: (m, e)" PythonFrExp = "Coeficiente e expoente de x: (m, e)"
PythonGamma = "Função gama" PythonGamma = "Função gama"
PythonGetPalette = "Obter paleta temática"
PythonGetPixel = "Devolve a cor do pixel (x,y)" PythonGetPixel = "Devolve a cor do pixel (x,y)"
PythonGetrandbits = "Número inteiro aleatório com k bits" PythonGetrandbits = "Número inteiro aleatório com k bits"
PythonGrid = "Alterar visibilidade da grelha" PythonGrid = "Alterar visibilidade da grelha"

View File

@@ -69,6 +69,7 @@ PythonCommandFloor = "floor(x)"
PythonCommandFmod = "fmod(a,b)" PythonCommandFmod = "fmod(a,b)"
PythonCommandFrExp = "frexp(x)" PythonCommandFrExp = "frexp(x)"
PythonCommandGamma = "gamma(x)" PythonCommandGamma = "gamma(x)"
PythonCommandGetPalette = "get_palette()"
PythonCommandGetPixel = "get_pixel(x,y)" PythonCommandGetPixel = "get_pixel(x,y)"
PythonCommandGetrandbits = "getrandbits(k)" PythonCommandGetrandbits = "getrandbits(k)"
PythonCommandGrid = "grid()" PythonCommandGrid = "grid()"

View File

@@ -197,7 +197,8 @@ const ToolboxMessageTree KandinskyModuleChildren[] = {
ToolboxMessageTree::Leaf(I18n::Message::PythonCommandDrawCircle, I18n::Message::PythonDrawCircle), ToolboxMessageTree::Leaf(I18n::Message::PythonCommandDrawCircle, I18n::Message::PythonDrawCircle),
ToolboxMessageTree::Leaf(I18n::Message::PythonCommandFillRect, I18n::Message::PythonFillRect), ToolboxMessageTree::Leaf(I18n::Message::PythonCommandFillRect, I18n::Message::PythonFillRect),
ToolboxMessageTree::Leaf(I18n::Message::PythonCommandFillCircle, I18n::Message::PythonFillCircle), ToolboxMessageTree::Leaf(I18n::Message::PythonCommandFillCircle, I18n::Message::PythonFillCircle),
ToolboxMessageTree::Leaf(I18n::Message::PythonCommandFillPolygon, I18n::Message::PythonFillPolygon) ToolboxMessageTree::Leaf(I18n::Message::PythonCommandFillPolygon, I18n::Message::PythonFillPolygon),
ToolboxMessageTree::Leaf(I18n::Message::PythonCommandGetPalette, I18n::Message::PythonGetPalette)
}; };
const ToolboxMessageTree IonModuleChildren[] = { const ToolboxMessageTree IonModuleChildren[] = {

View File

@@ -429,6 +429,13 @@ Q(large_font)
Q(small_font) Q(small_font)
Q(wait_vblank) Q(wait_vblank)
Q(get_keys) Q(get_keys)
Q(get_palette)
Q(PrimaryText)
Q(SecondaryText)
Q(AccentText)
Q(Toolbar)
Q(HomeBackground)
// Keys QSTRs // Keys QSTRs
Q(left) Q(left)

View File

@@ -2,9 +2,11 @@ extern "C" {
#include "modkandinsky.h" #include "modkandinsky.h"
#include <py/runtime.h> #include <py/runtime.h>
} }
#include <escher/palette.h>
#include <kandinsky.h> #include <kandinsky.h>
#include <ion.h> #include <ion.h>
#include "port.h" #include "port.h"
#include <py/obj.h>
static mp_obj_t TupleForKDColor(KDColor c) { static mp_obj_t TupleForKDColor(KDColor c) {
@@ -245,3 +247,14 @@ mp_obj_t modkandinsky_get_keys() {
return result; return result;
} }
mp_obj_t modkandinsky_get_palette() {
mp_obj_t modkandinsky_palette_table = mp_obj_new_dict(0);
mp_obj_dict_store(modkandinsky_palette_table, MP_ROM_QSTR(MP_QSTR_PrimaryText), TupleForKDColor(Palette::PrimaryText));
mp_obj_dict_store(modkandinsky_palette_table, MP_ROM_QSTR(MP_QSTR_SecondaryText), TupleForKDColor(Palette::SecondaryText));
mp_obj_dict_store(modkandinsky_palette_table, MP_ROM_QSTR(MP_QSTR_AccentText), TupleForKDColor(Palette::AccentText));
mp_obj_dict_store(modkandinsky_palette_table, MP_ROM_QSTR(MP_QSTR_Toolbar), TupleForKDColor(Palette::Toolbar));
mp_obj_dict_store(modkandinsky_palette_table, MP_ROM_QSTR(MP_QSTR_HomeBackground), TupleForKDColor(Palette::HomeBackground));
return modkandinsky_palette_table;
}

View File

@@ -11,3 +11,4 @@ mp_obj_t modkandinsky_fill_circle(size_t n_args, const mp_obj_t *args);
mp_obj_t modkandinsky_fill_polygon(size_t n_args, const mp_obj_t *args); mp_obj_t modkandinsky_fill_polygon(size_t n_args, const mp_obj_t *args);
mp_obj_t modkandinsky_wait_vblank(); mp_obj_t modkandinsky_wait_vblank();
mp_obj_t modkandinsky_get_keys(); mp_obj_t modkandinsky_get_keys();
mp_obj_t modkandinsky_get_palette();

View File

@@ -11,6 +11,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(modkandinsky_fill_circle_obj, 4, 4, m
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(modkandinsky_fill_polygon_obj, 2, 2, modkandinsky_fill_polygon); STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(modkandinsky_fill_polygon_obj, 2, 2, modkandinsky_fill_polygon);
STATIC MP_DEFINE_CONST_FUN_OBJ_0(modkandinsky_wait_vblank_obj, modkandinsky_wait_vblank); STATIC MP_DEFINE_CONST_FUN_OBJ_0(modkandinsky_wait_vblank_obj, modkandinsky_wait_vblank);
STATIC MP_DEFINE_CONST_FUN_OBJ_0(modkandinsky_get_keys_obj, modkandinsky_get_keys); STATIC MP_DEFINE_CONST_FUN_OBJ_0(modkandinsky_get_keys_obj, modkandinsky_get_keys);
STATIC MP_DEFINE_CONST_FUN_OBJ_0(modkandinsky_get_palette_obj, modkandinsky_get_palette);
STATIC const mp_rom_map_elem_t modkandinsky_module_globals_table[] = { STATIC const mp_rom_map_elem_t modkandinsky_module_globals_table[] = {
{ MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_kandinsky) }, { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_kandinsky) },
@@ -27,6 +28,7 @@ STATIC const mp_rom_map_elem_t modkandinsky_module_globals_table[] = {
{ MP_ROM_QSTR(MP_QSTR_small_font), mp_const_false }, { MP_ROM_QSTR(MP_QSTR_small_font), mp_const_false },
{ MP_ROM_QSTR(MP_QSTR_wait_vblank), (mp_obj_t)&modkandinsky_wait_vblank_obj }, { MP_ROM_QSTR(MP_QSTR_wait_vblank), (mp_obj_t)&modkandinsky_wait_vblank_obj },
{ MP_ROM_QSTR(MP_QSTR_get_keys), (mp_obj_t)&modkandinsky_get_keys_obj }, { MP_ROM_QSTR(MP_QSTR_get_keys), (mp_obj_t)&modkandinsky_get_keys_obj },
{ MP_ROM_QSTR(MP_QSTR_get_palette), (mp_obj_t)&modkandinsky_get_palette_obj },
}; };
STATIC MP_DEFINE_CONST_DICT(modkandinsky_module_globals, modkandinsky_module_globals_table); STATIC MP_DEFINE_CONST_DICT(modkandinsky_module_globals, modkandinsky_module_globals_table);