Came back to this for a couple of mins after a little more python reading, this is the code I have so far…
import direct.directbase.DirectStart
from direct.gui.DirectGui import *
class myWin:
"""myWin : My first python/panda3d program"""
def __init__(self):
# Just to know what Im dealing with
self.win = None
self.camera2d = None
self.windowProperties = None
self.render3d = None
self.render2d = None
self.dataRoot = None
self.dataRootNode = None
def openWin(self, sizeX, sizeY, originX, originY):
# setup the window properties
self.windowProperties = WindowProperties()
self.windowProperties.setSize( sizeX, sizeY )
self.windowProperties.setOrigin( originX, originY )
# open a window
self.win = base.openWindow(props = self.windowProperties, aspectRatio = 1, type = 'onscreen')
# create a 3d rendering context
self.render3d = NodePath('myWin_render3d')
# give the newly created camera to the renderer
base.camList[-1].reparentTo(self.render3d)
# create a 2d rendering context
self.render2d = NodePath('myWin_render2d')
# create a camera and parent it to the 2d renderer
self.camera2d = base.makeCamera2d( self.win )
self.camera2d.reparentTo( self.render2d )
# setup the default 2d rendering aspects
self.render2d.setDepthWrite( 0 )
self.render2d.setMaterialOff( 1 )
self.render2d.setTwoSided( 1 )
# set the background colour to black
base.setBackgroundColor( 0, 0, 0, 0, self.win )
# set the data root which will (hopefully) handle messages
self.dataRoot = NodePath('myWin_dataRoot')
self.dataRootNode = self.dataRoot.node()
# loop through the devices and add them to the dataRoot
for i in range(self.win.getNumInputDevices()):
name = self.win.getInputDeviceName(i)
mk = self.dataRoot.attachNewNode(MouseAndKeyboard(self.win, i, name))
# add the dataloop to the task manager
base.taskMgr.add(self.dataLoop, 'myWin_dataLoop', priority = -50)
def testButton(self, buttonText):
tmpButton = DirectButton( text = buttonText, scale = 0.5)
tmpButton.setPos(0, 0, 0)
tmpButton.reparentTo( self.render2d )
def dataLoop(self, state):
# traverse the data graph. This reads all the control
# inputs (from the mouse and keyboard, for instance) and also
# directly acts upon them (for instance, to move the avatar).
base.dgTrav.traverse(self.dataRootNode)
return Task.cont
# Panda startup
base.setBackgroundColor(0, 0, 0)
base.disableMouse()
camera.setPos ( 0, 0, 45 )
camera.setHpr ( 0, -90, 0 )
# My test program
newWin = myWin()
newWin.openWin( 100, 100, 0, 0 )
newWin.testButton('A Button!')
# *I used this line in first test and not the dataRoot node stuff in class*
#base.setupMouse(newWin.win)
# run app
run()
When I try to use base.setupMouse( newWin.win ) I got this error…
File “DataGraphTraverser”, line 92, in traverse
AssertionError: has_size() at line 146 of windowProperties.I
So I attempted to setup a similar thing to base with a dataRoot and a dataLoop function. However that generated the same error,
I also tried a few other things ( forgot exactly, I was just toying around ) and I was getting quite a few ‘AssertionError: has_size()’ errors.
I guess I must be doing something wrong with the windowProperties? Or perhaps I have completely misunderstood this 
Any advice greatly appreciated.