def setUpClass(self):
        print('=' * 50)
        print('setUpClass in TestEventHandler')
        print('-' * 50)
        self.paths = {
            'user_id': 'test_user',
            'workspace_directory': BASE_DIRECTORY + '/workspaces',
            'resource_directory': BASE_DIRECTORY + '/resources',
            'log_directory': BASE_DIRECTORY + '/log',
            'test_data_directory': BASE_DIRECTORY + '/test_data'
        }

        self.ekos = event_handler.EventHandler(**self.paths)

        self.workspace_alias = 'test_workspace'
        self.ekos.copy_workspace(source_uuid='default_workspace',
                                 target_alias=self.workspace_alias)

        self.workspace_uuid = self.ekos.get_unique_id_for_alias(
            self.workspace_alias)
        #
        self.ekos.action_workspace_load_default_data(self.workspace_uuid)
        #
        file_names = [
            'physicalchemical_sharkweb_data_fyskem_wb_2007-2017_20180320.txt'
        ]
        for file_name in file_names:
            print('AAAAAAAAAAAAAA', file_name)
            self.ekos.set_status_for_datasource(
                workspace_unique_id=self.workspace_uuid,
                file_name=file_name,
                status=True)

        self.ekos.load_data(unique_id=self.workspace_uuid)
예제 #2
0
def run(width=1920, height=1080):
    """Main run method"""

    pygame.init()

    screen = pygame.display.set_mode((width, height))
    pygame.display.toggle_fullscreen()

    clock = pygame.time.Clock()
    pool = entity_pool.EntityPool()
    box = text_box.TextBox(screen, pool)
    handler = event_handler.EventHandler(pool, box)
    outer_gui = gui.Gui(width, height)

    #Main logic loop
    while 1:
        screen.fill((137, 207, 255))
        handler.handle(pygame.event.get())
        delta = clock.tick()

        pool.update(delta)
        pool.render(screen)
        box.render()
        outer_gui.render(screen)

        pygame.display.flip()
예제 #3
0
 def test_add(self):
     """ Test a single add and call"""
     self.handler = event_handler.EventHandler()
     self.handler += self.do_call
     self.clear()
     self.handler(self, None)
     self.assertTrue(self.is_called)
     self.assertTrue(self.sender == self)
     self.assertTrue(self.obj == None)
예제 #4
0
파일: echo_stream.py 프로젝트: Torrib/EIT
 def __init__(self, strm):
     """ Constructor
     strm - stream to wrap 
     """
     stream.Stream.__init__(self)
     self.writing = False
     self.echo_byte = 0
     self._stream = strm
     self.echo = event_handler.EventHandler()
예제 #5
0
 def test_sub(self):
     """ Test Multi-add and call """
     self.handler = event_handler.EventHandler()
     self.handler += self.do_call
     self.handler += self.do_call2
     self.handler -= self.do_call2
     self.clear()
     self.handler(self, None)
     self.assertTrue(self.is_called and not self.is_called_2)
     self.assertTrue(self.sender == self)
     self.assertTrue(self.obj == None)
예제 #6
0
 def __init__(self, sql_conf_file):
     self.sql_conf_file = sql_conf_file
     self.jobs = {}
     self.connection = db_connection.Connection(
         config_file=self.sql_conf_file)
     self.connection.connect()
     event_connection = db_connection.Connection(
         config_file=self.sql_conf_file)
     event_connection.connect()
     self.event_handler = event_handler.EventHandler(event_connection)
     self.event_handler.start()
예제 #7
0
 def __init__(self, strm):
     """ Constructor
     stream - an open Stream
     """
     self._stream = strm
     self.dynamixel_error = event_handler.EventHandler()
     self._in_error_handler = False
     self._error_count_1st_header_byte = 0
     self._error_count_2nd_header_byte = 0
     self._error_count_3rd_header_byte = 0
     self._error_count_invalid_length = 0
     self._error_count_unexpected_ident = 0
     self._error_count_unexpected_length = 0
     self._response_total_elapsed = 0
     self._response_max_elapsed = 0
     self._response_count = 0
예제 #8
0
gamefield = field.Field()

# ======== Инициализируем игровое окно  =============
pygame.init()
screen = pygame.display.set_mode(gamefield.field_size)
screen.fill(colours.BACKGROUND)
pygame.display.set_caption('Convey`s game of Life')
clock = pygame.time.Clock()
# ===================================================

# ==== Инициализируем меню, счетчик, режим игры =====
menu = menu.Menu(gamefield)
menu.draw(screen)

handler = event_handler.EventHandler()

done = False
mode = 'draw'  # В игре пять положения: draw, evolution, restart, quit, pause
# ===================================================

# ======== Основной цикл игры ===========
while not done:

    mode, done = handler.event_handler(pygame.event.get(), mode, done,
                                       gamefield, menu)

    # Обработка состояний игры
    if mode == 'draw' or mode == 'pause':
        gamefield.draw(screen)  # Отрисовка живых клеток
        clock.tick(30)
 def setUp(self):
     self.ekos = event_handler.EventHandler(**self.paths)
     print(self.ekos.user_id)
