Commit 37040404 authored by Yori 'AGy' Fournier's avatar Yori 'AGy' Fournier
Browse files

Now possibility of loading and saving designs in design File

parent 72efa602
import sys
import json
# Qt4
try:
......@@ -12,6 +13,7 @@ except:
QApplication = QtGui.QApplication
QWidget = QtGui.QWidget
QVBoxLayout = QtGui.QVBoxLayout
QHBoxLayout = QtGui.QHBoxLayout
QGridLayout = QtGui.QGridLayout
QPushButton = QtGui.QPushButton
QMainWindow = QtGui.QMainWindow
......
......@@ -115,6 +115,7 @@ class QFunctionFormular(QWidget):
return(farguments)
class QOpenFileWidget(QWidget):
triggered = QSignal([str])
......
......@@ -5,19 +5,30 @@ from . import QLabel
from . import QLineEdit
from . import QTextEdit
from . import QPlainTextEdit
from . import QPushButton
from . import QHBoxLayout
from . import PythonHighlighter
from . import QFileDialog
from . import QSignal
from . import json
class QTabMyAxes(QWidget):
renamedClass = QSignal(str)
filesaved = QSignal(str)
savingFailed = QSignal(str)
def __init__(self, ClassName, parent=None):
super(QTabMyAxes, self).__init__(parent)
self.openFilePopup = QFileDialog()
self.openFilePopup.hide()
self.openFilePopup.fileSelected.connect(self.loadDesign)
self.layout = QGridLayout(self)
self.labelName = QLabel('Class Name', self)
......@@ -42,6 +53,13 @@ class QTabMyAxes(QWidget):
self.highlightPlotting = PythonHighlighter(self.editPlotting.document())
self.editPlotting.insertPlainText(DEFAULT_PLOTTING)
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.layout.addWidget(self.labelName, 0, 0)
self.layout.addWidget(self.editName, 0, 1)
self.layout.addWidget(self.labelDeclareKeywords, 1, 0, 1, 2)
......@@ -51,6 +69,12 @@ class QTabMyAxes(QWidget):
self.layout.addWidget(self.labelPlotting, 11, 0, 1, 2)
self.layout.addWidget(self.editPlotting, 12, 0, 10, 2)
self.subLayout = QHBoxLayout(self)
self.layout.addItem(self.subLayout, 22, 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 getAxesFunctions(self):
......@@ -70,7 +94,51 @@ class QTabMyAxes(QWidget):
name = str(self.editName.text())
return(name)
def saveDesign(self):
design = self.getAxesFunctions()
design.update({'className': self.getClassName()})
filename = './mydesigngui/myDesigns/axes/' + 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()
print('POPED UP?')
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)
declareKeywords = design.get('declareKeywords', DEFAULT_DECLARE_KEYWORDS)
formatRawData = design.get('formatRawData', DEFAULT_FORMAT_RAWDATA)
plotting = design.get('plotting', DEFAULT_PLOTTING)
if className is not None:
self.editName.setText(className)
self.editDeclareKeywords.setPlainText(declareKeywords)
self.editFormatRawdata.setPlainText(formatRawData)
self.editPlotting.setPlainText(plotting)
DEFAULT_DECLARE_KEYWORDS = '''
self.keywords = {}
......
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