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


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


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


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

Yan's avatar
Yan committed
47

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

    config = settings()
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88

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

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

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

    dialog.show()