config.py 6.56 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),
Yan's avatar
Yan committed
14
               ("view/digits", 2),
15
               ("view/oddeven", False),
Yan's avatar
Yan committed
16
               ("view/legend", True),
17
18
19
20
               ("print/msspec_xinch", 10),
               ("print/msspec_yinch", 4),
               ("print/msspec_dpi", 300),
               ("print/msspec_xtics", 5),
Yan's avatar
Yan committed
21
22
23
               ("print/zcespec_xinch", 5),
               ("print/zcespec_yinch", 2),
               ("print/zcespec_dpi", 300),
24
25
26
               ("print/reactspecspec_xinch", 3.5),
               ("print/reactspecspec_yinch", 2),
               ("print/reactspecspec_dpi", 300),
27
28
29
30
               ("imggen/msspec_xinch", 10),
               ("imggen/msspec_yinch", 4),
               ("imggen/msspec_dpi", 300),
               ("imggen/msspec_xtics", 5),
31
               ("imggen/msspec_onlymanann", False),
Yan's avatar
Yan committed
32
33
34
               ("imggen/zcespec_xinch", 5),
               ("imggen/zcespec_yinch", 2),
               ("imggen/zcespec_dpi", 300),
Yan's avatar
Yan committed
35
36
37
               ("imggen/drlspec_xinch", 10),
               ("imggen/drlspec_yinch", 4),
               ("imggen/drlspec_dpi", 300),
38
               ("imggen/path", True),
39
40
41
               ("imggen/reactspecspec_xinch", 3.5),
               ("imggen/reactspecspec_yinch", 2),
               ("imggen/reactspecspec_dpi", 300),
3Yan's avatar
3Yan committed
42
               ("reactivity/index", 0),
43
               ("reactivity/activetab", 0),
Yan's avatar
Yan committed
44
               ("recents", ""),
Yan's avatar
Yan committed
45
46
47
48
               ("timstof/ms_sampling", 500),
               ("timstof/ms_bins", 0.001),
               ("timstof/mob_sampling", 5000),
               ("timstof/mob_bins", 0.0001)}
Yan's avatar
Yan committed
49
    [settings.setValue(*i)
Yan's avatar
Yan committed
50
     for i in defvals if not settings.contains(i[0])]
Yan's avatar
Yan committed
51
52
53
    return settings


3Yan's avatar
3Yan committed
54
def pathsearch(text, value, config):
Yan's avatar
Yan committed
55
    filename = QtWidgets.QFileDialog.getExistingDirectory()
56
    if filename != '':
3Yan's avatar
3Yan committed
57
58
        text.setText(filename)
        config.setValue(value, filename)
Yan's avatar
Yan committed
59
60


61
def pathlineconf(label, value, config):
3Yan's avatar
3Yan committed
62
    """adds generic filepath config line"""
Yan's avatar
Yan committed
63
    textfield = QtWidgets.QLineEdit(str(config.value(value)))
3Yan's avatar
3Yan committed
64
65
66
67
68
69
    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
70
    layout.addWidget(QtWidgets.QLabel(str(label)))
3Yan's avatar
3Yan committed
71
72
73
74
    layout.addWidget(textfield)
    layout.addWidget(browse_button)
    return layout

Yan's avatar
Yan committed
75

76
def posvarconf(label, value, config, num="int"):
77
    """adds generic positive integer config line"""
Yan's avatar
Yan committed
78
    textfield = QtWidgets.QLineEdit(str(config.value(value)))
79
80
    textfield.editingFinished.connect(lambda: config.setValue(
        value, textfield.text()))
81
    validator = QtGui.QIntValidator() if num == "int"\
82
        else QtGui.QDoubleValidator()
83
84
85
86
87
88
89
90
91
    validator.setBottom(0)
    textfield.setValidator(validator)
    layout = QtWidgets.QHBoxLayout()
    layout.addWidget(QtWidgets.QLabel("{}:".format(label)))
    layout.addStretch()
    layout.addWidget(textfield)
    return layout


