|
from PyQt5.QtCore import *
from PyQt5.QtGui import *
from PyQt5.QtWidgets import *
#===================================================================
# A generic base class from which specialized tab pages are derived.
class AbstractTabPage(QWidget):
def __init__(self, panelName):
QWidget.__init__(self, None)
self.name = panelName
vlayout = QVBoxLayout()
self.setLayout(vlayout)
self.addWidgetsPanel(vlayout)
vlayout.addStretch()
self.setFocusPolicy( Qt.StrongFocus )
#---------------------------------------------------------------
def addWidgetsPanel(self, parentLayout):
raise NotImplementedError("addWidgetsPanel() must be implemented")
#---------------------------------------------------------------
def doAction(self, parentLayout):
raise NotImplementedError("doAction must be implemented")
#---------------------------------------------------------------
def focusOutEvent(self, event):
# A derived class should implement this if they wish to
# respond when a page loses focus.
pass
#---------------------------------------------------------------
def focusInEvent(self, event):
# A derived class should implement this if they wish to
# respond when a page gains focus.
pass
#===================================================================
class RedTabPage(AbstractTabPage):
def __init__(self, panelName):
AbstractTabPage.__init__(self, panelName)
# Note: the base class lays out the UI
#-------------------------------------------------------------
def addWidgetsPanel(self, parentLayout):
# Your custom UI widgets are added in this method - for example:
layout = QVBoxLayout()
self.label = QLabel()
self.label.setText(self.name)
self.label.setFont(QFont('Arial', 20, weight=QFont.Bold))
self.label.setStyleSheet('QLabel {color : red}')
layout.addWidget(self.label)
parentLayout.addLayout(layout)
#-------------------------------------------------------------
def doAction(self):
self.label.setText(self.name + ': doAction() has been called')
#-------------------------------------------------------------
def focusOutEvent(self, event):
self.label.setText(self.name)
#-------------------------------------------------------------------
class BlueTabPage(AbstractTabPage):
def __init__(self, panelName):
AbstractTabPage.__init__(self, panelName)
# Note: the base class lays out the UI
#-------------------------------------------------------------
def addWidgetsPanel(self, parentLayout):
# Your custom UI widgets are added in this method - for example:
layout = QVBoxLayout()
self.label = QLabel()
self.label.setText(self.name)
self.label.setFont(QFont("Arial", 20, weight=QFont.Bold))
self.label.setStyleSheet('QLabel {color : blue}')
layout.addWidget(self.label)
parentLayout.addLayout(layout)
#-------------------------------------------------------------
def doAction(self):
self.label.setText(self.name + ': doAction() has been called')
#-------------------------------------------------------------
def focusOutEvent(self, event):
self.label.setText(self.name)
#-------------------------------------------------------------------
|