TTµPythonSTUDIO

… downloads

REFERENCE / PYTHON AND GEM

The language.
The connection to GEM.

All 35 Python keywords from the MicroPython lexer used, with explanations and syntax snippets. Below that you will find the native GEM API of version 0.1.

60 concepts

False

Values & logic

The logical value false.

enabled = False

None

Values & logic

No value; often the result of a function without an explicit return.

value = None

True

Values & logic

The logical value true.

enabled = True

and

Values & logic

Logical AND; the right side is only evaluated when necessary.

if ready and enabled:
    print("start")

or

Values & logic

Logical OR, with short-circuit evaluation.

name = value or "Atari"

not

Values & logic

Inverts the logical value.

if not ready:
    print("wachten")

is

Values & logic

Compares object identity. Use == for equality of values.

if value is None:
    print("leeg")

in

Values & logic

Test membership or name the container in a for loop.

print(2 in [1, 2, 3])

if

Program flow

Begins a conditional block. Indentation determines which lines belong to it.

if score > 10:
    print("hoog")

elif

Program flow

Test another condition after if.

elif score == 10:
    print("precies")

else

Program flow

The alternative of if; also useful for loops and try.

else:
    print("alternatief")

for

Program flow

Loops through an iterable such as a list or range.

for i in range(3):
    print(i)

while

Program flow

Repeats as long as a condition is true.

while count < 3:
    count += 1

break

Program flow

Leave the inner loop.

if done:
    break

continue

Program flow

Continues with the next iteration of the inner loop.

if skip:
    continue

pass

Program flow

Does nothing; usable as a temporary empty block.

def later():
    pass

def

Features & classes

Defines a function. In the console, enter a blank line after the entire block.

def twice(x):
    return x * 2

return

Features & classes

Terminates a function and optionally returns a value.

return 42

class

Features & classes

Defines a class with its own methods and data.

class Counter:
    def __init__(self):
        self.value = 0

lambda

Features & classes

Creates a small function with one expression.

twice = lambda x: x * 2

yield

Features & classes

Returns a value from a generator and saves the resumeable state.

def numbers():
    yield 1
    yield 2

global

Features & classes

Allows a function to change a name in the module namespace.

global counter

nonlocal

Features & classes

From a nested function, refers to a name in an encompassing function scope.

nonlocal counter

del

Features & classes

Deletes a name, item, or supported attribute; this is not a guaranteed direct GC round.

del values[0]

try

Error handling

Starts an error handling block.

try:
    value = 1 // 0

except

Error handling

Catches the appropriate exception from a try block.

except ZeroDivisionError:
    print("opgevangen")

finally

Error handling

A cleanup block that is also executed after an exception.

finally:
    print("klaar")

raise

Error handling

Throws an exception or rethrows the active exception.

raise ValueError("Ongeldige waarde")

assert

Error handling

Checks an assumption; if false, AssertionError follows when assertions are active.

assert counter == 3

with

Error handling

Uses a context manager for controlled entry and cleanup. The port supports open() and with for text and binary files.

with resource as value:
    print(value)

import

Modules

Loads a module, such as the built-in gem or gc module.

import gem

from

Modules

Imports chosen names from a module.

from COUNTER import Counter

as

Modules

Provides a local alias on import or an except binding.

import gc as memory

async

Asynchronous syntax

Defines a coroutine. The syntax is enabled, but this port does not provide a asyncio module or ready-made event loop.

async def task():
    return 42

await

Asynchronous syntax

Wait for an awaitable within a coroutine. This in itself does not provide GEM or asyncio integration.

result = await task()

Window

GEM API

Creates a GEM window. Dimensions are those of the work area.

window = gem.Window("Hallo Atari", 360, 180)

Button

GEM API

A button within a Window. Link a Python function with on_click.

button = gem.Button(window, "Klik", 16, 32, 140, 28)

Label

GEM API

Shows text. The text property can be changed at runtime.

label = gem.Label(window, "Hallo", 16, 16, 280, 24)

TextBox

GEM API

A simple text field with mouse focus and keyboard input. on_change responds to input.

field = gem.TextBox(window, "Atari", 16, 48, 240, 24)

CheckBox

GEM API

A check mark of which checked indicates the on/off state.

check = gem.CheckBox(window, "Actief", 16, 96, 240, 24)
check.checked = True

RadioButton

GEM API

A radio button; group chooses the group and checks the selection.

radio = gem.RadioButton(window, "Keuze", 16, 16, 160, 24)

ListBox

GEM API

A list of up to 32 items. Multi_select allows multiple selections.

items = gem.ListBox(window, "", 16, 48, 160, 96)

ComboBox

GEM API

Editable text with a list. The arrow cycles through the items.

choice = gem.ComboBox(window, "", 16, 152, 160, 24)

enabled

GEM API

Enables or disables the operation of a control.

button.enabled = False

visible

GEM API

Shows or hides a control.

label.visible = True

add_item

GEM API

Adds text to a ListBox or ComboBox.

items.add_item("Eerste")

list_index

GEM API

The selected list index; -1 means no selection.

print(items.list_index)

multi_select

GEM API

Enables multiple selection in a ListBox.

items.multi_select = True

selected

GEM API

Asks if a list item is selected.

print(items.selected(0))

set_selected

GEM API

Changes the selection of a list item.

items.set_selected(0, True)

group

GEM API

Divides radio buttons into independent groups from 0 to 31.

radio.group = 1

show

GEM API

Opens the Window. First create the controls and connect their callbacks.

window.show()

close

GEM API

Close the Window. gem.run returns when all Python windows are closed.

window.close()

text

GEM API

Reads or changes the text of a supported control or window.

label.text = "De knop werkt!"

checked

GEM API

Reads or changes the state of a CheckBox.

print(check.checked)

on_click

GEM API

Connects a click to a function. The handler receives the control as a sender.

button.on_click(clicked)

on_change

GEM API

Associates keyboard changes in a TextBox with a function.

field.on_change(changed)

gem.run

GEM API

Processes GEM events until windows are closed or gem.exit is requested.

gem.run()

gem.exit

GEM API

Exit the GUI event loop. This is not the same as closing the Studio.

gem.exit()

gem.alert

GEM API

Shows a GEM message with OK. Maximum five lines of 38 characters; too long text gives ValueError.

gem.alert("Hallo vanaf de Atari!")

Its own module, not a standard library.

The eight GEM classes and their methods are specific to this Atari port. Import the module with import gem. Python standard libraries such as Tkinter or Qt are not included.

__debug__ is also listed in the lexer as a special constant. match and case are not a supported pattern matching feature in this port. The present async/await-syntax does not mean that a asynciolibrary is available.

Use the code snippets as syntax explanations; some belong within a larger block or require predefined variables. Full executable examples are on the examples page.

View a complete GEM program →

Important boundaries.

MicroPython is not a full CPython. The forms preview supports f-strings and open() for text and binary files. Os, network, pip and CPython extensions are not available.

Read the manual and verification →

What do you think?

Tell us what you make, ask a question or share your experience with the development environments.

The count starts with this update; previous downloads are unknown. ZIP packages and ST images count, not unique individuals.

Your name and comment will be visible on the homepage and the associated project site. No email address required. You can delete it via this browser on the site where you post the comment.

Loading comments…