Commit d359695d authored by Yan's avatar Yan
Browse files

Drag and drop support in main_window

parent ac52fa71
......@@ -20,12 +20,14 @@ import os.path
matplotlib.use("Qt5Agg")
def load_file(chrom_plot, spc, d_set, ms_s, fn, chrom_s, settings):
def load_file(chrom_plot, spc, d_set, ms_s, fn, chrom_s, settings,
filename=None):
"""populates dataset and plots it"""
directory=settings.value("open_folder")
if fn[0] is not None:
directory=fn[0]
filename = QtWidgets.QFileDialog.getOpenFileName(
if filename == None:
filename = QtWidgets.QFileDialog.getOpenFileName(
caption="Open spectrum",
directory=directory,
filter="Finnigan RAW files (*.raw, *.RAW)")[0]
......@@ -48,6 +50,19 @@ def update_spectrum(event, chromatogram, spect, ds,
spect.get_figure().canvas.draw()
def dropped(event, chromatogram, spectrum, ds, ms, filename, chrom,
config):
dropurl = event.mimeData().urls()[0].path()
load_file(chromatogram, spectrum, ds, ms, filename, chrom,
config, filename=dropurl)
def drag_entered(event):
if event.mimeData().hasUrls() and event.mimeData().urls()[0]\
.path().lower().endswith('.raw'):
event.accept()
def main():
# ds for data_set, ms for mass_spec_dataset, chrom for chrom_dataset
ds = dict(chrom_dat=None, masses=None, matrix=None)
......@@ -133,8 +148,6 @@ def main():
autozoomy.triggered.connect(lambda: gt.autozoomy(
autozoomy.isChecked(), spectrum, ms))
file_menu = QtWidgets.QMenu('&File', main_window)
main_window.menuBar().addMenu(file_menu)
file_menu.addAction(openact)
......@@ -173,14 +186,15 @@ def main():
mpl_canvas.mpl_connect('key_press_event', lambda event:
update_spectrum(event, chromatogram, spectrum, ds, ms,
filename, chrom, config))
main_window.dragEnterEvent = lambda event: drag_entered(event)
main_window.dropEvent = lambda event: dropped(
event, chromatogram, spectrum, ds, ms, filename, chrom,
config)
main_window.setAcceptDrops(True)
if len(sys.argv) == 2:
raw_file = sys.argv[1]
filename[0] = raw_file
ds['chrom_dat'], ds['masses'], ds['matrix'] = load_raw(
raw_file, config.value("tmp_location"))
gt.populate(chromatogram, spectrum, ds, ms, chrom)
load_file(chromatogram, spectrum, ds, ms, filename, chrom,
config, filename=sys.argv[1])
else:
gt.pop_plot(spectrum, ms)
gt.pop_plot(chromatogram, chrom)
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment