toftools.py 2.8 KB
Newer Older
Yan's avatar
Yan committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#!/usr/bin/env python3
from matplotlib.backends.backend_qt5agg import\
        FigureCanvasQTAgg as FigureCanvas
from matplotlib.figure import Figure
from PyQt5 import QtCore
from PyQt5 import QtWidgets
from PyQt5 import QtGui
import matplotlib
import numpy as np
import prasopes.datatools as dt
import prasopes.graphtools as gt
import prasopes.filetools as ft
import prasopes.config as cf
import prasopes.drltools as drl
import prasopes.imagetools as imgt
import os.path
import logging
matplotlib.use("Qt5Agg")


logger = logging.getLogger('tofLogger')
settings = cf.settings()

def main_window(parent, augCanvas, update_signal):
    reactlabels = dict(name="", xlabel="$time (??seconds??)\ \\it→$",
                       ylabel="$Intensity\ \\it→$")
    cache = augCanvas.tofcache

    def onclose(widget, event, ionstable, canvas, cache, update_fnc):
        logger.debug("custom close routine called")
        cache[0], cache[1] = ionstable, canvas
        update_signal.signal.disconnect(update_fnc)
        QtWidgets.QDialog.closeEvent(widget, event)

    def update_fnc():
        pop_dial(augCanvas, drls, dialspect, reactlabels, parselect)

    dial_widget = QtWidgets.QDialog(
            parent, windowTitle='Mobilogram')
    dial_widget.closeEvent = lambda event: onclose(
        dial_widget, event, update_fnc)
    update_signal.signal.connect(update_fnc)

    if cache == [None, None]:
        dial_graph = Figure(figsize=(5, 2), dpi=100, facecolor="None",
                            constrained_layout=True)
        dialspect = dial_graph.add_subplot(111, facecolor=(1, 1, 1, 0.8))
        graph_canvas = FigureCanvas(dial_graph)
        graph_canvas.setStyleSheet("background-color:transparent;")
        graph_canvas.setAutoFillBackground(False)
    
        gt.zoom_factory(dialspect, 1.15, reactlabels)
        gt.pan_factory(dialspect, reactlabels)
    
        ionstable = dt.table(["Name", "Start time (min)", "End time (min)",
                          "Mass (m/z)", "Peak width", "Profile"])
    else:
        ionstable = cache[0]
        grpah_canvas = cache[1]
        dialspect = graph_canvas.figure.axes[0]

    pushbtn = QtWidgets.QPushButton("Update")
    #pushbtn.clicked.connect(lambda: update_fnc())

    expbtn = QtWidgets.QPushButton("Export")
    """expbtn.clicked.connect(lambda: export_dial(
        augCanvas, drls, dialspect, reactlabels, parselect))"""

    buttlayout = QtWidgets.QHBoxLayout()
    buttlayout.addWidget(pushbtn)
    buttlayout.addStretch()
    buttlayout.addWidget(expbtn)
    #layouts.append(buttlayout)

    dial_layout = QtWidgets.QVBoxLayout(dial_widget)
    dial_layout.addWidget(graph_canvas, stretch=1)
    dial_layout.addWidget(ionstable)
    dial_layout.addLayout(buttlayout)
    #[dial_layout.addLayout(i) for i in layouts]
    dial_widget.setFocus()
    dial_widget.show()
    #update_fnc()