-
Notifications
You must be signed in to change notification settings - Fork 2
/
code_Preferences.py
126 lines (84 loc) · 3.69 KB
/
code_Preferences.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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
# import the GUI forms that we create with Qt Creator
import form_Preferences
# import the Qt components we'll use
# do this so later we won't have to clutter our code with references to parent Qt classes
from PyQt5.QtGui import (
QFont
)
from PyQt5.QtCore import (
pyqtSignal,
Qt
)
from PyQt5.QtWidgets import (
QFileDialog,
QMdiSubWindow
)
import os
class Preferences(QMdiSubWindow, form_Preferences.Ui_frmPreferences):
# create "resized" as a signal that the window can emit
# we respond to this signal with the form's resizeMe method below
resized = pyqtSignal()
def __init__(self):
super(self.__class__, self).__init__()
self.setupUi(self)
self.setAttribute(Qt.WA_DeleteOnClose,True)
self.mdiParent = ""
self.resized.connect(self.resizeMe)
self.buttonBox.accepted.connect(self.savePreferences)
self.buttonBox.rejected.connect(self.closeMe)
self.btnSelectStartupFolder.clicked.connect(self.selectStartupFolder)
self.btnSelectPhotoDataFile.clicked.connect(self.selectPhotoDataFile)
def fillPreferences(self):
self.txtStartupFolder.setText(self.mdiParent.db.getStartupFolder())
if self.mdiParent.db.getStartupFolder() != "":
self.chkStartupFolder.setChecked(True)
self.txtPhotoDataFile.setText(self.mdiParent.db.getPhotoDataFile())
if self.mdiParent.db.getPhotoDataFile() != "":
self.chkPhotoDataFile.setChecked(True)
def resizeEvent(self, event):
#routine to handle events on objects, like clicks, lost focus, gained forcus, etc.
self.resized.emit()
return super(self.__class__, self).resizeEvent(event)
def resizeMe(self):
return
def closeMe(self):
self.close()
def scaleMe(self):
fontSize = self.mdiParent.fontSize
#scale the font for all widgets in window
for w in ([
self.grpStartupFolder,
self.grpPhotoDataFile,
self.chkStartupFolder,
self.chkPhotoDataFile,
self.txtStartupFolder,
self.txtPhotoDataFile,
self.btnSelectStartupFolder,
self.btnSelectPhotoDataFile
]):
try:
w.setFont(QFont("Helvetica", fontSize))
except:
pass
self.adjustSize()
def savePreferences(self):
if self.chkStartupFolder.isChecked():
self.mdiParent.db.startupFolder = self.txtStartupFolder.text()
else:
self.mdiParent.db.startupFolder = ""
if self.chkPhotoDataFile.isChecked():
self.mdiParent.db.photoDataFile = self.txtPhotoDataFile.text()
else:
self.mdiParent.db.photoDataFile = ""
self.mdiParent.db.writePreferences()
self.close()
def selectStartupFolder(self):
folder = str(QFileDialog.getExistingDirectory(self, "Select Startup Folder", self.mdiParent.db.startupFolder))
if folder != "":
self.txtStartupFolder.setText(folder)
self.chkStartupFolder.setChecked(True)
def selectPhotoDataFile(self):
fname = QFileDialog.getOpenFileName(self,"Select Photo Data File", self.mdiParent.db.photoDataFile, "Photo Data Files (*.csv)")
if fname[0] != "":
self.txtPhotoDataFile.setText(fname[0])
self.chkPhotoDataFile.setChecked(True)