Commit 59ef87d2 authored by Yori 'AGy' Fournier's avatar Yori 'AGy' Fournier
Browse files

Openning Data is now working!

Need to be tested and checked, surely a lot of bugs.
But prototype is working!!
parent 0298cbb5
......@@ -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
......@@ -25,6 +25,7 @@ QAction = QtGui.QAction
QIcon = QtGui.QIcon
QComboBox = QtGui.QComboBox
QFileDialog = QtGui.QFileDialog
QFormLayout = QtGui.QFormLayout
# MatPlotLib
from matplotlib.backends.backend_qt4agg import FigureCanvasQTAgg as QCanvas
......
from readSerie import readSerie
# 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]
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)
......@@ -4,6 +4,7 @@ from . import QAction
from . import QIcon
from . import QWidget
from . import QOpenFileWidget
from . import myIOs
class QMyDesignGui(QMainWindow):
......@@ -16,6 +17,9 @@ class QMyDesignGui(QMainWindow):
self.initMenu()
self.openFilePopup = QOpenFileWidget()
self.openFilePopup.triggered.connect(self.executeFunct)
self.setCentralWidget(QMyDesignWidget(self))
self.setWindowTitle('My Design Gui')
......@@ -42,7 +46,8 @@ class QMyDesignGui(QMainWindow):
self.menusOfTheMenuBar['File'].addAction(self.actionOfTheMenuBar['open'])
def openData(self):
self.openFilePopup = QOpenFileWidget()
self.openFilePopup.resize(200, 200)
self.openFilePopup.show()
def executeFunct(self, function):
print('EXECUTE!!!' + str(function))
self.centralWidget().figContainer.rawdata = eval('myIOs.'+str(function))
......@@ -4,13 +4,9 @@ from . import QPushButton
from . import QMyFigContainer
from . import QMyDesignTabs
from . import Signal
class QMyDesignWidget(QWidget):
refreshed = Signal()
def __init__(self, parent=None):
super(QMyDesignWidget, self).__init__(parent)
......@@ -34,7 +30,6 @@ class QMyDesignWidget(QWidget):
def refresh(self):
plotDesign = self.designTabs.getPlotDesign()
self.figContainer.refresh(plotDesign) # Recreate the figure
self.repaint() # This will call paintEvent when all events are treated
......
......@@ -14,7 +14,9 @@ class QMyFigContainer(QWidget):
super(QMyFigContainer, self).__init__(parent)
self.figure = FigDesign(MyData(), plotDesign)
self.rawdata = MyData()
self.figure = FigDesign(self.rawdata, plotDesign)
self.canvas = QCanvas(self.figure)
self.layout = QVBoxLayout(self)
......@@ -27,9 +29,9 @@ class QMyFigContainer(QWidget):
# Recreate a figure
try:
self.figure = FigDesign(MyData(), plotDesign)
self.figure = FigDesign(self.rawdata, plotDesign)
except:
self.figure = FigDesign(MyData(), MyDesign())
self.figure = FigDesign(self.rawdata, MyDesign())
# Link the figure with the canvas
self.figure.set_canvas(self.canvas)
......
......@@ -4,38 +4,175 @@ 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('__'):
AVAIL_FUNCTIONS.append(key)
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)
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):
self.filename = QFileDialog.getOpenFileName(self)
self.fileNameLabel = QLineEdit(self)
self.fileNameLabel.setText(self.filename)
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.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.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.fileNameLabel.setText(str(self.argLabels))
# self.layout.addWidget(self.fileNameLabel)
self.layout = QVBoxLayout(self)
self.layout.addWidget(self.functionsCombo)
self.layout.addWidget(self.fileNameLabel)
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