Commit e19ac09b authored by Philipp Gast's avatar Philipp Gast
Browse files

added SSyntax highlighting for testing in Axes formatrawdata textbox.

include still dirty. change from QTextEdit to QPlainTextEdit

Merge remote-tracking branch 'origin/1-FEATURE-Tabs' into 5-feature-color-the-text-live-while-writting

Conflicts:
	__init__.py
	qTabMyAxes.py
parents 3c596f39 ee8f3405
......@@ -12,6 +12,7 @@ except:
QApplication = QtGui.QApplication
QWidget = QtGui.QWidget
QVBoxLayout = QtGui.QVBoxLayout
QGridLayout = QtGui.QGridLayout
QPushButton = QtGui.QPushButton
QMainWindow = QtGui.QMainWindow
QTabWidget = QtGui.QTabWidget
......@@ -24,10 +25,14 @@ QPlainTextEdit = QtGui.QPlainTextEdit
from matplotlib.backends.backend_qt4agg import FigureCanvasQTAgg as QCanvas
# MyPlotLib
from myplotlib import MyAxes, MyFig, MyData
from myplotlib.test import FigTest1, readStupidData, readStupidData2
from .mplDesign import AxDesign, FigDesign
# Local Import
from .qMyFigContainer import QMyFigContainer
from .qTabMyAxes import QTabMyAxes
from .qMyDesignTabs import QMyDesignTabs
from .qMyDesignWidget import QMyDesignWidget
from .qMyDesignGui import QMyDesignGui
from .syntax import PythonHighlighter
from . import MyAxes
from . import MyFig
DEFAULT_DECLARE_KEYWORDS = '''
self.keywords = {}
'''
DEFAULT_FORMAT_RAWDATA = '''
self.data = {'xdata': [-5, 2],
'ydata': [-2, 4]}
'''
DEFAULT_PLOTTING = '''
self.plot(self.data['xdata'], self.data['ydata'])
'''
_DEFAULT_FUNCTIONS = {'declareKeywords': DEFAULT_DECLARE_KEYWORDS,
'formatRawData': DEFAULT_FORMAT_RAWDATA,
'plotting': DEFAULT_PLOTTING}
class FigDesign(MyFig):
FIGSIZE = (8., 6.)
def __init__(self, rawdata, designDictionary, *args, **kwargs):
self.designDictionary = designDictionary
MyFig.__init__(self, rawdata, *args, **kwargs)
def addAxes(self):
functions = self.designDictionary.get('axes', _DEFAULT_FUNCTIONS)
ratio = 6./8.
frame = [0.2, 0.15, 0.6, 0.7]
self.add_axes(AxDesign(self, ratio, frame, functions=functions), 'myAxes')
class AxDesign(MyAxes):
def __init__(self, fig, ratio, frameRect, functions=_DEFAULT_FUNCTIONS, *args, **kwargs):
self.functions = functions
MyAxes.__init__(self, fig, ratio, frameRect, *args, **kwargs)
def declareKeywords(self):
if 'declareKeywords' in self.functions:
exec(''.join(str(self.functions['declareKeywords'])))
else:
pass
def plotting(self):
exec(''.join(str(self.functions['plotting'])))
return(True)
def formatRawData(self, rawdata):
exec(''.join(str(self.functions['formatRawData'])))
return(True)
......@@ -9,15 +9,8 @@ class QMyDesignGui(QMainWindow):
super(QMyDesignGui, self).__init__(parent)
self.statusBar() # an ugly wrapper to create the statusBar
self.setCentralWidget(QMyDesignWidget(self))
self.centralWidget().refreshed.connect(self.refreshed)
self.resize(self.layout().sizeHint()) # For QMainWindow layout is a function that returns the QLayout object.
self.setWindowTitle('My Design Gui')
self.show()
def refreshed(self):
self.resize(self.layout().sizeHint()) # For QMainWindow layout is a function that returns the QLayout object.
self.statusBar().showMessage("> status: Figure has been refreshed.")
from . import QTabWidget
from . import QWidget
from . import QTabMyAxes
class QMyDesignTabs(QTabWidget):
def __init__(self, parent=None):
super(QMyDesignTabs, self).__init__(parent)
self.figTab = QWidget(self)
self.axesTab = QTabMyAxes(self)
self.addTab(self.figTab, "MyFigure")
self.addTab(self.axesTab, "MyAxes")
def getFigDictionary(self):
figDictionary = {'axes': self.axesTab.getAxesFunctions()}
return(figDictionary)
from . import QWidget
from . import QVBoxLayout
from . import QGridLayout
from . import QPushButton
from . import QMyFigContainer
from . import QMyDesignTabs
from . import Signal
......@@ -14,21 +15,27 @@ class QMyDesignWidget(QWidget):
super(QMyDesignWidget, self).__init__(parent)
self.layout = QVBoxLayout(self)
self.layout = QGridLayout(self)
self.layout.setSpacing(10)
self.figContainer = QMyFigContainer(self)
self.designTabs = QMyDesignTabs(self)
self.refreshButton = QPushButton("Refresh", self)
self.layout.addWidget(self.figContainer)
self.layout.addWidget(self.refreshButton)
self.layout.addWidget(self.figContainer, 0, 1)
self.layout.addWidget(self.refreshButton, 1, 1)
self.layout.addWidget(self.designTabs, 0, 0, 2, 1)
self.refreshButton.clicked.connect(self.refresh)
def refresh(self):
self.figContainer.refresh() # Recreate the figure
self.resize(self.layout.sizeHint()) # Resize it-self depending on the figure.
self.refreshed.emit() # Emit refreshed such that the window knows it can refresh it-self
self.repaint() # Only then repaint to avoid blinking
figDictionary = self.designTabs.getFigDictionary()
self.figContainer.refresh(figDictionary) # Recreate the figure
self.repaint() # This will call paintEvent when all events are treated
def paintEvent(self, event):
......
......@@ -3,9 +3,8 @@ from . import QVBoxLayout
from . import QCanvas
from . import FigTest1
from . import readStupidData, readStupidData2
from . import FigDesign
from . import MyData
class QMyFigContainer(QWidget):
......@@ -14,8 +13,7 @@ class QMyFigContainer(QWidget):
super(QMyFigContainer, self).__init__(parent)
data = readStupidData('data1')
self.figure = FigTest1((data,))
self.figure = FigDesign(MyData(), {})
self.canvas = QCanvas(self.figure)
self.layout = QVBoxLayout(self)
......@@ -24,19 +22,13 @@ class QMyFigContainer(QWidget):
self.figure.plot()
self.canvas.draw()
def refresh(self):
# Just a stupid data switching to see an effect
if self.figure.rawdata[0].name == 'data1':
data = readStupidData2('data2')
else:
data = readStupidData('data1')
def refresh(self, figDictionary):
# Destroy the figure
del self.figure
# Recreate a figure
self.figure = FigTest1((data,))
self.figure = FigDesign(MyData(), figDictionary)
# Link the figure with the canvas
self.figure.set_canvas(self.canvas)
......@@ -46,12 +38,19 @@ class QMyFigContainer(QWidget):
self.figure.plot()
# RESIZE
self.setSizeToFigure()
def setSizeToFigure(self):
# Get the size of the figure
w, h = self.canvas.get_width_height()
# 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()
def paint(self):
......
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