Skip to content

Commit

Permalink
lint
Browse files Browse the repository at this point in the history
  • Loading branch information
fe-art committed Sep 10, 2024
1 parent c0e6552 commit 1f23d9e
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 33 deletions.
2 changes: 1 addition & 1 deletion clashroyalebuildabot/bot/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,4 +243,4 @@ def run(self):
logger.info("Thanks for using CRBAB, see you next time!")

def stop(self):
self.should_run = False
self.should_run = False
14 changes: 10 additions & 4 deletions clashroyalebuildabot/gui/animations.py
Original file line number Diff line number Diff line change
@@ -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)
Expand All @@ -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()
self.glow_animation.start()
18 changes: 14 additions & 4 deletions clashroyalebuildabot/gui/gameplay_widget.py
Original file line number Diff line number Diff line change
@@ -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):
Expand All @@ -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)
self.label.setPixmap(pixmap)
34 changes: 24 additions & 10 deletions clashroyalebuildabot/gui/layout_setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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)

Expand All @@ -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)

Expand All @@ -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)
Expand All @@ -187,19 +195,25 @@ 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
)

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)
Expand Down
4 changes: 3 additions & 1 deletion clashroyalebuildabot/gui/main_window.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
5 changes: 3 additions & 2 deletions clashroyalebuildabot/visualizer.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
Expand Down
11 changes: 0 additions & 11 deletions main.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import os
import signal
import sys

import yaml
from loguru import logger
from PyQt6.QtWidgets import QApplication

Expand All @@ -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(
Expand All @@ -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,
Expand Down

0 comments on commit 1f23d9e

Please sign in to comment.