Commit ce49ed19 authored by Yori Fournier's avatar Yori Fournier
Browse files

Merge branch '30-show-function-doc' into 'master'

Resolve "FEATURE: Show the doc of the imported functions"

Closes #30

See merge request !12
parents d4a7dca5 aed7c170
......@@ -59,6 +59,8 @@ from myplotlib import MyAxes, MyFig, MyData, np
from myplotlib.test import FigTest1, readStupidData, readStupidData2
from myplotlib import D_DEBUG
D_NO_VERBOSE = False
# CONSTANTS
DEFAULT_DECLARE_ALIASES = '''
self.aliases = {}
......
# IMPORTS
from . import sys
from . import INFO, SPCE, DBUG
from . import D_DEBUG
# CONFIG
D_NO_VERBOSE = False
from . import D_DEBUG
from . import D_NO_VERBOSE
#debug = D_DEBUG
debug = True
......
......@@ -6,6 +6,14 @@ _D_FILENAME = 'serieParam.org'
def readSerie(path2data, filename=_D_FILENAME, dtName=_D_DTNAME):
"""
Read a serieParam.org file from an MFD serie folder.
inputs are:
- path2data: path to the MFD serie folder
- filename: is filename different than serieParam.org
- dtName: name of the returned MyData object
"""
if(str(path2data)[-1] == '/'): path2data = path2data[:-1]
......
# Qt Imports
from . import QMyDesignWidget
from . import QOpenFileWidget
from . import QFileDialog
from . import QMainWindow
from . import QAction
from . import QIcon
from . import QWidget
from . import QOpenFileWidget
# FORMS
from . import INFO, SPCE, DBUG, WARN, SEVR
# DEBUG, VERBOSE
from . import D_DEBUG, D_NO_VERBOSE
# my IOs
from . import myIOs
class QMyDesignGui(QMainWindow):
def __init__(self, parent=None):
"""Constructor of QMyDesignGui. Inerit from QMainWindow"""
super(QMyDesignGui, self).__init__(parent)
......@@ -20,12 +31,18 @@ class QMyDesignGui(QMainWindow):
self.openFilePopup = QOpenFileWidget()
self.openFilePopup.triggered.connect(self.executeFunct)
self.fileSelector = QFileDialog()
self.fileSelector.fileSelected.connect(self.saveFigure)
self.setCentralWidget(QMyDesignWidget(self))
self.connectChildSignal()
self.setWindowTitle('My Design Gui')
self.show()
def initMenu(self):
"""Initialize the menu of QMyDesignGui"""
self.menuBar()
......@@ -33,12 +50,12 @@ class QMyDesignGui(QMainWindow):
'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'].setStatusTip('Open some data.')
self.actionOfTheMenuBar['save'].setStatusTip('Save the figure into a file.')
self.actionOfTheMenuBar['close'].setStatusTip('Not yet implemented.')
self.actionOfTheMenuBar['open'].triggered.connect(self.openData)
self.actionOfTheMenuBar['save'].triggered.connect(self.saveFigure)
self.actionOfTheMenuBar['save'].triggered.connect(self.selectFile)
self.menusOfTheMenuBar = {'File': self.menuBar().addMenu('&File'),
'Edit': self.menuBar().addMenu('&Edit'),
......@@ -46,14 +63,48 @@ class QMyDesignGui(QMainWindow):
self.menusOfTheMenuBar['File'].addAction(self.actionOfTheMenuBar['open'])
self.menusOfTheMenuBar['File'].addAction(self.actionOfTheMenuBar['save'])
def connectChildSignal(self):
"""Connect the Signals from childs to some StatusTips"""
self.centralWidget().designTabs.axesTab.fileSaved.connect(self.showStatusFileSaved)
self.centralWidget().designTabs.figTab.fileSaved.connect(self.showStatusFileSaved)
self.centralWidget().designTabs.axesTab.savingFailed.connect(self.showStatusSavingFailed)
self.centralWidget().designTabs.figTab.savingFailed.connect(self.showStatusSavingFailed)
def showStatusFileSaved(self, filename):
"""Show the name of the saved file in tha status bar"""
self.statusBar().showMessage(INFO + 'The file ' + str(filename) + ' has been saved.')
def showStatusSavingFailed(self, filename):
"""Show the name of the file that could not be saved in tha status bar"""
self.statusBar().showMessage(WARN + 'The file ' + str(filename) + ' could not be saved...')
def openData(self):
"""Show the QOpenFileWidget."""
self.openFilePopup.show()
def saveFigure(self):
self.centralWidget().figContainer.figure.print2file('/home/fournier/test.png')
def selectFile(self):
"""Selecte a file to save the figure."""
self.fileSelector.show()
def saveFigure(self, filename):
"""Save the figure into a file."""
self.fileSelector.hide()
try:
self.centralWidget().figContainer.figure.print2file(str(filename))
self.showStatusFileSaved(filename)
except:
self.showStatusSavingFailed(filename)
def executeFunct(self, function):
print('EXECUTE!!!' + str(function))
"""Execute the selected function with the given arguments."""
if D_DEBUG:
print(DBUG + 'Execute: ' + str(function))
elif not D_NO_VERBOSE:
print(INFO + 'Execute: ' + str(function))
else:
pass
self.centralWidget().openData(eval('myIOs.'+str(function)))
......@@ -7,6 +7,7 @@ from . import QLineEdit
from . import QFormLayout
from . import QPushButton
from . import QSignal
from . import QLabel
from types import FunctionType
from . import sys
......@@ -32,7 +33,9 @@ class QFunctionFormular(QWidget):
self.wOptionalArgs = []
self.unexplicitArgs = False
self.unexplicitKwArgs = False
documentation = None # Documentation of the function
if (PYVERSION < (3, 0)):
argCount = function.func_code.co_argcount # number of explicit arguments
argsName = function.func_code.co_varnames # list of the names of the local variables
......@@ -42,6 +45,8 @@ class QFunctionFormular(QWidget):
argsName = function.__code__.co_varnames # list of the names of the local variables
defaultValues = function.__defaults__ # default value of the optional arguments
documentation = function.__doc__
# extract the known arguments
self.explicitArgs = argsName[:argCount]
......@@ -73,6 +78,11 @@ class QFunctionFormular(QWidget):
self.layout = QFormLayout(self)
if documentation is not None:
self.docLabel = QLabel(documentation)
self.docLabel.setWordWrap(True)
self.layout.addRow(self.docLabel)
if self.requiredArgs != ():
# make a QLineEdit without default variable for each requiredArgs
for arg in self.requiredArgs:
......@@ -162,6 +172,7 @@ class QOpenFileWidget(QWidget):
self.functionWidgets[i].show()
self.currentFunctionWidget = self.functionWidgets[i]
self.resize(self.layout.sizeHint())
# self.filename = QFileDialog.getOpenFileName(self)
......
......@@ -22,7 +22,7 @@ from . import DEFAULT_PLOTTING
class QTabMyAxes(QWidget):
renamedClass = QSignal(str)
filesaved = QSignal(str)
fileSaved = QSignal(str)
savingFailed = QSignal(str)
def __init__(self, ClassName, parent=None):
......@@ -110,7 +110,7 @@ class QTabMyAxes(QWidget):
with open(filename, 'w') as designFile:
json.dump(design, designFile, sort_keys=True, indent=4, ensure_ascii=False)
self.filesaved.emit(filename)
self.fileSaved.emit(filename)
designFile.close()
except:
......@@ -118,7 +118,6 @@ class QTabMyAxes(QWidget):
def selectFile(self):
self.openFilePopup.show()
print('POPED UP?')
def loadDesign(self, filename):
......
......@@ -21,7 +21,7 @@ from . import DEFAULT_ADDAXES
class QTabMyFig(QWidget):
renamedClass = QSignal(str)
filesaved = QSignal(str)
fileSaved = QSignal(str)
savingFailed = QSignal(str)
def __init__(self, parent=None):
......@@ -98,7 +98,7 @@ class QTabMyFig(QWidget):
with open(filename, 'w') as designFile:
json.dump(design, designFile, sort_keys=True, indent=4, ensure_ascii=False)
self.filesaved.emit(filename)
self.fileSaved.emit(filename)
designFile.close()
except:
......
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