-
Notifications
You must be signed in to change notification settings - Fork 5
/
file_dialog.py
72 lines (62 loc) · 2.45 KB
/
file_dialog.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
69
70
71
72
import sys
from PyQt5.QtWidgets import QApplication, QWidget, QInputDialog, QLineEdit, QFileDialog
from PyQt5.QtGui import QIcon
from PyQt5 import QtCore, QtGui
import pickle
# file dialog window
# used to save and load the ground station, satellite and reception files
# it uses the function open_dialog(opt, type) to run the window
# opt is to choose 'save' or 'load' options
# type a string used to define the extension of the file
class Dialog(QWidget):
def __init__(self, opt, type):
super().__init__()
self.title = 'PyQt5 file dialogs - pythonspot.com'
self.left = 10
self.top = 10
self.width = 640
self.height = 480
self.opt = opt
self.type = type
self.initUI()
self.fileName = None
def initUI(self):
self.setWindowTitle(self.title)
self.setGeometry(self.left, self.top, self.width, self.height)
if self.opt == 'save':
self.saveFileDialog()
elif self.opt == 'load':
self.openFileNameDialog()
else:
sys.exit('Dialog boss option not expected!')
# self.openFileNamesDialog()
def openFileNameDialog(self):
options = QFileDialog.Options()
options |= QFileDialog.DontUseNativeDialog
fileDialog = QFileDialog(self)
fileDialog.setAttribute(QtCore.Qt.WA_QuitOnClose, False)
self.fileName, _ = fileDialog.getOpenFileName(None, "Open File", "",
self.type + ";;All Files (*)", options=options)
if self.fileName:
with open('temp\\load.pkl', 'wb') as f:
pickle.dump(self.fileName, f)
f.close()
return
else:
return
def saveFileDialog(self):
options = QFileDialog.Options()
options |= QFileDialog.DontUseNativeDialog
fileDialog = QFileDialog(self)
fileDialog.setAttribute(QtCore.Qt.WA_QuitOnClose, False)
self.fileName, _ = fileDialog.getSaveFileName(None, "Save File", "",
self.type + ";;All Files (*)", options=options)
if self.fileName:
with open('temp\\save.pkl', 'wb') as f:
pickle.dump(self.fileName, f)
f.close()
return
else:
return
def open_dialog(opt, type):
Dialog(opt, type)