Beispiel #1
0
    def __init__(self, tower: RingingRoomTower, row_generator: RowGenerator, do_up_down_in: bool,
                 stop_at_rounds: bool, rhythm: Rhythm, user_name: Optional[str] = None,
                 server_mode: bool = False) -> None:
        """ Initialise a Bot with all the parts it needs to run. """
        self._server_mode = server_mode
        self._last_activity_time = time.time()

        self._rhythm = rhythm
        self._do_up_down_in = do_up_down_in
        self._stop_at_rounds = stop_at_rounds
        self._user_name = user_name

        self.row_generator = row_generator
        # This is the row generator that will be used after 'Look to' is called for the next time, allowing
        # for changing the method or composition whilst Wheatley is running.
        self.next_row_generator: Optional[RowGenerator] = None

        self._tower = tower

        self._tower.invoke_on_call[calls.LOOK_TO].append(self._on_look_to)
        self._tower.invoke_on_call[calls.GO].append(self._on_go)
        self._tower.invoke_on_call[calls.BOB].append(self._on_bob)
        self._tower.invoke_on_call[calls.SINGLE].append(self._on_single)
        self._tower.invoke_on_call[calls.THATS_ALL].append(self._on_thats_all)
        self._tower.invoke_on_call[calls.STAND].append(self._on_stand_next)
        self._tower.invoke_on_bell_rung.append(self._on_bell_ring)
        self._tower.invoke_on_reset.append(self._on_size_change)
        if self._server_mode:
            self._tower.invoke_on_setting_change.append(self._on_setting_change)
            self._tower.invoke_on_row_gen_change.append(self._on_row_gen_change)
            self._tower.invoke_on_stop_touch.append(self._on_stop_touch)

        self._is_ringing = False
        self._is_ringing_rounds = True
        self._should_start_method = False
        self._should_start_ringing_rounds = False
        self._should_stand = False

        self._row_number = 0
        self._place = 0
        self._rounds: Row = rounds(MAX_BELL)
        self._row: Row = self._rounds

        self.logger = logging.getLogger(self.logger_name)

        # Log what we're going to ring
        self.logger.info(f"Wheatley will ring {self.row_generator.summary_string()}")
Beispiel #2
0
    def __init__(
        self,
        tower: RingingRoomTower,
        row_generator: RowGenerator,
        do_up_down_in: bool,
        stop_at_rounds: bool,
        call_comps: bool,
        rhythm: Rhythm,
        user_name: Optional[str] = None,
        server_instance_id: Optional[int] = None,
    ) -> None:
        """Initialise a Bot with all the parts it needs to run."""
        # If this is None then Wheatley is in client mode, otherwise Wheatley is in server mode
        self._server_instance_id = server_instance_id
        self._last_activity_time = time.time()

        self._rhythm = rhythm
        self._do_up_down_in = do_up_down_in
        self._stop_at_rounds = stop_at_rounds
        self._call_comps = call_comps
        self._user_name = user_name

        self.row_generator = row_generator
        # This is the row generator that will be used after 'Look to' is called for the next time,
        # allowing for changing the method or composition whilst Wheatley is running.
        self.next_row_generator: Optional[RowGenerator] = None

        self._tower = tower

        self._tower.invoke_on_call[calls.LOOK_TO].append(self._on_look_to)
        self._tower.invoke_on_call[calls.GO].append(self._on_go)
        self._tower.invoke_on_call[calls.BOB].append(self._on_bob)
        self._tower.invoke_on_call[calls.SINGLE].append(self._on_single)
        self._tower.invoke_on_call[calls.THATS_ALL].append(self._on_thats_all)
        self._tower.invoke_on_call[calls.ROUNDS].append(self._on_rounds)
        self._tower.invoke_on_call[calls.STAND].append(self._on_stand_next)
        self._tower.invoke_on_bell_rung.append(self._on_bell_ring)
        self._tower.invoke_on_reset.append(self._on_size_change)
        if self._server_mode:
            self._tower.invoke_on_setting_change.append(
                self._on_setting_change)
            self._tower.invoke_on_row_gen_change.append(
                self._on_row_gen_change)
            self._tower.invoke_on_stop_touch.append(self._on_stop_touch)

        self._is_ringing = False
        self._is_ringing_rounds = False
        self._is_ringing_opening_row = True
        # This is used as a counter - once `Go` or `Look To` is received, the number of rounds left
        # is calculated and then decremented at the start of every subsequent row until it reaches
        # 0, at which point the method starts.  We keep a counter rather than a simple flag so that
        # calls can be called **before** going into changes when Wheatley is calling (useful for
        # calling the first method name in spliced and early calls in Original, Erin, etc.).  The
        # value `None` is used to represent the case where we don't know when we will be starting
        # the method (and therefore there it makes no sense to decrement this counter).
        self._rounds_left_before_method: Optional[int] = None
        self._rows_left_before_rounds: Optional[int] = None
        self._should_stand = False

        self._row_number = 0
        self._place = 0
        self._opening_row: Row = row_generator.start_row
        self._rounds: Row = rounds(self.number_of_bells)
        self._row: Row = self._rounds

        # This is used because the row's calls are generated at the **end** of each row (or on
        # `Look To`), but need to be called at the **start** of the next row.
        self._calls: List[str] = []

        self.logger = logging.getLogger(self.logger_name)

        # Log what we're going to ring, and how to stop Wheatley
        self.logger.info(
            f"Wheatley will ring {self.row_generator.summary_string()}")
        self.logger.info(
            "Press `Control-C` to stop Wheatley ringing, e.g. to change method."
        )
Beispiel #3
0
 def _on_size_change(self) -> None:
     self._check_number_of_bells()
     self._opening_row = generate_starting_row(
         self.number_of_bells, self.row_generator.custom_start_row)
     self._rounds = rounds(self.number_of_bells)
     self._check_starting_row()
Beispiel #4
0
 def rounds(self) -> Row:
     """ Generate rounds of the stage given by this RowGenerator. """
     return rounds(self.stage)
Beispiel #5
0
 def _on_size_change(self) -> None:
     self._check_number_of_bells()
     self._rounds = rounds(self.number_of_bells)