config.py 4.12 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
               ("imggen/dpi", 300),
22
23
               ("imggen/xtics", 5),
               ("recents", "")}
Yan's avatar
Yan committed
24
    [settings.setValue(*i)
Yan's avatar
Yan committed
25
     for i in defvals if not settings.contains(i[0])]
Yan's avatar
Yan committed
26
27
28
    return settings


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


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

Yan's avatar
Yan committed
50

51
def posvarconf(label, value, config, num="int"):
52
    """adds generic positive integer config line"""
Yan's avatar
Yan committed
53
    textfield = QtWidgets.QLineEdit(str(config.value(value)))
54
55
    textfield.editingFinished.connect(lambda: config.setValue(
        value, textfield.text()))
56
    validator = QtGui.QIntValidator() if num == "int"\
57
        else QtGui.QDoubleValidator()
58
59
60
61
62
63
64
65
66
    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
67
68
69
70
def dial(parent):
    """constructs a dialog window"""
    dialog = QtWidgets.QDialog(
        parent, windowTitle='Settings')
71
    dialog.resize(600, -1)
Yan's avatar
Yan committed
72
73

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

    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)
87
88
89
90
91
    printlayout.addLayout(posvarconf(
        "Figure width (inch)", "print/xinch", config, "nonint"))
    printlayout.addLayout(posvarconf(
        "Figure height (inch)", "print/yinch", config, "nonint"))
    printlayout.addLayout(posvarconf(
92
        "Figure dpi", "print/dpi", config))
93
    printlayout.addLayout(posvarconf(
94
        "Figure x axis major ticks count", "print/xtics", config))
95
96
97
98
    tabs.addTab(printtab, "Printing")

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

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

    dialog.show()