# Path: StimControl/LightStim/Core.py
# class DefaultScreen(Screen):
#     """ Specified before stimulus definition.
#     """
#     screen = None
#     viewports = None
#     def __init__(self,viewports_list,bgcolor=(0.0,0.0,0.0)):
#         DefaultScreen.screen = Screen(viewports_list,bgcolor)
#         DefaultScreen.viewports = viewports_list
# 
# Path: StimControl/LightStim/LightData.py
# class dictattr(dict):
#     """ Dictionary with attribute access"""
#     def __init__(self, *args, **kwargs):
#         super(dictattr, self).__init__(*args, **kwargs)
#         for k, v in kwargs.iteritems():
#             self.__setitem__(k, v) # call our own __setitem__ so we get keys as attribs even on kwarg init
#     def __getattr__(self, key):
#         try:
#             return self[key]
#         except KeyError:
#             raise AttributeError, '%r object has no attribute %r' % ('dictattr', key)
#     def __setattr__(self, key, val):
#         self[key] = val
#     def __setitem__(self, key, val):
#         super(dictattr, self).__setitem__(key, val)
#         if key.__class__ == str and not key[0].isdigit(): # key isn't a number or a string starting with a number
#             key = key.replace(' ', '_') # get rid of any spaces
#             self.__dict__[key] = val # make the key show up as an attrib upon dir()


from distutils.version import LooseVersion as V
from StimControl.LightStim.Core import DefaultScreen
from StimControl.LightStim.LightData import dictattr
from VisionEgg.PyroHelpers import PyroServer
from VisionEgg.PyroApps.DropinServer import DropinMetaController
from VisionEgg.PyroApps.DropinGUI import DropinMetaParameters
import os
import ast
import Pyro
import pickle
import logging
import pygame
import VisionEgg
import VisionEgg.PyroApps.EPhysServer as server
        pass
    
class NewPyroServer(PyroServer):
    def __init__(self):
        Pyro.config.PYRO_MULTITHREADED = 1 # multithreading!
        PyroServer.__init__(self)
        
    def disconnect(self, _object):
        try:
            # pylint: disable=E1101
            VERSION = Pyro.core.constants.VERSION
        except:
            VERSION = Pyro.constants.VERSION
        if V(VERSION) >= V('3.2'):
            self.daemon.disconnect(_object)
        else:
            # workaround bug in Pyro pre-3.2
            del self.daemon.implementations[_object.GUID()]
            _object.setDaemon(None)

class StimServer(object):
    def __init__(self):
        self.presentation = None
        self.ephys_server = None
        self.server_modules = [VisionEgg.PyroApps.DropinServer]
        
    def start_server(self):
        pyro_server = NewPyroServer()
        default_viewports = ['left','right']
        DefaultScreen(default_viewports)

# Path: StimControl/LightStim/Core.py
# class DefaultScreen(Screen):
#     """ Specified before stimulus definition.
#     """
#     screen = None
#     viewports = None
#     def __init__(self,viewports_list,bgcolor=(0.0,0.0,0.0)):
#         DefaultScreen.screen = Screen(viewports_list,bgcolor)
#         DefaultScreen.viewports = viewports_list
# 
# Path: StimControl/LightStim/LightData.py
# class dictattr(dict):
#     """ Dictionary with attribute access"""
#     def __init__(self, *args, **kwargs):
#         super(dictattr, self).__init__(*args, **kwargs)
#         for k, v in kwargs.iteritems():
#             self.__setitem__(k, v) # call our own __setitem__ so we get keys as attribs even on kwarg init
#     def __getattr__(self, key):
#         try:
#             return self[key]
#         except KeyError:
#             raise AttributeError, '%r object has no attribute %r' % ('dictattr', key)
#     def __setattr__(self, key, val):
#         self[key] = val
#     def __setitem__(self, key, val):
#         super(dictattr, self).__setitem__(key, val)
#         if key.__class__ == str and not key[0].isdigit(): # key isn't a number or a string starting with a number
#             key = key.replace(' ', '_') # get rid of any spaces
#             self.__dict__[key] = val # make the key show up as an attrib upon dir()


# Path: StimControl/StimServer.py
from distutils.version import LooseVersion as V
from StimControl.LightStim.Core import DefaultScreen
from StimControl.LightStim.LightData import dictattr
from VisionEgg.PyroHelpers import PyroServer
from VisionEgg.PyroApps.DropinServer import DropinMetaController
from VisionEgg.PyroApps.DropinGUI import DropinMetaParameters
import os
import ast
import Pyro
import pickle
import logging
import pygame
import VisionEgg
import VisionEgg.PyroApps.EPhysServer as server

        pass
    
class NewPyroServer(PyroServer):
    def __init__(self):
        Pyro.config.PYRO_MULTITHREADED = 1 # multithreading!
        PyroServer.__init__(self)
        
    def disconnect(self, _object):
        try:
            # pylint: disable=E1101
            VERSION = Pyro.core.constants.VERSION
        except:
            VERSION = Pyro.constants.VERSION
        if V(VERSION) >= V('3.2'):
            self.daemon.disconnect(_object)
        else:
            # workaround bug in Pyro pre-3.2
            del self.daemon.implementations[_object.GUID()]
            _object.setDaemon(None)

class StimServer(object):
    def __init__(self):
        self.presentation = None
        self.ephys_server = None
        self.server_modules = [VisionEgg.PyroApps.DropinServer]
        
    def start_server(self):
        pyro_server = NewPyroServer()
        default_viewports = ['left','right']
        DefaultScreen(default_viewports)

        screen = DefaultScreen.screen