예제 #10
0
    def __init__(self):

        #Setup logging
        self.logger1 = log_handler.get_log_handler('door_controller_log.txt',
                                                   'info', 'door.IOHandler')

        self.logger1.info('Starting: InputOutputHandler')

        #Open config file
        self.logger1.debug('Getting config from: %s', CONFIG_FILE_NAME)
        config = get_config.get_config(CONFIG_FILE_NAME, True)

        #Parse inputs and outputs from config file
        self.inputs, self.outputs = parse_config(config)

        #Parse commands from config file in named tuple
        self.input_commands = InputCommands(
            toggle_door_cmd=config.get('Commands', 'toggle_door_cmd'),
            open_door_cmd=config.get('Commands', 'open_door_cmd'),
            close_door_cmd=config.get('Commands', 'close_door_cmd'),
            light_cmd=config.get('Commands', 'light_cmd'),
            control_wire=config.get('Commands', 'control_wire'),
            stop_cmd=config.get('Commands', 'stop_cmd'))

        #Lock status
        self.door_locked = False
        self.light_locked = False

        #Initialise PiFace and interrupts
        pifacedigitalio.init()
        self.pifacedigital = pifacedigitalio.PiFaceDigital()
        self.listener = pifacedigitalio.InputEventListener(
            chip=self.pifacedigital)

        #Output pins
        self.door_relay_pin = None
        self.led_status0_pin = None

        #Input pins
        self.door_status_pin = None

        #Queue to capture input events
        self.event_queue = pollable_queue.PollableQueue()

        #Queue to log events to
        self.logging_queue = pollable_queue.PollableQueue()

        #Instantiate logging module
        self.log_events = event_handler.EventHandler(
            self.logging_queue, self.input_commands.stop_cmd)

        #Log starting event
        self.logging_queue.put(self.__create_event_obj(INTERNAL, 'Starting'))

        #Dict to store interrupt functions about to be generated
        self.intrupt_funcs = {}

        #Generate dynamic functions to process interrupts
        for key in self.inputs:

            self.logger1.info('Processing Input: ' + key)
            piface_in = self.inputs[key]

            if piface_in.name == DOOR_STATUS_INPUT_NAME:
                self.logger1.info(
                    'Setting door status input to pin: {}'.format(
                        piface_in.pin))
                self.door_status_pin = piface_in.pin

            #Disable 10K pullup resistor on piface input pin
            if piface_in.disablepullup:
                self.logger1.info('Disabling pullup on input {}'.format(
                    piface_in.name))
                pifacedigitalio.digital_write_pullup(piface_in.pin, 0)

            #Create interrupt listener and associated function for falling edges
            if piface_in.falling:
                self.logger1.info(
                    'Creating Falling Edge Listener on input: {}'.format(
                        piface_in.name))
                #e_obj = self.__create_event_obj(piface_in.type, piface_in.name, 'Falling_Edge')
                self.intrupt_funcs[key + '_falling'] = getattr(
                    InterruptHandler(piface_in.type, piface_in.name,
                                     'Falling_Edge', self.event_queue),
                    'interrupt_function')
                self.listener.register(piface_in.pin,
                                       pifacedigitalio.IODIR_FALLING_EDGE,
                                       self.intrupt_funcs[key + '_falling'])

            #Create interrupt listener and associated function for rising edges
            if piface_in.rising:
                self.logger1.info(
                    'Creating Rising Edge Listener on input: {}'.format(
                        piface_in.name))
                #e_obj = self.__create_event_obj(piface_in.type, piface_in.name, 'Rising_Edge')
                self.intrupt_funcs[key + '_rising'] = getattr(
                    InterruptHandler(piface_in.type, piface_in.name,
                                     'Rising_Edge', self.event_queue),
                    'interrupt_function')
                self.listener.register(piface_in.pin,
                                       pifacedigitalio.IODIR_RISING_EDGE,
                                       self.intrupt_funcs[key + '_rising'])

        #Processing outputs
        for key in self.outputs:

            piface_out = self.outputs[key]

            #Set relay output pin on piface
            if piface_out.name == DOOR_RELAY_OUTPUT_NAME:
                self.logger1.info('Creating door relay on output: {}'.format(
                    piface_out.pin))
                self.door_relay_pin = piface_out.pin

            #Set status LED output pin on piface
            if piface_out.name == STATUS_LED_OUTPUT_NAME:
                self.logger1.info('Creating status LED on output: {}'.format(
                    piface_out.pin))
                self.led_status0_pin = piface_out.pin

        self.logger1.info('Starting worker threads')

        #Create threading events and clear them
        self.stop_event = threading.Event()
        self.operate_door = threading.Event()
        self.operate_light = threading.Event()

        self.stop_event.clear()
        self.operate_door.clear()
        self.operate_light.clear()

        #Start threads to process input events
        self.process_input_thread = threading.Thread(
            name='process_input_thread', target=self.__process_input)

        self.activate_door_thread = threading.Thread(
            name='act_door_thread', target=self.__door_activator)

        self.activate_light_thread = threading.Thread(
            name='act_light_thread', target=self.__light_activator)

        self.flash_led_thread = threading.Thread(
            name='flt', target=self.__flash_status_led)

        self.process_input_thread.start()
        self.activate_door_thread.start()
        self.activate_light_thread.start()
        self.flash_led_thread.start()

        self.check_relay_thread = None
        self.__check_relay_state()

        #Monitoring
        self.last_open_time = None
        self.last_closed_time = None
        self.last_status = None

        #Activate interrupts
        self.listener.activate()

        self.logger1.info('Initialisation of InputOutputHandler Complete')