1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181
|
/**
*
* This file is part of Tulip (www.tulip-software.org)
*
* Authors: David Auber and the Tulip development Team
* from LaBRI, University of Bordeaux 1 and Inria Bordeaux - Sud Ouest
*
* Tulip 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.
*
* Tulip 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 General Public License for more details.
*
*/
%Module _tulipgui
%PreInitialisationCode
bool initQt = true;
// test if there is an X server running on linux
// special case for PPA build, otherwise Python documentation is not generated
#if defined(__unix__)
char *display = getenv("DISPLAY");
initQt = (display != NULL);
#endif
// If there is no QApplication instance, it means that we are working from the classical Python shell
// or we are executing a script with the interpreter.
// Instantiate a QApplication but don't run its event loop continually through the exec method.
// Instead use the same hack as in PyQt4 in order to process qt events when the Python shell
// is waiting for input.
if (!QApplication::instance() && initQt) {
installQtInputHook();
#ifdef __APPLE__
// Hack for MacOS to avoid importing the qt_menu.nib file as it is
// not needed for our purpose and it forbids the tulipgui module to
// be imported when it has been installed through pip
QApplication::setAttribute(Qt::AA_MacPluginApplication);
#endif
new QApplication(argc, argv);
tlp::initTulipSoftware();
}
%End
%PostInitialisationCode
// rename tlp namespace into tlpgui
PyObject *moduleDict = PyModule_GetDict(sipModule);
PyObject *tlpClass = PyDict_GetItemString(moduleDict, "tlp");
PyDict_DelItemString(moduleDict, "tlp");
PyDict_SetItemString(moduleDict, "tlpgui", tlpClass);
%End
%ModuleHeaderCode
#include <string>
#include <cstdlib>
#include <QApplication>
#include <tulip/TlpTools.h>
#include <tulip/TlpQtTools.h>
#include <tulip/PluginLister.h>
#include <tulip/GlyphManager.h>
#include <tulip/EdgeExtremityGlyphManager.h>
#include <tulip/Interactor.h>
#include <tulip/PluginLibraryLoader.h>
#include <tulip/Perspective.h>
#include <tulip/Workspace.h>
static int argc = 1;
static char *argv[1] = {const_cast<char*>("tulipgui")};
extern void printErrorMessage(const std::string &errMsg);
extern void releaseSIPWrapper(void *wrappedCppObject, const sipTypeDef *td);
extern void installQtInputHook();
extern void removeQtInputHook();
namespace tlp {
extern void initInteractorsDependencies();
}
%End
%ModuleCode
void printErrorMessage(const std::string &errMsg) {
std::string pythonCode = "import sys\n"
"sys.stderr.write(\"";
pythonCode += errMsg;
pythonCode += "\\n\")";
PyRun_SimpleString(pythonCode.c_str());
}
void releaseSIPWrapper(void *wrappedCppObject, const sipTypeDef *td) {
PyObject *pyObj = sipGetPyObject(wrappedCppObject, td);
if (pyObj) {
sipTransferTo(pyObj, pyObj);
sipSimpleWrapper *wrapper = reinterpret_cast<sipSimpleWrapper *>(pyObj);
sipCommonDtor(wrapper);
}
}
namespace tlp {
void initInteractorsDependencies() {
tlp::InteractorLister::initInteractorsDependencies();
}
}
#include <QCoreApplication>
#include <QThread>
#if defined(Q_OS_WIN32) || defined(Q_OS_WIN)
#include <conio.h>
#include <QTimer>
#else
#include <QSocketNotifier>
#endif
// This is the input hook that will process events while the interpreter is
// waiting for interactive input (from PyQt).
extern "C" {static int qtInputHook();}
static int qtInputHook() {
QCoreApplication *app = QCoreApplication::instance();
if (app && app->thread() == QThread::currentThread()) {
#if defined(Q_OS_WIN32) || defined(Q_OS_WIN)
QTimer timer;
QObject::connect(&timer, SIGNAL(timeout()), app, SLOT(quit()));
while (!_kbhit()) {
timer.start(35);
QCoreApplication::exec();
timer.stop();
}
QObject::disconnect(&timer, SIGNAL(timeout()), app, SLOT(quit()));
#else
QSocketNotifier notifier(0, QSocketNotifier::Read, 0);
QObject::connect(¬ifier, SIGNAL(activated(int)), app, SLOT(quit()));
QCoreApplication::exec();
QObject::disconnect(¬ifier, SIGNAL(activated(int)), app, SLOT(quit()));
#endif
}
return 0;
}
void installQtInputHook() {
PyOS_InputHook = qtInputHook;
}
void removeQtInputHook() {
PyOS_InputHook = 0;
}
%End
namespace tlp {
void initInteractorsDependencies();
};
%Include Interactor.sip
%Include View.sip
%Include GlMainView.sip
%Include NodeLinkDiagramComponent.sip
%Include TulipGui.sip
%Import ../tulip-ogl/Module.sip
|