Commit 1635b4ff authored by Yan's avatar Yan
Browse files

Rewrote mass_selector

* intensity/mass selector with less spaghetti-code now
parent 0c286a23
......@@ -174,11 +174,7 @@ def oddeven_changed(chromatogram, spectrum, ds, ms, filename, chrom, config,
update_spectrum(chromatogram, spectrum, ds, ms, filename, chrom, config)
def key_pressed(event, chrom, spect, ds, ms_ds, fn, chrom_ds, config,
mass_selector, intensity_selector):
if event.modifiers() == QtCore.Qt.ShiftModifier:
mass_selector.active = False
intensity_selector.active = True
def key_pressed(event, chrom, spect, ds, ms_ds, fn, chrom_ds, config):
if event.key() == QtCore.Qt.Key_F5:
update_spectrum(chrom, spect, ds, ms_ds, fn, chrom_ds, config)
if event.key() == QtCore.Qt.Key_C:
......@@ -191,12 +187,6 @@ def key_pressed(event, chrom, spect, ds, ms_ds, fn, chrom_ds, config,
gt.shift_times(event, spect, chrom, ds, ms_ds, chrom_ds)
def key_released(event, spect, mass_selector, intensity_selector):
if event.key() == QtCore.Qt.Key_Shift:
mass_selector.active = True
intensity_selector.active = False
def about(parent):
"""constructs window with "about" info"""
QtWidgets.QMessageBox.information(
......@@ -260,23 +250,7 @@ def main():
gt.pan_factory(spectrum, ms)
gt.zoom_factory(spectrum, 1.15, ms)
gt.textedit_factory(spectrum, ms)
mass_selector = SpanSelector(
spectrum, lambda x_min, x_max: gt.pick_masses(
x_min, x_max, spectrum, ms), 'horizontal', minspan=0.01,
useblit=True, rectprops=dict(alpha=0.15, facecolor='purple'),
button=3)
intensity_selector = SpanSelector(
spectrum, lambda y_min, y_max: gt.pick_intensities(
y_max, spectrum, ms), 'vertical', minspan=0.01,
useblit=True, rectprops=dict(alpha=0.15, facecolor='purple'),
button=3)
intensity_selector.active=False
time_selector = SpanSelector(
chromatogram, lambda x_min, x_max: gt.pick_times(
x_min, x_max, spectrum, ds, chromatogram, ms, chrom, paramstable),
'horizontal', useblit=True, rectprops=dict(
alpha=0.15, facecolor='purple'), button=3)
mass_selector = gt.AugSpanSelector(spectrum, ms)
main_window = QtWidgets.QMainWindow(windowTitle="Prasopes")
if QtGui.QIcon.themeName() is "":
......@@ -441,10 +415,7 @@ def main():
chrom, update, config)
main_window.setAcceptDrops(True)
main_window.keyPressEvent = lambda event: key_pressed(event, chromatogram,
spectrum, ds, ms, filename, chrom, config,
mass_selector, intensity_selector)
main_window.keyReleaseEvent = lambda event: key_released(event, spectrum,
mass_selector, intensity_selector)
spectrum, ds, ms, filename, chrom, config)
main_window.addToolBar(QtCore.Qt.TopToolBarArea, toolBar)
main_window.addDockWidget(QtCore.Qt.LeftDockWidgetArea, treedock)
......
from PyQt5 import QtWidgets
from PyQt5 import QtCore
from matplotlib.widgets import SpanSelector
from matplotlib.transforms import blended_transform_factory
from matplotlib.patches import Rectangle
import numpy as np
import prasopes.datatools as dt
import prasopes.config as cf
......@@ -14,18 +16,37 @@ colors = np.array([[0, 0, 0], [255, 0, 0], [0, 255, 0], [0, 0, 255],
ann_bbox = dict(boxstyle="round", fc="w", ec="0.5", alpha=0.5)
class AugSpanSelector(SpanSelector):
def __init__(self, ax, data):
SpanSelector.__init__(self, ax, onselect=lambda x,y: None,
direction='horizontal', minspan=0.01, useblit=True,
rectprops=dict(alpha=0.15, facecolor='purple'),
onmove_callback=None, span_stays=False, button=3)
self.data = data
def _press(self, event):
"""on button press event override"""
if QtWidgets.QApplication.keyboardModifiers() ==\
QtCore.Qt.ShiftModifier:
self.direction = 'vertical'
self.onselect = self.pick_intensities
else:
self.direction = 'horizontal'
self.onselect = self.pick_masses
self.new_axes(self.ax)
SpanSelector._press(self, event)
def pick_masses(vmin, vmax, ax, data):
"""zoom the spectrum in x axis by mass range"""
ax.set_xlim(vmin, vmax)
autozoomy(ax)
ann_spec(ax, data)
def pick_masses(self, vmin, vmax):
"""zoom the spectrum in x axis by mass range"""
self.ax.set_xlim(vmin, vmax)
autozoomy(self.ax)
ann_spec(self.ax, self.data)
def pick_intensities(vmax, ax, data):
"""zoom the spectrum in y axis by top intensity from range"""
ax.set_ylim(-vmax*0.01, vmax)
ann_spec(ax, data)
def pick_intensities(self, vmin, vmax):
"""zoom the spectrum in y axis by top intensity from range"""
self.ax.set_ylim(-vmax*0.01, vmax)
ann_spec(self.ax, self.data)
def zoom_factory(axis, base_scale, plot_data=None):
......
Markdown is supported
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