Commit d7531555 authored by Yan's avatar Yan
Browse files

Improved exporting procedure

* improved code readability
parent 95f1bff0
......@@ -8,7 +8,7 @@ def open_dial(d_set):
filename = QtWidgets.QFileDialog.getOpenFileName(
caption="Open spectrum",
filter="Finnigan RAW files (*.raw, *.RAW)")[0]
if filename is not'':
if filename is not '':
d_set['chrom_dat'], d_set['masses'], d_set['matrix'] \
= load_raw(filename)
return filename
......@@ -16,6 +16,28 @@ def open_dial(d_set):
return None
def get_save_filename(caption, fnfilter, suffix, parent):
"""fix Qt5 "feature" - it does add sufix when exporting
and thus also cant check for file with the selected suffix"""
filename = QtWidgets.QFileDialog.getSaveFileName(
caption=caption, filter=fnfilter,
options = QtWidgets.QFileDialog.DontConfirmOverwrite)[0]
if suffix[0] is not ".":
suffix = ".{}".format(suffix)
if filename[-len(suffix):] != suffix:
filename = "".join((filename, suffix))
if os.path.isfile(filename):
quest = QtWidgets.QMessageBox.warning(
parent, caption,
"File {} already exists in the filesystem.\n"
"Do you want to overwrite it?"
.format(os.path.basename(filename)),
QtWidgets.QMessageBox.Yes, QtWidgets.QMessageBox.No)
if quest == QtWidgets.QMessageBox.No:
filename = ''
return filename
def export_dial(mass_spec, chrom_spec, fn, main_window):
"""exports the chromatogram into the .dat file format"""
if fn[0] is None:
......@@ -23,21 +45,9 @@ def export_dial(mass_spec, chrom_spec, fn, main_window):
main_window, "Export spectrum",
"Nothing to export, cancelling request")
return
exp_f_name = QtWidgets.QFileDialog.getSaveFileName(
caption="Export spectrum",
filter="dat table format (*.dat)")[0]
exp_f_name = get_save_filename(
"Export spectrum", "dat table (*.dat)", "dat", main_window)
if exp_f_name is not '':
# fix for Qt5 "Feature"
if exp_f_name[-4:] != '.dat':
exp_f_name = exp_f_name + ".dat"
if os.path.isfile(exp_f_name):
quest = QtWidgets.QMessageBox.warning(
main_window, "Export spectrum",
"{} already exists.\n Do you want to replace it?"
.format(os.path.basename(exp_f_name)),
QtWidgets.QMessageBox.Yes, QtWidgets.QMessageBox.No)
if(hex(quest)) == "0x10000":
return
expf = open(exp_f_name, 'w')
expf.write("mass ion_count\n"
"m/z\n"
......
import numpy as np
import prasopes.graphtools as gt
import os.path
import pkg_resources
from matplotlib.backends.backend_qt5agg import FigureCanvasQTAgg as FigureCanvas
from matplotlib.figure import Figure
from PyQt5 import QtCore
from PyQt5 import QtWidgets
import numpy as np
import prasopes.graphtools as gt
import prasopes.filetools as ft
import os.path
import pkg_resources
def pop_dial(zcespec, gradspect, data_set, widget, coff_d, grad_d,
......@@ -61,21 +62,9 @@ def exp_zce(zce_spec, zcegrad_spec, fn, parent):
parent, "Export ZCE spectrum",
"Nothing to export, cancelling request")
return
exp_f_name = QtWidgets.QFileDialog.getSaveFileName(
caption="Export ZCE spectrum",
filter="dat table format (*.dat)")[0]
exp_f_name = ft.get_save_filename(
"Export ZCE spectrum", "dat table (*.dat)", "dat", parent)
if exp_f_name is not '':
# fix for Qt5 "Feature"
if exp_f_name[-4:] != '.dat':
exp_f_name = exp_f_name + ".dat"
if os.path.isfile(exp_f_name):
quest = QtWidgets.QMessageBox.warning(
parent, "Export spectrum",
"{} already exists.\n Do you want to replace it?"
.format(os.path.basename(exp_f_name)),
QtWidgets.QMessageBox.Yes, QtWidgets.QMessageBox.No)
if(hex(quest)) == "0x10000":
return
expf = open(exp_f_name, 'w')
expf.write("mass ion_count ion_count_gradient fwhm_x fwhm_y\n"
"m/z\n"
......
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