API

This document describes the interfaces of PieTime.

Application

class pie_time.PieTime(deck, screen_size=(320, 240), fps=20, blanker_schedule=None, click_to_unblank_interval=None, click_to_transition=True, verbose=False, log_path=None)[source]

The PieTime application.

Parameters:
  • deck – the deck
  • screen_size – tuple of (width, height) to use as the screen size
  • fps – number of frames per second to limit rendering to
  • blanker_schedule – blanker schedule
  • click_to_unblank_interval – time interval for click to unblank
  • click_to_transition – boolean defining if click to transition is enabled
  • verbose – boolean defining if verbose logging should be on
  • log_path – path to log file (if omitted, stdout will be used)
BACKGROUND_COLOR = (0, 0, 0)

Default background color

BLANK_COLOR = (0, 0, 0)

Blanked screen color

CARD_INTERVAL = 60

Default card display duration interval

CLICK_TO_TRANSITION_REGION_SIZE = 30

Defines size of click to transition region square

KEY_QUIT = 27

Defines key which quits the application

destroy_cards()[source]

Destroys the cards.

Calls the pie_time.AbstractCard.quit() of each card.

events = None

List of events captured in this frame

fill_screen()[source]

Fills the screen surface with color defined in pie_time.PieTime.BACKGROUND_COLOR.

get_screen()[source]

Creates and returns the screen screen surface.

init_cards()[source]

Initializes the cards.

Initialization of a card consits of the following steps:

init_pygame()[source]

Initializes PyGame and the internal clock.

log_path = None

Path to log file. If None, stdout will be used for logging.

logger

The application-wide logging.Logger object.

quit()[source]

Tells the application to quit.

quit_pygame()[source]

Quits PyGame.

run(standalone=True)[source]

Runs the application.

This method contains the app’s main loop and it never returns. Upon quitting, this method will call the sys.exit() function with the status code (99 if an unhandled exception occurred, 0 otherwise).

The application will quit under one of the following conditions:

  • An unhandled exception reached this method,
  • PyGame requested to quit (e.g. due to closing the window),
  • Some other code called the pie_time.PieTime.quit() method on the application.

Before quitting the pie_time.PieTime.destroy_cards() and pie_time.PieTime.quit_pygame() methods will be called to clean up.

screen = None

The screen surface

screen_size = None

The screen size tuple

will_blank()[source]

Called before blanking the screen.

This method can be used to perform additional operations before blanking the screen.

The default implementation does nothing.

will_unblank()[source]

Called before unblanking the screen.

This method can be used to perform additional operations before unblanking the screen.

The default implementation does nothing.

Abstract Card

class pie_time.AbstractCard[source]

The abstract card class.

All the custom cards must inherit from this class.

Application binding and settings.

The application calls the card’s pie_time.AbstractCard.set_app() and pie_time.AbstractCard.set_settings() methods during initialization (before calling the pie_time.AbstractCard.initialize() method).

The application reference is stored in _app attribute.

The settings dictionary is stored in _settings attribute and defaults to an empty dictionary.

Drawing

All the drawing on the card’s surface should be done in the pie_time.AbstractCard.tick() method. The method’s implementation should be as fast as possible to avoid throttling the FPS down.

Resources

The pie_time.AbstractCard.path_for_resource() method can be used to get an absolute path to a resource file. The card’s resource folder should be placed along with the module containing the card’s class.

Name of the resource folder can be customized by overriding the pie_time.AbstractCard.RESOURCE_FOLDER attribute.

RESOURCE_FOLDER = 'resources'

Name of the folder containing the resources

background_color

The background color. Defaults to pie_time.PieTime.BACKGROUND_COLOR.

height

The card’s surface height. Defaults to the app screen’s height.

hide()[source]

Hides the card.

The application calls this method each time the card resignes the current card.

This method can be used to e.g. stop threads which aren’t supposed to be running when the card isn’t being displayed.

The default implementation does nothing.

initialize()[source]

Initializes the card.

The application calls this method right after creating an instance of the class.

This method can be used to perform additional initialization on the card, e.g. loading resources, setting the initial state etc.

The default implementation does nothing.

path_for_resource(resource, folder=None)[source]

Returns an absolute path for resource. The optional folder keyword argument allows specifying a subpath.

quit()[source]

Initializes the card.

This method can be used to perform additional cleanup on the card, e.g. stop threads, free resources etc.

The default implementation does nothing.

set_app(app)[source]

Binds the card with the app.

set_settings(settings)[source]

Sets settings as the card’s settings.

show()[source]

Shows the card.

The application calls this method each time the card becomes the current card.

This method can be used to reset initial state, e.g. sprite positions.

The default implementation does nothing.

surface

The cards surface. The surface width and height are defined by the respective properties of the class.

tick()[source]

Ticks the card.

The application calls this method on the current card in every main loop iteration.

This method should be used to perform drawing and other operations needed to properly display the card on screen.

Subclasses must override this method.

width

The card’s surface width. Defaults to the app screen’s width.