コード例 #1
0
    def save_configuration(self, json_file: str, message=True):
        config = {
            "teams": [{
                "name": str,
                "players": List[dict],
                "logo": str
            }, {
                "name": str,
                "players": List[dict],
                "logo": str
            }],
            "match":
            int,
            "timeout":
            int,
            "suspend":
            int
        }

        # Get config
        try:
            team1, team2, players1, players2, nums1, nums2, match, timeout, \
                suspend, logo1, logo2 = self.get_current_entries()
        except TypeError:  # If returned prematurely, with an error
            return

        config["teams"][0]["name"] = team1
        config["teams"][1]["name"] = team2

        config["teams"][0]["logo"] = logo1
        config["teams"][1]["logo"] = logo2

        players: List[dict] = []
        for name, number in zip(players1, nums1):
            player = {"name": name, "number": int(number)}
            players.append(player)
        config["teams"][0]["players"] = players
        players: List[dict] = []
        for name, number in zip(players2, nums2):
            player = {"name": name, "number": int(number)}
            players.append(player)
        config["teams"][1]["players"] = players

        config["match"] = int(match)
        config["timeout"] = int(timeout)
        config["suspend"] = int(suspend)

        with open(join(self.PATH_TO_CONFIGS, json_file + ".json"),
                  "w") as file:
            json.dump(config, file, sort_keys=True, indent=2)

        logger.info(f'Saved configuration "{json_file}"')
        if message:
            info(self.top_level, f'Saved configuration "{json_file}".')
コード例 #2
0
 def disqualify(self):
     if self.__selected_player is None:
         return
     if self.__selected_player.disqualified:
         info(self.root,
              f"{self.__selected_player.name} is already disqualified.")
         return
     if ask(
             self.root,
             f"Are you sure you want to disqualify {self.__selected_player.name}?"
     ):
         self.release()
         self.__selected_player.disqualify()
コード例 #3
0
    def change_round_time(self):
        if self.timer.get_going():
            logger.info("Stop the timer first")
            info(self.root, "Stop/Pause the timer first.")
            return

        def on_apply(seconds: int):
            self.timer = MainTimer(self.time_var, None, seconds * 60)
            self.time_var.set(self.timer.get_time())
            # self.match_data.round_time = minutes
            logger.debug("Main timer reset")

        window = tk.Toplevel()
        ChangeTimeWindow(window, on_apply)
コード例 #4
0
 def take_card(self, color: str):
     if self.__selected_player is None:
         return
     if self.__selected_player.disqualified:
         info(self.root, f"{self.__selected_player.name} is disqualified.")
         return
     self.__selected_player.take_card(color)
     self.selected_cards_var.set(
         "Cards: " +
         "{} yellow, ".format(self.__selected_player.yellow_cards) +
         "{} red".format(self.__selected_player.red_cards))
     self.__selected_player.text_var.set("{} [{:02d}]    {}".format(
         self.__selected_player.name, self.__selected_player.number,
         self.__selected_player.scores))
コード例 #5
0
    def generate_match_report(self):
        if self.has_started_match:
            file_name = filedialog.asksaveasfilename(parent=self.root,
                                                     defaultextension=".xlsx",
                                                     filetypes=[
                                                         ("Excel", ".xlsx"),
                                                         ("Excel", ".xls")
                                                     ])
            logger.debug(file_name)

            if file_name:
                generate_report(self.match_data, file_name)
                info(self.root, f"Report saved as {file_name}.")
        else:
            alert(self.root, "There is nothing to generate.")
コード例 #6
0
 def score_down(self):
     if self.__selected_player is None:
         return
     if self.__selected_player.disqualified:
         info(self.root, f"{self.__selected_player.name} is disqualified.")
         return
     self.__selected_player.score_down()
     self.selected_scores_var.set("Score: " +
                                  str(self.__selected_player.scores))
     self.__selected_player.text_var.set("{} [{:02d}]    {}".format(
         self.__selected_player.name, self.__selected_player.number,
         self.__selected_player.scores))
     if self.__selected_player.team.order == 1:
         self.score_team1_var.set(self.__selected_player.team.score)
     else:
         self.score_team2_var.set(self.__selected_player.team.score)
コード例 #7
0
    def time_out(self, team: Team):
        if not self.is_time_out and self.timer.get_going():
            team.request_time_out()
            self.timer.pause()
            self.do_players_timers(2)
            self.timer_text.grid_remove()

            self.time_out_timer.start()
            self.time_out_timer_text.grid()
            self.is_time_out = True
            try:
                self.spec_time_out()
            except Exception:
                pass
        else:
            info(self.root,
                 "The timer must be going or it is already time-out.")
