Commit a0e12f8c authored by Yan's avatar Yan
Browse files

Added more Qsettings for modifying GUI

* changed layout of the QSettings
* added functions for intensity annotation and some memory of user
  preferences
parent 123ca658
......@@ -108,7 +108,7 @@ def main():
ds = dict(chrom_dat=None, masses=None, matrix=None)
ms = dict(x=[0], y=[0], line=None, annotation=[],
name="Spectrum", xlabel="m/z", ylabel="ion count",
xtics=20, autoy=True, predict=None)
xtics=20, predict=None)
chrom = dict(x=[0], y=[0], line=None, t_start=None, t_end=None,
name="Chromatogram", xlabel="time(min)",
ylabel="total ion count", timesarg=None)
......@@ -190,11 +190,23 @@ def main():
aboutact = QtWidgets.QAction("&About Prasopes", None)
aboutact.triggered.connect(lambda: about(main_window))
autozoomy = QtWidgets.QAction(QtGui.QIcon.fromTheme(
"zoom-original"), "Auto Zoom Y", None, checkable=True, checked=True)
autozoomy.triggered.connect(lambda: gt.autozoomy(
autozoomy.isChecked(), spectrum, ms))
filebrowseract = QtWidgets.QAction("&File browser", None,
checkable=True, checked=True)
"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()))
autozoomy.triggered.connect(lambda: gt.autozoomy(spectrum, ms))
intensities = QtWidgets.QAction(
"&Show intensities", None, checkable=True,
checked=config.value("view/intensities", type=bool))
intensities.triggered.connect(lambda: config.setValue(
"view/intensities", intensities.isChecked()))
intensities.triggered.connect(lambda: gt.ann_spec(spectrum, ms))
intensities.triggered.connect(lambda: spectrum.figure.canvas.draw())
filebrowseract = QtWidgets.QAction(
"&File browser", None, checkable=True,
checked=config.value("view/filebrowservisible", type=bool))
filebrowseract.triggered.connect(lambda: config.setValue(
"view/filebrowservisible", filebrowseract.isChecked()))
filebrowseract.triggered.connect(
lambda: treedock.show() if filebrowseract.isChecked() == True
else treedock.hide())
......@@ -216,7 +228,11 @@ def main():
tools_menu.addAction(zceact)
tools_menu.addAction(drlact)
tools_menu.addSeparator()
tools_menu.addAction(filebrowseract)
view_menu = QtWidgets.QMenu('&View', main_window)
view_menu.addAction(filebrowseract)
view_menu.addAction(autozoomy)
view_menu.addAction(intensities)
main_window.menuBar().addMenu(view_menu)
help_menu = QtWidgets.QMenu('&Help', main_window)
main_window.menuBar().addMenu(help_menu)
help_menu.addAction(aboutact)
......@@ -233,13 +249,13 @@ def main():
toolBar.addAction(openact)
toolBar.addAction(exportact)
toolBar.addSeparator()
toolBar.addWidget(QtWidgets.QLabel("Predict Formula:"))
toolBar.addWidget(predictform)
toolBar.addSeparator()
toolBar.addAction(zceact)
toolBar.addAction(drlact)
toolBar.addSeparator()
toolBar.addAction(autozoomy)
toolBar.addSeparator()
toolBar.addWidget(QtWidgets.QLabel("Predict Formula:"))
toolBar.addWidget(predictform)
fileModel = QtWidgets.QFileSystemModel()
......@@ -252,6 +268,8 @@ def main():
dirview = QtWidgets.QListView()
dirview.setModel(fileModel)
treedock = QtWidgets.QDockWidget()
if not config.value("view/filebrowservisible",type=bool):
treedock.hide()
treedock.setWidget(QtWidgets.QWidget())
treedock_layout = QtWidgets.QVBoxLayout(treedock.widget())
treedock_layout.addWidget(treeview)
......
......@@ -7,6 +7,10 @@ from PyQt5 import QtPrintSupport
def settings():
settings = QtCore.QSettings("Yansoft","Prasopes")
defvals = {("view/autozoomy", True),
("view/filebrowservisible", True),
("view/intensities", False)}
[settings.setValue(i[0], i[1]) for i in defvals if settings.value(i[0]) == None]
return settings
......
import numpy as np
import prasopes.datatools as dt
import prasopes.config as cf
def zoom_factory(axis, base_scale, plot_data=None):
......@@ -86,7 +87,7 @@ def pan_factory(axis, plot=None):
def pick_masses(x_min, x_max, ms_spec, msdata):
"""zoom the spectrum in x axis by mass range"""
ms_spec.set_xlim(x_min, x_max)
autozoomy(msdata['autoy'], ms_spec, msdata)
autozoomy(ms_spec, msdata)
ann_spec(ms_spec, msdata)
......@@ -101,10 +102,10 @@ def plot_subtime(mpl_spectrum, mpl_chromatogram, data_set, mass_spect,
data_set['matrix'][chrom_spect['timesarg']], axis=0)
pop_plot(mpl_spectrum, mass_spect)
mpl_spectrum.set_xlim(slims[0])
if mass_spect['autoy'] is False:
if not cf.settings().value("view/autozoomy", type=bool):
mpl_spectrum.set_ylim(slims[1])
else:
autozoomy(mass_spect['autoy'], mpl_spectrum, mass_spect)
autozoomy(mpl_spectrum, mass_spect)
mpl_chromatogram.clear()
pop_plot(mpl_chromatogram, chrom_spect)
......@@ -144,9 +145,8 @@ def arrow_factory(spectrum, chromatogram, ds, mass_spect,
fig.canvas.mpl_connect('key_press_event', lambda event: arrow_fun(
event, spectrum, chromatogram, ds, mass_spect, chrom_spect))
def autozoomy(state, ms_spec, msdata):
if state is True:
msdata['autoy'] = True
def autozoomy(ms_spec, msdata):
if cf.settings().value("view/autozoomy", type=bool):
ms_spec.autoscale(True, 'y')
ymin = -0.01
argvis = dt.argsubselect(msdata['x'], *ms_spec.get_xlim())
......@@ -155,8 +155,6 @@ def autozoomy(state, ms_spec, msdata):
ms_spec.set_ylim(ymax*ymin,
ymax*1.1)
ms_spec.figure.canvas.draw()
else:
msdata['autoy'] = False
def ann_spec(ms_spec, msdata, ann_limit=0.01):
......@@ -208,12 +206,16 @@ def ann_spec(ms_spec, msdata, ann_limit=0.01):
msdata['annotation'].clear()
for i in s_peaks:
msdata['annotation'].append(ms_spec.annotate(
#annotation with peak-height
#'{0:.2f}\n{1: .2e}'.format(msdata['x'][i], msdata['y'][i]), xy=(msdata['x'][i], msdata['y'][i]),
'{0:.2f}'.format(msdata['x'][i]), xy=(msdata['x'][i], msdata['y'][i]),
textcoords='data'))
print(cf.settings().value("view/intensities", type=bool))
if cf.settings().value("view/intensities", type=bool):
annotation = '{0:.2f}\n{1: .2e}'.format(msdata['x'][i],
msdata['y'][i])
print("ifim")
else:
annotation = '{0:.2f}'.format(msdata['x'][i])
print("elsim")
msdata['annotation'].append(ms_spec.annotate(annotation,
xy=(msdata['x'][i], msdata['y'][i]), textcoords='data'))
def pop_plot(plot, plot_data):
"""Define and populate plot"""
......
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