__main__.py 18.2 KB
Newer Older
Yan's avatar
Yan committed
1
2
3
4
#!/usr/bin/env python3

from PyQt5 import QtCore
from PyQt5 import QtWidgets
Yan's avatar
Yan committed
5
from PyQt5 import QtGui
6
from PyQt5 import QtPrintSupport
Yan's avatar
Yan committed
7
from prasopes.predictmz import predict as getmzpattern
8
from pathlib import Path
Yan's avatar
Yan committed
9
try:
Yan's avatar
Yan committed
10
    import rawautoparams
Yan's avatar
Yan committed
11
    autoparams = True
12
except ImportError:
Yan's avatar
Yan committed
13
    autoparams = False
14
import copy
Yan's avatar
Yan committed
15
import rawprasslib
Yan's avatar
Yan committed
16
import prasopes.config as cf
17
import prasopes.datatools as dt
18
import prasopes.drltools_gui as drlgui
Yan's avatar
Yan committed
19
import prasopes.filetools as ft
Yan's avatar
Yan committed
20
21
import prasopes.graphtools as gt
import prasopes.imagetools as imgt
Yan's avatar
Yan committed
22
import prasopes.zcetools as zce
Yan's avatar
Yan committed
23
import prasopes.docks as docks
Yan's avatar
Yan committed
24
import prasopes.datasets as datasets
Yan's avatar
Yan committed
25
import prasopes.mobtools as mt
Yan's avatar
Yan committed
26
import prasopes.tangoicons
Yan's avatar
Yan committed
27
28
import sys
import logging
3Yan's avatar
3Yan committed
29
import os.path
Yan's avatar
Yan committed
30
31


32
33
34
35
class update_signal(QtCore.QObject):
    signal = QtCore.pyqtSignal()


36
37
38
39
class QStatusBarLogger(logging.Handler):
    def __init__(self, parent=None):
        super().__init__()
        self.statusBar = QtWidgets.QStatusBar(parent)
Yan's avatar
Yan committed
40
41
        self.trigger = update_signal()
        self.msg = str("")
42
43

    def emit(self, record):
Yan's avatar
Yan committed
44
45
        self.msg = self.format(record)
        self.trigger.signal.emit()
46
47


48
def show_exception_and_exit(exc_type, exc_value, tb):
49
50
    if "figure size must be positive finite not" in str(exc_value):
        return
51
52
    import traceback
    traceback.print_exception(exc_type, exc_value, tb)
Yan's avatar
Yan committed
53
54
    details = "\n".join(traceback.format_exception(exc_type, exc_value, tb))
    errmsg = "\n".join(traceback.format_exception_only(exc_type, exc_value))\
Yan's avatar
Yan committed
55
        + ("\n The program might misbehave, do you want to continue?")
Yan's avatar
Yan committed
56
57
58
59
60
61
    msgbox = QtWidgets.QMessageBox(
        3, "Exception!", errmsg,
        QtWidgets.QMessageBox.Yes | QtWidgets.QMessageBox.No)
    msgbox.setDetailedText(details)
    outvalue = msgbox.exec_()
    if outvalue != QtWidgets.QMessageBox.Yes:
3Yan's avatar
3Yan committed
62
        sys.exit(-1)
63
64


Yan's avatar
Yan committed
65
def load_file(parent, augCanvas, update, settings, loadthread, filename=None,
Yan's avatar
Yan committed
66
              nothreading=False):
Yan's avatar
Yan committed
67
    """populates dataset and plots it"""
Yan's avatar
Yan committed
68
    directory = augCanvas.ds.filename if augCanvas.ds\
Yan's avatar
Yan committed
69
        else settings.value("open_folder")
70
71
    filename = filename or QtWidgets.QFileDialog.getOpenFileName(
            caption="Open spectrum", directory=directory,
Yan's avatar
Yan committed
72
73
            filter="All supported formats (*.raw *.RAW *.d);;"
                   "Finnigan RAW files (*.raw *.RAW);;timsTOF file (*.d)")[0]
74
75
    if filename != '' and os.path.isfile(filename)\
            and not os.path.isdir(filename):
