-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcatbox.py
More file actions
80 lines (70 loc) · 2.27 KB
/
Copy pathcatbox.py
File metadata and controls
80 lines (70 loc) · 2.27 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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# Imports for PyQt5 Lib and Functions to be used
from PyQt5 import QtWidgets
from PyQt5.QtCore import Qt
from PyQt5.QtGui import QFont
from PyQt5.QtWidgets import QWidget,QApplication
import sys
# alignment to PyQt Widgets
setStyleQte = """QTextEdit {
font-family: "Courier";
font-size: 12pt;
font-weight: 600;
text-align: right;
background-color: Gainsboro;
}"""
setStyletui = """QLineEdit {
font-family: "Courier";
font-weight: 600;
text-align: left;
background-color: Gainsboro;
}"""
class Window(QtWidgets.QWidget):
def __init__(self):
'''
Initilize all the widgets then call the GuiSetup to customize them
'''
QtWidgets.QWidget.__init__(self)
self.v = None
self.layout = QtWidgets.QVBoxLayout(self)
self.button2 = QtWidgets.QPushButton('Start New Session')
self.font = QFont()
self.font.setPointSize(12)
self.chatlog = QtWidgets.QTextEdit()
self.userinput = QtWidgets.QLineEdit()
self.userinput.returnPressed.connect(self.AddToChatLogUser)
# self.button2.clicked.connect(self.getBot)
self.GuiSetup()
def GuiSetup(self):
'''
Styling and Layout.
'''
self.chatlog.setStyleSheet(setStyleQte)
self.userinput.setStyleSheet(setStyletui)
self.userinput.setFont(self.font)
self.button2.setFont(self.font)
self.layout.addWidget(self.button2)
self.layout.addWidget(self.chatlog)
self.layout.addWidget(self.userinput)
def UpdateCycle(self):
'''
Retrieves a new bot message and appends to the chat log.
'''
bmsg = self.v.getBotMessage()
self.chatlog.setAlignment(Qt.AlignRight)
[self.chatlog.append(m) for m in bmsg]
self.userinput.setFocus()
def AddToChatLogUser(self):
'''
Takes guest's entry and appends to the chatlog
'''
umsg = self.userinput.text()
self.chatlog.setAlignment(Qt.AlignLeft)
self.chatlog.append(umsg)
# self.chatlog.setAlignment(Qt.AlignRight)
self.userinput.setText("")
if __name__ == '__main__':
app = QtWidgets.QApplication(sys.argv)
win = Window()
win.setGeometry(10,10,480,480)
win.show()
sys.exit(app.exec_())