-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathChatTools.py
More file actions
61 lines (48 loc) · 1.95 KB
/
ChatTools.py
File metadata and controls
61 lines (48 loc) · 1.95 KB
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
import sys
from PyQt5.QtWidgets import QApplication, QWidget, QTextEdit, QLineEdit, QPushButton, QVBoxLayout, QSystemTrayIcon, QMenu
from PyQt5.QtGui import QIcon
from chatgpt import ChatGPT
class ChatGPTWindow(QWidget):
def __init__(self):
super().__init__()
self.chatbot = ChatGPT()
self.initUI()
def initUI(self):
# Création des widgets
self.text_edit = QTextEdit()
self.text_edit.setReadOnly(True)
self.text_input = QLineEdit()
self.text_input.returnPressed.connect(self.generate_response)
self.submit_button = QPushButton('Envoyer')
self.submit_button.clicked.connect(self.generate_response)
# Création du layout vertical et ajout des widgets
layout = QVBoxLayout()
layout.addWidget(self.text_edit)
layout.addWidget(self.text_input)
layout.addWidget(self.submit_button)
self.setLayout(layout)
self.setGeometry(100, 100, 900, 500)
self.setWindowTitle('ChatGPT')
def generate_response(self):
question = self.text_input.text()
response = self.chatbot.generate_response(question)
self.text_edit.append(f"Vous : {question}\nChatbot : {response}\n\n")
self.text_input.clear()
class SystemTrayIcon(QSystemTrayIcon):
def __init__(self, parent=None):
QSystemTrayIcon.__init__(self, parent)
self.setToolTip('ChatGPT')
self.setIcon(QIcon('icon.png'))
self.activated.connect(self.on_tray_activated)
def on_tray_activated(self, reason):
if reason == self.Trigger:
if not hasattr(self, 'chat_gpt_window') or not self.chat_gpt_window.isVisible():
self.chat_gpt_window = ChatGPTWindow()
self.chat_gpt_window.show()
else:
self.chat_gpt_window.hide()
if __name__ == '__main__':
app = QApplication(sys.argv)
tray_icon = SystemTrayIcon()
tray_icon.show()
sys.exit(app.exec_())