From 1f23d9e4f8099a03903bb6fa75b33cabe85e976b Mon Sep 17 00:00:00 2001 From: fe-art Date: Wed, 11 Sep 2024 00:59:29 +0200 Subject: [PATCH] lint --- clashroyalebuildabot/bot/bot.py | 2 +- clashroyalebuildabot/gui/animations.py | 14 ++++++--- clashroyalebuildabot/gui/gameplay_widget.py | 18 ++++++++--- clashroyalebuildabot/gui/layout_setup.py | 34 +++++++++++++++------ clashroyalebuildabot/gui/main_window.py | 4 ++- clashroyalebuildabot/visualizer.py | 5 +-- main.py | 11 ------- 7 files changed, 55 insertions(+), 33 deletions(-) diff --git a/clashroyalebuildabot/bot/bot.py b/clashroyalebuildabot/bot/bot.py index c248cee..1b13704 100644 --- a/clashroyalebuildabot/bot/bot.py +++ b/clashroyalebuildabot/bot/bot.py @@ -243,4 +243,4 @@ def run(self): logger.info("Thanks for using CRBAB, see you next time!") def stop(self): - self.should_run = False \ No newline at end of file + self.should_run = False diff --git a/clashroyalebuildabot/gui/animations.py b/clashroyalebuildabot/gui/animations.py index 1a7d187..074cdee 100644 --- a/clashroyalebuildabot/gui/animations.py +++ b/clashroyalebuildabot/gui/animations.py @@ -1,12 +1,18 @@ -from PyQt6.QtCore import QEasingCurve, QPropertyAnimation, Qt +from PyQt6.QtCore import QEasingCurve +from PyQt6.QtCore import QPropertyAnimation +from PyQt6.QtCore import Qt from PyQt6.QtWidgets import QGraphicsDropShadowEffect def start_play_button_animation(self): self.glow_effect = QGraphicsDropShadowEffect(self) - self.glow_effect.setBlurRadius(10) # Initial blur radius for the glow effect + self.glow_effect.setBlurRadius( + 10 + ) # Initial blur radius for the glow effect self.glow_effect.setColor(Qt.GlobalColor.cyan) - self.glow_effect.setOffset(0, 0) # Center the shadow to create the glow effect + self.glow_effect.setOffset( + 0, 0 + ) # Center the shadow to create the glow effect self.start_stop_button.setGraphicsEffect(self.glow_effect) _start_glow_animation(self) @@ -20,4 +26,4 @@ def _start_glow_animation(self): self.glow_animation.setDuration(2000) self.glow_animation.setEasingCurve(QEasingCurve.Type.SineCurve) self.glow_animation.setLoopCount(-1) - self.glow_animation.start() \ No newline at end of file + self.glow_animation.start() diff --git a/clashroyalebuildabot/gui/gameplay_widget.py b/clashroyalebuildabot/gui/gameplay_widget.py index 392b6bc..5c99a1c 100644 --- a/clashroyalebuildabot/gui/gameplay_widget.py +++ b/clashroyalebuildabot/gui/gameplay_widget.py @@ -1,5 +1,9 @@ -from PyQt6.QtWidgets import QLabel, QVBoxLayout, QWidget -from PyQt6.QtGui import QImage, QPixmap +from PyQt6.QtGui import QImage +from PyQt6.QtGui import QPixmap +from PyQt6.QtWidgets import QLabel +from PyQt6.QtWidgets import QVBoxLayout +from PyQt6.QtWidgets import QWidget + class ImageStreamWindow(QWidget): def __init__(self): @@ -14,7 +18,13 @@ def __init__(self): def update_frame(self, annotated_image): height, width, channel = annotated_image.shape bytes_per_line = 3 * width - q_image = QImage(annotated_image.data.tobytes(), width, height, bytes_per_line, QImage.Format.Format_RGB888) + q_image = QImage( + annotated_image.data.tobytes(), + width, + height, + bytes_per_line, + QImage.Format.Format_RGB888, + ) pixmap = QPixmap.fromImage(q_image) - self.label.setPixmap(pixmap) \ No newline at end of file + self.label.setPixmap(pixmap) diff --git a/clashroyalebuildabot/gui/layout_setup.py b/clashroyalebuildabot/gui/layout_setup.py index f6b4f20..babe819 100644 --- a/clashroyalebuildabot/gui/layout_setup.py +++ b/clashroyalebuildabot/gui/layout_setup.py @@ -58,7 +58,6 @@ def setup_top_bar(main_window): button_layout = QHBoxLayout() button_layout.setAlignment(Qt.AlignmentFlag.AlignRight) - main_window.play_pause_button = QPushButton("⏸️") main_window.play_pause_button.setFont(QFont("Arial", 18)) main_window.play_pause_button.setStyleSheet( @@ -146,7 +145,6 @@ def setup_tabs(main_window): main_window.visualize_tab = ImageStreamWindow() tab_widget.addTab(main_window.visualize_tab, "Visualize") - settings_tab = QWidget() settings_layout = QGridLayout(settings_tab) @@ -156,13 +154,17 @@ def setup_tabs(main_window): main_window.log_level_dropdown.addItems( ["INFO", "DEBUG", "WARNING", "ERROR", "CRITICAL"] ) - main_window.log_level_dropdown.setCurrentText(main_window.config["bot"]["log_level"]) + main_window.log_level_dropdown.setCurrentText( + main_window.config["bot"]["log_level"] + ) bot_layout.addRow("Log Level:", main_window.log_level_dropdown) main_window.adb_ip_input = QLineEdit() main_window.adb_ip_input.setText(main_window.config["adb"]["ip"]) main_window.device_serial_input = QLineEdit() - main_window.device_serial_input.setText(main_window.config["adb"]["device_serial"]) + main_window.device_serial_input.setText( + main_window.config["adb"]["device_serial"] + ) bot_layout.addRow("ADB IP Address:", main_window.adb_ip_input) bot_layout.addRow("Device Serial:", main_window.device_serial_input) @@ -171,11 +173,17 @@ def setup_tabs(main_window): visuals_group = QGroupBox("Visuals Settings") visuals_layout = QFormLayout() main_window.save_labels_checkbox = QCheckBox("Save labels") - main_window.save_labels_checkbox.setChecked(main_window.config["visuals"]["save_labels"]) + main_window.save_labels_checkbox.setChecked( + main_window.config["visuals"]["save_labels"] + ) main_window.save_images_checkbox = QCheckBox("Save images") - main_window.save_images_checkbox.setChecked(main_window.config["visuals"]["save_images"]) + main_window.save_images_checkbox.setChecked( + main_window.config["visuals"]["save_images"] + ) main_window.show_images_checkbox = QCheckBox("Show images") - main_window.show_images_checkbox.setChecked(main_window.config["visuals"]["show_images"]) + main_window.show_images_checkbox.setChecked( + main_window.config["visuals"]["show_images"] + ) visuals_layout.addRow(main_window.save_labels_checkbox) visuals_layout.addRow(main_window.save_images_checkbox) visuals_layout.addRow(main_window.show_images_checkbox) @@ -187,7 +195,9 @@ def setup_tabs(main_window): main_window.play_action_delay_input = QDoubleSpinBox() main_window.play_action_delay_input.setRange(0.1, 5.0) main_window.play_action_delay_input.setSingleStep(0.1) - main_window.play_action_delay_input.setValue(main_window.config["ingame"]["play_action"]) + main_window.play_action_delay_input.setValue( + main_window.config["ingame"]["play_action"] + ) ingame_layout.addRow( "Action Delay (sec):", main_window.play_action_delay_input ) @@ -195,11 +205,15 @@ def setup_tabs(main_window): main_window.load_deck_checkbox = QCheckBox( "Create deck code on game start" ) - main_window.load_deck_checkbox.setChecked(main_window.config["bot"]["load_deck"]) + main_window.load_deck_checkbox.setChecked( + main_window.config["bot"]["load_deck"] + ) ingame_layout.addRow(main_window.load_deck_checkbox) main_window.auto_start_game_checkbox = QCheckBox("Auto start game") - main_window.auto_start_game_checkbox.setChecked(main_window.config["bot"]["auto_start_game"]) + main_window.auto_start_game_checkbox.setChecked( + main_window.config["bot"]["auto_start_game"] + ) ingame_layout.addRow(main_window.auto_start_game_checkbox) ingame_group.setLayout(ingame_layout) diff --git a/clashroyalebuildabot/gui/main_window.py b/clashroyalebuildabot/gui/main_window.py index 4669fb6..56d6b93 100644 --- a/clashroyalebuildabot/gui/main_window.py +++ b/clashroyalebuildabot/gui/main_window.py @@ -107,7 +107,9 @@ def update_config(self): def bot_task(self): self.bot = Bot(actions=self.actions, config=self.config) - self.bot.visualizer.frame_ready.connect(self.visualize_tab.update_frame) + self.bot.visualizer.frame_ready.connect( + self.visualize_tab.update_frame + ) self.bot.run() def append_log(self, message): diff --git a/clashroyalebuildabot/visualizer.py b/clashroyalebuildabot/visualizer.py index 9f82593..1952fb7 100644 --- a/clashroyalebuildabot/visualizer.py +++ b/clashroyalebuildabot/visualizer.py @@ -1,11 +1,11 @@ from dataclasses import asdict import os -import cv2 -from PyQt6.QtCore import pyqtSignal, QObject import numpy as np from PIL import ImageDraw from PIL import ImageFont +from PyQt6.QtCore import pyqtSignal +from PyQt6.QtCore import QObject from clashroyalebuildabot.constants import CARD_CONFIG from clashroyalebuildabot.constants import LABELS_DIR @@ -34,6 +34,7 @@ class Visualizer(QObject): ] frame_ready = pyqtSignal(np.ndarray) + def __init__(self, save_labels, save_images, show_images): super().__init__() self.save_labels = save_labels diff --git a/main.py b/main.py index de6add6..02aa774 100644 --- a/main.py +++ b/main.py @@ -1,8 +1,6 @@ -import os import signal import sys -import yaml from loguru import logger from PyQt6.QtWidgets import QApplication @@ -16,7 +14,6 @@ from clashroyalebuildabot.actions import WitchAction from clashroyalebuildabot.gui.main_window import MainWindow from clashroyalebuildabot.gui.utils import load_config -from clashroyalebuildabot.constants import SRC_DIR logger.remove() logger.add( @@ -27,14 +24,6 @@ ) -def load_config(): - try: - config_path = os.path.join(SRC_DIR, "config.yaml") - with open(config_path, encoding="utf-8") as file: - return yaml.safe_load(file) - except Exception as e: - logger.error(f"Can't parse config, stacktrace: {e}") - def main(): actions = [ ArchersAction,