Skip to content

Commit

Permalink
add play pause button
Browse files Browse the repository at this point in the history
  • Loading branch information
fe-art committed Sep 10, 2024
1 parent e21d700 commit 44d5e7b
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 1 deletion.
26 changes: 26 additions & 0 deletions clashroyalebuildabot/gui/layout_setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,32 @@ 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(
"""
QPushButton {
background-color: #4B6EAF;
color: white;
min-width: 32px;
max-width: 32px;
min-height: 32px;
max-height: 32px;
border-radius: 5px;
}
QPushButton:hover {
background-color: #5C7EBF;
}
"""
)
main_window.play_pause_button.clicked.connect(
main_window.toggle_pause_resume_and_display
)

button_layout.addWidget(main_window.play_pause_button)
main_window.play_pause_button.hide()

main_window.start_stop_button = QPushButton("▶")
main_window.start_stop_button.setFont(QFont("Arial", 18))
main_window.start_stop_button.setStyleSheet(
Expand Down
13 changes: 12 additions & 1 deletion clashroyalebuildabot/gui/main_window.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from PyQt6.QtWidgets import QWidget

from clashroyalebuildabot import Bot
from clashroyalebuildabot.gui.gameplay_widget import ImageStreamWindow
from clashroyalebuildabot.bot.bot import pause_event
from clashroyalebuildabot.gui.layout_setup import setup_tabs
from clashroyalebuildabot.gui.layout_setup import setup_top_bar
from clashroyalebuildabot.gui.styles import set_styles
Expand Down Expand Up @@ -46,6 +46,15 @@ def toggle_start_stop(self):
else:
self.start_bot()

def toggle_pause_resume_and_display(self):
if not self.bot:
return
if pause_event.is_set():
self.play_pause_button.setText("▶")
else:
self.play_pause_button.setText("⏸️")
self.bot.pause_or_resume()

def start_bot(self):
if self.is_running:
return
Expand All @@ -55,6 +64,7 @@ def start_bot(self):
self.bot_thread.daemon = True
self.bot_thread.start()
self.start_stop_button.setText("■")
self.play_pause_button.show()
self.server_id_label.setText("Status - Running")
self.append_log("Bot started")

Expand All @@ -64,6 +74,7 @@ def stop_bot(self):
self.bot.stop()
self.is_running = False
self.start_stop_button.setText("▶")
self.play_pause_button.hide()
self.server_id_label.setText("Status - Stopped")
self.append_log("Bot stopped")

Expand Down

0 comments on commit 44d5e7b

Please sign in to comment.