config.py 3.61 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
17
18
19
               ("view/oddeven", False),
               ("print/xinch", 10),
               ("print/yinch", 4),
               ("print/dpi", 300),
               ("imggen/xinch", 10),
               ("imggen/yinch", 4),
               ("imggen/dpi", 300)}
Yan's avatar
Yan committed
20
    [settings.setValue(i[0], i[1]) for i in defvals if settings.value(i[0]) == None]
Yan's avatar
Yan committed
21
22
23
    return settings


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


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

Yan's avatar
Yan committed
45

46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
def posintvarconf(label, value, config):
    """adds generic positive integer config line"""
    textfield = QtWidgets.QLineEdit(config.value(value))
    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
61
62
63
64
65
66
67
def dial(parent):
    """constructs a dialog window"""
    dialog = QtWidgets.QDialog(
        parent, windowTitle='Settings')
    dialog.resize(600,-1)

    config = settings()
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98

    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))
    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))
    tabs.addTab(imggentab, "Image clip/export")

Yan's avatar
Yan committed
99
100
101
102
103
104
105
    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
106
    layout = QtWidgets.QVBoxLayout(dialog)
107
    layout.addWidget(tabs)
Yan's avatar
Yan committed
108
109
110
111
    layout.addStretch(1)
    layout.addLayout(butt_layout)

    dialog.show()