-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
60 lines (43 loc) · 1.74 KB
/
app.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
def app():
# ...
class App(QApplication):
def __init__(self, argv):
super().__init__(argv)
self.window = Window()
self.window.show()
sys.exit(self.exec())
class Window(QWidget):
def __init__(self):
super().__init__()
self.setWindowTitle("Assistente de programação")
self.setGeometry(50, 50, 600, 400)
self.menu_bar = QMenuBar(self)
self.file_menu = QMenu("Arquivo", self.menu_bar)
self.menu_bar.addMenu(self.file_menu)
self.exit_action = QAction("Sair", self)
self.exit_action.setShortcut("Ctrl+Q")
self.file_menu.addAction(self.exit_action)
self.search_label = QLabel("Pesquisar:")
self.search_line_edit = QLineEdit()
self.search_button = QPushButton("Pesquisar")
self.content_label = QLabel("")
self.layout = QVBoxLayout(self)
self.layout.addWidget(self.menu_bar)
self.layout.addWidget(self.search_label)
self.layout.addWidget(self.search_line_edit)
self.layout.addWidget(self.search_button)
self.layout.addWidget(self.content_label)
self.search_button.clicked.connect(self.on_search_clicked)
def on_search_clicked(self):
topic = self.search_line_edit.text()
self.content_label.setText("")
if topic:
with open(os.path.join(os.path.dirname(__file__), "database.json")) as database:
database_data = json.load(database)
for topic_name, topic_data in database_data.items():
if topic in topic_name:
self.content_label.setText(topic_data)
break
if __name__ == "__main__":
app()
app.exec()