config.py 4.52 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),
24
               ("recents", "")}
Yan's avatar
Yan committed
25
    [settings.setValue(*i)
Yan's avatar
Yan committed
26
     for i in defvals if not settings.contains(i[0])]
Yan's avatar
Yan committed
27
28
29
    return settings


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


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

Yan's avatar
Yan committed
51

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


68
69
70
71
72
73
74
75
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
76
77
78
79
def dial(parent):
    """constructs a dialog window"""
    dialog = QtWidgets.QDialog(
        parent, windowTitle='Settings')
80
    dialog.resize(600, -1)
Yan's avatar
Yan committed
81
82

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

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

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

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

    dialog.show()