config.py 1.69 KB
Newer Older
Yan's avatar
Yan committed
1
2
3
4
5
6
7
8
9
10
11
12
#!/usr/bin/env python3
from PyQt5 import QtCore
from PyQt5 import QtWidgets
from PyQt5 import QtGui
from PyQt5 import QtPrintSupport


def settings():
    settings = QtCore.QSettings("Yansoft","Prasopes")
    return settings


3Yan's avatar
3Yan committed
13
def pathsearch(text, value, config):
Yan's avatar
Yan committed
14
15
    filename = QtWidgets.QFileDialog.getExistingDirectory()
    if filename is not '':
3Yan's avatar
3Yan committed
16
17
        text.setText(filename)
        config.setValue(value, filename)
Yan's avatar
Yan committed
18
19


3Yan's avatar
3Yan committed
20
21
22
23
24
25
26
27
28
29
30
31
32
33
def pathlayout(label, value, config):
    """adds generic filepath config line"""
    textfield = QtWidgets.QLineEdit(config.value(value))
    textfield.editingFinished.connect(lambda: config.setValue(
        value, textfield.text()))
    browse_button = QtWidgets.QPushButton("Browse..")
    browse_button.clicked.connect(lambda: pathsearch(
        textfield, value, config))
    layout = QtWidgets.QHBoxLayout()
    layout.addWidget(QtWidgets.QLabel("{}:".format(label)))
    layout.addWidget(textfield)
    layout.addWidget(browse_button)
    return layout

Yan's avatar
Yan committed
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48

def dial(parent):
    """constructs a dialog window"""
    dialog = QtWidgets.QDialog(
        parent, windowTitle='Settings')
    dialog.resize(600,-1)

    config = settings()
    close_button = QtWidgets.QPushButton("Close")
    close_button.clicked.connect(dialog.close)

    butt_layout = QtWidgets.QHBoxLayout()
    butt_layout.addWidget(close_button)
    butt_layout.addStretch(1)

3Yan's avatar
3Yan committed
49
50
51
52
53
    layout = QtWidgets.QVBoxLayout(dialog)
    layout.addLayout(pathlayout("Acquisition temp folder",
                                "tmp_location", config))
    layout.addLayout(pathlayout("Default open folder",
                                "open_folder", config))
Yan's avatar
Yan committed
54
55
56
57
    layout.addStretch(1)
    layout.addLayout(butt_layout)

    dialog.show()