<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
		<id>http://cegui.org/wiki/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Rrp</id>
		<title>CEGUI Wiki - Crazy Eddie's GUI System (Open Source) - User contributions [en]</title>
		<link rel="self" type="application/atom+xml" href="http://cegui.org/wiki/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Rrp"/>
		<link rel="alternate" type="text/html" href="http://cegui.org/wiki/Special:Contributions/Rrp"/>
		<updated>2026-05-17T16:05:08Z</updated>
		<subtitle>User contributions</subtitle>
		<generator>MediaWiki 1.24.1</generator>

	<entry>
		<id>http://cegui.org/wiki/index.php?title=Python3_SWIG_interface&amp;diff=5809</id>
		<title>Python3 SWIG interface</title>
		<link rel="alternate" type="text/html" href="http://cegui.org/wiki/index.php?title=Python3_SWIG_interface&amp;diff=5809"/>
				<updated>2019-08-30T22:22:01Z</updated>
		
		<summary type="html">&lt;p&gt;Rrp: add category&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{VersionBadge|1.0}}&lt;br /&gt;
&lt;br /&gt;
Default branch of CEGUI provide Python3 binding with [http://www.swig.org/ SWIG]. Currently SWIG interface covers a large part of libCEGUIBase, but don't cover any renderer module.&lt;br /&gt;
&lt;br /&gt;
= About SWIG =&lt;br /&gt;
&lt;br /&gt;
SWIG is wrappers generators, it can generate Python and other APIs without the need writing a lot of wrapper code.&lt;br /&gt;
&lt;br /&gt;
== How it works ==&lt;br /&gt;
&lt;br /&gt;
SWIG parse &amp;lt;code&amp;gt;.i&amp;lt;/code&amp;gt; file and generate C++ file, that (in Python case) directly uses libpython (so no depends on boost, pybind or similar). C++ file is build into Python &amp;lt;code&amp;gt;.so&amp;lt;/code&amp;gt; lib. SWIG generate also small &amp;lt;code&amp;gt;.py&amp;lt;/code&amp;gt; file to support import this lib. Cmake run SWIG on &amp;lt;code&amp;gt;.i&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;$CXX&amp;lt;/code&amp;gt; on generated wrapper code (in Ogre case is very big file, so &amp;lt;code&amp;gt;$CXX&amp;lt;/code&amp;gt; need some time to build it).&lt;br /&gt;
&lt;br /&gt;
SWIG automatically generate wrapper from &amp;lt;code&amp;gt;.i&amp;lt;/code&amp;gt; file(s) and &amp;lt;code&amp;gt;%include&amp;lt;/code&amp;gt; C++ &amp;lt;code&amp;gt;.h&amp;lt;/code&amp;gt; files. SWIG &amp;lt;code&amp;gt;.i&amp;lt;/code&amp;gt; file is set of &amp;lt;code&amp;gt;%&amp;lt;/code&amp;gt; directive, such as:&lt;br /&gt;
* &amp;lt;code&amp;gt;%include &amp;quot;file.h&amp;quot;&amp;lt;/code&amp;gt; – add interface from file.h to generated API&lt;br /&gt;
* &amp;lt;code&amp;gt;%{ ... %}&amp;lt;/code&amp;gt; to add some C++ stuff (e.g. &amp;lt;code&amp;gt;#include&amp;lt;/code&amp;gt; directive with header needed to build whole generated &amp;lt;code&amp;gt;.cpp&amp;lt;/code&amp;gt; file)&lt;br /&gt;
* &amp;lt;code&amp;gt;%extend&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;%proxycode&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;%ignore&amp;lt;/code&amp;gt; to adjust generated API&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;.h&amp;lt;/code&amp;gt; files for classes that should be exposed in generated API must be directly &amp;lt;code&amp;gt;%include in &amp;lt;code&amp;gt;.i&amp;lt;/code&amp;gt; file (SWIG do not use &amp;lt;code&amp;gt;#include&amp;lt;/code&amp;gt; in &amp;lt;code&amp;gt;%include&amp;lt;/code&amp;gt; files as &amp;lt;code&amp;gt;%include&amp;lt;/code&amp;gt;). Order of &amp;lt;code&amp;gt;%include&amp;lt;/code&amp;gt; is important – first &amp;lt;code&amp;gt;%include&amp;lt;/code&amp;gt; base classes, otherwise SWIG generate warning about missing base class and in generated API is missing info about class hierarchy (can't put derived class object to function that get base class object, can't call base class method on derived class object).&lt;br /&gt;
&lt;br /&gt;
= Build CEGUI Python3 binding =&lt;br /&gt;
&lt;br /&gt;
To build CEGUI Python SWIG interface you should enable CEGUI_BUILD_PYTHON_MODULES_SWIG cmake option:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;mkdir build; cd build; cmake .. -D CEGUI_BUILD_PYTHON_MODULES_SWIG=ON &amp;amp;&amp;amp; make&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This require libpython3 and swig.&lt;br /&gt;
&lt;br /&gt;
= Usage CEGUI Python3 binding =&lt;br /&gt;
&lt;br /&gt;
Primary intention of this binding is allow use (and create) CEGUI object from Python scripts system in game engines.&lt;br /&gt;
&lt;br /&gt;
== Using with boost::python ==&lt;br /&gt;
&lt;br /&gt;
SWIG generated API can be used with code that use boost::python to expose own interface. For example, if some project use CEGUI and have python API created with boost, it can return some CEGUI object via boost and this object can be used in python with CEGUI SWIG interface (this need only small piece of code to “cast” object between boost and SWIG):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;&lt;br /&gt;
#include &amp;quot;swig2BoostPython.inl&amp;quot;&lt;br /&gt;
&lt;br /&gt;
#include &amp;lt;CEGUI/Window.h&amp;gt;&lt;br /&gt;
&lt;br /&gt;
PREPARE_EXPOSE_PTR_VIA_SWIG(CEGUI::Window, &amp;quot;CEGUI::Window *&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
CEGUI::Window * getRootWindow();&lt;br /&gt;
&lt;br /&gt;
BOOST_PYTHON_MODULE(MyPyAPI) {&lt;br /&gt;
	EXPOSE_PTR_VIA_SWIG(CEGUI::Window);&lt;br /&gt;
	boost::python::def(&lt;br /&gt;
		&amp;quot;getRootWindow&amp;quot;,   &amp;amp;getRootWindow,&lt;br /&gt;
		boost::python::return_value_policy&amp;lt;reference_existing_object_via_SWIG&amp;gt;()&lt;br /&gt;
	);&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;swig2BoostPython.inl&amp;lt;/code&amp;gt; is small, header only, MIT license lib for connect boost and swig interfaces available on [https://bitbucket.org/OpCode-eu-org/python-swig-boost bitbucket git repo].&lt;br /&gt;
&lt;br /&gt;
== Down-cast CEGUI::Window and subscribeEvent() ==&lt;br /&gt;
&lt;br /&gt;
SWIG Python interface provide down-casting function for CEGUI::Window class. For example to get CEGUI::FrameWindow form CEGUI::Window you should use CEGUI.toFrameWindow(win).&lt;br /&gt;
&lt;br /&gt;
In SWIG Python interface to subscribeEvent() function should be pass objects of python class with realize event action. This class must have run method witch get event argument and return bool value.This object can't be delete before run events.&lt;br /&gt;
&lt;br /&gt;
=== example of creating window from python (with close button event) ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
import CEGUI&lt;br /&gt;
import MyPyAPI&lt;br /&gt;
&lt;br /&gt;
mywin = CEGUI.WindowManager.getSingleton().loadLayoutFromFile(&amp;quot;Info.layout&amp;quot;)&lt;br /&gt;
class Callback(CEGUI.PySubscriber):&lt;br /&gt;
    def run(self, n):&lt;br /&gt;
        mywin.hide()&lt;br /&gt;
        return True; # must return bool&lt;br /&gt;
handleHideInfoWin = Callback() # can't be temporary object !!!&lt;br /&gt;
CEGUI.toFrameWindow(mywin).getCloseButton().subscribeEvent( CEGUI.PushButton.EventClicked.c_str(), handleHideInfoWin )&lt;br /&gt;
&lt;br /&gt;
MyPyAPI.getRootWindow().addChild(mywin)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[Category:HowTo]]&lt;/div&gt;</summary>
		<author><name>Rrp</name></author>	</entry>

	<entry>
		<id>http://cegui.org/wiki/index.php?title=Python3_SWIG_interface&amp;diff=5808</id>
		<title>Python3 SWIG interface</title>
		<link rel="alternate" type="text/html" href="http://cegui.org/wiki/index.php?title=Python3_SWIG_interface&amp;diff=5808"/>
				<updated>2019-08-30T22:21:18Z</updated>
		
		<summary type="html">&lt;p&gt;Rrp: initial version&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{VersionBadge|1.0}}&lt;br /&gt;
&lt;br /&gt;
Default branch of CEGUI provide Python3 binding with [http://www.swig.org/ SWIG]. Currently SWIG interface covers a large part of libCEGUIBase, but don't cover any renderer module.&lt;br /&gt;
&lt;br /&gt;
= About SWIG =&lt;br /&gt;
&lt;br /&gt;
SWIG is wrappers generators, it can generate Python and other APIs without the need writing a lot of wrapper code.&lt;br /&gt;
&lt;br /&gt;
== How it works ==&lt;br /&gt;
&lt;br /&gt;
SWIG parse &amp;lt;code&amp;gt;.i&amp;lt;/code&amp;gt; file and generate C++ file, that (in Python case) directly uses libpython (so no depends on boost, pybind or similar). C++ file is build into Python &amp;lt;code&amp;gt;.so&amp;lt;/code&amp;gt; lib. SWIG generate also small &amp;lt;code&amp;gt;.py&amp;lt;/code&amp;gt; file to support import this lib. Cmake run SWIG on &amp;lt;code&amp;gt;.i&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;$CXX&amp;lt;/code&amp;gt; on generated wrapper code (in Ogre case is very big file, so &amp;lt;code&amp;gt;$CXX&amp;lt;/code&amp;gt; need some time to build it).&lt;br /&gt;
&lt;br /&gt;
SWIG automatically generate wrapper from &amp;lt;code&amp;gt;.i&amp;lt;/code&amp;gt; file(s) and &amp;lt;code&amp;gt;%include&amp;lt;/code&amp;gt; C++ &amp;lt;code&amp;gt;.h&amp;lt;/code&amp;gt; files. SWIG &amp;lt;code&amp;gt;.i&amp;lt;/code&amp;gt; file is set of &amp;lt;code&amp;gt;%&amp;lt;/code&amp;gt; directive, such as:&lt;br /&gt;
* &amp;lt;code&amp;gt;%include &amp;quot;file.h&amp;quot;&amp;lt;/code&amp;gt; – add interface from file.h to generated API&lt;br /&gt;
* &amp;lt;code&amp;gt;%{ ... %}&amp;lt;/code&amp;gt; to add some C++ stuff (e.g. &amp;lt;code&amp;gt;#include&amp;lt;/code&amp;gt; directive with header needed to build whole generated &amp;lt;code&amp;gt;.cpp&amp;lt;/code&amp;gt; file)&lt;br /&gt;
* &amp;lt;code&amp;gt;%extend&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;%proxycode&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;%ignore&amp;lt;/code&amp;gt; to adjust generated API&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;.h&amp;lt;/code&amp;gt; files for classes that should be exposed in generated API must be directly &amp;lt;code&amp;gt;%include in &amp;lt;code&amp;gt;.i&amp;lt;/code&amp;gt; file (SWIG do not use &amp;lt;code&amp;gt;#include&amp;lt;/code&amp;gt; in &amp;lt;code&amp;gt;%include&amp;lt;/code&amp;gt; files as &amp;lt;code&amp;gt;%include&amp;lt;/code&amp;gt;). Order of &amp;lt;code&amp;gt;%include&amp;lt;/code&amp;gt; is important – first &amp;lt;code&amp;gt;%include&amp;lt;/code&amp;gt; base classes, otherwise SWIG generate warning about missing base class and in generated API is missing info about class hierarchy (can't put derived class object to function that get base class object, can't call base class method on derived class object).&lt;br /&gt;
&lt;br /&gt;
= Build CEGUI Python3 binding =&lt;br /&gt;
&lt;br /&gt;
To build CEGUI Python SWIG interface you should enable CEGUI_BUILD_PYTHON_MODULES_SWIG cmake option:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;mkdir build; cd build; cmake .. -D CEGUI_BUILD_PYTHON_MODULES_SWIG=ON &amp;amp;&amp;amp; make&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This require libpython3 and swig.&lt;br /&gt;
&lt;br /&gt;
= Usage CEGUI Python3 binding =&lt;br /&gt;
&lt;br /&gt;
Primary intention of this binding is allow use (and create) CEGUI object from Python scripts system in game engines.&lt;br /&gt;
&lt;br /&gt;
== Using with boost::python ==&lt;br /&gt;
&lt;br /&gt;
SWIG generated API can be used with code that use boost::python to expose own interface. For example, if some project use CEGUI and have python API created with boost, it can return some CEGUI object via boost and this object can be used in python with CEGUI SWIG interface (this need only small piece of code to “cast” object between boost and SWIG):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;&lt;br /&gt;
#include &amp;quot;swig2BoostPython.inl&amp;quot;&lt;br /&gt;
&lt;br /&gt;
#include &amp;lt;CEGUI/Window.h&amp;gt;&lt;br /&gt;
&lt;br /&gt;
PREPARE_EXPOSE_PTR_VIA_SWIG(CEGUI::Window, &amp;quot;CEGUI::Window *&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
CEGUI::Window * getRootWindow();&lt;br /&gt;
&lt;br /&gt;
BOOST_PYTHON_MODULE(MyPyAPI) {&lt;br /&gt;
	EXPOSE_PTR_VIA_SWIG(CEGUI::Window);&lt;br /&gt;
	boost::python::def(&lt;br /&gt;
		&amp;quot;getRootWindow&amp;quot;,   &amp;amp;getRootWindow,&lt;br /&gt;
		boost::python::return_value_policy&amp;lt;reference_existing_object_via_SWIG&amp;gt;()&lt;br /&gt;
	);&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;swig2BoostPython.inl&amp;lt;/code&amp;gt; is small, header only, MIT license lib for connect boost and swig interfaces available on [https://bitbucket.org/OpCode-eu-org/python-swig-boost bitbucket git repo].&lt;br /&gt;
&lt;br /&gt;
== Down-cast CEGUI::Window and subscribeEvent() ==&lt;br /&gt;
&lt;br /&gt;
SWIG Python interface provide down-casting function for CEGUI::Window class. For example to get CEGUI::FrameWindow form CEGUI::Window you should use CEGUI.toFrameWindow(win).&lt;br /&gt;
&lt;br /&gt;
In SWIG Python interface to subscribeEvent() function should be pass objects of python class with realize event action. This class must have run method witch get event argument and return bool value.This object can't be delete before run events.&lt;br /&gt;
&lt;br /&gt;
=== example of creating window from python (with close button event) ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
import CEGUI&lt;br /&gt;
import MyPyAPI&lt;br /&gt;
&lt;br /&gt;
mywin = CEGUI.WindowManager.getSingleton().loadLayoutFromFile(&amp;quot;Info.layout&amp;quot;)&lt;br /&gt;
class Callback(CEGUI.PySubscriber):&lt;br /&gt;
    def run(self, n):&lt;br /&gt;
        mywin.hide()&lt;br /&gt;
        return True; # must return bool&lt;br /&gt;
handleHideInfoWin = Callback() # can't be temporary object !!!&lt;br /&gt;
CEGUI.toFrameWindow(mywin).getCloseButton().subscribeEvent( CEGUI.PushButton.EventClicked.c_str(), handleHideInfoWin )&lt;br /&gt;
&lt;br /&gt;
MyPyAPI.getRootWindow().addChild(mywin)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;/div&gt;</summary>
		<author><name>Rrp</name></author>	</entry>

	</feed>