Yan's avatar
Yan committed
76
77
        error = update_signal()
        errormsg = []
78

79
        def runfnc():
Yan's avatar
Yan committed
80
            try:
Yan's avatar
Yan committed
81
82
83
                augCanvas.ds = datasets.ThermoRawDataset(filename) if\
                        os.path.splitext(filename)[1] in (".raw", ".RAW")\
                        else datasets.BrukerTimsDataset(filename)
84
            except rawprasslib.ParsingException as pex:
Yan's avatar
Yan committed
85
86
                errormsg.append("Opening of the file has failed!")
                errormsg.append(
87
88
                    "File is incompatible with the rawprasslib, "
                    "canceling request!\n\n"
Yan's avatar
Yan committed
89
                    "Error message:\n{}".format(pex.args[0]))
Yan's avatar
Yan committed
90
                error.signal.emit()
91
                return
92
            gt.populate(augCanvas)
93
94
            oldrecents = settings.value("recents")
            oldrecents.remove(filename) if filename in oldrecents else None
Yan's avatar
Yan committed
95
            settings.setValue("recents", [filename, *oldrecents][:10])
96
            update.signal.emit()
97
98
        error.signal.connect(lambda: QtWidgets.QMessageBox.critical(
            parent, errormsg[0], errormsg[1]))
Yan's avatar
Yan committed
99
100
101
102
103
        if nothreading:
            runfnc()
        else:
            loadthread.run = runfnc
            loadthread.start()
3Yan's avatar
3Yan committed
104

Yan's avatar
Yan committed
105

106
def print_graph(augCanvas):
Yan's avatar
Yan committed
107
    def printimage(printdevice, img):
Yan's avatar
Yan committed
108
        printer.setResolution(600)
Yan's avatar
Yan committed
109
        painter = QtGui.QPainter(printdevice)
Yan's avatar
Yan committed
110
111
112
113
        font = painter.font()
        linesize = printer.resolution()/15
        font.setPixelSize(linesize)
        painter.setFont(font)
114
        painter.drawImage(0, 0, img)
Yan's avatar
Yan committed
115
116
117
        offset = img.size().height()
        line = 1
        spacing = 1.5
118
119
120
121
122
        for row in range(augCanvas.paramstable.rowCount()):
            if augCanvas.paramstable.cellWidget(row, 0).checkState() == 2:
                text = augCanvas.paramstable.item(row, 1).text() +\
                       augCanvas.paramstable.item(row, 2).text()
                painter.drawText(300, int(offset+line*linesize*spacing), text)
Yan's avatar
Yan committed
123
                line += 1
Yan's avatar
Yan committed
124
        painter.end()
125
    # TODO: substitute the QPrintPreviewDialog with QPrintPreviewWidget
126
127
    printPreview = QtPrintSupport.QPrintPreviewDialog()
    printer = printPreview.printer()
Yan's avatar
Yan committed
128
129
    printer.setPageSize(printer.A5)
    printer.setDuplex(printer.DuplexNone)
130
    imggen = imgt.ImagePainter("msspec", printer)
Yan's avatar
Yan committed
131
    imggen.popfig = lambda: paint_override(imggen, augCanvas)
132
    image = imggen.paint()
Yan's avatar
Yan committed
133
    printPreview.paintRequested.connect(lambda:
Yan's avatar
Yan committed
134
                                        printimage(printer, image))
135
136
137
    printPreview.exec()


138
def update_spectrum(augCanvas, config):
Yan's avatar
Yan committed
139
    if augCanvas.ds:
140
141
        slims = [augCanvas.spectplot.get_xlim(),
                 augCanvas.spectplot.get_ylim()]
Yan's avatar
Yan committed
142
        augCanvas.ds.refresh()
143
144
145
146
147
        gt.populate(augCanvas)
        augCanvas.spectplot.set_xlim(slims[0])
        augCanvas.spectplot.set_ylim(slims[1])
        gt.ann_spec(augCanvas.spectplot, augCanvas.ms)
        augCanvas.draw()
Yan's avatar
Yan committed
148
149


