Hi guys, I have a problem with my code:
I don’t understand what’s wrong with my function to enable the swipe right gesture.
Thank you in advance.
# coding: utf-8
import ui
import console
import speech
shows_result = False
class Vocal():
vocal = False
def voice(quote, vocal):
if vocal:
speech.say(quote)
def button_pressed(sender):
deleteAll = 'AC'
deleteOne = 'C'
numbers = '0123456789'
symbols = '+-x÷='
st = sender.title
vocal = False
global shows_result
label = sender.superview['label1']
label2 = sender.superview['label2']
if st in numbers:
voice(st,Vocal.vocal)
if shows_result or label.text == '0':
label.text = st
else:
label.text += st
elif st == '.' and label.text[-1] != '.':
label.text += st
voice("punto", Vocal.vocal)
elif st in '+-x÷':
if label.text[-1] in '+-x÷':
label.text = label.text[:-1] + st
elif st == '+':
label.text = label.text + st
voice('più',Vocal.vocal)
elif st == '-':
label.text = label.text + st
voice('meno',Vocal.vocal)
elif st == 'x':
label.text = label.text + st
voice('per',Vocal.vocal)
elif st == '÷':
label.text = label.text + st
voice('diviso',Vocal.vocal)
else:
label.text += st
elif st == 'AC':
label.text = '0'
voice('Cancella tutto',Vocal.vocal)
if st == 'VO':
Vocal.vocal ^= True #con ^= cambio lo stato del booleano da true a false o da false a true
if Vocal.vocal:
voice('Audio attivato',1)
else:
voice('Audio disattivato',1)
elif st == 'C':
label.text = label.text[:-1]
voice('Cancella un carattere',Vocal.vocal)
elif st == '=':
voice("uguale",Vocal.vocal)
try:
label2.text = label.text + '='
expr = label.text.replace('÷', '/').replace('x', '*')
label.text = str(eval(expr))
voice(label.text,Vocal.vocal)
except (SyntaxError, ZeroDivisionError):
label.text = 'ERROR'
shows_result = True
if st != '=':
shows_result = False
def swipe_handler(sender):
gestures = Gestures()
l = ui.Label
Gestures.add_swipe(label.text, label.text[:-1], direction = Gestures.RIGHT)