PyOgre 1.2 getter/setters

mthorn

23-06-2006 18:15:08

Question for the guys working on 1.2, will you still be converting get*() and set*() to * = ''? I found it annoying that the way the library worked was different from the official ogre docs. I know it is a python branch and people want to make it more Pythonic. However, I think it would speed up binding with Python and development just to leave the functions as they are in Ogre.

Istari

24-06-2006 05:28:40

There are at least two ways to tackle this. One would be to modify ogre_attributes.i so that it supports both the Pythonic properties and the get/set methods. Another is to just read the docstrings for the classes.
Personally I'm in favor of the docstrings method since I don't fancy messing with the preprocessor stuff in ogre_attributes.i. Here is a simple app that I use to view the pyOgre docstrings:import re
import wx
import wx.html
import pydoc
from pyogre import ogre

class FindPrefixListBox(wx.ListBox):
def __init__(self, parent, id, pos=wx.DefaultPosition, size=wx.DefaultSize,
choices=[], style=0, validator=wx.DefaultValidator):
wx.ListBox.__init__(self, parent, id, pos, size, choices, style, validator)
self.typedText = ''
self.Bind(wx.EVT_KEY_DOWN, self.OnKey)

def FindPrefix(self, prefix):
if prefix:
prefix = prefix.lower()
length = len(prefix)

for x in range(self.GetCount()):
text = self.GetString(x)
text = text.lower()

if text[:length] == prefix:
return x

return -1

def OnKey(self, evt):
key = evt.GetKeyCode()

if key >= 32 and key <= 127:
self.typedText = self.typedText + chr(key)
item = self.FindPrefix(self.typedText)

if item != -1:
self.SetSelection(item)
elif key == wx.WXK_BACK: # backspace removes one character and backs up
self.typedText = self.typedText[:-1]

if not self.typedText:
self.SetSelection(0)
else:
item = self.FindPrefix(self.typedText)

if item != -1:
self.SetSelection(item)
elif key == wx.WXK_RETURN:
self.typedText = ''
self.AddPendingEvent(wx.CommandEvent(wx.EVT_LISTBOX.evtType[0], self.GetId()))
evt.Skip()
else:
self.typedText = ''
evt.Skip()

class HelpFrame(wx.Frame):
def __init__(self, parent=None, id=-1, title='pyOgre Help'):
wx.Frame.__init__(self, parent, id, title, size=(800,600))

self.splitter = wx.SplitterWindow(self, -1)
self.html = wx.html.HtmlWindow(self.splitter, -1)

ogreNames = dir(ogre)
ogreNames.sort()
self.list = FindPrefixListBox(self.splitter, -1, choices=ogreNames)

self.splitter.SetMinimumPaneSize(200)
self.splitter.SplitVertically(self.list, self.html, 200)

self.Bind(wx.EVT_LISTBOX, self.onItemSelected)

self.showItemDocs(ogre.Root)

def onItemSelected(self, event):
self.showItemDocs(getattr(ogre, self.list.GetString(self.list.GetSelection())))
event.Skip()

def showItemDocs(self, item):
object, name = pydoc.resolve(item, 0)
theText = pydoc.text.document(object, name)
theText = re.sub('.\b', '', theText)
theText = theText.replace('<', '&lt;').replace('>', '&gt;').replace('\n | ', '\n ')
self.html.SetPage(''.join(('<pre>', theText, '</pre>')))

class HelpApp(wx.App):
def OnInit(self):
self.frame = HelpFrame()
self.frame.Show(True)
return True

if __name__ == '__main__':
app = HelpApp(False)
app.MainLoop()

dermont

24-06-2006 10:07:08

Surely a simpler way would be to just ignore the ogre_attributes.i:

#ifdef OGRE_GET_SETS
%include ogre_attributes.i
#endif

There would be still some work to do to accessing the members from classes such as OgreVector3, OgreVector4,OgreVector2 and a few ifdef's here and there.

With Swig's limitation in wrapping public variables and anonymous unions / nested classe etc theres always going to be differences.

Istari

24-06-2006 14:24:18

I'll give it a look later, I still think that the simplest way is just to use the docstrings. ;)
For now though, since almost all the time I can spare for pyOgre are the weekends, I will be concentrating on the items in the pyOgreTODO so we'll get functionality first.

mthorn

26-06-2006 23:47:12

Since you already have to look up the Ogre docs for a function, it seems redundant to then look up the docstrings for the python implementation.

Just using help('pyogre.ogre.ClassName') works for looking up the docstrings, but it's a cumbersome extra step.