92
93
def checkboxconf(label, value, config):
    checkbox = QtWidgets.QCheckBox(label)
Yan's avatar
Yan committed
94
    checkbox.setChecked(config.value(value, type=bool))
95
96
97
98
99
    checkbox.stateChanged.connect(lambda: config.setValue(
        value, checkbox.checkState()))
    return checkbox


Yan's avatar
Yan committed
100
101
102
103
def dial(parent):
    """constructs a dialog window"""
    dialog = QtWidgets.QDialog(
        parent, windowTitle='Settings')
104
    dialog.resize(600, -1)
Yan's avatar
Yan committed
105
106

    config = settings()
107
108
109
110
111
112
113
114
115
116
117
118
119

    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)
120
121
122
123
124
    printlayout.addLayout(posvarconf(
        "Figure width (inch)", "print/xinch", config, "nonint"))
    printlayout.addLayout(posvarconf(
        "Figure height (inch)", "print/yinch", config, "nonint"))
    printlayout.addLayout(posvarconf(
125
        "Figure dpi", "print/dpi", config))
126
    printlayout.addLayout(posvarconf(
127
        "Figure x axis major ticks count", "print/xtics", config))
128
129
130
131
    tabs.addTab(printtab, "Printing")

    imggentab = QtWidgets.QWidget()
    imggenlayout = QtWidgets.QVBoxLayout(imggentab)
132
    imggenlayout.addLayout(posvarconf(
133
        "Figure width (inch)", "imggen/msspec_xinch", config, "nonint"))
134
    imggenlayout.addLayout(posvarconf(
135
        "Figure height (inch)", "imggen/msspec_yinch", config, "nonint"))
136
    imggenlayout.addLayout(posvarconf(
137
        "Figure dpi", "imggen/msspec_dpi", config))
138
    imggenlayout.addLayout(posvarconf(
139
        "Figure x axis major ticks count", "imggen/msspec_xtics", config))
140
    imggenlayout.addWidget(checkboxconf(
141
        "Manual annotation only", "imggen/msspec_onlymanann", config))
142
143
    imggenlayout.addWidget(checkboxconf(
        "Isert path to exported image", "imggen/path", config))
144
145
    tabs.addTab(imggentab, "Image clip/export")

Yan's avatar
Yan committed
146
147
148
    timstoftab = QtWidgets.QWidget()
    timstoflayout = QtWidgets.QVBoxLayout(timstoftab)
    timstoflayout.addLayout(posvarconf(
Yan's avatar
Yan committed
149
150
151
152
        "Maximum number of samples - MS", "timstof/ms_sampling", config))
    timstoflayout.addLayout(posvarconf(
        "Bins - MS", "timstof/ms_bins", config, "nonint"))
    timstoflayout.addLayout(posvarconf(
Yan's avatar
Yan committed
153
154
        "Maximum number of samples - mobility", "timstof/mob_sampling",
        config))
Yan's avatar
Yan committed
155
156
    timstoflayout.addLayout(posvarconf(
        "Bins - mobility", "timstof/mob_bins", config, "nonint"))
Yan's avatar
Yan committed
157
158
159
160
161
162
163
164
    tabs.addTab(timstoftab, "TimsTOF")

    viewtab = QtWidgets.QWidget()
    viewlayout = QtWidgets.QVBoxLayout(viewtab)
    viewlayout.addLayout(posvarconf(
        "number of digits after decimal point", "view/digits", config))
    tabs.addTab(viewtab, "View Settings")

Yan's avatar
Yan committed
165

Yan's avatar
Yan committed
166
167
168
169
170
171
172
    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
173
    layout = QtWidgets.QVBoxLayout(dialog)
Yan's avatar
Yan committed
174
    layout.addWidget(QtWidgets.QLabel("Changes are saved automatically"))
175
    layout.addWidget(tabs)
Yan's avatar
Yan committed
176
177
178
179
    layout.addStretch(1)
    layout.addLayout(butt_layout)

    dialog.show()