diff options
Diffstat (limited to 'lib/taurus/qt/qtdesigner')
-rw-r--r-- | lib/taurus/qt/qtdesigner/__init__.py | 25 | ||||
-rw-r--r-- | lib/taurus/qt/qtdesigner/containerplugin.py | 50 | ||||
-rw-r--r-- | lib/taurus/qt/qtdesigner/extraguiqwtplugin.py | 30 | ||||
-rw-r--r-- | lib/taurus/qt/qtdesigner/taurusdesigner.py | 61 | ||||
-rw-r--r-- | lib/taurus/qt/qtdesigner/taurusplugin/__init__.py | 25 | ||||
-rw-r--r-- | lib/taurus/qt/qtdesigner/taurusplugin/taurusplugin.py | 85 | ||||
-rw-r--r-- | lib/taurus/qt/qtdesigner/tauruspluginplugin.py | 181 |
7 files changed, 263 insertions, 194 deletions
diff --git a/lib/taurus/qt/qtdesigner/__init__.py b/lib/taurus/qt/qtdesigner/__init__.py index c1f43a9b..d4ab457a 100644 --- a/lib/taurus/qt/qtdesigner/__init__.py +++ b/lib/taurus/qt/qtdesigner/__init__.py @@ -1,28 +1,31 @@ #!/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/>. -## -############################################################################# +# +# ########################################################################### -"""The taurus.qt.qtdesigner submodule. It contains qt-specific part of taurus""" +"""The taurus.qt.qtdesigner submodule. It contains qt-specific part of taurus +""" -__docformat__ = 'restructuredtext' +__docformat__ = "restructuredtext" + +__all__ = [] diff --git a/lib/taurus/qt/qtdesigner/containerplugin.py b/lib/taurus/qt/qtdesigner/containerplugin.py index 83a87cb4..9cbbd1a4 100644 --- a/lib/taurus/qt/qtdesigner/containerplugin.py +++ b/lib/taurus/qt/qtdesigner/containerplugin.py @@ -1,27 +1,27 @@ #!/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 @@ -41,20 +41,27 @@ capabilities: editing the widget model (same has 'Edit model...' task menu item """ -from __future__ import absolute_import 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', - 'QPyDesignerTaskMenuExtension': 'com.trolltech.Qt.Designer.TaskMenu', - 'QPyDesignerMemberSheetExtension': 'com.trolltech.Qt.Designer.MemberSheet'} +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", +} class QGroupWidgetContainerExtension(QtDesigner.QPyDesignerContainerExtension): - def __init__(self, widget, parent=None): super(QGroupWidgetContainerExtension, self).__init__(parent) self._widget = widget @@ -94,12 +101,11 @@ class QGroupWidgetContainerExtension(QtDesigner.QPyDesignerContainerExtension): class QGroupWidgetExtensionFactory(QtDesigner.QExtensionFactory): - def __init__(self, parent=None): super(QGroupWidgetExtensionFactory, self).__init__(parent) def createExtension(self, obj, iid, parent): - if iid != Q_TYPEID['QPyDesignerContainerExtension']: + if iid != Q_TYPEID["QPyDesignerContainerExtension"]: return None if isinstance(obj, QGroupWidget): return QGroupWidgetContainerExtension(obj, parent) @@ -108,7 +114,8 @@ class QGroupWidgetExtensionFactory(QtDesigner.QExtensionFactory): def create_plugin(): from taurus.qt.qtdesigner.taurusplugin.taurusplugin import ( - TaurusWidgetPlugin) + TaurusWidgetPlugin, + ) class QGroupWidgetPlugin(TaurusWidgetPlugin): @@ -121,9 +128,12 @@ def create_plugin(): manager = formEditor.extensionManager() if manager: self.factory = QGroupWidgetExtensionFactory(manager) - manager.registerExtensions(self.factory, Q_TYPEID[ - 'QPyDesignerContainerExtension']) + manager.registerExtensions( + self.factory, Q_TYPEID["QPyDesignerContainerExtension"] + ) self.initialized = True + return QGroupWidgetPlugin + QGroupWidgetPlugin = create_plugin() diff --git a/lib/taurus/qt/qtdesigner/extraguiqwtplugin.py b/lib/taurus/qt/qtdesigner/extraguiqwtplugin.py index 318e2dda..10db57af 100644 --- a/lib/taurus/qt/qtdesigner/extraguiqwtplugin.py +++ b/lib/taurus/qt/qtdesigner/extraguiqwtplugin.py @@ -1,27 +1,27 @@ #!/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/>. -## -############################################################################# +# +# ########################################################################### """ guiqwt widgets plugins for Qt Designer @@ -29,11 +29,15 @@ guiqwt widgets plugins for Qt Designer try: from guiqwt.qtdesigner import create_qtdesigner_plugin - PlotPlugin = create_qtdesigner_plugin("guiqwt", "guiqwt.plot", "CurveWidget", - icon="curve.png") - ImagePlotPlugin = create_qtdesigner_plugin("guiqwt", "guiqwt.plot", "ImageWidget", - icon="image.png") + PlotPlugin = create_qtdesigner_plugin( + "guiqwt", "guiqwt.plot", "CurveWidget", icon="curve.png" + ) + + ImagePlotPlugin = create_qtdesigner_plugin( + "guiqwt", "guiqwt.plot", "ImageWidget", icon="image.png" + ) except ImportError: from taurus.core.util.log import debug + debug("failed to load guiqwt designer plugin") diff --git a/lib/taurus/qt/qtdesigner/taurusdesigner.py b/lib/taurus/qt/qtdesigner/taurusdesigner.py index 2d8c17b4..2237a886 100644 --- a/lib/taurus/qt/qtdesigner/taurusdesigner.py +++ b/lib/taurus/qt/qtdesigner/taurusdesigner.py @@ -1,29 +1,28 @@ #!/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/>. -## -############################################################################# +# +# ########################################################################### -from builtins import str import sys import click import os.path @@ -34,6 +33,7 @@ import taurus.tauruscustomsettings from taurus.external.qt import Qt from taurus.core.util.log import deprecation_decorator + def env_index(env, env_name): env_name = str(env_name) for i, e in enumerate(env): @@ -75,7 +75,9 @@ def append_or_create_env_list(env, env_name, env_value): def get_qtdesigner_bin(): - designer_bin = getattr(taurus.tauruscustomsettings, 'QT_DESIGNER_PATH', None) + designer_bin = getattr( + taurus.tauruscustomsettings, "QT_DESIGNER_PATH", None + ) if designer_bin: return designer_bin designer_bin = str(Qt.QLibraryInfo.location(Qt.QLibraryInfo.BinariesPath)) @@ -83,13 +85,14 @@ def get_qtdesigner_bin(): plat = sys.platform if plat == "darwin": designer_bin = os.path.join( - designer_bin, "Designer.app", "Contents", "MacOS", "designer") + designer_bin, "Designer.app", "Contents", "MacOS", "designer" + ) elif plat in ("win32", "nt"): designer_bin = os.path.join(designer_bin, "designer.exe") if not os.path.exists(designer_bin): # some installations don't properly install designer # in QLibraryInfo.BinariesPath. We do a best effort to find it - designer_bin = subprocess.check_output('where designer') + designer_bin = subprocess.check_output("where designer") designer_bin = designer_bin.decode().strip() else: designer_bin = os.path.join(designer_bin, "designer") @@ -100,11 +103,11 @@ def get_taurus_designer_path(): """Returns a list of directories containing taurus designer plugins""" # Set PYQTDESIGNERPATH to look inside taurus for designer plugins taurus_path = os.path.dirname(os.path.abspath(taurus.__file__)) - taurus_qt_designer_path = os.path.join(taurus_path, 'qt', 'qtdesigner') + taurus_qt_designer_path = os.path.join(taurus_path, "qt", "qtdesigner") return [taurus_qt_designer_path] -@deprecation_decorator(alt='get_taurus_designer_env', rel='4.5') +@deprecation_decorator(alt="get_taurus_designer_env", rel="4.5") def qtdesigner_prepare_taurus(env=None, taurus_extra_path=None): # Tell Qt Designer where it can find the directory containing the plugins if env is None: @@ -119,9 +122,6 @@ def qtdesigner_prepare_taurus(env=None, taurus_extra_path=None): if taurus_extra_path is not None: append_or_create_env(env, "TAURUSQTDESIGNERPATH", taurus_extra_path) append_or_create_env(env, "PYTHONPATH", taurus_extra_path) - - # print "PYTHONPATH=%s" % get_env(env, "PYTHONPATH") - # print "PYQTDESIGNERPATH=%s" % get_env(env, "PYQTDESIGNERPATH") return env @@ -150,9 +150,12 @@ def qtdesigner_start(args, env=None): designer.setProcessChannelMode(Qt.QProcess.ForwardedChannels) if isinstance(env, Qt.QProcessEnvironment): designer.setProcessEnvironment(env) - else: # obsolete call, only for bck-compat - taurus.deprecated(dep='passing env which is not a QProcessEnvironment', - alt='QProcessEnvironment', rel='4.5') + else: # obsolete call, only for bck-compat + taurus.deprecated( + dep="passing env which is not a QProcessEnvironment", + alt="QProcessEnvironment", + rel="4.5", + ) designer.setEnvironment(env) designer.start(designer_bin, args) designer.waitForFinished(-1) @@ -160,17 +163,21 @@ def qtdesigner_start(args, env=None): return designer.exitCode() -@click.command('designer') -@click.argument('ui_files', nargs=-1) -@click.option("--taurus-path", "tauruspath", - metavar='TAURUSPATH', - default=None, - help="additional directories to look for taurus widgets") +@click.command("designer") +@click.argument("ui_files", nargs=-1) +@click.option( + "--taurus-path", + "tauruspath", + metavar="TAURUSPATH", + default=None, + help="additional directories to look for taurus widgets", +) def designer_cmd(ui_files, tauruspath): """Launch a Taurus-customized Qt Designer application""" env = get_taurus_designer_env(taurus_extra_path=tauruspath) sys.exit(qtdesigner_start(ui_files, env=env)) + if __name__ == "__main__": designer_cmd() diff --git a/lib/taurus/qt/qtdesigner/taurusplugin/__init__.py b/lib/taurus/qt/qtdesigner/taurusplugin/__init__.py index cf7aec63..a3aa2de1 100644 --- a/lib/taurus/qt/qtdesigner/taurusplugin/__init__.py +++ b/lib/taurus/qt/qtdesigner/taurusplugin/__init__.py @@ -1,30 +1,31 @@ #!/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/>. -## -############################################################################# +# +# ########################################################################### -"""The taurus.qt.qtdesigner.taurusplugin submodule.""" +"""The taurus.qt.qtdesigner.taurusplugin submodule. +""" -__docformat__ = 'restructuredtext' +__docformat__ = "restructuredtext" -from .taurusplugin import * +from .taurusplugin import * # noqa: F403,F401 diff --git a/lib/taurus/qt/qtdesigner/taurusplugin/taurusplugin.py b/lib/taurus/qt/qtdesigner/taurusplugin/taurusplugin.py index 0034f8d7..3a593bd1 100644 --- a/lib/taurus/qt/qtdesigner/taurusplugin/taurusplugin.py +++ b/lib/taurus/qt/qtdesigner/taurusplugin/taurusplugin.py @@ -1,29 +1,30 @@ #!/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: +""" 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 @@ -37,7 +38,6 @@ editing the widget model (same has 'Edit model...' task menu item """ -from __future__ import print_function import inspect from taurus.external.qt import Qt @@ -47,9 +47,10 @@ from taurus.core.util.log import Logger def Q_TYPEID(class_name): - """ Helper function to generate an IID for Qt.""" + """Helper function to generate an IID for Qt.""" return "com.trolltech.Qt.Designer.%s" % class_name + designer_logger = Logger("PyQtDesigner") @@ -62,8 +63,9 @@ class TaurusWidgetPlugin(QtDesigner.QPyDesignerCustomWidgetPlugin): self.initialized = False def initialize(self, formEditor): - """ Overwrite if necessary. Don't forget to call this method in case you - want the generic taurus extensions in your widget.""" + """Overwrite if necessary. Don't forget to call this method in case you + want the generic taurus extensions in your widget. + """ if self.isInitialized(): return @@ -86,13 +88,14 @@ class TaurusWidgetPlugin(QtDesigner.QPyDesignerCustomWidgetPlugin): if aspec.defaults is None: kwspec = {} else: - kwspec = dict(zip(aspec.args[-len(aspec.defaults):], - aspec.defaults)) + kwspec = dict( + zip(aspec.args[-len(aspec.defaults) :], aspec.defaults) + ) args, kwargs = [], {} - if 'designMode' in kwspec: - kwargs['designMode'] = designMode - if 'parent' in kwspec: - kwargs['parent'] = parent + if "designMode" in kwspec: + kwargs["designMode"] = designMode + if "parent" in kwspec: + kwargs["parent"] = parent else: args.append(parent) return args, kwargs @@ -100,22 +103,25 @@ class TaurusWidgetPlugin(QtDesigner.QPyDesignerCustomWidgetPlugin): def createWidget(self, parent): try: klass = self.getWidgetClass() - args, kwargs = self.__getWidgetArgs(klass=klass, - designMode=True, - parent=parent) + args, kwargs = self.__getWidgetArgs( + klass=klass, designMode=True, parent=parent + ) w = klass(*args, **kwargs) except Exception as e: name = self._getWidgetClassName() print(100 * "=") - print("taurus designer plugin error creating %s: %s" % (name, str(e))) + print( + "taurus designer plugin error creating %s: %s" % (name, str(e)) + ) print(100 * "-") import traceback + traceback.print_exc() w = None return w def getWidgetInfo(self, key, dft=None): - if not hasattr(self, '_widgetInfo'): + if not hasattr(self, "_widgetInfo"): self._widgetInfo = self.getWidgetClass().getQtDesignerPluginInfo() return self._widgetInfo.get(key, dft) @@ -125,46 +131,47 @@ class TaurusWidgetPlugin(QtDesigner.QPyDesignerCustomWidgetPlugin): return self._getWidgetClassName() def group(self): - """ Returns the name of the group in Qt Designer's widget box that this - widget belongs to. - It returns 'Taurus Widgets'. Overwrite if want another group.""" - return self.getWidgetInfo('group', 'Taurus Widgets') + """Returns the name of the group in Qt Designer's widget box that this + widget belongs to. + It returns 'Taurus Widgets'. Overwrite if want another group. + """ + return self.getWidgetInfo("group", "Taurus Widgets") def getIconName(self): - return self.getWidgetInfo('icon') + return self.getWidgetInfo("icon") def icon(self): - icon = self.getWidgetInfo('icon') + icon = self.getWidgetInfo("icon") if icon is None: return Qt.QIcon() elif isinstance(icon, Qt.QIcon): return icon else: if icon.find(":") == -1: - icon = 'designer:%s' % icon + icon = "designer:%s" % icon return Qt.QIcon(icon) def domXml(self): name = str(self.name()) lowerName = name[0].lower() + name[1:] - return '<widget class="%s" name=\"%s\" />\n' % (name, lowerName) + return '<widget class="%s" name="%s" />\n' % (name, lowerName) def includeFile(self): - """Returns the module containing the custom widget class. It may include - a module path.""" - return self.getWidgetInfo('module') + """Returns the module containing the custom widget class. It may + include a module path.""" + return self.getWidgetInfo("module") def toolTip(self): - tooltip = self.getWidgetInfo('tooltip') + tooltip = self.getWidgetInfo("tooltip") if tooltip is None: tooltip = "A %s" % self._getWidgetClassName() return tooltip def whatsThis(self): - whatsthis = self.getWidgetInfo('whatsthis') + whatsthis = self.getWidgetInfo("whatsthis") if whatsthis is None: whatsthis = "This is a %s widget" % self._getWidgetClassName() return whatsthis def isContainer(self): - return self.getWidgetInfo('container', False) + return self.getWidgetInfo("container", False) diff --git a/lib/taurus/qt/qtdesigner/tauruspluginplugin.py b/lib/taurus/qt/qtdesigner/tauruspluginplugin.py index 5a875ffe..ab2540a1 100644 --- a/lib/taurus/qt/qtdesigner/tauruspluginplugin.py +++ b/lib/taurus/qt/qtdesigner/tauruspluginplugin.py @@ -1,34 +1,84 @@ #!/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/>. -## -############################################################################# +# +# ########################################################################### """ -tauruspluginplugin.py: +Plugin module for QtDesigner that auto generates a the collections of plugins +to be added to the Qt designer catalog """ -from __future__ import absolute_import from taurus.external.qt import QtDesigner +from importlib import import_module + + +_DEFAULT_TAURUS_WIDGET_CATALOG = [ + "taurus.qt.qtgui.button:TaurusCommandButton", + "taurus.qt.qtgui.button:TaurusLauncherButton", + "taurus.qt.qtgui.button:TaurusLockButton", + "taurus.qt.qtgui.compact:TaurusBoolRW", + "taurus.qt.qtgui.compact:TaurusLabelEditRW", + "taurus.qt.qtgui.compact:TaurusReadWriteSwitcher", + "taurus.qt.qtgui.container:TaurusFrame", + "taurus.qt.qtgui.container:TaurusGroupBox", + "taurus.qt.qtgui.container:TaurusScrollArea", + "taurus.qt.qtgui.container:TaurusWidget", + "taurus.qt.qtgui.display:QLed", + "taurus.qt.qtgui.display:QPixmapWidget", + "taurus.qt.qtgui.display:TaurusLCD", + "taurus.qt.qtgui.display:TaurusLabel", + "taurus.qt.qtgui.display:TaurusLed", + "taurus.qt.qtgui.extra_guiqwt:TaurusImageDialog", + "taurus.qt.qtgui.extra_guiqwt:TaurusTrend2DDialog", + "taurus.qt.qtgui.extra_nexus:TaurusNeXusBrowser", + "taurus.qt.qtgui.graphic.jdraw:TaurusJDrawSynopticsView", + "taurus.qt.qtgui.graphic:TaurusGraphicsView", + "taurus.qt.qtgui.help:AboutDialog", + "taurus.qt.qtgui.help:HelpPanel", + "taurus.qt.qtgui.input:GraphicalChoiceWidget", + "taurus.qt.qtgui.input:TaurusAttrListComboBox", + "taurus.qt.qtgui.input:TaurusValueCheckBox", + "taurus.qt.qtgui.input:TaurusValueComboBox", + "taurus.qt.qtgui.input:TaurusValueLineEdit", + "taurus.qt.qtgui.input:TaurusValueSpinBox", + "taurus.qt.qtgui.input:TaurusWheelEdit", + "taurus.qt.qtgui.panel:DefaultReadWidgetLabel", + "taurus.qt.qtgui.panel:TangoConfigLineEdit", + "taurus.qt.qtgui.panel:TaurusAttrForm", + "taurus.qt.qtgui.panel:TaurusCommandsForm", + "taurus.qt.qtgui.panel:TaurusForm", + "taurus.qt.qtgui.panel:TaurusModelChooser", + "taurus.qt.qtgui.panel:TaurusModelList", + "taurus.qt.qtgui.panel:TaurusModelSelectorTree", + "taurus.qt.qtgui.table:QLoggingWidget", + "taurus.qt.qtgui.table:TaurusDbTableWidget", + "taurus.qt.qtgui.table:TaurusGrid", + "taurus.qt.qtgui.table:TaurusPropTable", + "taurus.qt.qtgui.table:TaurusValuesTable", + "taurus.qt.qtgui.tree:TaurusDbTreeWidget", +] + +_plugins = {} def build_qtdesigner_widget_plugin(klass): @@ -40,78 +90,64 @@ def build_qtdesigner_widget_plugin(klass): Plugin.__name__ = klass.__name__ + "QtDesignerPlugin" return Plugin -_SKIP = ["QLogo", "QGroupWidget", "TaurusGroupWidget"] - -_plugins = {} +def _create_plugins(): + from taurus import Logger -def main(): - from taurus.core.util.log import Logger - from taurus.qt.qtgui.util import TaurusWidgetFactory Logger.setLogLevel(Logger.Debug) _log = Logger(__name__) + ok = 0 + + # use explicit list of specs instead of original approach of instrospecting + # with TaurusWidgetFactory().getWidgetClasses() + # TODO: complement specs with an entry-point + specs = _DEFAULT_TAURUS_WIDGET_CATALOG + for spec in specs: + spec = spec.strip() + msg = spec + " : " + try: + assert ":" in spec, "expected 'modname:classname'" + _mod_name, _cls_name = spec.rsplit(":", maxsplit=1) + widget_class = getattr(import_module(_mod_name), _cls_name) + except Exception as e: + _log.warning(msg + "error importing: %s", e) + continue + + try: + qt_info = widget_class.getQtDesignerPluginInfo() + assert qt_info is not None, "getQtDesignerPluginInfo() -> None" + assert "module" in qt_info, "'module' key not available" + except Exception as e: + _log.warning(msg + "error getting plugin info: %s", e) + continue + + try: + # dynamically create taurus plugin classes and expose them + plugin_class = build_qtdesigner_widget_plugin(widget_class) + plugin_class_name = plugin_class.__name__ + globals()[plugin_class_name] = plugin_class + _plugins[plugin_class_name] = plugin_class + except Exception as e: + _log.warning(msg + "error creating plugin: %s", e) + continue + + # if we got here, everything went fine for this + _log.info(msg + "ok") + ok += 1 + _log.info("Designer plugins: %d created, %d failed", ok, len(specs) - ok) + + +def main(): try: - wf = TaurusWidgetFactory() - klasses = wf.getWidgetClasses() - ok_nb, skipped_nb, e1_nb, e2_nb, e3_nb, e4_nb = 0, 0, 0, 0, 0, 0 - for widget_klass in klasses: - name = widget_klass.__name__ - #_log.debug("Processing %s" % name) - if name in _SKIP: - #_log.debug("Skipped %s" % name) - skipped_nb += 1 - continue - # if getQtDesignerPluginInfo does not exist, returns None or raises - # an exception: forget the widget - cont = False - try: - qt_info = widget_klass.getQtDesignerPluginInfo() - if qt_info is None: - #_log.debug("E1: Canceled %s (getQtDesignerPluginInfo)" % name) - e1_nb += 1 - cont = True - except AttributeError: - #_log.debug("E2: Canceled %s (widget doesn't have getQtDesignerPluginInfo())" % name) - e2_nb += 1 - cont = True - except Exception as e: - #_log.debug("E3: Canceled %s (%s)" % (name, str(e))) - e3_nb += 1 - cont = True - - if cont: - continue - for k in ('module', ): - if k not in qt_info: - #_log.debug("E4: Canceled %s (getQtDesignerPluginInfo doesn't have key %s)" % (name, k)) - e4_nb += 1 - cont = True - if cont: - continue - - plugin_klass = build_qtdesigner_widget_plugin(widget_klass) - plugin_klass_name = plugin_klass.__name__ - globals()[plugin_klass_name] = plugin_klass - _plugins[plugin_klass_name] = plugin_klass - - ok_nb += 1 - #_log.debug("DONE processing %s" % name) - _log.info("Inpected %d widgets. %d (OK), %d (Skipped), %d (E1), %d (E2), %d (E3), %d(E4)" % ( - len(klasses), ok_nb, skipped_nb, e1_nb, e2_nb, e3_nb, e4_nb)) - _log.info("E1: getQtDesignerPluginInfo() returns None") - _log.info("E2: widget doesn't implement getQtDesignerPluginInfo()") - _log.info("E3: getQtDesignerPluginInfo() throws exception") - _log.info( - "E4: getQtDesignerPluginInfo() returns dictionary with missing key (probably 'module' key)") - except Exception as e: + _create_plugins() + except Exception: import traceback + traceback.print_exc() - # print e class TaurusWidgets(QtDesigner.QPyDesignerCustomWidgetCollectionPlugin): - def __init__(self, parent=None): QtDesigner.QPyDesignerCustomWidgetCollectionPlugin.__init__(parent) self._widgets = None @@ -121,5 +157,6 @@ class TaurusWidgets(QtDesigner.QPyDesignerCustomWidgetCollectionPlugin): self._widgets = [w(self) for w in _plugins.values()] return self._widgets + if __name__ != "__main__": main() |