cegui.ScriptModule

20 views
Skip to first unread message

Krešimir Špes

unread,
Jul 9, 2007, 12:41:43 PM7/9/07
to Python Ogre Developers
I'm trying to write a python script module (in python) for CEGUI but I
keep bumping into problems.

for instance,

class ScriptModule(cegui.ScriptModule):
def __init__(self):
cegui.ScriptModule.__init__(self)
self.identifierString= 'CEGUI Python scripting module v0.1'


excepts in AttributeError: can't set attribute on identifierString


when creating a script module, how can I register it within CEGUI?
aparently, all I have to do is call the cegui.ScriptModule constructor
before initialising cegui.system, but the log says:

---- Scripting module is: None ----

Krešimir Špes

unread,
Jul 9, 2007, 1:18:44 PM7/9/07
to Python Ogre Developers
sorry, my bad. i forgot to pass scriptModule parameter to cegui.System

still, doesn't explain why I can't set the identifier string :/


anyway, I'll probably finish the code tonight (CEST) and it will make
a nice wiki tutorial :)


for those of you who don't know what can be done with a ScriptModule:

you can assing actual python functions to events in .layout files and
have your class assign proper callback functions. eg:

<Window Type='wusLook/Editbox' Name='wus_console_input'>
<Property Name='Text' Value=''/>
<Event Name='Clicked' Function='on_console_click' />
</Window>

that way, your gui designers (or yourself :) ) can set events in an
easier and more logical manner.

Andy Miller

unread,
Jul 9, 2007, 6:27:07 PM7/9/07
to python-ogre...@googlegroups.com
I'll be supprised if this works as it's not something I've tested as as it seems to use callbacks it probably needs to be "hand wrapped".
 
Also the identifier_string is read only (in the C++ header) which is why you can't set it..
 
If you'd like to get as far as you can (ie write the test code etc that "should" work) then I'm happy to look at the wrapper further
 
Cheers

Andy

 

Krešimir Špes

unread,
Jul 9, 2007, 7:12:58 PM7/9/07
to Python Ogre Developers
the attribute is protected, not read only. it should be accesible from
within the class.

here's the sample code:


class events:
def OnTabsLeft(self,args):
print 'OnTabsLeft'

_events=events()

class ScriptModule(cegui.ScriptModule):
def __init__(self):
cegui.ScriptModule.__init__(self)

# self.identifierString= 'CEGUI Python scripting module by
Cateia games v0.1'
def createBindings(self):
cegui.Logger.getSingleton().logEvent( "---- Creating Python
bindings ----" )

def subscribeEvent(self,target,event_name,subscriber_name):
return target.subscribeEvent(event_name,_events,'OnTabsLeft')


def InitCEGUI(self):
global script_module
self.guiRenderer =
cegui.OgreCEGUIRenderer(self.renderWindow,
ogre.RENDER_QUEUE_OVERLAY, True, 0, self.sceneManager)
script_module=ScriptModule()
self.guiSystem = cegui.System(self.guiRenderer,logFile='logs/
gui.log',scriptModule=script_module)
.......


and put this in a layout file somewhere.

this code has to work,it was copy-translated from a working C++ code.


everything seem to be in order, except when I get a call to
subscribeEvent. I return a connected event, but the following
excoption raises:

TypeError: No registered converter was able to produce a C++ rvalue of
type class CEGUI::RefCounted<class CEGUI::BoundSlot> from this Python
object of type EventConnection

EventConnection and CEGUI::RefCounted<class CEGUI::BoundSlot> are the
same class. just typedefed.

Krešimir Špes

unread,
Jul 9, 2007, 7:13:43 PM7/9/07
to Python Ogre Developers
put this in a layout file:

<Event Name='Clicked' Function='some_function' />

Andy Miller

unread,
Jul 9, 2007, 8:26:11 PM7/9/07
to python-ogre...@googlegroups.com
OK, so this will definately not work with the current code -- however not a big issue to resolve it either.
 
Basically in hand_made_wrappers I have to handle the callbacks and manually expose each 'type' of eventset.. And I exposed all (I hope) the classes that are based upon CEGUI::EventSet (such as PushButton, System, Titlebar etc), I just didn't expose the simple one, EventSet itself :(
 
Anyway, I'll update the svn and put out a binary version for you to test with (you building from source?)
 
Cheers
Andy

 
On 10/07/07, Krešimir Špes <kresim...@gmail.com> wrote:

Krešimir Špes

unread,
Jul 9, 2007, 10:34:08 PM7/9/07
to Python Ogre Developers
that'd be great :)

I'm using rc2 binary on windows and linux right now.

On Jul 10, 2:26 am, "Andy Miller" <nzmill...@gmail.com> wrote:

>
> Anyway, I'll update the svn and put out a binary version for you to test
> with (you building from source?)
>
> Cheers
> Andy
>

Andy Miller

unread,
Jul 10, 2007, 6:36:39 AM7/10/07
to python-ogre...@googlegroups.com
 
You need to extract it and run "python setup.py install"  -- also note the new plugins (incase you have changed your dir structure)..
 
Let me know if this works and if not send me a complete demo package so I can test it properly
 
Cheers
Andy

 

Krešimir Špes

unread,
Jul 10, 2007, 8:54:36 AM7/10/07
to Python Ogre Developers
nope, python crashes on cegui.System initialisation. if I don't pass
the scriptModule parameter, it runs ok.

I've modified Demo_GUI with my class:

http://www.cateia.com/python-ogre/Demo_CEGUI_Gui.py

Andy Miller

unread,
Jul 12, 2007, 12:00:48 PM7/12/07
to python-ogre...@googlegroups.com
OK, so I've fixed the crashing issue - a not nice bug in CEGUI with an undefined variable - at times like this I REALLY like Python :)
 
You still don't get access to the protected variable (as we currently don't expose these with Py++), however I've changed the constructor for ScriptModule to take a string which is the identifier.
 
I've only rebuilt the CEGUI files so you'll need to put them in your ogre.gui.CEGUI directory -- updated one is here: http://files.python-ogre.org/downloads/CEGUI_2.rar
 
Change your demo class to be:
class ScriptModule(CEGUI.ScriptModule):
    def __init__(self, name, target):
        CEGUI.ScriptModule.__init__(self, name)
        self.target = target
       
   def subscribeEvent(self,target,event_name,subscriber_name):
        target.subscribeEvent(event_name,self.target,subscriber_name)
        ## OK so this is ugly -- ScriptModule expects a Event::Connection return variable
        ## it doesn't actually do anything with it but if we don't do this it breaks...
        return CEGUI.Connection()
 
Note the dummy return from subscribeEvent -  let me know if it works for you..
 
Thanks
Andy


 
On 10/07/07, Krešimir Špes <kresim...@gmail.com > wrote:
Reply all
Reply to author
Forward
0 new messages