1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74
|
""" A view containing a colored panel! """
from traits.etsconfig.api import ETSConfig
from pyface.workbench.api import View
class ColorView(View):
""" A view containing a colored panel! """
# 'IView' interface ----------------------------------------------------
# The category that the view belongs to.
category = "Color"
# ------------------------------------------------------------------------
# 'IWorkbenchPart' interface.
# ------------------------------------------------------------------------
# Trait initializers ---------------------------------------------------
def _id_default(self):
""" Trait initializer. """
# By making the Id the same as the name, we make it easy to specify
# the views in the example perspectives. Note for larger applications
# the Id should be globally unique, and by default we use the module
# name and class name.
return self.name
# Methods --------------------------------------------------------------
def create_control(self, parent):
""" Creates the toolkit-specific control that represents the view.
'parent' is the toolkit-specific control that is the view's parent.
"""
method = getattr(self, "_%s_create_control" % ETSConfig.toolkit, None)
if method is None:
raise SystemError("Unknown toolkit %s", ETSConfig.toolkit)
color = self.name.lower()
return method(parent, color)
# ------------------------------------------------------------------------
# Private interface.
# ------------------------------------------------------------------------
def _wx_create_control(self, parent, color):
""" Create a wx version of the control. """
import wx
panel = wx.Panel(parent, -1)
panel.SetBackgroundColour(color)
return panel
def _qt4_create_control(self, parent, color):
""" Create a Qt4 version of the control. """
from pyface.qt import QtGui
widget = QtGui.QWidget(parent)
palette = widget.palette()
palette.setColor(QtGui.QPalette.ColorRole.Window, QtGui.QColor(color))
widget.setPalette(palette)
widget.setAutoFillBackground(True)
return widget
|