[go: up one dir, main page]

Menu

[eaaafa]: / APP_INPUT.py  Maximize  Restore  History

Download this file

118 lines (98 with data), 3.4 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
# 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)