* cleanup of the code

* fixed the table view of the PeakWidget
This commit is contained in:
Markus Rosenstihl 2013-07-12 16:11:29 +02:00
parent 805a726346
commit 5f49684e01
7 changed files with 42 additions and 26 deletions

View File

@ -2,7 +2,7 @@
# Form implementation generated from reading ui file 'ConductivityGroupBox.ui' # Form implementation generated from reading ui file 'ConductivityGroupBox.ui'
# #
# Created: Wed Jul 10 18:32:01 2013 # Created: Wed Jul 10 18:57:09 2013
# by: PyQt4 UI code generator 4.10.2 # by: PyQt4 UI code generator 4.10.2
# #
# WARNING! All changes made in this file will be lost! # WARNING! All changes made in this file will be lost!

View File

@ -2,7 +2,7 @@
# Form implementation generated from reading ui file 'PeakGroupBox.ui' # Form implementation generated from reading ui file 'PeakGroupBox.ui'
# #
# Created: Wed Jul 10 18:32:01 2013 # Created: Wed Jul 10 18:57:09 2013
# by: PyQt4 UI code generator 4.10.2 # by: PyQt4 UI code generator 4.10.2
# #
# WARNING! All changes made in this file will be lost! # WARNING! All changes made in this file will be lost!

42
QDS.py
View File

@ -8,17 +8,19 @@ import signal
from PyQt4.QtCore import * from PyQt4.QtCore import *
from PyQt4.QtGui import * from PyQt4.QtGui import *
import matplotlib
import matplotlib.colors
#from matplotlib.backends.backend_qt4agg import FigureCanvasQTAgg as FigureCanvas #from matplotlib.backends.backend_qt4agg import FigureCanvasQTAgg as FigureCanvas
from matplotlib.backends.backend_qt4agg import NavigationToolbar2QTAgg as NavigationToolbar from matplotlib.backends.backend_qt4agg import NavigationToolbar2QTAgg as NavigationToolbar
#import matplotlib.pyplot as plt #import matplotlib.pyplot as plt
import matplotlib.colors
matplotlib.rc_file("default.mplrc")
import numpy as N import numpy as N
import scipy.odr as O import scipy.odr as O
import scipy.optimize as opt import scipy.optimize as opt
import MatplotlibWidget import matplotlibWidget
import QDSMain import QDSMain
import PeakWidget import PeakWidget
from data import Data, Conductivity, conductivity from data import Data, Conductivity, conductivity
@ -267,7 +269,6 @@ class AppWindow(QMainWindow):
TODO: FIX RESIZEING keeping mainwindow maximised for now TODO: FIX RESIZEING keeping mainwindow maximised for now
:param evt: :param evt:
""" """
self.mplWidget.canvas.draw() self.mplWidget.canvas.draw()
self.mplWidget._bg_cache = self.mplWidget.canvas.copy_from_bbox(self.mplWidget.canvas.axes.bbox) self.mplWidget._bg_cache = self.mplWidget.canvas.copy_from_bbox(self.mplWidget.canvas.axes.bbox)
for line in self.mplWidget.canvas.axes.get_lines(): for line in self.mplWidget.canvas.axes.get_lines():
@ -422,6 +423,7 @@ class AppWindow(QMainWindow):
def openFile(self): def openFile(self):
ax = self.mplWidget.canvas.axes ax = self.mplWidget.canvas.axes
ax.clear()
path = unicode(QFileDialog.getOpenFileName(self, "Open file")) path = unicode(QFileDialog.getOpenFileName(self, "Open file"))
# TODO anaylize file (LF,MF, HF) and act accordingly # TODO anaylize file (LF,MF, HF) and act accordingly
data = N.loadtxt(path, skiprows=4) data = N.loadtxt(path, skiprows=4)
@ -499,20 +501,28 @@ class AppWindow(QMainWindow):
else: else:
self.data.fitted_curve.set_xdata(nu[mask]) self.data.fitted_curve.set_xdata(nu[mask])
self.data.fitted_curve.set_ydata(fit[mask]) self.data.fitted_curve.set_ydata(fit[mask])
# handling of fit limit bars
# if self.mplWidget._axvlims != []:
# [axv.remove() for axv in self.mplWidget._axvlims]
# self.mplWidget._axvlims = []
# if self.mplWidget._axvname != []:
# [axvname.remove() for axvname in self.mplWidget._axvname]
# self.mplWidget._axvname = []
#print self.mplWidget._axvlims
if self.mplWidget._axvlims == []:
for i,xlim in enumerate(self.data.fit_limits[:2]):
if self.mplWidget._axvlims != []: self.mplWidget._axvlims.append(ax.axvline(xlim, color="k", ls="--", alpha=0.5, animated=True))
[axv.remove() for axv in self.mplWidget._axvlims] self.mplWidget._axvname.append(ax.text(xlim, y_min*3. , "%.3g"%xlim,
self.mplWidget._axvlims = []
if self.mplWidget._axvname != []:
[axvname.remove() for axvname in self.mplWidget._axvname]
self.mplWidget._axvname = []
for xlim in self.data.fit_limits[:2]:
self.mplWidget._axvlims.append(ax.axvline(xlim, color="k", ls="--", alpha=0.5, animated=True))
self.mplWidget._axvname.append(ax.text(xlim, y_min*3. , "%.3g"%xlim,
horizontalalignment='center', horizontalalignment='center',
verticalalignment='center', verticalalignment='center',
animated=True) ) animated=True) )
else:
for i,xlim in enumerate(self.data.fit_limits[:2]):
self.mplWidget._axvlims[i].set_xdata(xlim)
self.mplWidget._axvname[i].set_x(xlim)
self.mplWidget._axvname[i].set_text("%.3g"%xlim)
self.mplWidget.canvas.restore_region(self.mplWidget._bg_cache) self.mplWidget.canvas.restore_region(self.mplWidget._bg_cache)
self.legend = ax.legend(title="T=%.2f" % (self.data.meta["T"])) self.legend = ax.legend(title="T=%.2f" % (self.data.meta["T"]))
self.legend.set_animated(True) self.legend.set_animated(True)
@ -526,7 +536,7 @@ class PlotWidget(QWidget):
def __init__(self, parent=None): def __init__(self, parent=None):
QWidget.__init__(self) QWidget.__init__(self)
super(PlotWidget, self).__init__(parent) super(PlotWidget, self).__init__(parent)
self.mplwidget = MatplotlibWidget.MatplotlibWidget(hold=True, self.mplwidget = matplotlibWidget.MatplotlibWidget(hold=True,
xlim=(1e-2, 1e7), xlim=(1e-2, 1e7),
xscale='log', xscale='log',
yscale='log') yscale='log')
@ -628,7 +638,7 @@ class CustomToolbar(NavigationToolbar):
self.iend = event.x self.iend = event.x
if self.iend < self.istart: if self.iend < self.istart:
self.iend, self.istart = self.istart, self.iend self.iend, self.istart = self.istart, self.iend
print "released", self.xstart, self.xend #print "released", self.xstart, self.xend
if self._pressed: if self._pressed:
if self.ignore(event): if self.ignore(event):
self.istart = 0 self.istart = 0

