LINUX.ORG.RU

pyqt5 + QPyDesignerTaskMenuExtension

 ,


0

1

Не работает, делаю по кальке с PyQt4. Что я делаю не так?

#!/usr/bin/env python

"""
AnalogViewPlugin.py

"""

from PyQt5.QtGui import QIcon
from PyQt5.QtCore import pyqtSlot
from PyQt5.QtWidgets import QAction 
from PyQt5.QtDesigner import (QDesignerFormWindowInterface, QExtensionFactory,
        QPyDesignerContainerExtension, QPyDesignerCustomWidgetPlugin,
        QPyDesignerPropertySheetExtension, QPyDesignerTaskMenuExtension)


from analogview import AnalogView



class GeoLocationMenuEntry(QPyDesignerTaskMenuExtension):

    def __init__(self, obj, parent):
        QPyDesignerTaskMenuExtension.__init__(self, parent)
        self.editStateAction = QAction('dddd', self)
        self.editStateAction.clicked.connect(self.setPV)

    def preferredEditAction(self):
        return self.editStateAction

    def taskActions(self):
        return [self.editStateAction]

    @pyqtSlot()
    def setPV(self):
        pass

class GeoLocationTaskMenuFactory(QExtensionFactory):

    def __init__(self, parent=None):

       QExtensionFactory.__init__(self, parent)


    def createExtension(self, obj, iid, parent):

        if iid != "com.trolltech.Qt.Designer.TaskMenu":
            return None

        if isinstance(obj, AnalogView):
            return GeoLocationMenuEntry(obj, parent)

        return None


########################


class AnalogViewPlugin(QPyDesignerCustomWidgetPlugin):
    """AnalogViewPlugin(QPyDesignerCustomWidgetPlugin)

    Provides a Python custom plugin for Qt Designer by implementing the
    QDesignerCustomWidgetPlugin via a PyQt-specific custom plugin class.
    """

    # The __init__() method is only used to set up the plugin and define its
    # initialized variable.
    def __init__(self, parent=None):

        super(AnalogViewPlugin, self).__init__(parent)

        self.initialized = False

    def initialize(self, formEditor):

        if self.initialized:
            return
        manager = formEditor.extensionManager()
        if manager:
            self.factory = GeoLocationTaskMenuFactory(manager)
            manager.registerExtensions(self.factory, "com.trolltech.Qt.Designer.TaskMenu")
        self.initialized = True

    def isInitialized(self):

        return self.initialized

    # This factory method creates new instances of our custom widget with the
    # appropriate parent.
    def createWidget(self, parent):
        widget = AnalogView(parent)
        # widget.setValue(1)
        return widget

    # This method returns the name of the custom widget class that is provided
    # by this plugin.
    def name(self):
        return "AnalogView"

    # Returns the name of the group in Qt Designer's widget box that this
    # widget belongs to.
    def group(self):
        return "SCADA"

    # Returns the icon used to represent the custom widget in Qt Designer's
    # widget box.
    def icon(self):
        return QIcon()

    # Returns a short description of the custom widget for use in a tool tip.
    def toolTip(self):
        return ""

    # Returns a short description of the custom widget for use in a "What's
    # This?" help message for the widget.
    def whatsThis(self):
        return ""

    # Returns True if the custom widget acts as a container for other widgets;
    # otherwise returns False. Note that plugins for custom containers also
    # need to provide an implementation of the QDesignerContainerExtension
    # interface if they need to add custom editing support to Qt Designer.
    def isContainer(self):
        return False

    # Returns an XML description of a custom widget instance that describes
    # default values for its properties. Each custom widget created by this
    # plugin will be configured using this description.
    def domXml(self):
        return '<widget class="AnalogView" name="analogView" />\n'

    # Returns the module containing the custom widget class. It may include
    # a module path.
    def includeFile(self):
        return "analogview"

★★