Commit 2b21c210 authored by Yan's avatar Yan
Browse files

Opening files in separate thread, treeView fix

* FileTree now loads in better view
* GUI is not frozen anymore during file loading
parent b69fcb72
......@@ -47,7 +47,7 @@ class QStatusBarLogger(logging.Handler):
def load_file(parent, chrom_plot, spc, d_set, ms_s, fn, chrom_s,
update, settings, filename=None):
update, settings, loadthread, filename=None):
"""populates dataset and plots it"""
directory=settings.value("open_folder")
if fn[0] is not None:
......@@ -57,37 +57,42 @@ def load_file(parent, chrom_plot, spc, d_set, ms_s, fn, chrom_s,
caption="Open spectrum",
directory=directory,
filter="Finnigan RAW files (*.raw, *.RAW)")[0]
if filename is not '' and os.path.isfile(filename):
try:
d_set.clear()
chrom_s['timesarg'].clear()
[d_set.append(dict(chrom_dat=i[0], masses=i[1], matrix=i[2])) for i
in load_raw(filename, settings.value("tmp_location"))]
except rawprasslib.ParsingException as pex:
QtWidgets.QMessageBox.critical(
parent, "Opening of the file has failed!",
"File is incompatible with the rawprasslib, "
"canceling request!\n\n"
"Error message:\n{}".format(pex.args[0]))
return
[i.clear() for i in (ms_s['params'],ms_s['headers'])]
if autoparams == True:
if filename is not '' and os.path.isfile(filename)\
and not os.path.isdir(filename):
def runfnc():
try:
ms_s['params'], rawheaders = load_params(filename)
segments = [len(subset['chrom_dat'][0]) for subset in d_set]
indicies = [sum(segments[:i+1]) for i in range(len(segments))]
ms_s['headers'] = np.split(rawheaders, indicies)[:-1]
except Exception as pex:
d_set.clear()
chrom_s['timesarg'].clear()
[d_set.append(dict(chrom_dat=i[0], masses=i[1], matrix=i[2]))
for i in load_raw(filename, settings.value("tmp_location"))]
except rawprasslib.ParsingException as pex:
QtWidgets.QMessageBox.critical(
parent, "Parameters readout has failed!",
"File is incompatible with the rawautoparams, "
"no parameters loaded!\n\n"
parent, "Opening of the file has failed!",
"File is incompatible with the rawprasslib, "
"canceling request!\n\n"
"Error message:\n{}".format(pex.args[0]))
gt.populate(chrom_plot, spc, d_set, ms_s, chrom_s)
fn[0] = filename
parent.setWindowTitle("Prasopes - {}".format(
os.path.basename(filename)))
update.signal.emit()
return
[i.clear() for i in (ms_s['params'],ms_s['headers'])]
if autoparams == True:
try:
ms_s['params'], rawheaders = load_params(filename)
segments = [len(subset['chrom_dat'][0]) for subset in d_set]
indicies = [sum(segments[:i+1]) for i in
range(len(segments))]
ms_s['headers'] = np.split(rawheaders, indicies)[:-1]
except Exception as pex:
QtWidgets.QMessageBox.critical(
parent, "Parameters readout has failed!",
"File is incompatible with the rawautoparams, "
"no parameters loaded!\n\n"
"Error message:\n{}".format(pex.args[0]))
gt.populate(chrom_plot, spc, d_set, ms_s, chrom_s)
fn[0] = filename
parent.setWindowTitle("Prasopes - {}".format(
os.path.basename(filename)))
update.signal.emit()
loadthread.run = runfnc
loadthread.start()
def print_graph(data_set, mass_spec, chrom_spec, spect, fn):
......@@ -121,10 +126,10 @@ def update_spectrum(chromatogram, spect, ds, ms, fn, chrom, config):
def dropped(event, parent, chromatogram, spectrum, ds, ms, filename,
chrom, update, config):
chrom, update, config, loadthread):
dropurl = event.mimeData().urls()[0].toLocalFile()
load_file(parent, chromatogram, spectrum, ds, ms, filename,
chrom, update, config, filename=dropurl)
chrom, update, config, loadthread, filename=dropurl)
def drag_entered(event):
......@@ -170,11 +175,12 @@ def about(parent):
QtWidgets.QMessageBox.information(
parent, "About Prasopes",
"Prasopes Finnigan raw file viewer\n\n"
"Version: 0.0.11 (alpha)")
"Version: 0.0.12 (alpha)")
def main():
app = QtWidgets.QApplication(sys.argv)
loadthread = QtCore.QThread()
ds = []
ms = dict(annotation=[], name="Spectrum", xlabel="m/z",
......@@ -192,16 +198,20 @@ def main():
barHandler = QStatusBarLogger()
p_logger = logging.getLogger('parseLogger')
params_logger = logging.getLogger('acqLogLogger')
drl_logger = logging.getLogger('drlLogger')
zce_logger = logging.getLogger('zceLogger')
logging.basicConfig()
#p_logger.setLevel("WARN")
p_logger.setLevel("DEBUG")
p_logger.setLevel("WARN")
#p_logger.setLevel("DEBUG")
#drl_logger.setLevel("INFO")
drl_logger.setLevel("DEBUG")
#drl_logger.setLevel("DEBUG")
zce_logger.setLevel("DEBUG")
params_logger.setLevel("DEBUG")
p_logger.addHandler(barHandler)
zce_logger.addHandler(barHandler)
params_logger.addHandler(barHandler)
barHandler.setLevel("DEBUG")
graph = Figure(figsize=(5, 4), dpi=100, facecolor="None")
grid = graph.add_gridspec(2, 1)
......@@ -237,7 +247,7 @@ def main():
openact.setShortcut(QtCore.Qt.CTRL + QtCore.Qt.Key_O)
openact.triggered.connect(lambda: load_file(
main_window, chromatogram, spectrum, ds, ms, filename, chrom,
update, config))
update, config, loadthread))
exportact = QtWidgets.QAction(QtGui.QIcon.fromTheme(
"document-save-as"), "&Export...", None)
exportact.setShortcut(QtCore.Qt.CTRL + QtCore.Qt.Key_E)
......@@ -343,13 +353,8 @@ def main():
toolBar.addSeparator()
toolBar.addAction(autozoomy)
#fileModel gots stuck sometimes, better give it a separate thread
#it complains at the start, but works and I did not found better solution
fileModel = QtWidgets.QFileSystemModel()
treedockThread = QtCore.QThread()
treedockThread.start()
fileModel.setRootPath('')
fileModel.moveToThread(treedockThread)
activeDir = fileModel.index(config.value("open_folder"))
treeview = QtWidgets.QTreeView()
treeview.setModel(fileModel)
......@@ -358,6 +363,14 @@ def main():
dirview = QtWidgets.QListView()
dirview.setModel(fileModel)
treedock = QtWidgets.QDockWidget()
def scrolltoonce():
fileModel.directoryLoaded.disconnect(scrolltoonce)
treeview.scrollTo(fileModel.index(config.value("open_folder")), 1)
fileModel.directoryLoaded.connect(scrolltoonce)
fileModel.directoryLoaded.connect(
lambda: treeview.resizeColumnToContents(0))
if not config.value("view/filebrowservisible",type=bool):
treedock.hide()
treedock.setWidget(QtWidgets.QWidget())
......@@ -370,10 +383,17 @@ def main():
os.path.dirname(os.path.realpath(filename[0])))))
clickload = lambda index: load_file(
main_window, chromatogram, spectrum, ds, ms, filename, chrom,
update, config, filename=fileModel.filePath(index))
update, config, loadthread, filename=fileModel.filePath(index))
for i in [treeview.doubleClicked, dirview.doubleClicked, dirview.clicked]:
i.connect(clickload)
#fileModel gots stuck sometimes, better give it a separate thread
#it complains at the start, but still works later
#and I did not found better solution
treedockThread = QtCore.QThread()
treedockThread.start()
fileModel.moveToThread(treedockThread)
def closeOverride(event, dock, action):
action.setChecked(False)
dock.hide()
......@@ -397,7 +417,8 @@ def main():
if len(sys.argv) == 2:
load_file(main_window, chromatogram, spectrum, ds, ms,
filename, chrom, update, config, filename=sys.argv[1])
filename, chrom, update, config, loadthread,
filename=sys.argv[1])
else:
gt.pop_plot(0, 0, spectrum, ms)
gt.pop_plot(0, 0, chromatogram, chrom)
......
......@@ -5,7 +5,7 @@ with open("README.md", "r") as fh:
setup(
name="prasopes",
version="0.0.11",
version="0.0.12",
author="Jan Zelenka",
author_email="3yanyanyan@gmail.com",
description="Thermo/Finnigan .raw file viewer based on rawprasslib",
......
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