View File

@ -2,7 +2,7 @@
# Form implementation generated from reading ui file 'QDSMain.ui' # Form implementation generated from reading ui file 'QDSMain.ui'
# #
# Created: Wed Jul 10 18:32:01 2013 # Created: Wed Jul 10 18:57:09 2013
# by: PyQt4 UI code generator 4.10.2 # by: PyQt4 UI code generator 4.10.2
# #
# WARNING! All changes made in this file will be lost! # WARNING! All changes made in this file will be lost!
@ -64,7 +64,7 @@ class Ui_MainWindow(object):
self.scrollArea.setWidgetResizable(True) self.scrollArea.setWidgetResizable(True)
self.scrollArea.setObjectName(_fromUtf8("scrollArea")) self.scrollArea.setObjectName(_fromUtf8("scrollArea"))
self.scrollAreaWidgetContents = QtGui.QWidget() self.scrollAreaWidgetContents = QtGui.QWidget()
self.scrollAreaWidgetContents.setGeometry(QtCore.QRect(0, 0, 298, 585)) self.scrollAreaWidgetContents.setGeometry(QtCore.QRect(0, 0, 298, 568))
self.scrollAreaWidgetContents.setObjectName(_fromUtf8("scrollAreaWidgetContents")) self.scrollAreaWidgetContents.setObjectName(_fromUtf8("scrollAreaWidgetContents"))
self.verticalLayout_2 = QtGui.QVBoxLayout(self.scrollAreaWidgetContents) self.verticalLayout_2 = QtGui.QVBoxLayout(self.scrollAreaWidgetContents)
self.verticalLayout_2.setObjectName(_fromUtf8("verticalLayout_2")) self.verticalLayout_2.setObjectName(_fromUtf8("verticalLayout_2"))
@ -80,6 +80,7 @@ class Ui_MainWindow(object):
self.statusbar.setObjectName(_fromUtf8("statusbar")) self.statusbar.setObjectName(_fromUtf8("statusbar"))
MainWindow.setStatusBar(self.statusbar) MainWindow.setStatusBar(self.statusbar)
self.toolBar = QtGui.QToolBar(MainWindow) self.toolBar = QtGui.QToolBar(MainWindow)
self.toolBar.setToolButtonStyle(QtCore.Qt.ToolButtonTextUnderIcon)
self.toolBar.setObjectName(_fromUtf8("toolBar")) self.toolBar.setObjectName(_fromUtf8("toolBar"))
MainWindow.addToolBar(QtCore.Qt.TopToolBarArea, self.toolBar) MainWindow.addToolBar(QtCore.Qt.TopToolBarArea, self.toolBar)
self.actionAdd_Peak = QtGui.QAction(MainWindow) self.actionAdd_Peak = QtGui.QAction(MainWindow)

