#!/usr/bin/env python
# ###########################################################################
#
# This file is part of Taurus
#
# http://taurus-scada.org
#
# Copyright 2011 CELLS / ALBA Synchrotron, Bellaterra, Spain
#
# Taurus is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Taurus is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with Taurus. If not, see <http://www.gnu.org/licenses/>.
#
# ###########################################################################
"""
Every TaurusWidget should have the following Qt Designer extended
capabilities:
- Task menu:
it means when you right click on the widget in the designer, it will have
the following additional items:
- 'Edit model...': opens a customized dialog for editing the widget model
- Property Sheet:
it means that in the Qt Designer property sheet it will have the following
properties customized:
- 'model': will have a '...' button that will open a customized dialog for
editing the widget model (same has 'Edit model...' task menu item
"""
from taurus.external.qt import QtDesigner
from taurus.qt.qtgui.container.qcontainer import QGroupWidget
__all__ = [
"Q_TYPEID",
"QGroupWidgetContainerExtension",
"QGroupWidgetExtensionFactory",
"create_plugin",
"QGroupWidgetPlugin",
]
Q_TYPEID = {
"QPyDesignerContainerExtension": "com.trolltech.Qt.Designer.Container",
"QPyDesignerPropertySheetExtension": "com.trolltech.Qt.Designer.PropertySheet", # noqa
"QPyDesignerTaskMenuExtension": "com.trolltech.Qt.Designer.TaskMenu",
"QPyDesignerMemberSheetExtension": "com.trolltech.Qt.Designer.MemberSheet",
}
[docs]
class QGroupWidgetExtensionFactory(QtDesigner.QExtensionFactory):
def __init__(self, parent=None):
super(QGroupWidgetExtensionFactory, self).__init__(parent)
[docs]
def createExtension(self, obj, iid, parent):
if iid != Q_TYPEID["QPyDesignerContainerExtension"]:
return None
if isinstance(obj, QGroupWidget):
return QGroupWidgetContainerExtension(obj, parent)
return None
[docs]
def create_plugin():
from taurus.qt.qtdesigner.taurusplugin.taurusplugin import (
TaurusWidgetPlugin,
)
class QGroupWidgetPlugin(TaurusWidgetPlugin):
WidgetClass = QGroupWidget
def initialize(self, formEditor):
if self.isInitialized():
return
manager = formEditor.extensionManager()
if manager:
self.factory = QGroupWidgetExtensionFactory(manager)
manager.registerExtensions(
self.factory, Q_TYPEID["QPyDesignerContainerExtension"]
)
self.initialized = True
return QGroupWidgetPlugin
QGroupWidgetPlugin = create_plugin()