gint — CASIO calculator hardware access

The gint module provides a high-level interface to the gint library, allowing direct access to the calculator’s hardware features like the display and keyboard.

Classes

class gint.KeyEvent

A data object representing a keyboard event. This object is returned by functions like pollevent() and getkey(). It contains the following read-only attributes:

time

Timestamp of the event.

mod
shift
alpha

Booleans indicating the state of modifier keys.

type

The type of event, such as KEYEV_DOWN or KEYEV_UP.

key

The key code of the key involved in the event (e.g., KEY_EXE).

x
y

For touch events, the coordinates of the touch.

class gint.image

Represents a graphical image stored in VRAM. It is designed to handle various pixel formats.

On black-and-white models, it supports 2-5 colors through different profiles, with data stored in a packed row-major format (32 pixels per 4-byte word).

__init__(profile, color_count, width, height, stride, data, palette)

Constructs an image from pixel data and palette information.

Parameters:
  • profile – Image format constant (e.g., IMAGE_MONO, IMAGE_RGB565A).

  • color_count – Number of colors in the palette.

  • width – Image width in pixels.

  • height – Image height in pixels.

  • stride – Number of bytes per row of pixel data.

  • data – A buffer-like object containing the raw pixel data.

  • palette – A buffer-like object containing the color palette data.

format

The image format, represented by an IMAGE_* constant.

flags
color_count

Number of colors in the image’s palette.

width
height

The dimensions of the image in pixels.

stride

The number of bytes per row in the image data.

data

A buffer-like object holding the raw pixel data.

palette

A buffer-like object holding the color palette.

class gint.GintFont

Represents a custom font that can be used for drawing text. Created by the font() constructor.

prop
line_height
data_height
block_count
glyph_count
char_spacing
line_distance
blocks
data
width
storage_size
glyph_index
glyph_width

Functions

Keyboard Functions

gint.clearevents()

Clears all pending keyboard events from the event queue. This is useful when you need to check the immediate keyboard state with keydown() without being influenced by historical events. It is equivalent to running

while pollevent().type != KEYEV_NONE: pass
gint.pollevent() KeyEvent

Retrieves the oldest unread keyboard event from the queue. This function is non-blocking.

Returns:

A KeyEvent object describing the event. If the queue is empty, it returns a dummy event where type is KEYEV_NONE.

Example:

# Process all queued events
while True:
    ev = pollevent()
    if ev.type == KEYEV_NONE:
        break
    # Handle the event here
gint.keydown(key) bool

Checks if a specific key is currently held down.

Parameters:

key – The key to check, using a KEY_* constant.

Returns:

True if the key is pressed, False otherwise.

Note

This function requires that the event queue has been recently processed by calling clearevents() or pollevent().

gint.keydown_all(keys) bool

Checks if all specified keys are currently held down simultaneously.

Parameters:

keys – A list of KEY_* constants.

Returns:

True if all keys are pressed, False otherwise.

gint.keydown_any(keys) bool

Checks if any of the specified keys are currently held down.

Parameters:

keys – A list of KEY_* constants.

Returns:

True if at least one key is pressed, False otherwise.

gint.cleareventflips()

Resets the tracking state for key presses and releases. This should be called before using keypressed() or keyreleased() in a loop (e.g., at the start of each frame in a game).

gint.keypressed(key) bool

Checks if a key was pressed since the last call to cleareventflips().

Parameters:

key – The KEY_* constant to check.

Returns:

True if the key transitioned from a released to a pressed state.

gint.keyreleased(key) bool

Checks if a key was released since the last call to cleareventflips().

Parameters:

key – The KEY_* constant to check.

Returns:

True if the key transitioned from a pressed to a released state.

gint.getkey() KeyEvent

Waits (blocks execution) for a key press or repeat event and returns it. System actions like pressing the MENU key may exit the program.

Returns:

A KeyEvent object with details of the key press, including shift/alpha modifiers.

gint.getkey_opt(options, timeout_ms=None) KeyEvent

A configurable, non-blocking version of getkey() with a timeout.

Parameters:
  • options – A combination of GETKEY_* flags (e.g., GETKEY_MOD_SHIFT | GETKEY_REP_ARROWS).

  • timeout_ms – The maximum time to wait in milliseconds. If None, it waits indefinitely.

Returns:

A KeyEvent object, or a dummy event with type=KEYEV_NONE if the timeout is reached.

gint.keycode_function(keycode) int

Gets the F-key number (1-6) associated with a key code.

Parameters:

keycode – A key code constant (e.g., KEY_F1).

Returns:

The F-key number, or -1 if the key is not an F-key.

gint.keycode_digit(keycode) int

Gets the digit (0-9) associated with a numeric key code.

Parameters:

keycode – A key code constant (e.g., KEY_0).

Returns:

The digit value, or -1 if the key is not a digit key.

Display Functions

gint.C_RGB(r, g, b) int

Creates a color value from RGB components.

Note

This function is only available on color display models.

Parameters:
  • r – Red component (0-31).

  • g – Green component (0-31).

  • b – Blue component (0-31).

Returns:

An integer representing the color.

gint.dclear(color)

Fills the entire screen with a specified color.

gint.dupdate()

Refreshes the display to show all changes made to the VRAM. This must be called after drawing operations for them to become visible.

gint.dpixel(x, y, color)

Draws a single pixel at the specified coordinates.

gint.dgetpixel(x, y) int

Gets the color of the pixel at the specified coordinates from VRAM.

Returns:

The color value, or -1 if the coordinates are out of bounds.

