Example #1
0
    def setupContextMenu(self, vobj, menu):
        action1 = QtGui.QAction(
            Gui.getIcon("Std_TransformManip.svg"),
            translate("Command",
                      "Transform"),  # Context `Command` instead of `draft`.
            menu)
        QtCore.QObject.connect(action1, QtCore.SIGNAL("triggered()"),
                               self.transform)
        menu.addAction(action1)

        return True  # Removes `Transform` and `Set colors` from the default
Example #2
0
def getIcon(obj, disabled=False, path=None):
    if not path:
        path = iconPath
    if not getattr(obj, '_icon', None):
        obj._icon = addIconToFCAD(obj._iconName, path)
    if not disabled:
        return obj._icon
    if not getattr(obj, '_iconDisabled', None):
        name = getattr(obj, '_iconDisabledName', None)
        if name:
            obj._iconDisabled = addIconToFCAD(name, path)
        else:
            key = os.path.join(path, obj._iconName) + '.disabled'
            fmt = None
            try:
                if FreeCADGui.isIconCached(key):
                    obj._iconDisabled = key
                    return key
                else:
                    fmt = 'PNG'
            except Exception:
                pass
            pixmap = FreeCADGui.getIcon(obj._icon).pixmap(*iconSize,
                                                          mode=QIcon.Disabled)
            icon = QIcon(pixmapDisabled)
            icon.paint(QPainter(pixmap), 0, 0, iconSize[0], iconSize[1],
                       Qt.AlignCenter)
            data = QByteArray()
            buf = QBuffer(data)
            buf.open(QIODevice.WriteOnly)
            if fmt:
                pixmap.save(buf, fmt)
                FreeCADGui.addIcon(key, data.data(), fmt)
            else:
                pixmap.save(buf, 'XPM')
                key = data.data().decode('latin1')
            obj._iconDisabled = key
    return obj._iconDisabled