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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -197,7 +197,8 @@ const ToolboxMessageTree KandinskyModuleChildren[] = {
ToolboxMessageTree::Leaf(I18n::Message::PythonCommandDrawCircle, I18n::Message::PythonDrawCircle),
ToolboxMessageTree::Leaf(I18n::Message::PythonCommandFillRect, I18n::Message::PythonFillRect),
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[] = {

View File

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

View File

@@ -2,9 +2,11 @@ extern "C" {
#include "modkandinsky.h"
#include <py/runtime.h>
}
#include <escher/palette.h>
#include <kandinsky.h>
#include <ion.h>
#include "port.h"
#include <py/obj.h>
static mp_obj_t TupleForKDColor(KDColor c) {
@@ -245,3 +247,14 @@ mp_obj_t modkandinsky_get_keys() {
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_wait_vblank();
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_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_palette_obj, modkandinsky_get_palette);
STATIC const mp_rom_map_elem_t modkandinsky_module_globals_table[] = {
{ 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_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_palette), (mp_obj_t)&modkandinsky_get_palette_obj },
};
STATIC MP_DEFINE_CONST_DICT(modkandinsky_module_globals, modkandinsky_module_globals_table);