drltools.py 3.8 KB
Newer Older
Yan's avatar
Yan committed
1
2
3
4
5
6
7
8
9
10
11
12
#!/usr/bin/env python3

from matplotlib.backends.backend_qt5agg import FigureCanvasQTAgg as FigureCanvas
from matplotlib.figure import Figure
from matplotlib.widgets import SpanSelector
from PyQt5 import QtCore
from PyQt5 import QtWidgets
import sys
import matplotlib
import numpy as np
matplotlib.use("Qt5Agg")

Yan's avatar
Yan committed
13

Yan's avatar
Yan committed
14
15
16
17
18
19
20
21
class HBar(QtWidgets.QFrame):
    def __init__(self):
        super(HBar, self).__init__()
        self._main = QtWidgets.QWidget()
        self.setFrameShape(QtWidgets.QFrame.HLine)


def dialog(parent, ds, filename):
Yan's avatar
Yan committed
22
23
    dial_widget = QtWidgets.QDialog(
        parent, windowTitle='Delayed reactant labelling')
Yan's avatar
Yan committed
24

Yan's avatar
Yan committed
25
26
    dial_graph = Figure(figsize=(5, 2), dpi=100, facecolor="None")
    chromplot = dial_graph.add_subplot(111, facecolor=(1, 1, 1, 0.8))
Yan's avatar
Yan committed
27
28
29
30
    graph_canvas = FigureCanvas(dial_graph)
    graph_canvas.setStyleSheet("background-color:transparent;")
    graph_canvas.setAutoFillBackground(False)

Yan's avatar
Yan committed
31
32
33
34
    main_layout = QtWidgets.QVBoxLayout(dial_widget)
    sub_layout = QtWidgets.QHBoxLayout()
    main_layout.addLayout(sub_layout)
    main_layout.addWidget(HBar())
Yan's avatar
Yan committed
35

Yan's avatar
Yan committed
36
37
    tablelayout = QtWidgets.QVBoxLayout()
    main_butlayout = QtWidgets.QHBoxLayout()
Yan's avatar
Yan committed
38
39
40
41

    drl_load = QtWidgets.QPushButton("Load")
    drl_save = QtWidgets.QPushButton("Save")
    drl_export = QtWidgets.QPushButton("Export")
Yan's avatar
Yan committed
42
    cancel = QtWidgets.QPushButton("Cancel")
Yan's avatar
Yan committed
43

Yan's avatar
Yan committed
44
45
46
47
48
49
    main_layout.addLayout(main_butlayout)
    main_butlayout.addWidget(drl_load)
    main_butlayout.addWidget(drl_save)
    main_butlayout.addStretch(1)
    main_butlayout.addWidget(drl_export)
    main_butlayout.addWidget(cancel)
Yan's avatar
Yan committed
50

Yan's avatar
Yan committed
51
52
53
54
    # pt = parenttable
    pt = QtWidgets.QTableWidget(columnCount=3)
    pt.setSizePolicy(QtWidgets.QSizePolicy.Fixed,
                     QtWidgets.QSizePolicy.Expanding)
Yan's avatar
Yan committed
55
    pt.setRowCount(5)
Yan's avatar
Yan committed
56
57
    pt.setHorizontalHeaderLabels(
        ["Name", "start (m/z)", "end (m/z)", "intensity"])
Yan's avatar
Yan committed
58
59
60
    ptx = pt.verticalHeader().width() + pt.verticalScrollBar().height()
    for n in range(pt.columnCount()):
        ptx = ptx + pt.columnWidth(n)
Yan's avatar
Yan committed
61
62
    pt.setMinimumSize(ptx, 0)
    pt.horizontalHeader().setSectionResizeMode(2, QtWidgets.QHeaderView.Stretch)
Yan's avatar
Yan committed
63
    pt.setVerticalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOn)
Yan's avatar
Yan committed
64
65
66
    pt_butlayout = QtWidgets.QHBoxLayout()
    pt_add = QtWidgets.QPushButton("Add")
    pt_rem = QtWidgets.QPushButton("Remove")
Yan's avatar
Yan committed
67
68
69
70

    # dt = daughtertable
    dt = QtWidgets.QTableWidget(columnCount=4)
    dt.setSizePolicy(QtWidgets.QSizePolicy.Fixed, QtWidgets.QSizePolicy.Expanding)
Yan's avatar
Yan committed
71
    dt.setRowCount(3)
Yan's avatar
Yan committed
72
73
    dt.setHorizontalHeaderLabels(
        ["Name", "start (m/z)", "end (m/z)", "corr to"])
Yan's avatar
Yan committed
74
75
76
    dtx = pt.verticalHeader().width() + pt.verticalScrollBar().height()
    for n in range(dt.columnCount()):
        dtx = dtx + dt.columnWidth(n)
Yan's avatar
Yan committed
77
78
79
    dt.setMinimumSize(dtx, 0)
    dt.horizontalHeader().setSectionResizeMode(
        dt.columnCount()-1, QtWidgets.QHeaderView.Stretch)
Yan's avatar
Yan committed
80
    dt.setVerticalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOn)
Yan's avatar
Yan committed
81
82
83
84
    dt_butlayout = QtWidgets.QHBoxLayout()
    dt_add = QtWidgets.QPushButton("Add")
    dt_rem = QtWidgets.QPushButton("Remove")

Yan's avatar
Yan committed
85
86
    add_corr_widget = QtWidgets.QDialog(dial_widget)

Yan's avatar
Yan committed
87
88
    add_corr = QtWidgets.QPushButton("Add correction")
    add_corr.clicked.connect(add_corr_widget.show)
Yan's avatar
Yan committed
89

Yan's avatar
Yan committed
90
91
92
93
94
    sub_layout.addWidget(graph_canvas)
    sub_layout.addLayout(tablelayout)
    tablelayout.addWidget(QtWidgets.QLabel("Raw ions table:"))
    tablelayout.addWidget(pt)
    tablelayout.addLayout(pt_butlayout)
Yan's avatar
Yan committed
95
96
97
    pt_butlayout.addWidget(pt_add)
    pt_butlayout.addWidget(pt_rem)
    pt_butlayout.addStretch(1)
Yan's avatar
Yan committed
98
99
100
101
    tablelayout.addWidget(HBar())
    tablelayout.addWidget(QtWidgets.QLabel("Corrected ions table:"))
    tablelayout.addWidget(dt)
    tablelayout.addLayout(dt_butlayout)
Yan's avatar
Yan committed
102
103
104
    dt_butlayout.addWidget(dt_add)
    dt_butlayout.addWidget(dt_rem)
    dt_butlayout.addStretch(1)
Yan's avatar
Yan committed
105
    dt_butlayout.addWidget(add_corr)
Yan's avatar
Yan committed
106
    dial_widget.show()