config.py 4.1 KB
Newer Older
Yan's avatar
Yan committed
1
2
3
4
5
6
7
#!/usr/bin/env python3
from PyQt5 import QtCore
from PyQt5 import QtWidgets
from PyQt5 import QtGui


def settings():
8
    settings = QtCore.QSettings("Yansoft", "Prasopes")
Yan's avatar
Yan committed
9
10
    defvals = {("view/autozoomy", True),
               ("view/filebrowservisible", True),
Yan's avatar
Yan committed
11
12
               ("view/consolevisible", True),
               ("view/acqparvisible", True),
13
               ("view/intensities", False),
14
15
16
17
               ("view/oddeven", False),
               ("print/xinch", 10),
               ("print/yinch", 4),
               ("print/dpi", 300),
18
               ("print/xtics", 5),
19
20
               ("imggen/xinch", 10),
               ("imggen/yinch", 4),
21
22
               ("imggen/dpi", 300),
               ("imggen/xtics", 5)}
Yan's avatar
Yan committed
23
24
    [print("will set value", i[0])
     for i in defvals if not settings.contains(i[0])]
Yan's avatar
Yan committed
25
26
27
    return settings


3Yan's avatar
3Yan committed
28
def pathsearch(text, value, config):
Yan's avatar
Yan committed
29
    filename = QtWidgets.QFileDialog.getExistingDirectory()
30
    if filename != '':
3Yan's avatar
3Yan committed
31
32
        text.setText(filename)
        config.setValue(value, filename)
Yan's avatar
Yan committed
33
34


35
def pathlineconf(label, value, config):
3Yan's avatar
3Yan committed
36
    """adds generic filepath config line"""
Yan's avatar
Yan committed
37
    textfield = QtWidgets.QLineEdit(str(config.value(value)))
3Yan's avatar
3Yan committed
38
39
40
41
42
43
    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()
Yan's avatar
Yan committed
44
    layout.addWidget(QtWidgets.QLabel(str(label)))
3Yan's avatar
3Yan committed
45
46
47
48
    layout.addWidget(textfield)
    layout.addWidget(browse_button)
    return layout

Yan's avatar
Yan committed
49

50
def posvarconf(label, value, config, num="int"):
51
    """adds generic positive integer config line"""
Yan's avatar
Yan committed
52
    textfield = QtWidgets.QLineEdit(str(config.value(value)))
53
54
    textfield.editingFinished.connect(lambda: config.setValue(
        value, textfield.text()))
55
    validator = QtGui.QIntValidator() if num == "int"\
56
        else QtGui.QDoubleValidator()
57
58
59
60
61
62
63
64
65
    validator.setBottom(0)
    textfield.setValidator(validator)
    layout = QtWidgets.QHBoxLayout()
    layout.addWidget(QtWidgets.QLabel("{}:".format(label)))
    layout.addStretch()
    layout.addWidget(textfield)
    return layout


Yan's avatar
Yan committed
66
67
68
69
def dial(parent):
    """constructs a dialog window"""
    dialog = QtWidgets.QDialog(
        parent, windowTitle='Settings')
70
    dialog.resize(600, -1)
Yan's avatar
Yan committed
71
72

    config = settings()
73
74
75
76
77
78
79
80
81
82
83
84
85

    tabs = QtWidgets.QTabWidget()

    pathtab = QtWidgets.QWidget()
    pathlayout = QtWidgets.QVBoxLayout(pathtab)
    pathlayout.addLayout(pathlineconf(
        "Acquisition temp folder", "tmp_location", config))
    pathlayout.addLayout(pathlineconf(
        "Default open folder", "open_folder", config))
    tabs.addTab(pathtab, "Paths")

    printtab = QtWidgets.QWidget()
    printlayout = QtWidgets.QVBoxLayout(printtab)
86
87
88
89
90
    printlayout.addLayout(posvarconf(
        "Figure width (inch)", "print/xinch", config, "nonint"))
    printlayout.addLayout(posvarconf(
        "Figure height (inch)", "print/yinch", config, "nonint"))
    printlayout.addLayout(posvarconf(
91
        "Figure dpi", "print/dpi", config))
92
    printlayout.addLayout(posvarconf(
93
        "Figure x axis major ticks count", "print/xtics", config))
94
95
96
97
    tabs.addTab(printtab, "Printing")

    imggentab = QtWidgets.QWidget()
    imggenlayout = QtWidgets.QVBoxLayout(imggentab)
98
99
100
101
102
    imggenlayout.addLayout(posvarconf(
        "Figure width (inch)", "imggen/xinch", config, "nonint"))
    imggenlayout.addLayout(posvarconf(
        "Figure height (inch)", "imggen/yinch", config, "nonint"))
    imggenlayout.addLayout(posvarconf(
103
        "Figure dpi", "imggen/dpi", config))
104
    imggenlayout.addLayout(posvarconf(
105
        "Figure x axis major ticks count", "imggen/xtics", config))
106
107
    tabs.addTab(imggentab, "Image clip/export")

Yan's avatar
Yan committed
108
109
110
111
112
113
114
    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
115
    layout = QtWidgets.QVBoxLayout(dialog)
Yan's avatar
Yan committed
116
    layout.addWidget(QtWidgets.QLabel("Changes are saved automatically"))
117
    layout.addWidget(tabs)
Yan's avatar
Yan committed
118
119
120
121
    layout.addStretch(1)
    layout.addLayout(butt_layout)

    dialog.show()