Menu

APP_TEMPLATE

Benedict Jäggi

APP_TEMPLATE.py

Go back [Home]

This file provides an App-class derived from APP_BASE.BaseAppClass.

A basic application with a close button.
Use this template to create your own apps.
Just save it as another file name and fiddle around with it.
Don't forget to import it in MAIN.py ([MAIN]), else it won't work.
Also, don't forget to set the right App name in the APP_BASE.registerApplication call at the end of the file.
It's usually the App file name without .py.
This name is used when calling APP_BASE.setCurrentApp.

App class Functions

You can overwrite each of the following functions or leave them alone.
Note that, when you NOT overwrite the update function, it will draw the "empty application" screen.

def __init__()

Constructor. Use this to create class member variables.
But load stuff into them with initialize() when everything is set up properly.

def initialize(self)

Will be called when you first start the app. It will be called once in the whole system running process.
If you want to do something each time the app is switched to, use onSwitchToApp() instead.

def update(self, screen, deltatime)

This is the main update function of your app. It gets called every frame, after the screen was cleared and before the display gets flipped.
Use that function to update and draw your app. This function is only called on the current running App.

screen is the pygame screen surface to be drawed on. Use it when you draw directly to the screen.
deltatime is the time in seconds that passed since the last frame. e.g. 0.01 = 10ms. Use it to update your stuff "in time".
e.g. x = x + speed * deltatime = move speed pixels in one second

def backgroundUpdate(self, deltatime)

This is the update function for Apps that run in the background (no matter which App is the active one).
It gets called every frame for ALL Apps that are initialized. It also gets called when the App is the current one,
right before the Apps update function.

e.g. Update an alarm clock timer with backgroundUpdate so that it updates the time even if another App is running.

deltatime is the time that passed since the last frame in seconds. See update above for further information.

def onSwitchToApp(self)

Gets called every time the app is switched to with APP_BASE.setCurrentApp().

def onLeaveApp(self)

Gets called when this is the active app and APP_BASE.setCurrentApp is called.
(Even if the new App is the same App.)

def onMouseDown(self)

Gets called ONCE when the display is touched FIRST.
If you need the mouse position, import UITools.py and use UITools.mousex and UITools.mousey.

def onMouseUp(self)

Gets called ONCE when the display is released.
If you need the mouse position, import UITools.py and use UITools.mousex and UITools.mousey.


That's everything you need to create, initialize and update your app. Have Fun creating your own one.
You can draw stuff using the pygame library which is used all over in this system.
Pygame has its own documentation here: https://www.pygame.org/docs/


The next section is [UITools] for drawing generic stuff and helper variables which are used all over.
You may use that in your own apps to generate a "system styled" view of your stuff.

If you want to go deeper in the system, look at [APP_BASE] instead.

Or look at [APP_MENU] to create another main menu app.

Or you may go back [Home].


Related

Wiki: APP_BASE
Wiki: APP_MENU
Wiki: Complex Main Example
Wiki: Home
Wiki: MAIN
Wiki: NEW_MAIN_EXAMPLE
Wiki: UITools

MongoDB Logo MongoDB