Code:
import appuifw, e32, key_codes, graphics
RED = (255,0,0) #tuple
BLUE = (0,0,255) #tuple
GRAY = (150, 150, 150)
RectCord = [50,100,80,140]
RountPoint = [125,125]
Direction = u"None"
shap = u"None"
def DrawRound():
shap = u"Round"
img.clear(GRAY)
img.point((125,125), outline = BLUE, width = 30)
handle_redraw(None)
def DrewRect():
shap = u"Rect"
img.clear(GRAY)
img.rectangle((50,100,80,140), fill = RED)
handle_redraw(None)
def MoveRect(Direction):
# put negetive check later
img.clear(GRAY)
if Direction == u"Left":
img.rectangle((50-10,100,80-10,140),fill = RED)
elif Direction == u"Right":
img.rectangle((50+10,100,80+10,140),fill = RED)
elif Direction == u"Up":
img.rectangle((50,100-10,80,140-10),fill = RED)
elif Direction == u"Down":
img.rectangle((50,100+10,80,140+10),fill = RED)
def MoveRound (Direction):
# put negetive check later
img.clear(GRAY)
if Direction == u"Left":
img.point((125-10,125),outline = BLUE, width = 30)
elif Direction == u"Right":
img.point((125+10,125),outline = BLUE, width = 30)
elif Direction == u"Up":
img.point((125,125-10),outline = BLUE, width = 30)
elif Direction == u"Down":
img.point((125,125+10),outline = BLUE, width = 30)
def handle_redraw(rect):
if img:
canvas.blit(img)
def handle_event(event):
if event['keycode'] == key_codes.EKeyLeftArrow:
Direction = u"Left"
if shap.find(u"Round") == 1:
MoveRound(Direction)
else:
MoveRect(Direction)
elif event['keycode'] == key_codes.EKeyRightArrow:
Direction = u"Right"
if shap.find(u"Round") == 1:
MoveRound(Direction)
else:
MoveRect(Direction)
elif event['keycode'] == key_codes.EKeyUpArrow:
Direction = u"Up"
if shap.find(u"Round") == 1:
MoveRound(Direction)
else:
MoveRect(Direction)
elif event['keycode'] == key_codes.EKeyDownArrow:
Direction = u"Down"
if shap.find(u"Round") == 1:
MoveRound(Direction)
else:
MoveRect(Direction)
handle_redraw(None)
def quit():
app_lock.signal()
appuifw.app.title = u"shapMoving"
appuifw.app.menu = [(u"Round",DrawRound),(u"Rectangle",DrewRect)]
img = None
canvas = appuifw.Canvas(redraw_callback = handle_redraw, event_callback = handle_event)
appuifw.app.body = canvas
appuifw.app.screen = "normal"
appuifw.app.exit_key_handler = quit
# Intialise screen with gray
w,h = canvas.size
img = graphics.Image.new((w,h))
img.clear(GRAY)
app_lock = e32.Ao_lock()
app_lock.wait()
here everything is done by appuifw module.