-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathassistant_name.py
More file actions
55 lines (43 loc) · 1.62 KB
/
Copy pathassistant_name.py
File metadata and controls
55 lines (43 loc) · 1.62 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
import os
import sys
from PyQt5.QtWidgets import QApplication, QWidget, QVBoxLayout, QLabel, QLineEdit, QPushButton, QMessageBox
# File to store the assistant's name
NAME_FILE = "///" #Path for saving name of the assistant(.txt file)
class NamingPage(QWidget):
def __init__(self):
super().__init__()
self.initUI()
def initUI(self):
self.setWindowTitle("Name Your Assistant")
self.resize(400, 200)
# Layout and widgets
layout = QVBoxLayout()
label = QLabel("Enter a name for your assistant:")
layout.addWidget(label)
self.name_input = QLineEdit(self)
self.name_input.setPlaceholderText("Type the name here...")
layout.addWidget(self.name_input)
save_button = QPushButton("Save Name")
save_button.clicked.connect(self.save_name)
layout.addWidget(save_button)
self.setLayout(layout)
def save_name(self):
name = self.name_input.text().strip()
if name:
with open(NAME_FILE, "w") as f:
f.write(name)
QMessageBox.information(self, "Success", f"Assistant named '{name}'!")
self.close() # Close the naming page
else:
QMessageBox.warning(self, "Input Error", "Please enter a valid name.")
def main():
# Check if the assistant name is already set
if not os.path.exists(NAME_FILE):
app = QApplication(sys.argv)
naming_page = NamingPage()
naming_page.show()
sys.exit(app.exec_())
else:
print("Assistant name is already set. No naming page needed.")
if __name__ == "__main__":
main()