forked from mherrmann/fbs-tutorial
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
38 lines (33 loc) · 1.13 KB
/
main.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
from fbs_runtime.application_context import ApplicationContext, cached_property
from PyQt5.QtCore import Qt
from PyQt5.QtWidgets import QWidget, QLabel, QPushButton, QVBoxLayout
import requests
import sys
class AppContext(ApplicationContext):
def run(self):
stylesheet = self.get_resource('styles.qss')
self.app.setStyleSheet(open(stylesheet).read())
self.window.show()
return self.app.exec_()
@cached_property
def window(self):
return MainWindow()
class MainWindow(QWidget):
def __init__(self):
super().__init__()
text = QLabel()
text.setWordWrap(True)
button = QPushButton('Next quote >')
button.clicked.connect(lambda: text.setText(_get_quote()))
layout = QVBoxLayout()
layout.addWidget(text)
layout.addWidget(button)
layout.setAlignment(button, Qt.AlignHCenter)
self.setLayout(layout)
def _get_quote():
response = requests.get('https://talaikis.com/api/quotes/random/')
return response.json()['quote']
if __name__ == '__main__':
appctxt = AppContext()
exit_code = appctxt.run()
sys.exit(exit_code)