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

Add a + tab to create new axes

Working but ugly... requires serious cleaning.
parent 6abbb0e7
......@@ -28,6 +28,9 @@ QFileDialog = QtGui.QFileDialog
QFormLayout = QtGui.QFormLayout
QListWidget = QtGui.QListWidget
MouseButtonDblClick = QtCore.QEvent.MouseButtonDblClick
LeftButton = QtCore.Qt.LeftButton
# MatPlotLib
from matplotlib.backends.backend_qt4agg import FigureCanvasQTAgg as QCanvas
......
......@@ -5,6 +5,9 @@ from . import QTabMyFig
from . import QTabMyData
from . import MyDesign
from . import MouseButtonDblClick
from . import LeftButton
class QMyDesignTabs(QTabWidget):
......@@ -13,19 +16,76 @@ class QMyDesignTabs(QTabWidget):
super(QMyDesignTabs, self).__init__(parent)
self.figTab = QTabMyFig(self)
self.axesTab = QTabMyAxes(self)
self.axesTab = QTabMyAxes("MyAxes0", self)
self.dataTab = QTabMyData(self)
self.addTab(self.dataTab, "MyData")
self.addTab(self.figTab, "MyFigure")
self.addTab(self.axesTab, "MyAxes")
self.addTab(self.axesTab, "MyAxes0")
self.addTab(QWidget(self), "+")
self.setTabEnabled(self.tabBar().count()-1, False)
self.setTabsClosable(True)
# self.installEventFilter(self.tabBar()) # Not like that... eventhought It would make more sence.
self.tabBar().installEventFilter(self)
# works with Qt5.2 ...
# self.tabBarDoubleClicked.connect(self.doubleClicked)
self.tabBar().tabCloseRequested.connect(self.closeTab)
# self.tabBar().setTabButton(0, 1, QWidget(self))
self.tabBar().setTabButton(0, 1, None)
self.tabBar().setTabButton(1, 1, None)
self.tabBar().setTabButton(self.tabBar().count()-1, 1, None)
self.axesTab.renamedClass.connect(self.renameTab)
def renameTab(self, newClassName):
bar = self.tabBar()
for index in range(0, bar.count()):
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:
if event.button() == LeftButton:
if obj.tabRect(obj.count()-1).contains(event.pos()):
tabAxes = QTabMyAxes("MyAxes"+str(obj.count()-3), self)
tabAxes.renamedClass.connect(self.renameTab)
self.addTab(tabAxes, "MyAxes"+str(obj.count()-3))
obj.moveTab(obj.count()-1, obj.count()-2)
self.setCurrentIndex(obj.count()-2)
print('new tab!!')
return super(QMyDesignTabs, self).eventFilter(obj, event)
def doubleClicked(self, index):
if index == -1:
print('CREATE NEW TAB!!')
def getPlotDesign(self):
plotDesign = MyDesign()
plotDesign.figClassName = self.figTab.getClassName()
plotDesign.axesClassName.append(self.axesTab.getClassName())
plotDesign.update({plotDesign.figClassName: self.figTab.getFigFunctions(),
plotDesign.axesClassName[0]: self.axesTab.getAxesFunctions()})
plotDesign.update({plotDesign.figClassName: self.figTab.getFigFunctions()})
for index in range(2, self.count()-1):
widget = self.widget(index)
plotDesign.axesClassName.append(widget.getClassName())
plotDesign.update({widget.getClassName(): widget.getAxesFunctions()})
return(plotDesign)
......@@ -7,10 +7,14 @@ from . import QTextEdit
from . import QPlainTextEdit
from . import PythonHighlighter
from . import QSignal
class QTabMyAxes(QWidget):
def __init__(self, parent=None):
renamedClass = QSignal(str)
def __init__(self, ClassName, parent=None):
super(QTabMyAxes, self).__init__(parent)
......@@ -18,7 +22,7 @@ class QTabMyAxes(QWidget):
self.labelName = QLabel('Class Name', self)
self.editName = QLineEdit(self)
self.editName.setText('MyAxes')
self.editName.setText(ClassName)
self.labelDeclareKeywords = QLabel('def declareKeywords(self):', self)
self.editDeclareKeywords = QPlainTextEdit(self)
......@@ -46,7 +50,9 @@ class QTabMyAxes(QWidget):
self.layout.addWidget(self.editFormatRawdata, 6, 0, 5, 2)
self.layout.addWidget(self.labelPlotting, 11, 0, 1, 2)
self.layout.addWidget(self.editPlotting, 12, 0, 10, 2)
self.editName.textChanged[str].connect(self.renamedClass.emit)
def getAxesFunctions(self):
functions = {'declareKeywords': u'',
......
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