Commit a7893c0a authored by Yan's avatar Yan
Browse files

Moved AugFigureCanvas into graphtools, minor fixes

* AugFigureCanvas moved from __main__ into graphtools where it belongs
* stderr/stdout redirection of console improved
* inverted scroll action - now without shift it scroll on y-axis
parent 89180a1e
#!/usr/bin/env python3
from matplotlib.backends.backend_qt5agg import\
FigureCanvasQTAgg as FigureCanvas
from matplotlib.figure import Figure
from matplotlib.widgets import SpanSelector
from PyQt5 import QtCore
from PyQt5 import QtWidgets
from PyQt5 import QtGui
......@@ -27,10 +23,8 @@ import prasopes.zcetools as zce
import prasopes.docks as docks
import prasopes.tangoicons
import sys
import matplotlib
import logging
import os.path
matplotlib.use("Qt5Agg")
class update_signal(QtCore.QObject):
......@@ -49,43 +43,6 @@ class QStatusBarLogger(logging.Handler):
self.trigger.signal.emit()
class AugFigureCanvas(FigureCanvas):
# TODO: move the widget into graphtools when I'm done
def __init__(self):
self.figure = Figure(figsize=(5, 4), dpi=100, facecolor="None",
constrained_layout=True)
super().__init__(self.figure)
self.ds = []
self.ms = dict(annotation=[], name="Spectrum", xlabel="m/z",
ylabel="ion count", xtics=20, predict=None,
params=[], headers=[], texts=[])
self.chrom = dict(
x=[0], y=[0], t_start=None, t_end=None, machtype=None,
name="Chromatogram", xlabel="time(min)", ylabel="total ion count",
timesarg=[])
self.filename = None
self.drlcache = [None, None]
grid = self.figure.add_gridspec(2, 1)
self.chromplot = self.figure.add_subplot(grid[0, 0],
facecolor=(1, 1, 1, 0.8))
self.spectplot = self.figure.add_subplot(grid[1, 0],
facecolor=(1, 1, 1, 0.8))
self.setStyleSheet("background-color:transparent;")
self.setAutoFillBackground(False)
self.paramstable = dt.table(["", "name", "value"], 100)
gt.pan_factory(self.chromplot)
gt.zoom_factory(self.chromplot, 1.15)
gt.pan_factory(self.spectplot, self.ms)
gt.zoom_factory(self.spectplot, 1.15, self.ms)
gt.textedit_factory(self.spectplot, self.ms)
self.mass_selector = gt.AugSpanSelector(self.spectplot, self.ms)
# TODO: rewrite timeSelector to better shape when I'm done
self.time_selector = SpanSelector(
self.chromplot, lambda x_min, x_max: gt.pick_times(
x_min, x_max, self), 'horizontal', useblit=True,
rectprops=dict(alpha=0.15, facecolor='purple'), button=3)
def load_file(parent, augCanvas, update, settings, loadthread, filename=None):
"""populates dataset and plots it"""
directory = augCanvas.filename or settings.value("open_folder")
......@@ -245,7 +202,7 @@ def main():
app = QtWidgets.QApplication(sys.argv)
loadthread = QtCore.QThread()
augCanvas = AugFigureCanvas()
augCanvas = gt.AugFigureCanvas()
update = update_signal()
config = cf.settings()
......@@ -258,8 +215,6 @@ def main():
params_logger = logging.getLogger('acqLogLogger')
drl_logger = logging.getLogger('drlLogger')
zce_logger = logging.getLogger('zceLogger')
# mpl_logger = logging.getLogger('matplotlib')
# mpl_logger.setLevel("DEBUG")
logging.basicConfig()
# p_logger.setLevel("WARN")
# p_logger.setLevel("DEBUG")
......
......@@ -59,11 +59,11 @@ def consoleDockWidget(localvars, actionname, cfval):
console = InteractiveConsole(locals=loc)
text = inp.text()
inp.setText("")
with contextlib.redirect_stdout(stream):
with contextlib.redirect_stdout(stream), contextlib.redirect_stderr(stream):
outp.append(">>>"+text)
console.runcode(text)
outtext = stream.getvalue()
if outtext == "":
if outtext == "" and text != "":
with contextlib.redirect_stderr(StringIO()):
# Brief sanitization
console.runcode("""print(eval('{}'.format(str('""" +
......
from PyQt5 import QtWidgets
from PyQt5 import QtCore
from matplotlib.backends.backend_qt5agg import\
FigureCanvasQTAgg as FigureCanvas
from matplotlib.figure import Figure
from matplotlib.widgets import SpanSelector
import numpy as np
import prasopes.datatools as dt
import prasopes.config as cf
import matplotlib
matplotlib.use("Qt5Agg")
colors = np.array([[0, 0, 0], [255, 0, 0], [0, 255, 0], [0, 0, 255],
......@@ -16,6 +20,42 @@ 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 AugFigureCanvas(FigureCanvas):
"""Figure canvas fitted with mass spectrum, chromatogram and more"""
def __init__(self):
self.figure = Figure(figsize=(5, 4), dpi=100, facecolor="None",
constrained_layout=True)
super().__init__(self.figure)
self.ds = []
self.ms = dict(annotation=[], name="Spectrum", xlabel="m/z",
ylabel="ion count", xtics=20, predict=None,
params=[], headers=[], texts=[])
self.chrom = dict(
x=[0], y=[0], t_start=None, t_end=None, machtype=None,
name="Chromatogram", xlabel="time(min)", ylabel="total ion count",
timesarg=[])
self.filename = None
self.drlcache = [None, None]
grid = self.figure.add_gridspec(2, 1)
self.chromplot = self.figure.add_subplot(grid[0, 0],
facecolor=(1, 1, 1, 0.8))
self.spectplot = self.figure.add_subplot(grid[1, 0],
facecolor=(1, 1, 1, 0.8))
self.setStyleSheet("background-color:transparent;")
self.setAutoFillBackground(False)
self.paramstable = dt.table(["", "name", "value"], 100)
pan_factory(self.chromplot)
zoom_factory(self.chromplot, 1.15)
pan_factory(self.spectplot, self.ms)
zoom_factory(self.spectplot, 1.15, self.ms)
textedit_factory(self.spectplot, self.ms)
self.mass_selector = AugSpanSelector(self.spectplot, self.ms)
self.time_selector = SpanSelector(
self.chromplot, lambda x_min, x_max: pick_times(
x_min, x_max, self), 'horizontal', useblit=True,
rectprops=dict(alpha=0.15, facecolor='purple'), button=3)
class AugSpanSelector(SpanSelector):
def __init__(self, ax, data):
super().__init__(
......@@ -93,7 +133,7 @@ def zoom_factory(axis, base_scale, plot_data=None):
# should not happen
scale_factor = 1
print(event.button)
if QtWidgets.QApplication.keyboardModifiers() ==\
if QtWidgets.QApplication.keyboardModifiers() !=\
QtCore.Qt.ShiftModifier:
data = event.ydata
new_top = data + (ax.get_ylim()[1] - data) \
......
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