openteachermaintainers team mailing list archive
-
openteachermaintainers team
-
Mailing list archive
-
Message #00018
OpenTeacher 3.x mockup
Hello,
I've added the earlier on IRC discussed tabbar at the bottom for lesson
mode switching to the prototype, see the attachement.
- Marten de Vries
import sys
from PyQt4 import QtCore, QtGui
class CloseButton(QtGui.QAbstractButton):
def __init__(self, parent=None):
super(self.__class__, self).__init__(parent)
self.setFocusPolicy(QtCore.Qt.NoFocus)
self.setCursor(QtCore.Qt.ArrowCursor)
self.setToolTip(self.tr("Close Tab"))
self.resize(self.sizeHint())
def sizeHint(self):
self.ensurePolished()
width = self.style().pixelMetric(QtGui.QStyle.PM_TabCloseIndicatorWidth, None, self)
height = self.style().pixelMetric(QtGui.QStyle.PM_TabCloseIndicatorHeight, None, self)
return QtCore.QSize(width, height)
def enterEvent(self, event):
if self.isEnabled():
self.update()
super(self.__class__, self).enterEvent(event)
def leaveEvent(self, event):
if self.isEnabled():
self.update()
super(self.__class__, self).leaveEvent(event)
def paintEvent(self, event):
p = QtGui.QPainter(self)
opt = QtGui.QStyleOption()
opt.initFrom(self)
opt.state = opt.state | QtGui.QStyle.State_AutoRaise
if self.isEnabled() and self.underMouse() and not self.isChecked() and not self.isDown():
opt.state = opt.state | QtGui.QStyle.State_Raised
if self.isChecked():
opt.state = opt.state | QtGui.QStyle.State_On
if self.isDown():
opt.state = opt.state | QtGui.QStyle.State_Sunken
tb = self.parent()
if tb.__class__ == QtGui.QTabBar:
index = tb.currentIndex()
position = self.style().styleHint(QtGui.QStyle.SH_TabBar_CloseButtonPosition, None, tb)
if tb.tabButton(index, position) == self:
opt.state = opt.state | QtGui.QStyle.State_Selected
self.style().drawPrimitive(QtGui.QStyle.PE_IndicatorTabClose, opt, p, self)
class LessonTabWidget(QtGui.QTabWidget):
def __init__(self, *args, **kwargs):
super(self.__class__, self).__init__(*args, **kwargs)
self.addTab(QtGui.QWidget(self), "Enter list")
self.addTab(QtGui.QWidget(self), "Teach me!")
self.setTabPosition(QtGui.QTabWidget.South)
self.setDocumentMode(True)
class ExpandingButton(QtGui.QPushButton):
def __init__(self, *args, **kwargs):
super(self.__class__, self).__init__(*args, **kwargs)
self.setSizePolicy(
QtGui.QSizePolicy.Expanding,
QtGui.QSizePolicy.Expanding
)
class StartWidget(QtGui.QWidget):
def __init__(self, parent=None):
super(self.__class__, self).__init__(parent)
createWordListButton = ExpandingButton("Create word list")
createTextLessonButton = ExpandingButton("Create text lesson")
createTopoLessonButton = ExpandingButton("Create topo lesson")
createButton = ExpandingButton("Create ...")
createLessonLayout = QtGui.QGridLayout()
createLessonLayout.addWidget(createWordListButton, 0, 0)
createLessonLayout.addWidget(createTextLessonButton, 0, 1)
createLessonLayout.addWidget(createTopoLessonButton, 1, 0)
createLessonLayout.addWidget(createButton, 1, 1)
createLessonGroupBox = QtGui.QGroupBox("Create lesson:")
createLessonGroupBox.setLayout(createLessonLayout)
loadFromFileButton = ExpandingButton("Load from file")
loadFromWrtsButton = ExpandingButton("Load from WRTS")
verticalSpacer = QtGui.QSpacerItem(20, 40, QtGui.QSizePolicy.Minimum, QtGui.QSizePolicy.Expanding)
loadLessonLayout = QtGui.QGridLayout()
loadLessonLayout.addWidget(loadFromFileButton, 0, 0)
loadLessonLayout.addWidget(loadFromWrtsButton, 0, 1)
loadLessonLayout.addItem(verticalSpacer, 1, 0, 1, 2)
loadLessonGroupBox = QtGui.QGroupBox("Load lesson:")
loadLessonGroupBox.setLayout(loadLessonLayout)
openLayout = QtGui.QVBoxLayout()
openLayout.addWidget(createLessonGroupBox)
openLayout.addWidget(loadLessonGroupBox)
openWidget= QtGui.QWidget(self)
openWidget.setLayout(openLayout)
recentlyOpenedListView = QtGui.QListView()
recentlyOpenedListView.setModel(QtGui.QStringListModel([
"French (words)",
"Europe (topo)",
"Exam German (text)"
], self))
recentlyOpenedLayout = QtGui.QVBoxLayout()
recentlyOpenedLayout.addWidget(recentlyOpenedListView)
recentlyOpenedGridBox = QtGui.QGroupBox("Recently opened:")
recentlyOpenedGridBox.setLayout(recentlyOpenedLayout)
splitter = QtGui.QSplitter(self)
splitter.addWidget(openWidget)
splitter.addWidget(recentlyOpenedGridBox)
layout = QtGui.QVBoxLayout(self)
layout.addWidget(splitter)
self.setLayout(layout)
class OpenTeacher(QtGui.QMainWindow):
def __init__(self, parent=None):
super(self.__class__, self).__init__(parent)
self.resize(640, 480)
self.indexes = []
#tabWidget
self.tabWidget = QtGui.QTabWidget(self)
self.tabWidget.addTab(StartWidget(self), "+")
self.tabWidget.setDocumentMode(True)
self.setCentralWidget(self.tabWidget)
self.addTab("French (words)")
self.addTab("Europe (topo)")
fileMenu = self.menuBar().addMenu("File")
editMenu = self.menuBar().addMenu("Edit")
helpMenu = self.menuBar().addMenu("Help")
self.setWindowTitle("OpenTeacher 3.x")
def addTab(self, text):
position = self.tabWidget.count() -1 # because of +-button
i = self.tabWidget.insertTab(position, LessonTabWidget(self), text)
closeButton = CloseButton(self.tabWidget)
self.indexes.append(closeButton)
self.tabWidget.tabBar().setTabButton(i, QtGui.QTabBar.RightSide, closeButton)
closeButton.clicked.connect(self.closeTab)
def closeTab(self):
closeButton = self.sender()
i = self.indexes.index(closeButton) #always -1 because of +-button
self.tabWidget.removeTab(i)
del self.indexes[i]
if __name__ == "__main__":
app = QtGui.QApplication(sys.argv)
widget = OpenTeacher()
widget.show()
app.exec_()