Commit 3ad665d7 authored by Yori 'AGy' Fournier's avatar Yori 'AGy' Fournier
Browse files

Now it is possible to change the size of the figure on the fly

parent ce49ed19
......@@ -14,6 +14,7 @@ _DEFAULT_DESIGN = {'declareKeywords': DEFAULT_DECLARE_KEYWORDS,
_DEFAULT_FIG_DESIGN = {'declareAliases': DEFAULT_DECLARE_ALIASES,
'addAxes': DEFAULT_ADDAXES}
class MyDesign(dict):
def __init__(self):
......@@ -21,6 +22,7 @@ class MyDesign(dict):
dict.__init__(self)
self.figClassName = None
self.figsize = (8., 6.)
self.axesClassName = []
......@@ -31,6 +33,8 @@ class FigDesign(MyFig):
def __init__(self, rawdata, design, *args, **kwargs):
self.design = design
if isinstance(design.figsize, tuple):
kwargs.update({'figsize': design.figsize})
MyFig.__init__(self, rawdata, *args, **kwargs)
......
......@@ -80,6 +80,7 @@ class QMyDesignTabs(QTabWidget):
plotDesign = MyDesign()
plotDesign.figClassName = self.figTab.getClassName()
plotDesign.figsize = self.figTab.getFigsize()
plotDesign.update({plotDesign.figClassName: self.figTab.getFigFunctions()})
......
......@@ -39,7 +39,6 @@ class QMyDesignWidget(QWidget):
self.repaint() # This will call paintEvent when all events are treated
def paintEvent(self, event):
self.figContainer.paint()
def openData(self, data):
......
......@@ -7,6 +7,9 @@ from . import FigDesign
from . import MyDesign
from . import MyData
from PyQt4.QtCore import QSize, QRect
from PyQt4.QtGui import QResizeEvent
class QMyFigContainer(QWidget):
......@@ -32,26 +35,42 @@ class QMyFigContainer(QWidget):
self.figure = FigDesign(rawdata, MyDesign())
# Link the figure with the canvas
w, h = self.canvas.get_width_height()
oldsize = QSize(w, h)
self.figure.set_canvas(self.canvas)
self.canvas.figure = self.figure
w, h = self.canvas.get_width_height()
newsize = QSize(w, h)
print("OLDSIZE: " + str(oldsize))
print("NEWSIZE: " + str(newsize))
# Plot the figure
self.figure.plot()
# RESIZE
self.setSizeToFigure()
self.canvas.setMinimumSize(newsize)
self.canvas.setMaximumSize(newsize)
self.setSizePolicy(0, 1)
# self.canvas.resize(newsize)
# self.resize(self.layout.sizeHint())
self.resizeEvent(QResizeEvent(oldsize, newsize))
# self.setSizeToFigure()
def setSizeToFigure(self):
# Get the size of the figure
w, h = self.canvas.get_width_height()
self.canvas.setMinimumSize(QSize(w, h))
self.canvas.setMaximumSize(QSize(w, h))
# Resize the canvas to figure size
self.canvas.resize(w, h)
# Resize the Widget to the Layout size (Canvas + borders)
self.resize(self.layout.sizeHint())
def resizeEvent(self, event):
self.setSizeToFigure()
# print("EVENT: " + str(event))
#self.setSizeToFigure()
# Resize the Widget to the Layout size (Canvas + borders)
# self.canvas.resize(event.size())
self.resize(self.layout.sizeHint())
def paint(self):
......
......@@ -44,6 +44,10 @@ class QTabMyFig(QWidget):
self.editName = QLineEdit(self)
self.editName.setText('MyFig')
self.labelFigsize = QLabel('Figsize', self)
self.editFigsize = QLineEdit(self)
self.editFigsize.setText('(8., 6.)')
self.labelDeclareAliases = QLabel('def declareAliases(self):', self)
self.editDeclareAliases = QPlainTextEdit(self)
self.editDeclareAliases.setFont(QFont('Monospace'))
......@@ -58,13 +62,15 @@ class QTabMyFig(QWidget):
self.layout.addWidget(self.labelName, 0, 0)
self.layout.addWidget(self.editName, 0, 1)
self.layout.addWidget(self.labelDeclareAliases, 1, 0, 1, 2)
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.layout.addWidget(self.labelFigsize, 0, 2)
self.layout.addWidget(self.editFigsize, 0, 3)
self.layout.addWidget(self.labelDeclareAliases, 1, 0, 1, 4)
self.layout.addWidget(self.editDeclareAliases, 2, 0, 3, 4)
self.layout.addWidget(self.labelAddAxes, 5, 0, 1, 4)
self.layout.addWidget(self.editAddAxes, 6, 0, 10, 4)
self.subLayout = QHBoxLayout(self)
self.layout.addItem(self.subLayout, 16, 0, 1, 2)
self.layout.addItem(self.subLayout, 16, 0, 1, 4)
self.subLayout.addWidget(self.loadButton)
self.subLayout.addWidget(self.saveButton)
self.subLayout.setSpacing(6)
......@@ -87,6 +93,12 @@ class QTabMyFig(QWidget):
return(name)
def getFigsize(self):
figsize = eval(str(self.editFigsize.text()))
return(figsize)
def saveDesign(self):
design = self.getFigFunctions()
......
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