Commit 4e4cfd13 authored by Yori Fournier's avatar Yori Fournier
Browse files

Merge branch '13-data-visualisator' into 'master'

Resolve "FEATURE: Data visualisator" and "FEATURE: Open data button"

Closes #13 and #10

See merge request !7
parents a8c68298 6abbb0e7
......@@ -4,7 +4,7 @@ import sys
try:
from PyQt4 import QtGui
from PyQt4 import QtCore
Signal = QtCore.pyqtSignal
QSignal = QtCore.pyqtSignal
except:
from PySide import QtGui
from PySide import QtCore
......@@ -21,12 +21,18 @@ QLabel = QtGui.QLabel
QLineEdit = QtGui.QLineEdit
QTextEdit = QtGui.QTextEdit
QPlainTextEdit = QtGui.QPlainTextEdit
QAction = QtGui.QAction
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
# MyPlotLib
from myplotlib import MyAxes, MyFig, MyData
from myplotlib import MyAxes, MyFig, MyData, np
from myplotlib.test import FigTest1, readStupidData, readStupidData2
from .mplDesign import MyDesign, AxDesign, FigDesign
......@@ -35,7 +41,13 @@ 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
from .qMyDesignGui import QMyDesignGui
# Import IOs
import myIOs
......@@ -2,6 +2,11 @@ from . import sys
from . import QApplication
from . import QMyDesignGui
from . import myIOs
for key in myIOs.__dict__.keys():
if key not in myIOs.__builtins__.keys() and not key.startswith('__'):
print(key)
app = QApplication(sys.argv)
......
*
!.gitignore
# ATTENTION !! THIS FILE SHOULD NOT BE MODIFIED !!
# IF SOME STUFF LOOK WIERD THEY ALL HAVE A REASON !
# IMPORT OS -- SHOULD BE DONE THAT WAY TO DETECT THE FUNCTION PROPERLY
import os
# LIST OF FILE NAMES IN myIOS/*.py (except *_*.py)
functions = []
for function in os.listdir(os.path.dirname(os.path.abspath(__file__))):
if function[-3:] == '.py' and '_' not in os.path.basename(function):
functions.append(function[:-3])
# LOOP OVER FILES AND IMPORT THE FUNCTION
# THIS IS EQUIVALENT TO: FROM .FILE IMPORT FILE
for function in functions:
module = __import__('mydesigngui.myIOs', globals(), locals(), [function], -1)
subMod = vars(module)[function]
vars()[function] = vars(subMod)[function]
from .. import MyData # CLASSES
from .readOrgFile import readOrgFile # FUNCTIONS
_D_DTNAME = None
_D_FILENAME = 'serieParam.org'
def readSerie(path2data, filename=_D_FILENAME, dtName=_D_DTNAME):
if(str(path2data)[-1] == '/'): path2data = path2data[:-1]
# CREATE LOCAL RAW DATA CONTAINER ------------------------------------
lrawdata = MyData()
# Give a name to the data set
if(dtName is not None):
lrawdata.name = str(dtName)
else:
lrawdata.name = str(path2data).split('/')[-1]
# READ SERIEPARAM.ORG
lrawdata.data = readOrgFile(path2data, filename=filename)
return(lrawdata)
def functionTest(a, b, c):
dol=45
return(42)
def functionTest2(d, e, f=12):
dol=45
return(43)
def functionTest3(g, h, k, *args):
dol=45
return(44)
def functionTest4(i, *args, **kwargs):
dol=45
return(45)
def functionTest5(j, f, **kwargs):
dol=45
return(45)
def functionTest6(j, f=13, **kwargs):
d=41
return(45)
from . import QMyDesignWidget
from . import QMainWindow
from . import QAction
from . import QIcon
from . import QWidget
from . import QOpenFileWidget
from . import myIOs
class QMyDesignGui(QMainWindow):
......@@ -10,7 +15,40 @@ class QMyDesignGui(QMainWindow):
self.statusBar() # an ugly wrapper to create the statusBar
self.initMenu()
self.openFilePopup = QOpenFileWidget()
self.openFilePopup.triggered.connect(self.executeFunct)
self.setCentralWidget(QMyDesignWidget(self))
self.setWindowTitle('My Design Gui')
self.show()
def initMenu(self):
self.menuBar()
self.actionOfTheMenuBar = {'open': QAction(QIcon('open.png'), '&Open', self),
'save': QAction(QIcon('save.png'), '&Save', self),
'close': QAction(QIcon('exit.png'), '&Exit', self)}
self.actionOfTheMenuBar['open'].setStatusTip('Open some data')
self.actionOfTheMenuBar['save'].setStatusTip('Not yet implemented')
self.actionOfTheMenuBar['close'].setStatusTip('Not yet implemented')
self.actionOfTheMenuBar['open'].triggered.connect(self.openData)
self.menusOfTheMenuBar = {'File': self.menuBar().addMenu('&File'),
'Edit': self.menuBar().addMenu('&Edit'),
'Help': self.menuBar().addMenu('&Help')}
self.menusOfTheMenuBar['File'].addAction(self.actionOfTheMenuBar['open'])
def openData(self):
self.openFilePopup.show()
def executeFunct(self, function):
print('EXECUTE!!!' + 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,14 +3,11 @@ from . import QGridLayout
from . import QPushButton
from . import QMyFigContainer
from . import QMyDesignTabs
from . import Signal
from . import MyData
class QMyDesignWidget(QWidget):
refreshed = Signal()
def __init__(self, parent=None):
super(QMyDesignWidget, self).__init__(parent)
......@@ -18,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')
......@@ -30,14 +30,30 @@ 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)
print('OPENED DATA: ' + str(self.openedData))
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,11 +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.figure = FigDesign(MyData(), plotDesign)
self.figure = FigDesign(rawdata, plotDesign)
self.canvas = QCanvas(self.figure)
self.layout = QVBoxLayout(self)
......@@ -23,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(MyData(), plotDesign)
self.figure = FigDesign(rawdata, plotDesign)
except:
self.figure = FigDesign(MyData(), MyDesign())
self.figure = FigDesign(rawdata, MyDesign())
# Link the figure with the canvas
self.figure.set_canvas(self.canvas)
......
from . import QWidget
from . import QComboBox
from . import QVBoxLayout
from . import myIOs
from . import QFileDialog
from . import QLineEdit
from . import QFormLayout
from . import QPushButton
from . import QSignal
from types import FunctionType
AVAIL_FUNCTIONS = []
for key in myIOs.__dict__.keys():
if key not in myIOs.__builtins__.keys() and not key.startswith('__'):
print(myIOs.__dict__[key])
if isinstance(myIOs.__dict__[key], FunctionType):
AVAIL_FUNCTIONS.append(myIOs.__dict__[key])
class QFunctionFormular(QWidget):
def __init__(self, function, parent=None):
super(QFunctionFormular, self).__init__(parent)
self.explicitArgs = () # Args except *args and **kwargs
self.requiredArgs = () # required arguments
self.wRequiredArgs = [] # Widgets Of the Required Args
self.optionalArgs = () # optional arguments
self.wOptionalArgs = []
self.unexplicitArgs = False
self.unexplicitKwArgs = False
argCount = function.func_code.co_argcount # number of explicit arguments
argsName = function.func_code.co_varnames # list of the names of the local variables
defaultValues = function.func_defaults # default value of the optional arguments
# extract the known arguments
self.explicitArgs = argsName[:argCount]
# verify is **kargs is present
if 'kwargs' in argsName:
self.unexplicitKwArgs = True
self.requiredArgs = self.explicitArgs
self.wUnexplicitKwArgs = QLineEdit(self)
# verify if *args present
if 'args' in argsName:
self.unexplicitArgs = True
self.requiredArgs = self.explicitArgs
self.wUnexplicitArgs = QLineEdit(self)
# Is there some optional args
elif len(self.explicitArgs) < len(argsName) and defaultValues is not None:
# get the number of optional arguments
print('EXARGS: ' + str(self.explicitArgs))
print('ARGNAME: ' + str(argsName))
idxOpt = int(-1 * len(defaultValues))
self.requiredArgs = self.explicitArgs[:idxOpt]
self.optionalArgs = self.explicitArgs[idxOpt:]
self.defaultValues = defaultValues
# If neither *arg nor optionals
else:
self.requiredArgs = self.explicitArgs
self.layout = QFormLayout(self)
if self.requiredArgs != ():
# make a QLineEdit without default variable for each requiredArgs
for arg in self.requiredArgs:
self.wRequiredArgs.append(QLineEdit(self))
self.layout.addRow(str(arg), self.wRequiredArgs[-1])
if self.optionalArgs != ():
# make a QLineEdit with default variable for each optionalArgs
for arg, default in zip(self.optionalArgs, self.defaultValues):
self.wOptionalArgs.append(QLineEdit(str(default), self))
self.layout.addRow(str(arg), self.wOptionalArgs[-1])
# make a QLineEdit for the args
if self.unexplicitArgs:
self.layout.addRow('*args', self.wUnexplicitArgs)
# make a QLineEdit for the kwargs
if self.unexplicitKwArgs:
self.layout.addRow('**kwargs', self.wUnexplicitKwArgs)
def getArguments(self):
arguments = []
for widget in self.wRequiredArgs:
arguments.append(str(widget.text()))
if self.wOptionalArgs != []:
for arg, widget in zip(self.optionalArgs, self.wOptionalArgs):
arguments.append(str(arg)+'='+str(widget.text()))
elif self.unexplicitArgs:
arguments.append(str(self.wUnexplicitArgs.text()))
if self.unexplicitKwArgs:
arguments.append(str(self.wUnexplicitKwArgs.text()))
farguments = '({args})'.format(args=', '.join(tuple(arguments)))
return(farguments)
class QOpenFileWidget(QWidget):
triggered = QSignal([str])
def __init__(self, parent=None):
super(QOpenFileWidget, self).__init__(parent)
self.layout = QVBoxLayout(self)
self.functionsCombo = QComboBox(self)
self.layout.addWidget(self.functionsCombo)
self.functionWidgets = []
for function in AVAIL_FUNCTIONS:
self.functionsCombo.addItem(function.__name__)
index = AVAIL_FUNCTIONS.index(function)
print('> FUNCTION:' + str(type(AVAIL_FUNCTIONS[index])))
self.functionWidgets.append(QFunctionFormular(AVAIL_FUNCTIONS[index], self))
self.layout.addWidget(self.functionWidgets[-1])
self.openButton = QPushButton("Open Data", self)
self.layout.addWidget(self.openButton)
self.openButton.clicked.connect(self.emitOpenData)
self.functionsCombo.currentIndexChanged.connect(self.switchFormular)
for widget in self.functionWidgets:
widget.hide()
self.functionWidgets[0].show()
self.currentFunctionWidget = self.functionWidgets[0]
def emitOpenData(self):
functionName = self.functionsCombo.currentText()
arguments = self.currentFunctionWidget.getArguments()
self.triggered.emit(str(functionName)+str(arguments))
self.hide()
def switchFormular(self, i):
for widget in self.functionWidgets:
widget.hide()
self.functionWidgets[i].show()
self.currentFunctionWidget = self.functionWidgets[i]
# self.filename = QFileDialog.getOpenFileName(self)
# self.fileNameLabel = QLineEdit(self)
# self.fileNameLabel.setText(self.filename)
# self.argLabels = []
# for i in range(0, myIOs.__dict__[AVAIL_FUNCTIONS[0]].func_code.co_argcount):
# self.argLabels.append(myIOs.__dict__[AVAIL_FUNCTIONS[0]].func_code.co_varnames[i])
# a = int(-1 * len(myIOs.__dict__[AVAIL_FUNCTIONS[0]].func_defaults))
# for label in self.argLabels[a:]:
# self.argLabels.append(myIOs.__dict__[AVAIL_FUNCTIONS[0]].func_code.co_varnames[i] + '=')
# self.fileNameLabel.setText(str(self.argLabels))
# self.layout.addWidget(self.fileNameLabel)
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