150
def update_recents(rcm, main_window, augCanvas, update, config, loadthread):
151
    """updates recents_menu (rcm)"""
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
    rcm.clear()
    # Actions need to be stored somewhere. Otherwise they end up in garbage.
    rcm.actionCache = []
    for i, j in enumerate(config.value("recents"), start=1):
        rcm.actionCache.append(QtWidgets.QAction("&{}. {}".format(i, j), None))
        rcm.actionCache[-1].triggered.connect(lambda _, fn=j: load_file(
            main_window, augCanvas, update, config, loadthread, filename=fn))
    rcm.actionCache.append(rcm.addSeparator())
    rcm.actionCache.append(QtWidgets.QAction("Clear Recents", None))
    [rcm.actionCache[-1].triggered.connect(i) for i in (
         lambda: config.setValue("recents", ""), lambda: update_recents(
             rcm, main_window, augCanvas, update, config, loadthread))]
    rcm.addActions(rcm.actionCache)


167
def dropped(event, parent, augCanvas, update, config, loadthread):
168
    dropurl = event.mimeData().urls()[0].toLocalFile()
169
    load_file(parent, augCanvas, update, config, loadthread, filename=dropurl)
Yan's avatar
Yan committed
170
171
172
173


def drag_entered(event):
    if event.mimeData().hasUrls() and event.mimeData().urls()[0]\
174
            .toLocalFile().lower().endswith('.raw'):
Yan's avatar
Yan committed
175
176
177
        event.accept()


178
def predictmz(form, augCanvas):
Yan's avatar
Yan committed
179
180
    text = form.text()
    if text == "":
181
        augCanvas.ms["predict"] = None
Yan's avatar
Yan committed
182
        return
183
184
185
186
187
188
189
    slims = [augCanvas.spectplot.get_xlim(),
             augCanvas.spectplot.get_ylim()]
    augCanvas.ms["predict"] = getmzpattern(text)
    gt.populate(augCanvas)
    augCanvas.spectplot.set_xlim(slims[0])
    augCanvas.spectplot.set_ylim(slims[1])
    augCanvas.draw()
Yan's avatar
Yan committed
190
191


192
def oddeven_changed(augCanvas, config, oddevenact):
Yan's avatar
Yan committed
193
    print("trigd")
3Yan's avatar
3Yan committed
194
    config.setValue("view/oddeven", oddevenact.isChecked())
195
    update_spectrum(augCanvas, config)
3Yan's avatar
3Yan committed
196
197


Yan's avatar
Yan committed
198
def legendvis_changed(augCanvas, config, legendact):
Yan's avatar
Yan committed
199
    config.setValue("view/legend", legendact.isChecked())
Yan's avatar
Yan committed
200
201
202
203
204
205
    if augCanvas.chromplot.get_legend():
        for ax in (augCanvas.spectplot, augCanvas.chromplot):
            ax.get_legend().set_visible(config.value("view/legend", type=bool))
        augCanvas.draw()


Yan's avatar
Yan committed
206
def paint_override(self, augCanvas):
207
208
209
210
    self.plot.set_xlim(augCanvas.spectplot.get_xlim())
    self.plot.set_ylim(augCanvas.spectplot.get_ylim())
    data = [line.get_data() for line in augCanvas.spectplot.lines]
    texts = copy.copy(augCanvas.ms)
Yan's avatar
Yan committed
211
    if augCanvas.ds and augCanvas.ds.headers:
212
213
214
215
216
217
        legend = augCanvas.spectplot.get_legend().get_texts()
        [gt.pop_plot(*line, self.plot, texts, i, legend[i].get_text(),
                     not (cf.settings().value(
                         self.conftype.format("onlymanann"), type=bool)))
            for i, line in enumerate(data)]
        legend = 1
Yan's avatar
Yan committed
218
        if legend:
219
220
221
222
223
224
            self.plot.legend(loc=2)
    else:
        [gt.pop_plot(*line, self.plot, texts, i)
            for i, line in enumerate(data)]
    xtics = int(cf.settings().value(self.conftype.format("xtics")))
    self.plot.locator_params(nbins=xtics, axis='x')
Yan's avatar
Yan committed
225
    if augCanvas.ds:
226
        self.plot.set_title(Path(
Yan's avatar
Yan committed
227
            *Path(augCanvas.ds.filename).resolve().parts[-2:]), loc="right")
228
229


3Yan's avatar
3Yan committed
230
def key_pressed(event, augCanvas, config, update):
Yan's avatar
Yan committed
231
    if event.key() == QtCore.Qt.Key_F5:
232
        update_spectrum(augCanvas, config)
Yan's avatar
Yan committed
233
        if augCanvas.ds:
3Yan's avatar
3Yan committed
234
            update.signal.emit()
235
236
    if event.key() == QtCore.Qt.Key_C:
        if event.modifiers().__int__() == QtCore.Qt.ControlModifier:
237
238
239
            if augCanvas.paramstable.underMouse():
                dt.clip_tablestr(augCanvas)
            else:
240
                painter = imgt.ImagePainter("msspec")
Yan's avatar
Yan committed
241
                painter.popfig = lambda: paint_override(painter, augCanvas)
242
                painter.clip()
243
244
        if event.modifiers().__int__() == QtCore.Qt.ControlModifier + \
                QtCore.Qt.ShiftModifier:
245
            dt.clip_spectstr(augCanvas)
Yan's avatar
Yan committed
246
    if event.key() in (QtCore.Qt.Key_Left, QtCore.Qt.Key_Right):
247
        gt.shift_times(event, augCanvas)
Yan's avatar
Yan committed
248
249


Yan's avatar
Yan committed
250
251
def about(parent):
    """constructs window with "about" info"""
Yan's avatar
Yan committed
252
    rawparver = rawautoparams.__version__ if autoparams else\
Yan's avatar
Yan committed
253
        "library not found"
Yan's avatar
Yan committed
254

Yan's avatar
Yan committed
255
256
257
    QtWidgets.QMessageBox.information(
            parent, "About Prasopes",
            "Prasopes Finnigan raw file viewer\n\n"
Yan's avatar
Yan committed
258
259
260
261
            "Version: {} (alpha)\n\n"
            "Rawprasslib version: {}\n"
            "Rawautoparams version: {}".format(
                prasopes.__version__, rawprasslib.__version__, rawparver))
Yan's avatar
Yan committed
262
263


Yan's avatar
Yan committed
264
def main():
265
266
267
    # thx to: https://stackoverflow.com/questions/779675/stop-python-from-closing-on-error/781074#781074
    sys.excepthook = show_exception_and_exit

268
    app = QtWidgets.QApplication(sys.argv)
269
    loadthread = QtCore.QThread()
270

271
    augCanvas = gt.AugFigureCanvas()
272
    update = update_signal()
Yan's avatar
Yan committed
273

Yan's avatar
Yan committed
274
275
    config = cf.settings()

276
    barHandler = QStatusBarLogger()
277
278
    barHandler.trigger.signal.connect(
        lambda: barHandler.statusBar.showMessage(barHandler.msg))
279

Yan's avatar
Yan committed
280
    p_logger = logging.getLogger('parseLogger')
281
    params_logger = logging.getLogger('acqLogLogger')
Yan's avatar
Yan committed
282
    drl_logger = logging.getLogger('drlLogger')
283
284
    zce_logger = logging.getLogger('zcelogger')
    rxn_logger = logging.getLogger('reactivityLogger')
Yan's avatar
Yan committed
285
    ds_logger = logging.getLogger('dsLogger')
Yan's avatar
Yan committed
286
287
    toflogger = logging.getLogger('tofLogger')
    toflogger.setLevel("DEBUG")
Yan's avatar
Yan committed
288
    logging.basicConfig()
289
    # p_logger.setLevel("WARN")
290
    p_logger.setLevel("DEBUG")
Yan's avatar
Yan committed
291
    ds_logger.setLevel("DEBUG")
292
    rxn_logger.setLevel("DEBUG")
293
    # drl_logger.setLevel("INFO")
Yan's avatar
Yan committed
294
    drl_logger.setLevel("DEBUG")
295
    zce_logger.setLevel("DEBUG")
296
    # params_logger.setLevel("DEBUG")
