在 Taipy - 虚拟环境中刷新变量

问题描述 投票:0回答:2

我在虚拟环境中制作了一个 Taipy 应用程序,并在执行一些操作后使用 state.refresh 来实现窗口,并且运行正常。我已更改为其他计算机,最初重新创建了虚拟环境,在运行“requirements.txt”以具有相同的库并运行程序和服务器正常初始化后。但 state.refresh 不起作用并显示以下错误:

“用户警告:on_action:函数“on_iniciar”中引发异常: 变量“刷新”未定义。 用户警告:on_action:'tpec_TpExPr_on_iniciar_TPMDL_3'不是有效函数”

他将刷新视为变量而不是方法。

可能出现什么问题?

附上代码

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)
virtualenv refresh taipy
2个回答
0
投票

你能用这样简单的代码复制它吗?如果这有效,请尝试简化您的代码,直到它再次有效。

from taipy import Gui 
import pandas as pd


data = pd.DataFrame({"x": [1, 2, 3], "y": [4, 5, 6]})

md = """
<|{data}|table|> <|Update|button|on_action=on_update|>
"""

def on_update(state):
    state.data["x"][2] = 10
    state.refresh('data')

Gui(md).run()

另外,你用的 Taipy 版本是什么?


0
投票

我发现问题了。由于某种原因,在重新创建虚拟环境时,或者它丢失了一些信息,或者它从缓存中收集了信息(taipy 版本不同)。我卸载了taipy,用“pip cache purge”清除了缓存并重新安装,它工作正常,我意识到当在工作的机器上调用“state.refresh”时,它会正确地建议刷新变量,而在不工作的机器上它没有显示建议

© www.soinside.com 2019 - 2024. All rights reserved.