gint.drect(x1, y1, x2, y2, color)

Draws a filled rectangle. The coordinates (x1, y1) and (x2, y2) can be any two opposite corners.

gint.drect_border(x1, y1, x2, y2, fill_color, border_width, border_color)

Draws a filled rectangle with an inner border.

gint.dline(x1, y1, x2, y2, color)

Draws a straight line between two points.

gint.dhline(y, color)

Draws a horizontal line across the entire width of the screen at a given y-coordinate.

gint.dvline(x, color)

Draws a vertical line across the entire height of the screen at a given x-coordinate.

gint.dcircle(x, y, r, fill, border)

Draws a circle with a specified fill and border color. Use C_NONE for a transparent fill or border.

gint.dellipse(x1, y1, x2, y2, fill, border)

Draws an ellipse that fits within the specified bounding box.

gint.dpoly(vertices, fill, border)

Draws a polygon. The polygon is automatically closed if the first and last vertices are not the same.

Parameters:
  • vertices – A flat list of coordinates, e.g., [x0, y0, x1, y1, ...].

  • fill – The fill color (use C_NONE for transparent).

  • border – The border color (use C_NONE for no border).

gint.dtext(x, y, fg, text)

Draws a string of text at the specified coordinates.

Parameters:
  • x – Left starting position in pixels.

  • y – Top starting position in pixels.

  • fg – The text color.

  • text – The string to display.

gint.dtext_opt(x, y, fg, bg, halign, valign, text, size)

Draws text with advanced options for alignment, background, and wrapping.

Parameters:
  • x – Reference X coordinate.

  • y – Reference Y coordinate.

  • fg – Text color.

  • bg – Background color (C_NONE for transparent).

  • halign – Horizontal alignment (DTEXT_LEFT, DTEXT_CENTER, DTEXT_RIGHT).

  • valign – Vertical alignment (DTEXT_TOP, DTEXT_MIDDLE, DTEXT_BOTTOM).

  • text – The string to display.

  • size – Maximum width for wrapping; -1 to disable.

gint.dimage(x, y, img)

Draws a complete image object at the specified coordinates.

gint.dsubimage(x, y, img, left, top, width, height)

Draws a specific subregion of an image object at the specified coordinates.

Image Constructors

Note

The following functions are used to create image objects for color displays.

gint.image_rgb565(width, height, data) image
gint.image_rgb565a(width, height, data) image
gint.image_p8_rgb565(width, height, data, palette) image
gint.image_p8_rgb565a(width, height, data, palette) image
gint.image_p4_rgb565(width, height, data, palette) image
gint.image_p4_rgb565a(width, height, data, palette) image

Font Constructor

gint.font(...) GintFont

Constructs a custom GintFont object. Takes numerous parameters describing the font’s properties and glyph data, such as line_height, char_spacing, blocks, and data.

Constants

Keyboard Constants

  • Key Codes: KEY_F1, KEY_F2, KEY_F3, KEY_F4, KEY_F5, KEY_F6, KEY_SHIFT, KEY_OPTN, KEY_VARS, KEY_MENU, KEY_LEFT, KEY_UP, KEY_ALPHA, KEY_SQUARE, KEY_POWER, KEY_EXIT, KEY_DOWN, KEY_RIGHT, KEY_XOT, KEY_LOG, KEY_LN, KEY_SIN, KEY_COS, KEY_TAN, KEY_FRAC, KEY_FD, KEY_LEFTP, KEY_RIGHTP, KEY_COMMA, KEY_ARROW, KEY_7, KEY_8, KEY_9, KEY_DEL, KEY_4, KEY_5, KEY_6, KEY_MUL, KEY_DIV, KEY_1, KEY_2, KEY_3, KEY_ADD, KEY_SUB, KEY_0, KEY_DOT, KEY_EXP, KEY_NEG, KEY_EXE, KEY_ACON, KEY_HELP.

  • Key Event Types: KEYEV_NONE, KEYEV_DOWN, KEYEV_UP, KEYEV_HOLD, KEYEV_TOUCH_DOWN, KEYEV_TOUCH_UP, KEYEV_TOUCH_DRAG.

  • getkey() Options: GETKEY_MOD_SHIFT, GETKEY_MOD_ALPHA, GETKEY_BACKLIGHT, GETKEY_MENU, GETKEY_REP_ARROWS, GETKEY_REP_ALL, GETKEY_REP_PROFILE, GETKEY_FEATURES, GETKEY_NONE, GETKEY_DEFAULT.

Display Constants

  • Screen Dimensions: DWIDTH, DHEIGHT.

  • Text Alignment: DTEXT_LEFT, DTEXT_CENTER, DTEXT_RIGHT, DTEXT_TOP, DTEXT_MIDDLE, DTEXT_BOTTOM.

  • Colors: C_WHITE, C_LIGHT, C_DARK, C_BLACK, C_INVERT, C_NONE, C_LIGHTEN, C_DARKEN, C_RED, C_GREEN, C_BLUE.

  • Image Formats: IMAGE_MONO, IMAGE_MONO_ALPHA, IMAGE_GRAY, IMAGE_GRAY_ALPHA, IMAGE_RGB565, IMAGE_RGB565A, IMAGE_P8_RGB565, IMAGE_P8_RGB565A, IMAGE_P4_RGB565, IMAGE_P4_RGB565A.

  • Image Flags: IMAGE_FLAGS_DATA_RO, IMAGE_FLAGS_PALETTE_RO, IMAGE_FLAGS_DATA_ALLOC, IMAGE_FLAGS_PALETTE_ALLOC.