297
298
    p_logger.addHandler(barHandler)
    zce_logger.addHandler(barHandler)
299
300
    params_logger.addHandler(barHandler)
    barHandler.setLevel("DEBUG")
Yan's avatar
Yan committed
301

Yan's avatar
Yan committed
302
    main_window = QtWidgets.QMainWindow(windowTitle="Prasopes")
303
    update.signal.connect(lambda: main_window.setWindowTitle(
Yan's avatar
Yan committed
304
        "Prasopes - {}".format(os.path.basename(augCanvas.ds.filename))))
Yan's avatar
Yan committed
305

306
    if QtGui.QIcon.themeName() == "":
Yan's avatar
Yan committed
307
308
        QtGui.QIcon.setThemeName("TangoMFK")

Yan's avatar
Yan committed
309
310
311
    consoledock = docks.consoleDockWidget(
            locals(), "&Console", "view/consolevisible")
    treedock = docks.treeDockWidget(
312
313
            "&File browser", "view/filebrowservisible", update, load_file,
            main_window, augCanvas, config, loadthread)
Yan's avatar
Yan committed
314
    paramsdock = docks.AugDock("Acquisition parameters", "&Acq parameters",
315
                               "view/acqparvisible")
316
317
    update.signal.connect(lambda: gt.update_paramstable(augCanvas))
    paramsdock.setWidget(augCanvas.paramstable)
Yan's avatar
Yan committed
318

Yan's avatar
Yan committed
319
    openact = QtWidgets.QAction(QtGui.QIcon.fromTheme(
Yan's avatar
Yan committed
320
        "document-open"), "&Open...", None)
Yan's avatar
Yan committed
321
322
    openact.setShortcut(QtCore.Qt.CTRL + QtCore.Qt.Key_O)
    openact.triggered.connect(lambda: load_file(
323
        main_window, augCanvas, update, config, loadthread))
Yan's avatar
Yan committed
324
    exportact = QtWidgets.QAction(QtGui.QIcon.fromTheme(
Yan's avatar
Yan committed
325
        "document-save-as"), "&Export...", None)
Yan's avatar
Yan committed
326
327
    exportact.setShortcut(QtCore.Qt.CTRL + QtCore.Qt.Key_E)
    exportact.triggered.connect(lambda: ft.export_dial(
328
        augCanvas, main_window))
329
330
331
    printact = QtWidgets.QAction(QtGui.QIcon.fromTheme(
        "document-print"), "&Print", None)
    printact.setShortcut(QtCore.Qt.CTRL + QtCore.Qt.Key_P)
332
    printact.triggered.connect(lambda: print_graph(augCanvas))
Yan's avatar
Yan committed
333
    settingsact = QtWidgets.QAction(QtGui.QIcon.fromTheme(
Yan's avatar
Yan committed
334
        "preferences-system"), "&Settings...", None)
Yan's avatar
Yan committed
335
336
    settingsact.triggered.connect(lambda: cf.dial(main_window))
    quitact = QtWidgets.QAction(QtGui.QIcon.fromTheme(
Yan's avatar
Yan committed
337
        "application-exit"), "&Quit", None)
Yan's avatar
Yan committed
338
339
340
    quitact.setShortcut(QtCore.Qt.CTRL + QtCore.Qt.Key_Q)
    quitact.triggered.connect(main_window.close)
    zceact = QtWidgets.QAction(QtGui.QIcon.fromTheme(
Yan's avatar
Yan committed
341
        "applications-utilities"), "&TSQ zce...", None)
Yan's avatar
Yan committed
342
343
    zceact.setShortcut(QtCore.Qt.CTRL + QtCore.Qt.Key_T)
    zceact.triggered.connect(lambda: zce.dialog(
344
        main_window, augCanvas, update))
Yan's avatar
Yan committed
345
    drlact = QtWidgets.QAction(QtGui.QIcon.fromTheme(
Yan's avatar
Yan committed
346
        "applications-utilities"), "&DRL...", None)
Yan's avatar
Yan committed
347
    drlact.setShortcut(QtCore.Qt.CTRL + QtCore.Qt.Key_D)
