-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathui_settings.py
101 lines (86 loc) · 3.67 KB
/
ui_settings.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
from PyQt5 import QtWidgets, QtCore
stylesheet = open('style-css.txt', 'r').read()
def read_settings() :
with open('settings.txt', 'r') as file0 :
return eval(file0.read())
def write_settings(speed, region, no_of_words, camera_on) :
file0 = open('settings.txt', 'w')
d = {
"Narration": {
"Speed": f"{speed}",
"Region": f"{region}",
"Maximum_Words_Read": f"{no_of_words}"
},
"On-Startup": {
"Camera-on": camera_on
}
}
file0.write(str(d))
file0.close()
class PreferencesDialog(QtWidgets.QDialog) :
def __init__(self) :
super(PreferencesDialog, self).__init__()
self.setFixedSize(600, 400)
self.setWindowTitle('Preferences')
self.setStyleSheet(stylesheet)
d = read_settings()
self.buttonbox = QtWidgets.QDialogButtonBox(self)
self.buttonbox.setGeometry(20, 340, 560, 28)
self.buttonbox.setOrientation(QtCore.Qt.Horizontal)
self.buttonbox.setStandardButtons(QtWidgets.QDialogButtonBox.Cancel|QtWidgets.QDialogButtonBox.Ok)
self.buttonbox.accepted.connect(self.ok)
self.buttonbox.rejected.connect(self.cancel)
self.groupbox = QtWidgets.QGroupBox(self, title='Narration')
self.groupbox.setGeometry(20, 20, 560, 200)
self.formlayout = QtWidgets.QFormLayout()
self.formlayout.setVerticalSpacing(24)
self.groupbox.setLayout(self.formlayout)
self.radiogroup = QtWidgets.QHBoxLayout()
self.radioslow = QtWidgets.QRadioButton()
self.radioslow.setText('Slow')
self.radiogroup.addWidget(self.radioslow)
self.radionormal = QtWidgets.QRadioButton()
self.radionormal.setText('Normal')
if d :
if (d['Narration']['Speed'] == 'Slow') :
self.radioslow.setChecked(True)
else :
self.radionormal.setChecked(True)
self.radiogroup.addWidget(self.radionormal)
self.formlayout.addRow(QtWidgets.QLabel('Speed:'), self.radiogroup)
self.langbox = QtWidgets.QComboBox()
self.langbox.addItems(['English (India)', 'English (US)', 'English (UK)'])
if d :
if (d['Narration']['Region'] == 'English (US)') :
self.langbox.setCurrentIndex(1)
elif (d['Narration']['Region'] == 'English (UK)') :
self.langbox.setCurrentIndex(2)
self.formlayout.addRow(QtWidgets.QLabel('Region:'), self.langbox)
self.numberbox = QtWidgets.QSpinBox()
self.numberbox.setRange(1, 10)
if d :
self.numberbox.setValue(int(d['Narration']['Maximum_Words_Read']))
self.numberbox.setFixedWidth(100)
self.formlayout.addRow(QtWidgets.QLabel('Maximum words spoken at once:'), self.numberbox)
self.groupbox2 = QtWidgets.QGroupBox(self, title='On Startup')
self.groupbox2.setGeometry(20, 240, 560, 80)
self.formlayout2 = QtWidgets.QFormLayout()
self.formlayout2.setVerticalSpacing(24)
self.groupbox2.setLayout(self.formlayout2)
self.cameraonbox = QtWidgets.QCheckBox()
self.cameraonbox.setText('Camera on by default on startup')
if d :
self.cameraonbox.setChecked(d['On-Startup']['Camera-on'])
self.formlayout2.addRow(self.cameraonbox)
def ok(self) :
speedbool = self.radioslow.isChecked()
speed = 'Normal'
if speedbool :
speed = 'Slow'
region = self.langbox.currentText()
no_of_words = int(self.numberbox.value())
camera_on = self.cameraonbox.isChecked()
write_settings(speed, region, no_of_words, camera_on)
self.close()
def cancel(self) :
self.close()