Commit 16619e58 authored by Yori 'AGy' Fournier's avatar Yori 'AGy' Fournier
Browse files

Now visualisation is working!!

The loaded data build rawdata that is transmitted to the plot

may need some cleaning.
parent 59ef87d2
......@@ -26,6 +26,7 @@ QIcon = QtGui.QIcon
QComboBox = QtGui.QComboBox
QFileDialog = QtGui.QFileDialog
QFormLayout = QtGui.QFormLayout
QListWidget = QtGui.QListWidget
# MatPlotLib
from matplotlib.backends.backend_qt4agg import FigureCanvasQTAgg as QCanvas
......@@ -40,6 +41,7 @@ from .pythonHighlighter import PythonHighlighter
from .qMyFigContainer import QMyFigContainer
from .qTabMyAxes import QTabMyAxes
from .qTabMyFig import QTabMyFig
from .qTabMyData import QTabMyData
from .qMyDesignTabs import QMyDesignTabs
from .qMyDesignWidget import QMyDesignWidget
from .qOpenFileWidget import QOpenFileWidget
......
*
!.gitignore
from .. import np
def readOrgFile(path2data, filename='runParam.org'):
# THROUGH THE POSSIBLE lAST / AWAY
if path2data[-1] == '/': path2data = path2data[:-1]
# TRY TO READ
try:
# INIT
firstLine = True # bool for testing first line
runs = None # future np.recarray to output
# OPENING
f = open(str(path2data)+'/'+str(filename), 'r')
# READING
for line in f.readlines():
# IF THE LINE LOOK LIKE AN ORG ARRAY (EXCLUDING |---+--...)
if(line[0] == '|' and line[1] != '-'):
# IF FIRST LINE -> DETECT NAMES
if(firstLine):
names = line.split('|')[1:-1]
# THROUGH AWAY THE WHITESPACES
for i in np.arange(0, len(names)):
names[i] = names[i].replace(" ", "")
# CREATE THE CORRESPONDING DTYPE
dtype = []
for name in names:
# NAMES ENDING IN _S are STRINGS
if name[-2:] == '_s':
dtype_tmp = (str(name[:-2]), '|S14')
dtype.append(dtype_tmp)
# OTHER FLOATS
else:
dtype_tmp = (str(name), float)
dtype.append(dtype_tmp)
firstLine = False
# IF WE ARE READING DATA
else:
run = line.split('|')[1:-1]
tmp = []
# CREATE THE RECARRAY CORRESPONDING TO THE LINE
for (dtp, data) in zip(dtype, run):
# IF DTYPE SAYS STRING MAKE A STRING WITHOUT WHITE SPACE
if dtp[1] == '|S14':
tmp.append(str(data.replace(' ', '')))
# IF DTYPE SAYS FLOAT MAKE A FLOAT
else:
# IF EMPTY MAKE 0.0
if(str(data).replace(' ', '') != ''):
tmp.append(float(data))
else:
tmp.append(0.0)
# CREATE THE RECARRAY FROM DATA and DTYPE
sglrun = np.array([tuple(tmp)], dtype=dtype)
tmp = None
# APPEND THE CURRENT LINE TO RUNS
if(runs is None):
runs = sglrun
else:
runs = np.append(runs, sglrun)
sglrun = None
# IF IOERROR TELLS THE USER AND RETURN NONE.
except IOError:
return(None)
# MAKE THE NDARRAY TO BECOME A RECARRAY
runs = runs.view(np.recarray)
return(runs)
......@@ -47,7 +47,8 @@ class QMyDesignGui(QMainWindow):
def openData(self):
self.openFilePopup.show()
def executeFunct(self, function):
print('EXECUTE!!!' + str(function))
self.centralWidget().figContainer.rawdata = eval('myIOs.'+str(function))
self.centralWidget().openData(eval('myIOs.'+str(function)))
......@@ -2,6 +2,7 @@ from . import QTabWidget
from . import QWidget
from . import QTabMyAxes
from . import QTabMyFig
from . import QTabMyData
from . import MyDesign
......@@ -13,7 +14,9 @@ class QMyDesignTabs(QTabWidget):
self.figTab = QTabMyFig(self)
self.axesTab = QTabMyAxes(self)
self.dataTab = QTabMyData(self)
self.addTab(self.dataTab, "MyData")
self.addTab(self.figTab, "MyFigure")
self.addTab(self.axesTab, "MyAxes")
......
......@@ -3,6 +3,7 @@ from . import QGridLayout
from . import QPushButton
from . import QMyFigContainer
from . import QMyDesignTabs
from . import MyData
class QMyDesignWidget(QWidget):
......@@ -14,9 +15,12 @@ class QMyDesignWidget(QWidget):
self.layout = QGridLayout(self)
self.layout.setSpacing(10)
self.openedData = {}
self.rawdata = MyData()
self.designTabs = QMyDesignTabs(self)
plotDesign = self.designTabs.getPlotDesign()
self.figContainer = QMyFigContainer(plotDesign, self)
self.figContainer = QMyFigContainer(plotDesign, self.rawdata, self)
self.refreshButton = QPushButton("Refresh", self)
self.refreshButton.setShortcut('F5')
......@@ -26,13 +30,29 @@ class QMyDesignWidget(QWidget):
self.layout.addWidget(self.designTabs, 0, 0, 2, 1)
self.refreshButton.clicked.connect(self.refresh)
self.designTabs.dataTab.updated.connect(self.updateRawdata)
def refresh(self):
plotDesign = self.designTabs.getPlotDesign()
self.figContainer.refresh(plotDesign) # Recreate the figure
self.figContainer.refresh(plotDesign, self.rawdata) # Recreate the figure
self.repaint() # This will call paintEvent when all events are treated
def paintEvent(self, event):
self.figContainer.paint()
def openData(self, data):
self.openedData.update({data.name: data})
self.designTabs.dataTab.refreshOpenedList(data.name)
def updateRawdata(self):
self.rawdata = ()
for item in self.designTabs.dataTab.loadedList.iterItems():
self.rawdata = self.rawdata + (self.openedData[str(item.text())],)
print(self.rawdata)
......@@ -10,13 +10,11 @@ from . import MyData
class QMyFigContainer(QWidget):
def __init__(self, plotDesign, parent=None):
def __init__(self, plotDesign, rawdata, parent=None):
super(QMyFigContainer, self).__init__(parent)
self.rawdata = MyData()
self.figure = FigDesign(self.rawdata, plotDesign)
self.figure = FigDesign(rawdata, plotDesign)
self.canvas = QCanvas(self.figure)
self.layout = QVBoxLayout(self)
......@@ -25,13 +23,13 @@ class QMyFigContainer(QWidget):
self.figure.plot()
self.canvas.draw()
def refresh(self, plotDesign):
def refresh(self, plotDesign, rawdata):
# Recreate a figure
try:
self.figure = FigDesign(self.rawdata, plotDesign)
self.figure = FigDesign(rawdata, plotDesign)
except:
self.figure = FigDesign(self.rawdata, MyDesign())
self.figure = FigDesign(rawdata, MyDesign())
# Link the figure with the canvas
self.figure.set_canvas(self.canvas)
......
from . import QWidget
from . import QGridLayout
from . import QLabel
from . import QListWidget
from . import QPushButton
from . import QSignal
class MyListWidget(QListWidget):
def iterItems(self):
index = 0
while index < self.count():
yield self.item(index)
index += 1
class QTabMyData(QWidget):
updated = QSignal()
def __init__(self, parent=None):
super(QTabMyData, self).__init__(parent)
self.layout = QGridLayout(self)
self.openedLabel = QLabel('Opened', self)
self.openedList = MyListWidget(self)
self.loadButton = QPushButton('Load', self)
self.loadedLabel = QLabel('Rawdata', self)
self.loadedList = MyListWidget(self)
self.unloadButton = QPushButton('Unload', self)
self.layout.addWidget(self.openedLabel, 0, 0)
self.layout.addWidget(self.openedList, 1, 0, 15, 1)
self.layout.addWidget(self.loadButton, 16, 0)
self.layout.addWidget(self.loadedLabel, 0, 1)
self.layout.addWidget(self.loadedList, 1, 1, 15, 1)
self.layout.addWidget(self.unloadButton, 16, 1)
self.loadButton.clicked.connect(self.loadData)
self.unloadButton.clicked.connect(self.unloadData)
def loadData(self):
for item in self.openedList.selectedItems():
self.loadedList.addItem(item.text())
self.updated.emit()
def unloadData(self):
for item in self.loadedList.selectedItems():
self.loadedList.takeItem(self.loadedList.row(item))
self.updated.emit()
def refreshOpenedList(self, datakey):
alreadyThere = False
for item in self.openedList.iterItems():
if item.text() == datakey:
alreadyThere = True
if not alreadyThere:
self.openedList.addItem(datakey)
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