config.py 4.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),
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
               ("imggen/xtics", 5),
23
               ("imggen/onlymanann", False),
3Yan's avatar
3Yan committed
24
               ("reactivity/index", 0),
25
               ("recents", "")}
Yan's avatar
Yan committed
26
    [settings.setValue(*i)
Yan's avatar
Yan committed
27
     for i in defvals if not settings.contains(i[0])]
Yan's avatar
Yan committed
28
29
30
    return settings


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


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

Yan's avatar
Yan committed
52

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


69
70
71
72
73
74
75
76
def checkboxconf(label, value, config):
    checkbox = QtWidgets.QCheckBox(label)
    checkbox.setChecked(config.value(value,type=bool))
    checkbox.stateChanged.connect(lambda: config.setValue(
        value, checkbox.checkState()))
    return checkbox


Yan's avatar
Yan committed
77
78
79
80
def dial(parent):
    """constructs a dialog window"""
    dialog = QtWidgets.QDialog(
        parent, windowTitle='Settings')
81
    dialog.resize(600, -1)
Yan's avatar
Yan committed
82
83

    config = settings()
84
85
86
87
88
89
90
91
92
93
94
95
96

    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)
97
98
99
100
101
    printlayout.addLayout(posvarconf(
        "Figure width (inch)", "print/xinch", config, "nonint"))
    printlayout.addLayout(posvarconf(
        "Figure height (inch)", "print/yinch", config, "nonint"))
    printlayout.addLayout(posvarconf(
102
        "Figure dpi", "print/dpi", config))
103
    printlayout.addLayout(posvarconf(
104
        "Figure x axis major ticks count", "print/xtics", config))
105
106
107
108
    tabs.addTab(printtab, "Printing")

    imggentab = QtWidgets.QWidget()
    imggenlayout = QtWidgets.QVBoxLayout(imggentab)
109
110
111
112
113
    imggenlayout.addLayout(posvarconf(
        "Figure width (inch)", "imggen/xinch", config, "nonint"))
    imggenlayout.addLayout(posvarconf(
        "Figure height (inch)", "imggen/yinch", config, "nonint"))
    imggenlayout.addLayout(posvarconf(
114
        "Figure dpi", "imggen/dpi", config))
115
    imggenlayout.addLayout(posvarconf(
116
        "Figure x axis major ticks count", "imggen/xtics", config))
117
118
    imggenlayout.addWidget(checkboxconf(
        "Manual annotation only", "imggen/onlymanann", config))
119
120
    tabs.addTab(imggentab, "Image clip/export")

Yan's avatar
Yan committed
121
122
123
124
125
126
127
    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
128
    layout = QtWidgets.QVBoxLayout(dialog)
Yan's avatar
Yan committed
129
    layout.addWidget(QtWidgets.QLabel("Changes are saved automatically"))
130
    layout.addWidget(tabs)
Yan's avatar
Yan committed
131
132
133
134
    layout.addStretch(1)
    layout.addLayout(butt_layout)

    dialog.show()