config.py 1.94 KB
Newer Older
Yan's avatar
Yan committed
1
2
3
4
5
6
7
8
9
#!/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")
Yan's avatar
Yan committed
10
11
    defvals = {("view/autozoomy", True),
               ("view/filebrowservisible", True),
12
13
               ("view/intensities", False),
               ("view/oddeven", False)}
Yan's avatar
Yan committed
14
    [settings.setValue(i[0], i[1]) for i in defvals if settings.value(i[0]) == None]
Yan's avatar
Yan committed
15
16
17
    return settings


3Yan's avatar
3Yan committed
18
def pathsearch(text, value, config):
Yan's avatar
Yan committed
19
20
    filename = QtWidgets.QFileDialog.getExistingDirectory()
    if filename is not '':
3Yan's avatar
3Yan committed
21
22
        text.setText(filename)
        config.setValue(value, filename)
Yan's avatar
Yan committed
23
24


3Yan's avatar
3Yan committed
25
26
27
28
29
30
31
32
33
34
35
36
37
38
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53

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
54
55
56
57
58
    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
59
60
61
62
    layout.addStretch(1)
    layout.addLayout(butt_layout)

    dialog.show()