def _setUpResources(self):
        sf.setupLogging()
        sf.info ("Entering _setupresources")
        # register the quickgui script handler..
        gui.registerScriptReader()

        # load the default resources
        sf.Application._setUpResources ( self )
        
        # Now load any extra resource locations that we might need..  
        Ogre.ResourceGroupManager.getSingleton().addResourceLocation("media/textures","FileSystem", "General")
        Ogre.ResourceGroupManager.getSingleton().addResourceLocation("media/qgui.core.zip", "Zip")
        #Ogre.ResourceGroupManager.getSingleton().addResourceLocation("media","FileSystem", "General")
        sf.info ( "Done _setup resources")
    def createGUI ( self ):  
        self.callbacks=[]
        sf.info ("Creating GUI")
        dm = gui.DescManager.getSingletonPtr()
        
        sd = dm.getDefaultSheetDesc()
        sd.resetToDefault()
        sd.widget_name = "QuickGui.MainSheet"
        sd.widget_dimensions.size = gui.Size(800,600)
        self.mSheet = gui.SheetManager.getSingleton().createSheet(sd)
        self.mSheet.addWidgetEventHandler(gui.WIDGET_EVENT_SIZE_CHANGED,self.MakeCallback( self.onSheetResized) )
        
		
        
        self.TreeView = createWidget ( self.mSheet,"TreeView", gui.Rect(0,75,200,300) )
        self.Panel = createWidget (  self.mSheet,"Panel", gui.Rect(225,75,150,217), name="MainPanel", 
                        widget_resizeFromBottom=True, widget_resizeFromRight = True )
        #self.bd = createWidget(  self.mSheet,"ScrollButton", gui.Rect(400,250,75,23) )
        self.tb = createWidget(  self.mSheet,"ToolBar", gui.Rect(0,0,800,20), name="TestToolBar")
        print dir(self.tb)
        self.tb.createMenu("File")

        menu = dm.getDefaultMenuDesc()
        menu.resetToDefault()
        menu.widget_name = "Edit"
        menu.textDesc.segments.append(gui.TextSegment("micross.12",gui.ColourValue().Black,"Edit"))
        
        sv = gui.vector_QuickGUITextSegment()
        sv.append (gui.TextSegment("micross.12",gui.ColourValue().Black,"Edit"))
        
        m = self.tb.createMenu()
        m.createSubMenu ("test")
        
        m.createTextItem ( sv )
        m.createTextItem ( "Item2" )
        m.createSubMenu ("test")
        #m.createTextItem ( gui.TextSegment("micross.12",gui.ColourValue().Black,"Item1") )
        #m.createTextItem ( gui.TextSegment("micross.12",gui.ColourValue().Black,"Item2") )
        
        self.tb.createMenu("Format")
        
        
        ##self.addMenuItem ( self.tb, "File")
        self.combo = createWidget ( self.mSheet,"ComboBox", gui.Rect(400,100,125,20), combobox_dropDownMaxHeight = 60 )
        
        if False:
          pd = descFactory.getInstance("DefaultPanelDesc")
          bd = descFactory.getInstance("DefaultButtonDesc")
          cbd = descFactory.getInstance("DefaultCheckBoxDesc")
          ltiDesc = descFactory.getInstance("DefaultListTextItemDesc")
          vsd = descFactory.getInstance("DefaultVScrollBarDesc")
          tad = descFactory.getInstance("DefaultTextAreaDesc")
          combod = descFactory.getInstance("DefaultComboBoxDesc")
          md = descFactory.getInstance("DefaultMenuDesc")
          textBoxD = descFactory.getInstance("DefaultTextBoxDesc")
          hsd = descFactory.getInstance("DefaultHScrollBarDesc")
          progDesc =descFactory.getInstance("DefaultProgressBarDesc")
          listDesc = descFactory.getInstance("DefaultListDesc")
          mld = descFactory.getInstance("DefaultMenuLabelDesc")
          tbd = descFactory.getInstance("DefaultToolBarDesc")
          cd = descFactory.getInstance("DefaultConsoleDesc")
          tvd = descFactory.getInstance("DefaultTreeViewDesc")
          sf.info ("CreateGUI part 1")

          md.resetToDefault()
          md.widget_name = "File"
          md.textDesc.segments.append(gui.TextSegment("micross.12",Ogre.ColourValue().Black,"File"))
          tb.createMenu(md)

          md.resetToDefault()
          md.widget_name = "Edit"
          md.textDesc.segments.append(gui.TextSegment("micross.12",Ogre.ColourValue().Black,"Edit"))
          tb.createMenu(md)

          md.resetToDefault()
          md.widget_name = "Format"
          md.textDesc.segments.append(gui.TextSegment("micross.12",Ogre.ColourValue().Black,"Format"))
          m1 = tb.createMenu(md)

          md.resetToDefault()
          md.widget_name = "WordWrap"
          md.textDesc.segments.append(gui.TextSegment("micross.12",Ogre.ColourValue().Black,"Word Wrap"))
          m2 = m1.createSubMenu(md)

          mld.resetToDefault()
          mld.widget_name = "Font"
          mld.textDesc.segments.append(gui.TextSegment("micross.12",Ogre.ColourValue().Black,"Font..."))
          m1.createMenuLabel(mld)

          mld.resetToDefault()
          mld.widget_name = "Item1"
          mld.textDesc.segments.append(gui.TextSegment("micross.12",Ogre.ColourValue().Black,"Item 1"))
          m2.createMenuLabel(mld)

          md.resetToDefault()
          md.widget_name = "Item2"
          md.textDesc.segments.append(gui.TextSegment("micross.12",Ogre.ColourValue().Black,"Item 2"))
          m3 = m2.createSubMenu(md)

          mld.resetToDefault()
          mld.widget_name = "Item2.1"
          mld.textDesc.segments.append(gui.TextSegment("micross.12",Ogre.ColourValue().Green,"Item 2.1"))
          m3.createMenuLabel(mld)


          ltiDesc.resetToDefault()
          ltiDesc.textDesc.horizontalTextAlignment = gui.TEXT_ALIGNMENT_HORIZONTAL_CENTER
          t =gui.VectorTextSegment()
          t.append(gui.TextSegment("micross.12",Ogre.ColourValue().White,"CB Item 1"))
          ltiDesc.textDesc.segments=t
          comboBox.createItem(ltiDesc)

          ltiDesc.resetToDefault()
          t =gui.VectorTextSegment()
          t.append(gui.TextSegment("micross.12",Ogre.ColourValue().White,"CB Item 2"))
          ltiDesc.textDesc.segments=t
          comboBox.createItem(ltiDesc)

          ltiDesc.resetToDefault()
          t =gui.VectorTextSegment()
          t.append(gui.TextSegment("micross.12",Ogre.ColourValue().White,"CB Item 3"))
          ltiDesc.textDesc.segments=t
          comboBox.createItem(ltiDesc)

          textBoxD.widget_name = "TestTextBox"
          textBoxD.textbox_defaultFontName = "micross.12"
          textBoxD.widget_dimensions = gui.Rect(350,350,100,20)
          textBoxD.textbox_maskText = True
          textBoxD.textbox_maskSymbol = 42
          self.mGUIManager.getActiveSheet().createTextBox(textBoxD)

          tad.widget_name = "TestArea1"
          tad.textarea_defaultFontName = "micross.16"
          tad.widget_dimensions = gui.Rect(575,300,200,200)
          self.mGUIManager.getActiveSheet().createTextArea(tad)

          cd.resetToDefault()
          cd.widget_dimensions = gui.Rect(300,300,200,200)

          vsd.resetToDefault() 
          vsd.widget_name = "TestVSD1" 
          vsd.widget_dimensions = gui.Rect(50,50,15,100) 
          win.createVScrollBar(vsd) 

          vsd.widget_name = "TestVSD2" 
          vsd.vscrollbar_scrollBarButtonLayout = gui.VSCROLL_BAR_BUTTON_LAYOUT_ADJACENT_UP 
          vsd.widget_dimensions = gui.Rect(70,50,15,100) 
          win.createVScrollBar(vsd) 

          vsd.widget_name = "TestVSD3" 
          vsd.vscrollbar_scrollBarButtonLayout = gui.VSCROLL_BAR_BUTTON_LAYOUT_ADJACENT_DOWN 
          vsd.widget_dimensions = gui.Rect(90,50,15,100) 
          win.createVScrollBar(vsd) 

          vsd.widget_name = "TestVSD4" 
          vsd.vscrollbar_scrollBarButtonLayout = gui.VSCROLL_BAR_BUTTON_LAYOUT_MULTIPLE_BOTH 
          vsd.widget_dimensions = gui.Rect(110,50,15,100) 
          win.createVScrollBar(vsd) 

          vsd.widget_name = "TestVSD5" 
          vsd.vscrollbar_scrollBarButtonLayout = gui.VSCROLL_BAR_BUTTON_LAYOUT_MULTIPLE_DOWN 
          vsd.widget_dimensions = gui.Rect(130,50,15,100) 
          win.createVScrollBar(vsd) 

          vsd.widget_name = "TestVSD6" 
          vsd.vscrollbar_scrollBarButtonLayout = gui.VSCROLL_BAR_BUTTON_LAYOUT_MULTIPLE_UP 
          vsd.widget_dimensions = gui.Rect(150,50,15,100) 
          win.createVScrollBar(vsd) 

          vsd.widget_name = "TestVSD7" 
          vsd.vscrollbar_scrollBarButtonLayout = gui.VSCROLL_BAR_BUTTON_LAYOUT_NONE 
          vsd.widget_dimensions = gui.Rect(170,50,15,100) 
          win.createVScrollBar(vsd) 

          hsd.resetToDefault() 
          hsd.widget_name = "TestHSD1" 
          hsd.widget_dimensions = gui.Rect(50,160,100,15) 
          win.createHScrollBar(hsd) 

          progDesc.widget_name = "Prog"
          progDesc.textDesc.segments.append(gui.TextSegment("micross.12",Ogre.ColourValue().White,"Progress Bar"))
          progDesc.textDesc.horizontalTextAlignment = gui.TEXT_ALIGNMENT_HORIZONTAL_CENTER
          progDesc.widget_dimensions = gui.Rect(100,400,200,35)
          progDesc.progressbar_fillDirection = gui.PROGRESSBAR_FILLS_POSITIVE_TO_NEGATIVE
          progDesc.progressbar_clippingEdge = gui.PROGRESSBAR_CLIP_RIGHT_TOP
          progDesc.progressbar_layout = gui.PROGRESSBAR_LAYOUT_VERTICAL
          self.mGUIManager.getActiveSheet().createProgressBar(progDesc)

          bd.resetToDefault()
          bd.widget_name = "Minus"
          bd.widget_dimensions = gui.Rect(100,440,100,35)
          bd.textDesc.segments.append(gui.TextSegment("micross.12",Ogre.ColourValue().Green,"Minus"))
          bd.textDesc.horizontalTextAlignment = gui.TEXT_ALIGNMENT_HORIZONTAL_CENTER
          minus = self.mGUIManager.getActiveSheet().createButton(bd)
          
          minus.addWidgetEventHandler(gui.WIDGET_EVENT_MOUSE_BUTTON_UP,self.MakeCallback (self.test1) )

          bd.widget_name = "Plus"
          bd.widget_dimensions = gui.Rect(200,440,100,35)
          bd.textDesc.segments.append(gui.TextSegment("micross.12",Ogre.ColourValue().Green,"Plus"))
          plus = self.mGUIManager.getActiveSheet().createButton(bd)
          
          plus.addWidgetEventHandler(gui.WIDGET_EVENT_MOUSE_BUTTON_UP,self.MakeCallback (self.test2) )

          listDesc.widget_name = "TestList"
          listDesc.widget_dimensions = gui.Rect(330,400,200,100)
          listDesc.list_listItemHeight = 20
          listDesc.list_supportMultiSelect = True
          list_ = self.mGUIManager.getActiveSheet().createList(listDesc)
          
          ## PythonOgre change - we don't have a clear() function on vectors so have
          ## to create a new one each time
          t =gui.VectorTextSegment()
          t.append(gui.TextSegment("micross.12",Ogre.ColourValue().White,"Item 1"))
          ltiDesc.textDesc.segments= t
          list_.createItem(ltiDesc)

          t =gui.VectorTextSegment()
          t.append(gui.TextSegment("micross.12",Ogre.ColourValue().Green,"Item 2"))
          ltiDesc.textDesc.segments=t
          list_.createItem(ltiDesc)

          t =gui.VectorTextSegment()
          t.append(gui.TextSegment("micross.12",Ogre.ColourValue().Red,"Item 3"))
          ltiDesc.textDesc.segments=t
          list_.createItem(ltiDesc)

          t =gui.VectorTextSegment()
          t.append(gui.TextSegment("micross.12",Ogre.ColourValue().Blue,"Item 4"))
          ltiDesc.textDesc.segments=t
          list_.createItem(ltiDesc)

          t =gui.VectorTextSegment()
          t.append(gui.TextSegment("micross.12",Ogre.ColourValue().Black,"Item 5"))
          ltiDesc.textDesc.segments=t
          list_.createItem(ltiDesc)

          cbd.widget_name = "TestCheckBox"
          cbd.widget_dimensions.size = gui.Size(25,25)
          cbd.widget_dimensions.position = gui.Point(250,350)
          self.mGUIManager.getActiveSheet().createCheckBox(cbd)
          
        self.mGUIManager.setActiveSheet(self.mSheet);
        
        if False:
            pd = dm.getDefaultPanelDesc()
            pd.resetToDefault()
            pd.widget_name = "AnimationViewerControlPanel"
            pd.widget_dimensions = gui.Rect(0,450,600,150)
            pd.containerwidget_supportScrollBars = False
            self.mControlPanel = self.mSheet.createPanel(pd)
            # CREATE IMAGES
            self.mGridMaterial = "AnimationViewer.Grid.Material"
            self.mDefaultCameraRTTName = "AnimationViewer.DefaultCam.RTT"
            self.mSideCameraRTTName = "AnimationViewer.SideCam.RTT"
            self.mTopCameraRTTName = "AnimationViewer.TopCam.RTT"
            self.mFrontCameraRTTName = "AnimationViewer.FrontCam.RTT"
            
            id = dm.getDefaultImageDesc()
            id.resetToDefault()
            id.image_updateEveryFrame = True
            id.widget_name = "TopView"
            id.image_imageName = self.mTopCameraRTTName
            id.widget_dimensions.size = gui.Size(300,225)
            self.mTopViewImage = self.mSheet.createImage(id)

            id.widget_name = "SideView"
            id.widget_dimensions.position = gui.Point(300,0)
            id.image_imageName = self.mSideCameraRTTName
            self.mSideViewImage = self.mSheet.createImage(id)

            id.widget_name = "FrontView"
            id.widget_dimensions.position = gui.Point(0,225)
            id.image_imageName = self.mFrontCameraRTTName
            self.mFrontViewImage = self.mSheet.createImage(id)

            id.widget_name = "PerspectiveView"
            id.widget_dimensions.position = gui.Point(300,225)
            id.image_imageName = self.mDefaultCameraRTTName
            self.mPerspectiveViewImage = self.mSheet.createImage(id)
    def _createScene(self):
        sf.info ("Entering _createScene")
        self.mDebugDisplayShown=True
        ## Set ambient light
        self.sceneManager.setAmbientLight((0.5, 0.5, 0.5))

        ## Create a SkyBox
        self.sceneManager.setSkyBox(True,"Examples/EveningSkyBox")

        ## Create a light
        l = self.sceneManager.createLight("MainLight")
        ## Accept default settings: point light, white diffuse, just set position
        ## NB I could attach the light to a SceneNode if I wanted it to move automatically with
        ##  other objects, but I don't
        l.setPosition(0,175,550)
        
        self.robot = self.sceneManager.createEntity("ChuckNorris", "robot.mesh")

        robotNode = self.sceneManager.getRootSceneNode().createChildSceneNode()
        robotNode.attachObject(self.robot)
        robotNode.yaw(Ogre.Radian(Ogre.Degree(-90)))
        robotNode.scale = (1.25,1.25,1.25)
        
        ##  This ensures the camera doesn't move when we move the cursor.
        #3 However we do the same thing by setting MenuMode to True in the frameListerner further down
        self.camera.setAutoTracking(True, robotNode)

        plane = Ogre.Plane( Ogre.Vector3().UNIT_Y, 0 )
        Ogre.MeshManager.getSingleton().createPlane("ground",
           Ogre.ResourceGroupManager.DEFAULT_RESOURCE_GROUP_NAME, plane,
           1500,1500,20,20,True,1,5,5,Ogre.Vector3().UNIT_Z)
        ground = self.sceneManager.createEntity( "GroundEntity", "ground" )
        self.sceneManager.getRootSceneNode().createChildSceneNode().attachObject(ground)
        ground.setMaterialName("Examples/Rockwall")
        ground.setCastShadows(False)

        self.camera.setPosition(0,125,500)
        self.camera.pitch(Ogre.Radian(Ogre.Degree(-15)))

        ## Setup Render To Texture for preview window
        texture = Ogre.TextureManager.getSingleton().createManual( "RttTex", 
                        Ogre.ResourceGroupManager.DEFAULT_RESOURCE_GROUP_NAME, Ogre.TEX_TYPE_2D, 
                        512, 512, 0, Ogre.PixelFormat.PF_R8G8B8, Ogre.TU_RENDERTARGET )
        self.rttTex = texture.getBuffer().getRenderTarget()

        
        ## From CEGUI example.  The camera position doesn't fit the robot setup, so I changed it some.
        rttCam = self.sceneManager.createCamera("RttCam")
        camNode = self.sceneManager.getRootSceneNode().createChildSceneNode("rttCamNode")
        camNode.attachObject(rttCam)
        rttCam.setPosition(0,75,225)

        v = self.rttTex.addViewport( rttCam )
        ## Alternatively, use the main camera for the self.rttText, imitating the main screen
        ##Viewport *v = self.rttTex.addViewport( self.camera )
        v.setOverlaysEnabled( False )
        v.setClearEveryFrame( True )
        v.setBackgroundColour( Ogre.ColourValue().Black )
        sf.info ("Creating gui")
        self.guiroot = gui.Root()
        sf.info ("GUI OK, loading types")
        gui.SkinTypeManager.getSingleton().loadTypes()
        sf.info ("done load types")
        self.desc = gui.GUIManagerDesc()
        sf.info ("done self.desc")
