-
-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2d8426b
commit 0bd8fc1
Showing
5 changed files
with
160 additions
and
311 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,39 @@ | ||
from PySide6.QtWidgets import QApplication | ||
import sys | ||
from pyclashbot.interface.layout import FrontEnd | ||
from pyclashbot.bot.stats import window, app | ||
from pyclashbot.bot.states import StateTree | ||
from threading import Thread | ||
from PySide6.QtCore import QThread | ||
|
||
def main(): | ||
window.start_button.clicked.connect(on_start_button_clicked) | ||
window.show() | ||
sys.exit(app.exec()) | ||
|
||
def run_backend(): | ||
job_list = ["fight", "upgrade", "restart"] | ||
state_tree = StateTree(job_list) | ||
state_tree.run() | ||
|
||
|
||
def main(): | ||
app = QApplication(sys.argv) | ||
def start_worker_thread(): | ||
thread = QThread() | ||
jobs = window.get_checkboxes() # Correct instance of Layout class | ||
worker = StateTree(jobs=jobs) | ||
worker.moveToThread(thread) | ||
|
||
# Initialize frontend | ||
frontend = FrontEnd() | ||
frontend.show() | ||
thread.started.connect(worker.run) | ||
worker.finished.connect(thread.quit) | ||
worker.finished.connect(worker.deleteLater) | ||
thread.finished.connect(thread.deleteLater) | ||
|
||
# Start backend in a separate thread | ||
backend_thread = Thread(target=run_backend) | ||
backend_thread.start() | ||
# Ensure the thread and worker are properly managed | ||
window.thread = thread | ||
window.worker = worker | ||
|
||
# Run the application | ||
sys.exit(app.exec()) | ||
thread.start() | ||
|
||
def on_start_button_clicked(): | ||
print('Start button!') | ||
|
||
# Create and start the worker thread | ||
start_worker_thread() | ||
|
||
|
||
if __name__ == "__main__": | ||
print('\n'*50) | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,21 @@ | ||
from PySide6.QtCore import QObject, Signal, Slot | ||
from pyclashbot.bot.stats import stats | ||
import time | ||
from pyclashbot.bot.event_dispatcher import event_dispatcher | ||
from pyclashbot.bot.update_stats import increment_bot_failures,stat_tester | ||
from pyclashbot.bot.test_state import do_fight | ||
|
||
class StateTree: | ||
def __init__(self, job_list): | ||
self.job_list = job_list | ||
class StateTree(QObject): | ||
def __init__(self, jobs=False): | ||
super().__init__() | ||
self.jobs = jobs | ||
|
||
finished = Signal() | ||
|
||
@Slot() | ||
def run(self): | ||
print("Running statetree.run()") | ||
while True: | ||
time.sleep(1) | ||
stat_tester() | ||
print("Jobs in state tree:") | ||
for job_name, value in self.jobs.items(): | ||
print(' -{:^40} : {}'.format(job_name, value)) | ||
|
||
while True: | ||
do_fight() | ||
time.sleep(10) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import sys | ||
from pyclashbot.interface.layout import Layout | ||
from PySide6.QtWidgets import QApplication | ||
from PySide6.QtCore import Signal, QObject | ||
|
||
|
||
class Stats(QObject): | ||
update_signal = Signal(int) | ||
|
||
def __init__(self, window): | ||
super().__init__() | ||
self.wins = 0 | ||
self.losses = 0 | ||
self.window = window | ||
self.update_signal.connect(self.update_window) | ||
|
||
def increment_wins(self): | ||
self.wins += 1 | ||
self.update_window() | ||
|
||
def increment_losses(self): | ||
self.losses += 1 | ||
self.update_window() | ||
|
||
def update_window(self): | ||
self.window.losses_textbox.setText(str(self.losses)) # update losses | ||
self.window.wins_textbox.setText(str(self.wins)) # update wins | ||
|
||
|
||
app = QApplication(sys.argv) | ||
window = Layout() | ||
stats = Stats(window) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import time | ||
import random | ||
from pyclashbot.bot.stats import stats | ||
|
||
|
||
|
||
#simulate running a fight in the backend and updateing the gui with values | ||
def do_fight(): | ||
fight_duration = 10#s | ||
start_time = time.time() | ||
|
||
print(f'Simulating a fight for {fight_duration} seconds') | ||
|
||
while time.time() - start_time < fight_duration: | ||
#randomly update values | ||
if random.randint(1,3)== 1: | ||
stats.increment_wins() | ||
print('incrementing wins') | ||
if random.randint(1,3)== 1: | ||
stats.increment_losses() | ||
print('incrementing losses') | ||
|
||
time.sleep(0.3) | ||
|
||
return True | ||
|
Oops, something went wrong.