348
    drlact.triggered.connect(lambda: drlgui.main_window(
349
        main_window, augCanvas, update))
Yan's avatar
Yan committed
350
351
352
    tofact = QtWidgets.QAction(QtGui.QIcon.fromTheme(
        "applications-utilities"), "TO&F...", None)
    tofact.setShortcut(QtCore.Qt.CTRL + QtCore.Qt.Key_F)
Yan's avatar
Yan committed
353
    tofact.triggered.connect(lambda: mt.main_window(
Yan's avatar
Yan committed
354
        main_window, augCanvas, update))
Yan's avatar
Yan committed
355
356
    aboutact = QtWidgets.QAction("&About Prasopes", None)
    aboutact.triggered.connect(lambda: about(main_window))
Yan's avatar
Yan committed
357
    autozoomy = QtWidgets.QAction(QtGui.QIcon.fromTheme(
Yan's avatar
Yan committed
358
359
360
361
        "zoom-original"), "Auto Zoom Y", None, checkable=True,
        checked=config.value("view/autozoomy", type=bool))
    autozoomy.triggered.connect(lambda: config.setValue(
                                "view/autozoomy", autozoomy.isChecked()))
Yan's avatar
Yan committed
362
    autozoomy.triggered.connect(lambda: gt.autozoomy(augCanvas.spectplot))
363
    intensitiesact = QtWidgets.QAction(
Yan's avatar
Yan committed
364
365
        "&Show intensities", None, checkable=True,
        checked=config.value("view/intensities", type=bool))
366
367
    intensitiesact.triggered.connect(lambda: config.setValue(
        "view/intensities", intensitiesact.isChecked()))
Yan's avatar
Yan committed
368
369
    intensitiesact.triggered.connect(lambda: gt.ann_spec(
        augCanvas.spectplot, augCanvas.ms))
370
    intensitiesact.triggered.connect(lambda: augCanvas.draw())
Yan's avatar
Yan committed
371
372
373
374
375
    legendact = QtWidgets.QAction(
        "&Show legend", None, checkable=True,
        checked=config.value("view/legend", type=bool))
    legendact.triggered.connect(lambda: legendvis_changed(
        augCanvas, config, legendact))
376
    oddevenact = QtWidgets.QAction(
Yan's avatar
Yan committed
377
378
            "&Odd / even", None, checkable=True,
            checked=config.value("view/oddeven", type=bool))
379
380
    oddevenact.triggered.connect(
        lambda: oddeven_changed(augCanvas, config, oddevenact))
Yan's avatar
Yan committed
381

Yan's avatar
Yan committed
382
383
    predictform = QtWidgets.QLineEdit(maximumWidth=150)
    predictform.editingFinished.connect(lambda: predictmz(
384
        predictform, augCanvas))
Yan's avatar
Yan committed
385

386
387
388
389
390
391
    recents_menu = QtWidgets.QMenu('Open &Recent', main_window)
    update_recents(recents_menu, main_window, augCanvas,
                   update, config, loadthread)
    update.signal.connect(lambda: update_recents(
        recents_menu, main_window, augCanvas, update, config, loadthread))

Yan's avatar
Yan committed
392
393
    file_menu = QtWidgets.QMenu('&File', main_window)
    main_window.menuBar().addMenu(file_menu)
Yan's avatar
Yan committed
394
    file_menu.addAction(openact)
395
    file_menu.addMenu(recents_menu)
Yan's avatar
Yan committed
396
397
    file_menu.addAction(exportact)
    file_menu.addSeparator()
398
399
    file_menu.addAction(printact)
    file_menu.addSeparator()
Yan's avatar
Yan committed
400
401
402
    file_menu.addAction(settingsact)
    file_menu.addSeparator()
    file_menu.addAction(quitact)
Yan's avatar
Yan committed
403
404
    tools_menu = QtWidgets.QMenu('&Tools', main_window)
    main_window.menuBar().addMenu(tools_menu)
Yan's avatar
Yan committed
405
406
    tools_menu.addAction(zceact)
    tools_menu.addAction(drlact)
