Skip to content

Commit 763c2ba

Browse files
committed
Proof of concept for injectible python works
1 parent e5f0e1b commit 763c2ba

File tree

1 file changed

+44
-1
lines changed

1 file changed

+44
-1
lines changed

src/Core/Application/Application.cc

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
#include <Core/Services/ServiceLog.h>
4646
#include <Core/Services/ServiceDB.h>
4747
#include <Core/Services/ServiceManager.h>
48+
#include <Core/Python/PythonInterpreter.h>
4849

4950
using namespace SCIRun::Core;
5051
using namespace SCIRun::Core::Logging;
@@ -155,6 +156,48 @@ void Application::readCommandLine(int argc, const char* argv[])
155156
Logging::Log::get().setVerbose(parameters()->verboseMode());
156157
}
157158

159+
namespace
160+
{
161+
#ifdef BUILD_WITH_PYTHON
162+
163+
class HardCodedPythonTestCommand : public ParameterizedCommand
164+
{
165+
public:
166+
virtual bool execute() override
167+
{
168+
PythonInterpreter::Instance().run_string("import SCIRunPythonAPI; from SCIRunPythonAPI import *");
169+
PythonInterpreter::Instance().run_string("scirun_set_module_state(scirun_module_ids()[-1], \"FileTypeName\", \"Matlab Matrix (*.mat)\") if scirun_module_ids()[-1].startswith('ReadMatrix') else 'not ReadMatrix'");
170+
return true;
171+
}
172+
};
173+
174+
class HardCodedPythonFactory : public NetworkEventCommandFactory
175+
{
176+
public:
177+
virtual CommandHandle create(NetworkEventCommands type) const override
178+
{
179+
switch (type)
180+
{
181+
case NetworkEventCommands::PostModuleAdd:
182+
return boost::make_shared<HardCodedPythonTestCommand>();
183+
}
184+
return nullptr;
185+
}
186+
};
187+
188+
189+
#endif
190+
191+
NetworkEventCommandFactoryHandle makeNetworkEventCommandFactory()
192+
{
193+
#ifdef BUILD_WITH_PYTHON
194+
return boost::make_shared<HardCodedPythonFactory>();
195+
#else
196+
return boost::make_shared<NullCommandFactory>();
197+
#endif
198+
}
199+
}
200+
158201
NetworkEditorControllerHandle Application::controller()
159202
{
160203
ENSURE_NOT_NULL(private_, "Application internals are uninitialized!");
@@ -168,7 +211,7 @@ NetworkEditorControllerHandle Application::controller()
168211
ExecutionStrategyFactoryHandle exe(new DesktopExecutionStrategyFactory(parameters()->threadMode()));
169212
AlgorithmFactoryHandle algoFactory(new HardCodedAlgorithmFactory);
170213
ReexecuteStrategyFactoryHandle reexFactory(new DynamicReexecutionStrategyFactory(parameters()->reexecuteMode()));
171-
NetworkEventCommandFactoryHandle eventCmdFactory(new NullCommandFactory);
214+
auto eventCmdFactory(makeNetworkEventCommandFactory());
172215
private_->controller_.reset(new NetworkEditorController(moduleFactory, sf, exe, algoFactory, reexFactory, private_->cmdFactory_, eventCmdFactory));
173216

174217
/// @todo: sloppy way to initialize this but similar to v4, oh well

0 commit comments

Comments
 (0)