コード例 #8
0
 def release(self):
     if self.__selected_player is None:
         return
     if self.__selected_player.disqualified:
         info(self.root, f"{self.__selected_player.name} is disqualified.")
         return
     if self.__selected_player.can_release():
         if self.__selected_player.team.order == 1:
             with self.lock1:
                 for player in self.suspended_players1:
                     if int((player.main_label["text"]
                             )[0:2]) == self.__selected_player.number:
                         self.__selected_player.release()
                         player.main_label.destroy()
                         try:
                             player.spec_label.destroy()
                         except AttributeError:
                             pass
                         self.suspended_players1.remove(player)
                         break
                 else:
                     logger.info("Could not find " +
                                 str(self.__selected_player) +
                                 " in suspended players")
         else:
             with self.lock2:
                 for player in self.suspended_players2:
                     if int((player.main_label["text"]
                             )[0:2]) == self.__selected_player.number:
                         self.__selected_player.release()
                         player.main_label.destroy()
                         try:
                             player.spec_label.destroy()
                         except AttributeError:
                             pass
                         self.suspended_players2.remove(player)
                         break
                 else:
                     logger.info("Could not find " +
                                 str(self.__selected_player) +
                                 " in suspended players")
コード例 #9
0
    def open_spectator_window(self, x: int = 0, y: int = 0):
        if MainApplication.spectator_window.window is None:
            window = tk.Toplevel()
            MainApplication.spectator_window.window = window
            SpectatorWindow(window,
                            x,
                            y,
                            players1=self.team1.players,
                            players2=self.team2.players,
                            time_var=self.time_var,
                            round_num_var=self.round_num_var,
                            score_team1_var=self.score_team1_var,
                            score_team2_var=self.score_team2_var,
                            name_team1_var=self.name_team1_var,
                            name_team2_var=self.name_team2_var,
                            time_out_var=self.time_out_var,
                            logo1=self.logo1,
                            logo2=self.logo2,
                            spectator_window=self.spectator_window,
                            to_give_back=self.take_from_window)

            currently_selected_player = self.__selected_player
            with self.lock1:
                with self.lock2:
                    for suspended_player in self.suspended_players1 + self.suspended_players2:
                        self.__selected_player = suspended_player
                        self.put_suspended_player_on_spec(
                            self.__selected_player.team.order)
            self.__selected_player = currently_selected_player

            if self.is_time_out:
                try:
                    self.spec_time_out()
                except Exception:
                    pass
        else:
            info(self.root, "There can only be one spectator window open.")
コード例 #10
0
    def advance_round(self):
        if ask(self.root,
               "Are you sure you want to advance to the next round?"):
            try:
                if self.round_num_var.get() < 4:
                    # Save current round data
                    try:
                        self.match_data.rounds.append(
                            RoundData(self.team1, self.team2))
                    except AttributeError:  # match_data is None
                        logger.info("Teams aren't initialized")
                        info(self.root, "Teams aren't initialized.")
                    else:
                        no_round = self.round_num_var.get()
                        if no_round == 3:
                            self.round_num_var.set("end")
                        else:
                            self.round_num_var.set(no_round + 1)

                        self.stop()
                        self.reset_teams(
                            self.team1.name, self.team2.name,
                            list(
                                map(lambda player: player.name,
                                    self.team1.players)),
                            list(
                                map(lambda player: player.name,
                                    self.team2.players)),
                            list(
                                map(lambda player: str(player.number),
                                    self.team1.players)),
                            list(
                                map(lambda player: str(player.number),
                                    self.team2.players)))
            except tk.TclError:  # the variable is "end", so you cannot advance further
                logger.info("Max 3 rounds are allowed")
コード例 #11
0
    def suspend(self):
        if self.__selected_player is None:
            return
        if self.__selected_player.disqualified:
            info(self.root, f"{self.__selected_player.name} is disqualified.")
            return
        if self.__selected_player.can_suspend():
            if not self.timer.get_going() or self.time_out_timer.get_going():
                self.__selected_player.suspend(start=False)
            else:
                self.__selected_player.suspend()

            if self.__selected_player.team.order == 1:
                self.put_suspended_player_on_main(1)
                self.put_suspended_player_on_spec(1)

                with self.lock1:
                    self.suspended_players1.append(self.__selected_player)
            else:
                self.put_suspended_player_on_main(2)
                self.put_suspended_player_on_spec(2)

                with self.lock2:
                    self.suspended_players2.append(self.__selected_player)