config.py 1.9 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
12
13
    defvals = {("view/autozoomy", True),
               ("view/filebrowservisible", True),
               ("view/intensities", False)}
    [settings.setValue(i[0], i[1]) for i in defvals if settings.value(i[0]) == None]
Yan's avatar
Yan committed
14
15
16
    return settings


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


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

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

    dialog.show()