-
Notifications
You must be signed in to change notification settings - Fork 0
/
start.py
68 lines (48 loc) · 1.69 KB
/
start.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
60
61
62
63
64
65
66
67
68
import os
import sys
from PyQt5.QtWidgets import QMainWindow, QApplication, QFileDialog
import main
from data.start_ui import Ui_MainWindow
def create_files():
if not os.path.exists('progress.txt'):
with open('progress.txt', 'w'):
pass
if not os.path.exists('last_book.txt'):
with open('last_book.txt', 'w'):
pass
class StartWindow(QMainWindow, Ui_MainWindow):
def __init__(self):
super().__init__()
self.setupUi(self)
self.setWindowTitle('Choose a book')
self.conf_btn.clicked.connect(self.choose)
self.browse_btn.clicked.connect(self.browse)
with open('last_book.txt') as file:
self.last_book_path = file.read()
self.path_inp.setText(self.last_book_path)
def browse(self):
filepath, ok = QFileDialog.getOpenFileName(self, 'Выберите книгу', '',
'Текстовый файл (*.txt)')
if ok:
self.path_inp.setText(filepath)
def choose(self):
new_path = self.path_inp.text()
if not new_path:
self.error_label.setText('Error: empty path')
return
if not new_path == self.last_book_path:
with open('last_book.txt', 'w') as book_file:
book_file.write(new_path)
with open('progress.txt', 'w') as progress_file:
progress_file.write('')
self.close()
self.main_window = main.MainWindow()
self.main_window.show()
def run():
create_files()
app = QApplication(sys.argv)
ex = StartWindow()
ex.show()
sys.exit(app.exec_())
if __name__ == '__main__':
run()