qdsfit/gui/graphs.py

83 lines
2.2 KiB
Python

# coding=utf-8
from PyQt4.QtCore import pyqtSignal
from PyQt4.QtGui import QColor
from data.data import Daten
from libmath.functions import ModelFunction
__author__ = 'markusro'
import pyqtgraph as pg
class Graph(object):
def __init__(self,x = None, y = None):
super(Graph, self).__init__(self)
print "Graph"
self._pen = pg.mkPen(color="w", width=2.0, style=3)
self.graph_real = pg.PlotDataItem(x=x, y=y, pen=self._pen)
self.graph_imag = pg.PlotDataItem(x=x, y=y, pen=self._pen)
@property
def color(self):
return self._pen.color()
@color.setter
def color(self, c):
self._pen.setColor(c)
@property
def style(self):
return self._pen.style()
@style.setter
def style(self, s):
self._pen.setStyle(s)
@property
def width(self):
return self._pen.width()
@width.setter
def width(self, w):
self._pen.setWidth(w)
def set_symbol(self, s):
for gr in self.graph_real, self.graph_imag:
gr.setSymbol(s)
gr.setStyle(0)
def update_graph_data(self, x, y_real, y_imag):
"""
Update Graph data.
@param x:
@param y_real:
@param y_imag:
"""
self.graph_real.setData(x, y_real)
self.graph_imag.setData(x, y_imag)
class DataGraph(Graph):
def __init__(self):
super(DataGraph, self).__init__()
self._pen = pg.mkPen(QColor(0, 0, 0, 0))
self.graph_real = pg.PlotDataItem(x=x, y=y, pen=self._pen, symbol="o", symbolBrush=(255, 127, 0, 127))
self.graph_imag = pg.PlotDataItem(x=x, y=y, pen=self._pen, symbol="o", symbolBrush=(255, 127, 0, 127))
class GraphObject(Graph, Daten, ModelFunction):
parameter_changed_signal = pyqtSignal(list)
def __init__(self):
super(GraphObject, self).__init__(self)
self.data_changed_signal.connect(self.update_graph_data)
def update(self, x, p):
if self.model is not None:
_x, ry, iy = self.model.calculate(x, p)
self.set_data(_x, ry, iy)
self.parameter_changed_signal.emit(list(p))
else:
print "doing nothing"
pass