コード例 #1
0
Py::Object ViewProviderPy::getIcon(void) const
{
#if 0
    QByteArray ba;
    QDataStream str(&ba, QIODevice::WriteOnly);
    QIcon icon = getViewProviderPtr()->getIcon();
    str << icon;
    return Py::String(ba.constData(), ba.size());
#else
    PythonWrapper wrap;
    wrap.loadGuiModule();
    QIcon icon = getViewProviderPtr()->getIcon();
    return wrap.fromQIcon(new QIcon(icon));
#endif
}
コード例 #2
0
PyObject* Application::sGetMainWindow(PyObject * /*self*/, PyObject *args,PyObject * /*kwd*/)
{
    if (!PyArg_ParseTuple(args, ""))
        return NULL;

    PythonWrapper wrap;
    wrap.loadCoreModule();
    wrap.loadGuiModule();
    try {
        return Py::new_reference_to(wrap.fromQWidget(Gui::getMainWindow(), "QMainWindow"));
    }
    catch (const Py::Exception&) {
        return 0;
    }
}
コード例 #3
0
void ViewProviderPythonFeatureImp::setupContextMenu(QMenu* menu)
{
    // Run the attach method of the proxy object.
    Base::PyGILStateLocker lock;
    try {
        App::Property* proxy = object->getPropertyByName("Proxy");
        if (proxy && proxy->getTypeId() == App::PropertyPythonObject::getClassTypeId()) {
            Py::Object vp = static_cast<App::PropertyPythonObject*>(proxy)->getValue();
            if (vp.hasAttr(std::string("setupContextMenu"))) {
                if (vp.hasAttr("__object__")) {
                    PythonWrapper wrap;
                    wrap.loadGuiModule();
                    wrap.loadWidgetsModule();
                    Py::Callable method(vp.getAttr(std::string("setupContextMenu")));
                    Py::Tuple args(1);
                    args.setItem(0, wrap.fromQWidget(menu, "QMenu"));
                    method.apply(args);
                }
                else {
                    PythonWrapper wrap;
                    wrap.loadGuiModule();
                    wrap.loadWidgetsModule();
                    Py::Callable method(vp.getAttr(std::string("setupContextMenu")));
                    Py::Tuple args(2);
                    args.setItem(0, Py::Object(object->getPyObject(), true));
                    args.setItem(1, wrap.fromQWidget(menu, "QMenu"));
                    method.apply(args);
                }
            }
        }
    }
    catch (Py::Exception&) {
        Base::PyException e; // extract the Python error text
        e.ReportException();
    }
}
コード例 #4
0
PyObject* Application::sGetMainWindow(PyObject * /*self*/, PyObject *args)
{
    if (!PyArg_ParseTuple(args, ""))
        return NULL;

    PythonWrapper wrap;
    if (!wrap.loadCoreModule() ||
        !wrap.loadGuiModule() ||
        !wrap.loadWidgetsModule()) {
        PyErr_SetString(PyExc_RuntimeError, "Failed to load Python wrapper for Qt");
        return 0;
    }
    try {
        return Py::new_reference_to(wrap.fromQWidget(Gui::getMainWindow(), "QMainWindow"));
    }
    catch (const Py::Exception&) {
        return 0;
    }
}