-
Notifications
You must be signed in to change notification settings - Fork 1
/
dialogs.py
52 lines (39 loc) · 1.4 KB
/
dialogs.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
import json
import os
from PyQt5.QtWidgets import QDialog, QFileDialog
from gui_preferences import Ui_Dialog
from gui_vanilla_map import Ui_Dialog_2
class VanillaDialog(QDialog, Ui_Dialog_2):
def __init__(self, parent=None):
super().__init__(parent)
self.setupUi(self)
class PreferencesDialog(QDialog, Ui_Dialog):
def __init__(self, parent=None):
super().__init__(parent)
self.setupUi(self)
self.init_events()
def browse(self, text):
folder = str(QFileDialog.getExistingDirectory(self, "Select a directory"))
if folder == "":
print("None selected")
return
folder = os.path.abspath(folder)
text.setText(folder)
def browse_map(self):
self.browse(self.lineEdit)
def browse_save(self):
self.browse(self.lineEdit_2)
def save(self):
config = os.path.join(os.path.dirname(os.path.abspath(__file__)), "config.json")
data = {
"aoc_folder": self.lineEdit.text(),
"save_folder": self.lineEdit_2.text()
}
with open(config, 'w') as file:
json.dump(data, file)
self.close()
def init_events(self):
self.pushButton.clicked.connect(self.browse_map)
self.pushButton_2.clicked.connect(self.browse_save)
self.pushButton_3.clicked.connect(self.save)
self.pushButton_4.clicked.connect(self.close)