-
Notifications
You must be signed in to change notification settings - Fork 0
/
gui.py
45 lines (38 loc) · 1.72 KB
/
gui.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
import sys
from PyQt5.QtWidgets import QApplication, QMainWindow, QFileDialog, QTextEdit, QPushButton, QVBoxLayout, QWidget
class MainWindow(QMainWindow):
def __init__(self, parent=None):
super(MainWindow, self).__init__(parent)
self.setWindowTitle("Python Learning Tool")
# Initialize widgets
self.textEdit = QTextEdit()
self.uploadButton = QPushButton("Upload .py file")
self.downloadButton = QPushButton("Download .apkg file")
# Connect signals and slots
self.uploadButton.clicked.connect(self.upload_file)
self.downloadButton.clicked.connect(self.download_file)
# Set layout
layout = QVBoxLayout()
layout.addWidget(self.textEdit)
layout.addWidget(self.uploadButton)
layout.addWidget(self.downloadButton)
mainWidget = QWidget()
mainWidget.setLayout(layout)
self.setCentralWidget(mainWidget)
def upload_file(self):
options = QFileDialog.Options()
fileName, _ = QFileDialog.getOpenFileName(self, "QFileDialog.getOpenFileName()", "", "Python Files (*.py)", options=options)
if fileName:
with open(fileName, 'r') as file:
self.textEdit.setText(file.read())
def download_file(self):
options = QFileDialog.Options()
fileName, _ = QFileDialog.getSaveFileName(self, "QFileDialog.getSaveFileName()", "", "Anki Package (*.apkg)", options=options)
if fileName:
# TODO: Implement the functionality to generate and download .apkg file
pass
if __name__ == "__main__":
app = QApplication(sys.argv)
window = MainWindow()
window.show()
sys.exit(app.exec_())