I made a Taipy app in a virtual enviroment and had use state.refresh to actualize the window after some actions, and had running OK. I had change to other computer an initially had re-create the virtual enviroiment, after run the "requirements.txt" to has the same libraries and had running the program and the server initialized normally. But the state.refresh dont work and show the following error:
"UserWarning: on_action: Exception raised in function 'on_iniciar': Variable 'refresh' is not defined. UserWarning: on_action: 'tpec_TpExPr_on_iniciar_TPMDL_3' is not a valid function"
He identify the refresh as a variable and not as a method.
What may the problem?
Code atached
from taipy import Gui
from taipy.gui import State, notify
from DAQ_Teclado4x4 import JigaAngejiga
import serial.tools.list_ports
import numpy as np
import time
import csv
import configparser
import winsound
...
def on_iniciar(state):
starttime = time.time()
aux_valindexPress = 0
if state.keypad_choice[aux_valindexPress]==state.keypad[aux_valindexPress+1][0]:
notify(state, "info", "Clicar na membrana")
state.keypad_choice[aux_valindexPress]=state.keypad[aux_valindexPress+1][1]
state.refresh("keypad_choice")
while aux_valindexPress<15:
aux_valindexPress, valResistencia = avaliaTecla(state)
if aux_valindexPress !=-1 :
#print("{:.2f}".format(valResistencia))
state.resData[aux_valindexPress]=valResistencia
state.dados_teclado.update({"Resistencia":state.resData})
state.refresh("dados_teclado")
if ((valResistencia>=state.limite_inferior) and (valResistencia<=state.limite_superior)):
state.keypad_choice[aux_valindexPress]=state.keypad[aux_valindexPress+1][2]
state.valor_aprovado+=1
else:
state.keypad_choice[aux_valindexPress]=state.keypad[aux_valindexPress+1][0]
state.valor_aprovado-=1
state.refresh("keypad_choice")
#notify(state, "info", "Tecla -OK")
if aux_valindexPress<15:
state.keypad_choice[aux_valindexPress+1]=state.keypad[aux_valindexPress+2][1]
state.refresh("keypad_choice")
#print(state.valor_aprovado)
#print(aux_valindexPress)
if (state.valor_aprovado>=16) and (aux_valindexPress==15):
state.label_end="APROVADO"
state.tag_class="success"
winsound.Beep(3800, 200)
winsound.Beep(3800, 200)
t = time.time()
current_datetime=time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(t))
csv_data = [current_datetime] + state.resData + ["APROVADO"] + [state.limite_superior] + [state.limite_inferior]
# Write data to CSV file
with open(state.csv_caminho_arquivo, mode="a", newline="") as csv_file:
csv_writer = csv.writer(csv_file)
csv_writer.writerow(csv_data)
# print(f"Data saved to {csv_caminho_arquivo}")
elif (state.valor_aprovado<16) and (aux_valindexPress==15):
state.label_end="REPROVADO"
state.tag_class="error"
winsound.Beep(5200, 1000)
t = time.time()
current_datetime=time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(t))
csv_data = [current_datetime] + state.resData +["REPROVADO"] + [state.limite_superior] + [state.limite_inferior]
# Write data to CSV file
with open(state.csv_caminho_arquivo, mode="a", newline="") as csv_file:
csv_writer = csv.writer(csv_file)
csv_writer.writerow(csv_data)
#print(f"Data saved to {csv_caminho_arquivo}")
telaps=round((time.time()-starttime),2)
# print(telaps)
if telaps >state.tempo_teste:
aux_valindexPress=16
if (state.valor_aprovado<16):
state.label_end="REPROVADO"
state.tag_class="error"
winsound.Beep(5200, 1000)
notify(state, "warning", "Teste concluido")
...
#GUIDE
root_md="# TECLADO DE MEMBRANA <|navbar|>"
page1_md= """
## TESTE
<|layout|columns = 500px 1fr|
<|
<|
<center>
<|{label_end}|button|id=btn03|class_name={tag_class}|>
</center>
|>
<|
<center>
| <|{keypad_choice[0]}|status|lov={keypad[1]}|> | <|{keypad_choice[1]}|status|lov={keypad[2]}|> | <|{keypad_choice[2]}|status|lov={keypad[3]}|> | <|{keypad_choice[3]}|status|lov={keypad[4]}|>|
</center>
|>
<|
<center>
| <|{keypad_choice[4]}|status|lov={keypad[5]}|> | <|{keypad_choice[5]}|status|lov={keypad[6]}|> | <|{keypad_choice[6]}|status|lov={keypad[7]}|> | <|{keypad_choice[7]}|status|lov={keypad[8]}|>|
</center>
|>
<|
<center>
| <|{keypad_choice[8]}|status|lov={keypad[9]}|> | <|{keypad_choice[9]}|status|lov={keypad[10]}|> | <|{keypad_choice[10]}|status|lov={keypad[11]}|> | <|{keypad_choice[11]}|status|lov={keypad[12]}|>|
</center>
|>
<|
<center>
| <|{keypad_choice[12]}|status|lov={keypad[13]}|> | <|{keypad_choice[13]}|status|lov={keypad[14]}|> | <|{keypad_choice[14]}|status|lov={keypad[15]}|> | <|{keypad_choice[15]}|status|lov={keypad[16]}|>|
</center>
|>
<|INICIAR|button|on_action={on_iniciar}|id=btn01|>
<|RESET|button|on_action={on_reset}|id=btn02|>
|>
<|
<|{dados_teclado}|chart|mode=lines|x=Teclas|y[1]=Resistencia|y[2]=ResMax|y[3]=ResMin|line[1]=dash|color[2]=blue|color[3]=red|>>
|>
|>
"""
page2_md="""
## ENGENHARIA
#####Porta de comunicação com a Jiga
<|layout|columns = 200px 1fr|
<|
<|{porta_jiga}|selector|lov={ports}|dropdown|>
|>
<|
<|{sel_porta_jiga}|toggle|lov={[("id1", "Não conetada"), ("id2", "Conetada - OK")]}|on_change={on_selportaJiga}|allow_unselect=True|>
|>
|>
#####Límite do valor de resistência
<|layout|columns = 200px 200px 200px
<|
Superior (Ohms)
<|{limite_superior}|number|on_change={change_up_limit}|>
|>
<|
Inferior (Ohms)
<|{limite_inferior}|number|on_change={change_down_limit}|>
|>
|>
#####Tempo de teste
<|layout|columns = 200px 200px 200px
<|
Tempo (seg)
<|{tempo_teste}|number|>
|>
|>
"""
#Nao pode usar acento no nome da pagina, pois nao aparece a certa
pages = {
"/": root_md,
"Teste": page1_md,
"Engenharia": page2_md
}
Gui(pages=pages).run(use_reloader=True,port=50000)
I found the problem. For some reason when recreating the virtual environment or it had some loss of information or it collected information from the cache (the taipy version was different). I uninstalled taipy, cleared cache with "pip cache purge" and reinstalled and it worked normally, I realized that when calling "state.refresh" on the machine that worked and it suggested the refresh variable correctly and on the machine that didn't work it didn't show a suggestion