# INPUT APPLICATION WITH KEYBOARD TO GET USER INPUT
# Get the Input with the APP_INPUT.inputText Variable
import APP_BASE
import APP_MENU
import UITools as ui
inputText=""
inputTitle="Input Please"
underlyingApp="APP_BASE"
exitFunc=ui.nullfunc
def openInputDialog(returnApp="APP_BASE", title="Input", exitfunc=ui.nullfunc, clearinput=True):
global exitFunc
global inputTitle
global inputText
global underlyingApp
underlyingApp=returnApp
exitFunc=exitfunc
inputTitle=title
if clearinput==True:
inputText=""
APP_BASE.setCurrentApp("APP_INPUT", False)
class App(APP_BASE.BaseAppClass):
numberArray=["1","2","3","DEL", "4","5","6","CLR", "7","8","9","", "", "0","", "EXIT"]
def setInputTitle(self):
global inputText, inputTitle
if inputText!="":
APP_MENU.CURRENT_MENU.menuTitle=inputText
else:
APP_MENU.CURRENT_MENU.menuTitle=inputTitle
def menuExitFunc(self):
global underlyingApp, exitFunc
APP_BASE.setCurrentApp(underlyingApp)
exitFunc()
def menuCancelFunc(self):
global underlyingApp
APP_BASE.setCurrentApp(underlyingApp)
def menuDeleteFunc(self):
global inputText
global inputTitle
t=""
if inputText!="":
for q in range(len(inputText)-1):
t=t+inputText[q]
inputText=t
self.setInputTitle()
def menuClearFunc(self):
global inputText
global inputTitle
inputText=""
self.setInputTitle()
def buttonPress(self):
global inputText
if APP_MENU.buttonIndex>=0:
if self.numberArray[APP_MENU.buttonIndex]!="":
inputText=inputText+self.numberArray[APP_MENU.buttonIndex]
self.setInputTitle()
# __init__ is the class constructor.
# It's called by creating an instance below.
# define your non static class member vars here.
def __init__(self):
global inputTitle
self.inputmenu=APP_MENU.cMenu(4,4, inputTitle)
for i in range(len(self.numberArray)):
self.inputmenu.setMenuItem(i, self.numberArray[i], self.buttonPress)
self.inputmenu.setMenuItem(1*4-1,"DEL", self.menuDeleteFunc)
self.inputmenu.setMenuItem(2*4-1,"CLR", self.menuClearFunc)
self.inputmenu.setMenuItem(3*4-1, "CANCEL", self.menuCancelFunc)
self.inputmenu.setMenuItem(4*4-1,"ENTER", self.menuExitFunc)
return
# initialize is called ONCE on FIRST startup of the app,
# after everything is initialized.
def initialize(self):
return
# onSwitchToApp is called everytime when switched to this app
def onSwitchToApp(self):
APP_MENU.CURRENT_MENU=self.inputmenu
self.setInputTitle()
APP_BASE.setCurrentApp("APP_MENU", False)
# onLeaveApp is called everytime when this app is hidden/
# (When it was the current app and APP_BASE.setCurrentApp is called.)
def onLeaveApp(self):
print("--> Left/closed the INPUT Application")
# called once when the mouse/touch is pressed first.
def onMouseDown(self):
return
# called once when the mouse/touch is released
def onMouseUp(self):
return
# main update function when the app is the current app.
def update(self, screen, deltatime):
ui.drawCloseButton(screen)
return
# will be called in each frame when the app was initialized.
# even if it is not the current app.
# called before update.
# drawing screen not available here, only in update.
def backgroundUpdate(self, deltatime):
return
APP_BASE.registerApplication("APP_INPUT", App(), False)