generated from jtyska/ine-5404-sistema-chatbot-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinterface.py
147 lines (101 loc) · 5.01 KB
/
interface.py
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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
import PySimpleGUI as psg
import textwrap as tw
from SistemaChatBot import SistemaChatBot as scb
from Bots.BotZangado import BotZangado
from Bots.BotAmigavel import BotAmigavel
from Bots.BotFitness import BotFitness
from logger import JSONLogger
def criarWindowAjuda():
comandosDocinho = '--> Bom dia;\n\n--> Conte uma piada;\n\n--> Quero um conselho.'
comandosFlorzinha = '--> Bom dia;\n\n--> Conte uma piada;\n\n--> Quero um conselho.'
comandosLindinha = '--> Quero uma opinião sobre o meu treino;\n\n--> Treino para braço;\n\n--> Quero uma opinião sobre o meu shape.\n'
layout_ajuda = [[psg.Text("Comandos de docinho: ", font=('Arial bold', 15))], [psg.Text(comandosDocinho, font = ('Arial', 11))],
[psg.Text("Comandos de florzinha: ", font=('Arial bold', 15))], [psg.Text(comandosFlorzinha, font = ('Arial', 11))],
[psg.Text("Comandos de lindinha: ", font=('Arial bold', 15))], [psg.Text(comandosLindinha, font = ('Arial', 11))],
[psg.Button("Fechar", key='-ajuda_fechada-')]]
return psg.Window("Ajuda", layout_ajuda, size=(350, 340))
lista_bots = [BotZangado("Docinho"), BotAmigavel("Florzinha"), BotFitness("Lindinha")]
sys = scb.SistemaChatBot("Fivebots", lista_bots)
#comandos
comandosDocinho = '--> Bom dia;\n\n--> Conte uma piada;\n\n--> Quero um conselho.'
comandosFlorzinha = '--> Bom dia;\n\n--> Conte uma piada;\n\n--> Quero um conselho.'
comandosLindinha = '--> Quero uma opinião sobre o meu treino;\n\n--> Treino para braço;\n\n--> Quero uma opinião sobre o meu shape.\n'
logger = JSONLogger('logs.json')
logger.log("Sistema iniciado")
logger.save_logs()
#predefinicoes
number_msg = 0
cor_selecionada = "#083C6B"
nome_bot = "Bot: "
psg.theme('DarkBlue14')
restart = True
active = False
ja_somou = False
deleted = []
conversation_column =[[]]
#window ajuda
#layout
layout = [[psg.Text("\nConverse com seu chatbot favorito! (comece falando qualquer coisa)\n", background_color="#083C6B")],
[psg.Column(conversation_column, key="coluna", scrollable=True, vertical_scroll_only = True,
size=(430, 432))],
[psg.Input(default_text="", key='-enviado-', do_not_clear=False), psg.Button("Enviar", key='-mensagem_enviar-', bind_return_key=True),
psg.Button("Reset", key = '-reset-')],
[psg.Button("Fechar", key ='-fechar_app-'), psg.Button("Ajuda", key = '-help-')]]
#window
window = psg.Window("Fivebots", layout, size=(470,550), background_color=cor_selecionada)
#event loop
while restart:
restart = False
while True:
event, values = window.read()
if event == psg.WIN_CLOSED or event=='-fechar_app-':
break
elif event == '-mensagem_enviar-':
if active:
number_msg += 1
ja_somou = True
if number_msg in deleted:
if not active:
number_msg = 1
active = True
window[f'user{number_msg}'].update("Você:")
window[f"message_user_number{number_msg}"].update(values['-enviado-'])
window[f'bot{number_msg}'].update("Bot: ")
window[f'message_bot_number{number_msg}'].update(sys.formatado(number_msg, values['-enviado-']))
else:
active = False
if not ja_somou:
number_msg += 1
ja_somou = False
window.extend_layout(
window['coluna'],[[psg.Text("Você:", key=f'user{number_msg}'), psg.Text(values['-enviado-'],
key=f"message_user_number{number_msg}")]]
)
window.extend_layout(
window['coluna'], [[psg.Image('imagem_bot.png', subsample=32, key=f'bot{number_msg}'),
psg.Text(sys.formatado(number_msg, values['-enviado-']), key=f'message_bot_number{number_msg}')]]
)
window.refresh()
window.visibility_changed()
window['coluna'].contents_changed()
elif event == '-reset-':
for i in range(number_msg):
if (i+1) not in deleted:
deleted.append(i+1)
window[f'message_user_number{i+1}'].update("")
window[f'user{i+1}'].update("")
window[f'message_bot_number{i+1}'].update("")
window[f'bot{i+1}'].update("")
active = False
sys.botRemove()
elif event == '-help-':
window_ajuda = criarWindowAjuda()
while True:
event, values = window_ajuda.read()
if event == psg.WIN_CLOSED or event == '-ajuda_fechada-':
break
window_ajuda.close()
window.close()
#README - features
#auto-apaga input depois de enviar; botão enter envia mensagens automaticamente; input já vem selecionado
#automaticamente; botão de ajuda (ajuda não feita ainda); mecanismo de quebra de linhas; reset assíncrono.