Commit 2e3be497 authored by Yori 'AGy' Fournier's avatar Yori 'AGy' Fournier
Browse files

Now one can save Figures too

parent f6a15c69
# System
import sys
import os
import json
# Qt4
......
......@@ -35,4 +35,4 @@ for function in functions:
subMod = vars(module)[function]
vars()[function] = vars(subMod)[function]
except:
print(WARN + "The function " + function.__name__ + " could not be loaded...")
print(WARN + "The function " + function + " could not be loaded...")
......@@ -38,16 +38,21 @@ class QMyDesignGui(QMainWindow):
self.actionOfTheMenuBar['close'].setStatusTip('Not yet implemented')
self.actionOfTheMenuBar['open'].triggered.connect(self.openData)
self.actionOfTheMenuBar['save'].triggered.connect(self.saveFigure)
self.menusOfTheMenuBar = {'File': self.menuBar().addMenu('&File'),
'Edit': self.menuBar().addMenu('&Edit'),
'Help': self.menuBar().addMenu('&Help')}
self.menusOfTheMenuBar['File'].addAction(self.actionOfTheMenuBar['open'])
self.menusOfTheMenuBar['File'].addAction(self.actionOfTheMenuBar['save'])
def openData(self):
self.openFilePopup.show()
def saveFigure(self):
self.centralWidget().figContainer.figure.print2file('/home/fournier/test.png')
def executeFunct(self, function):
print('EXECUTE!!!' + str(function))
self.centralWidget().openData(eval('myIOs.'+str(function)))
......
......@@ -40,6 +40,7 @@ class QMyDesignTabs(QTabWidget):
self.tabBar().setTabButton(self.tabBar().count()-1, 1, None)
self.axesTab.renamedClass.connect(self.renameTab)
self.figTab.renamedClass.connect(self.renameTab)
def renameTab(self, newClassName):
......@@ -48,15 +49,14 @@ class QMyDesignTabs(QTabWidget):
widget = self.widget(index)
if widget == self.sender():
bar.setTabText(index, newClassName)
def closeTab(self, index):
# if the tab is not MyData, MyFig, MyAxes and +
if index not in (0, 1, self.tabBar().count()-1):
self.removeTab(index)
else:
print('These tabs are protected')
def eventFilter(self, obj, event):
if event.type() == MouseButtonDblClick:
......
......@@ -30,7 +30,7 @@ class QTabMyAxes(QWidget):
super(QTabMyAxes, self).__init__(parent)
self.openFilePopup = QFileDialog()
self.openFilePopup.hide()
# self.openFilePopup.hide() # This produce a segmentation fault in some configs...
self.openFilePopup.fileSelected.connect(self.loadDesign)
self.layout = QGridLayout(self)
......
......@@ -6,18 +6,40 @@ from . import QLineEdit
from . import QTextEdit
from . import QPlainTextEdit
from . import PythonHighlighter
from . import QPushButton
from . import QFileDialog
from . import QHBoxLayout
from . import QSignal
from . import json
from . import DEFAULT_DECLARE_ALIASES
from . import DEFAULT_ADDAXES
class QTabMyFig(QWidget):
renamedClass = QSignal(str)
filesaved = QSignal(str)
savingFailed = QSignal(str)
def __init__(self, parent=None):
super(QTabMyFig, self).__init__(parent)
self.layout = QGridLayout(self)
self.openFilePopup = QFileDialog()
self.openFilePopup.fileSelected.connect(self.loadDesign)
self.saveButton = QPushButton('Save', self)
self.saveButton.setStatusTip('Save into a .design file')
self.saveButton.clicked.connect(self.saveDesign)
self.loadButton = QPushButton('Load', self)
self.loadButton.setStatusTip('Load from a .design file')
self.loadButton.clicked.connect(self.selectFile)
self.labelName = QLabel('Class Name', self)
self.editName = QLineEdit(self)
self.editName.setText('MyFig')
......@@ -40,6 +62,14 @@ class QTabMyFig(QWidget):
self.layout.addWidget(self.editDeclareAliases, 2, 0, 3, 2)
self.layout.addWidget(self.labelAddAxes, 5, 0, 1, 2)
self.layout.addWidget(self.editAddAxes, 6, 0, 10, 2)
self.subLayout = QHBoxLayout(self)
self.layout.addItem(self.subLayout, 16, 0, 1, 2)
self.subLayout.addWidget(self.loadButton)
self.subLayout.addWidget(self.saveButton)
self.subLayout.setSpacing(6)
self.editName.textChanged[str].connect(self.renamedClass.emit)
def getFigFunctions(self):
......@@ -56,3 +86,45 @@ class QTabMyFig(QWidget):
name = str(self.editName.text())
return(name)
def saveDesign(self):
design = self.getFigFunctions()
design.update({'className': self.getClassName()})
filename = './mydesigngui/myDesigns/figures/' + str(self.getClassName()) + '.design'
try:
with open(filename, 'w') as designFile:
json.dump(design, designFile, sort_keys=True, indent=4, ensure_ascii=False)
self.filesaved.emit(filename)
designFile.close()
except:
self.savingFailed.emit(filename)
def selectFile(self):
self.openFilePopup.show()
def loadDesign(self, filename):
with open(filename, 'r') as designFile:
design = json.load(designFile)
self.setDesign(design)
self.openFilePopup.hide()
designFile.close()
def setDesign(self, design):
className = design.get('className', None)
declareAliases = design.get('declareAliases', DEFAULT_DECLARE_ALIASES)
addAxes = design.get('addAxes', DEFAULT_ADDAXES)
if className is not None:
self.editName.setText(className)
self.editDeclareAliases.setPlainText(declareAliases)
self.editAddAxes.setPlainText(addAxes)
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