View File

@ -77,7 +77,7 @@
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>298</width> <width>298</width>
<height>585</height> <height>568</height>
</rect> </rect>
</property> </property>
<layout class="QVBoxLayout" name="verticalLayout_2"/> <layout class="QVBoxLayout" name="verticalLayout_2"/>
@ -103,6 +103,9 @@
<property name="windowTitle"> <property name="windowTitle">
<string>toolBar</string> <string>toolBar</string>
</property> </property>
<property name="toolButtonStyle">
<enum>Qt::ToolButtonTextUnderIcon</enum>
</property>
<attribute name="toolBarArea"> <attribute name="toolBarArea">
<enum>TopToolBarArea</enum> <enum>TopToolBarArea</enum>
</attribute> </attribute>

10
data.py
View File

@ -1,6 +1,6 @@
from PyQt4.QtCore import QObject, pyqtSignal from PyQt4.QtCore import QObject, pyqtSignal
import numpy as N import numpy as N
import ConductivityWidget import conductivityWidget
class Data: class Data:
@ -14,8 +14,8 @@ class Data:
self.fit_limits = (frequency.min(), frequency.max(), die_imag.min(), die_imag.max()) self.fit_limits = (frequency.min(), frequency.max(), die_imag.min(), die_imag.max())
def __del__(self): def __del__(self):
self.remove_curves() #self.remove_curves()
pass
#def set_fit_limits(self, limits=(None,None,None,None)): #def set_fit_limits(self, limits=(None,None,None,None)):
def get_data(self): def get_data(self):
""" """
@ -27,7 +27,9 @@ class Data:
return self.frequency[mask], self.epsilon[mask] return self.frequency[mask], self.epsilon[mask]
def remove_curves(self): def remove_curves(self):
print "remove data_curve"
if self.data_curve is not None: self.data_curve.remove() if self.data_curve is not None: self.data_curve.remove()
print "remove fitted_curve"
if self.fitted_curve is not None: self.fitted_curve.remove() if self.fitted_curve is not None: self.fitted_curve.remove()
@ -37,7 +39,7 @@ class Conductivity(QObject):
def __init__(self, mpl=None): def __init__(self, mpl=None):
QObject.__init__(self) QObject.__init__(self)
super(Conductivity, self) super(Conductivity, self)
self.widget = ConductivityWidget.ConductivityWidget() self.widget = conductivityWidget.ConductivityWidget()
self.widget.changedTable.connect(self.updateData) self.widget.changedTable.connect(self.updateData)
self.mpl_line = None self.mpl_line = None
self.mpl_line_static = None self.mpl_line_static = None

View File

@ -2,7 +2,7 @@
# Resource object code # Resource object code
# #
# Created: Mi. Jul 10 18:32:00 2013 # Created: Mi. Jul 10 18:57:09 2013
# by: The Resource Compiler for PyQt (Qt v4.8.4) # by: The Resource Compiler for PyQt (Qt v4.8.4)
# #
# WARNING! All changes made in this file will be lost! # WARNING! All changes made in this file will be lost!