Package VisionEgg :: Package PyroApps :: Module GridServer |
[frames] | no frames]

# Source Code for Module VisionEgg.PyroApps.GridServer

      1  #!/usr/bin/env python
      2  #
      3  # The Vision Egg: GridServer
      4  #
      5  # Copyright (C) 2001-2003 Andrew Straw.
      6  # Author: Andrew Straw <astraw@users.sourceforge.net>
      7  # URL: <http://www.visionegg.org/>
      8  #
      9  # Distributed under the terms of the GNU Lesser General Public License
     10  # (LGPL). See LICENSE.TXT that came with this file.
     11  #
     12  # $Id$
     13
     14  import VisionEgg, string
     15  __version__ = VisionEgg.release_name
     16  __cvs__ = string.split('$Revision$')[1]
     17  __date__ = string.join(string.split('$Date$')[1:3], ' ')
     18  __author__ = 'Andrew Straw <astraw@users.sourceforge.net>'
     19
     20  import sys, os, math
     21  import VisionEgg.Core
     22  import VisionEgg.FlowControl
     23  import VisionEgg.Textures
     24  import VisionEgg.SphereMap
     25  import VisionEgg.PyroHelpers
     26  import Pyro.core
     27
     28  from VisionEgg.PyroApps.ScreenPositionServer import ScreenPositionMetaController
     29  from VisionEgg.PyroApps.ScreenPositionGUI import ScreenPositionParameters
     30  from VisionEgg.PyroApps.GridGUI import GridMetaParameters
     31
     32 -class GridMetaController( Pyro.core.ObjBase ):
     33 -    def __init__(self,screen,presentation,stimuli):
     34
     35          # get the instance of Stimulus that was created
     36          assert( stimuli[0][0] == '3d_perspective_with_set_viewport_callback' )
     37          grid = stimuli[0][1]
     38
     39          Pyro.core.ObjBase.__init__(self)
     40          self.meta_params = GridMetaParameters()
     41          if not isinstance(screen,VisionEgg.Core.Screen):
     42              raise ValueError("Expecting instance of VisionEgg.Core.Screen")
     43          if not isinstance(presentation,VisionEgg.FlowControl.Presentation):
     44              raise ValueError("Expecting instance of VisionEgg.FlowControl.Presentation")
     45          if not isinstance(grid,VisionEgg.SphereMap.AzElGrid):
     46              raise ValueError("Expecting instance of VisionEgg.SphereMap.SphereMap")
     47          self.p = presentation
     48          self.stim = grid
     49
     50          screen.parameters.bgcolor = (1.0, 1.0, 1.0, 0.0)
     51
     52 -    def get_parameters(self):
     53          return self.meta_params
     54
     55 -    def set_parameters(self, new_parameters):
     56          if isinstance(new_parameters, GridMetaParameters):
     57              self.meta_params = new_parameters
     58          else:
     59              raise ValueError("Argument to set_parameters must be instance of GridMetaParameters")
     60          self.update()
     61
     62 -    def update(self):
     63          self.p.parameters.go_duration = ( 0.0, 'seconds')
     64
     65 -    def go(self):
     66          self.p.parameters.enter_go_loop = 1
     67
     68 -    def quit_server(self):
     69          self.p.parameters.quit = 1
     70
     71 -def get_meta_controller_class():
     72      return GridMetaController
     73
     74 -def make_stimuli():
     75      stimulus = VisionEgg.SphereMap.AzElGrid()
     76      def set_az_el_grid_viewport(viewport):
     77          stimulus.parameters.my_viewport = viewport
     78      return [('3d_perspective_with_set_viewport_callback',stimulus,set_az_el_grid_viewport)] # return ordered list of tuples
     79
     80 -def get_meta_controller_stimkey():
     81      return "grid_server"
     82
     83  # Don't do anything unless this script is being run
     84  if __name__ == '__main__':
     85
     86      pyro_server = VisionEgg.PyroHelpers.PyroServer()
     87
     88      screen = VisionEgg.Core.Screen.create_default()
     89
     90      # get Vision Egg stimulus ready to go
     91      stimuli = make_stimuli()
     92      stimulus = stimuli[0][1]
     93      temp = ScreenPositionParameters()
     94
     95      projection = VisionEgg.Core.PerspectiveProjection(temp.left,
     96                                                        temp.right,
     97                                                        temp.bottom,
     98                                                        temp.top,
     99                                                        temp.near,
    100                                                        temp.far)
    101      viewport = VisionEgg.Core.Viewport(screen=screen,stimuli=[stimulus],projection=projection)
    102      p = VisionEgg.FlowControl.Presentation(viewports=[viewport])
    103
    104      # now hand over control of projection to ScreenPositionMetaController
    105      projection_controller = ScreenPositionMetaController(p,projection)
    106      pyro_server.connect(projection_controller,"projection_controller")
    107
    108      # now hand over control of drum to GridMetaController
    109      meta_controller = GridMetaController(screen,p,stimuli)
    110      pyro_server.connect(meta_controller,get_meta_controller_stimkey())
    111
    112      # get listener controller and register it
    113      p.add_controller(None,None, pyro_server.create_listener_controller())
    114
    115      # enter endless loop
    116      p.run_forever()
    117