Yan's avatar
Yan committed
407
    tools_menu.addAction(tofact)
408
    tools_menu.addSeparator()
Yan's avatar
Yan committed
409
    view_menu = QtWidgets.QMenu('&View', main_window)
410
411
    [view_menu.addAction(i.action) for i in
     (treedock, paramsdock, consoledock)]
Yan's avatar
Yan committed
412
    [view_menu.addAction(i) for i in (autozoomy, intensitiesact, legendact)]
413
414
    view_menu.addSeparator()
    view_menu.addAction(oddevenact)
Yan's avatar
Yan committed
415
    main_window.menuBar().addMenu(view_menu)
Yan's avatar
Yan committed
416
417
418
    help_menu = QtWidgets.QMenu('&Help', main_window)
    main_window.menuBar().addMenu(help_menu)
    help_menu.addAction(aboutact)
Yan's avatar
Yan committed
419

420
    main_window.setCentralWidget(augCanvas)
Yan's avatar
Yan committed
421

Yan's avatar
Yan committed
422
423
424
425
426
    toolBar = QtWidgets.QToolBar(main_window)
    toolBar.setAllowedAreas(QtCore.Qt.TopToolBarArea)
    toolBar.setFloatable(False)
    toolBar.setMovable(False)
    toolBar.setToolButtonStyle(QtCore.Qt.ToolButtonTextBesideIcon)
Yan's avatar
Yan committed
427

Yan's avatar
Yan committed
428
429
430
    toolBar.addAction(openact)
    toolBar.addAction(exportact)
    toolBar.addSeparator()
Yan's avatar
Yan committed
431
432
433
    toolBar.addWidget(QtWidgets.QLabel("Predict Formula:"))
    toolBar.addWidget(predictform)
    toolBar.addSeparator()
Yan's avatar
Yan committed
434
435
    toolBar.addAction(zceact)
    toolBar.addAction(drlact)
Yan's avatar
Yan committed
436
    toolBar.addAction(tofact)
Yan's avatar
Yan committed
437
438
    toolBar.addSeparator()
    toolBar.addAction(autozoomy)
Yan's avatar
Yan committed
439

Yan's avatar
Yan committed
440
441
    main_window.dragEnterEvent = lambda event: drag_entered(event)
    main_window.dropEvent = lambda event: dropped(
442
        event, main_window, augCanvas, update, config, loadthread)
Yan's avatar
Yan committed
443
    main_window.setAcceptDrops(True)
444
    main_window.keyPressEvent = lambda event: key_pressed(
3Yan's avatar
3Yan committed
445
            event, augCanvas, config, update)
Yan's avatar
Yan committed
446
447
    main_window.resizeEvent = lambda event: augCanvas.constrained_draw()
    update.signal.connect(lambda: augCanvas.constrained_draw())
Yan's avatar
Yan committed
448

449
450
    main_window.addToolBar(QtCore.Qt.TopToolBarArea, toolBar)
    main_window.addDockWidget(QtCore.Qt.LeftDockWidgetArea, treedock)
Yan's avatar
Yan committed
451
    main_window.addDockWidget(QtCore.Qt.RightDockWidgetArea, paramsdock)
Yan's avatar
Yan committed
452
    main_window.addDockWidget(QtCore.Qt.RightDockWidgetArea, consoledock)
453
    main_window.setStatusBar(barHandler.statusBar)
454
455
456

    main_window.setFocus()

Yan's avatar
Yan committed
457
    if len(sys.argv) == 2:
458
        load_file(main_window, augCanvas, update, config, loadthread,
Yan's avatar
Yan committed
459
                  filename=sys.argv[1], nothreading=True)
Yan's avatar
Yan committed
460
    else:
3Yan's avatar
3Yan committed
461
462
        gt.pop_plot([], [], augCanvas.spectplot, augCanvas.ms)
        gt.pop_plot([], [], augCanvas.chromplot, augCanvas.chrom)
Yan's avatar
Yan committed
463
464
465

    main_window.show()
    sys.exit(app.exec_())
Yan's avatar
Yan committed
466

467

Yan's avatar
Yan committed
468
469
if __name__ == "__main__":
    main()