#     
        r = gui.Root.getSingleton()
        sf.info ("got root")
        print "\nROOT: ",r
        print self.desc
        self.mGUIManager = gui.Root.getSingleton().createGUIManager(self.desc)
        sf.info ("Created guimanager")
        self.mGUIManager.setSceneManager(self.sceneManager) 
        self.mGUIManager.viewport = self.camera.getViewport()
# 
        casi = self.robot.getAllAnimationStates().getAnimationStateIterator()
        state = 0
        while( casi.hasMoreElements() ):
            animName = casi.getNext().getAnimationName()
            if state == 0:
                self.robotAnimationState = self.robot.getAnimationState(animName)
                self.robotAnimationState.setEnabled(True)
                self.robotAnimationState.setTimePosition(0.0)
                self.robotAnimationState.setLoop(True)
            state+=1

        self.createGUI()
    def __init__(self):
        self.client = None  
        self.root = ogre.Root( sf.getPluginPath() )
        config = ogre.ConfigFile()
        config.load('../resources.cfg' ) 
        
        ## this is still ugly as we need to create a real python iterator...
        
        
        section_iter = config.getSectionIterator()
        while section_iter.hasMoreElements():
            section_name = section_iter.peekNextKey()
            settings = section_iter.getNext()
            for item in settings:
                ogre.ResourceGroupManager.getSingleton().addResourceLocation(item.value, item.key, section_name)

        
                
        renList = self.root.getAvailableRenderers()
        miscParams = ogre.NameValuePairList()
        bOpenGL = True
        
        for r in renList:
            print "Renederer",r.getName(), r, type(r)
            if r.getName().startswith( "OpenGL" ) and bOpenGL:
                self.root.setRenderSystem ( r )
                miscParams["FSAA"] = "1"
                #miscParams["Full Screen"] = "Yes"
                miscParams["Full Screen"] = "No"
                
                miscParams["Video Mode"]= "1024 X 768 @ 32-bit colour"
                miscParams["title"]="Python-Ogre is COOL - Check the source to see how to set the title!!"
                stdout.write("Using OpenGL renderer")
            else:
               if r.getName().startswith('Direct') and not bOpenGL:
                    self.root.setRenderSystem ( r )
                    stdout.write("Using DirectX renderer")
                    miscParams["VSYNC"] = "YES"
                    miscParams["Anti aliasing"] = "Level4"
           
        self.root.initialise(False)
        
        self.renderWindow = self.root.createRenderWindow( "Python-Ogre Window", 800, 600, False, miscParams )
        self.sceneManager = self.root.createSceneManager(ogre.ST_GENERIC,"Test")
        
        self.camera = self.sceneManager.createCamera( "RootCam" )
        self.camera.nearClipDistance = 5
        self.camera.setPosition (180, 300, 335)
        self.camera.lookAt(0,0,0)
       
        ogre.TextureManager.getSingleton().defaultNumMipmaps = 5
        ogre.ResourceGroupManager.getSingleton().initialiseAllResourceGroups()
        self.viewport = self.renderWindow.addViewport( self.camera )
        self.viewport.setBackgroundColour (ogre.ColourValue(0, 0, 0))
        # create head entity
        entity = self.sceneManager.createEntity('head', 'ogrehead.mesh')
        self.sceneManager.getRootSceneNode().createChildSceneNode().attachObject(entity)
        
        self.camera.setPosition (20, 0, 100)
        self.camera.lookAt(0, 0, 0)     
        self._createFrameListener()