Skip to content

Commit

Permalink
make UI collapsable (#410)
Browse files Browse the repository at this point in the history
  • Loading branch information
martinmiglio committed Apr 7, 2024
1 parent 13fa9c9 commit d04cb1e
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 79 deletions.
24 changes: 5 additions & 19 deletions src/pyclashbot/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -341,23 +341,6 @@ def stop_button_event(logger: Logger, window, thread: StoppableThread) -> None:
thread.shutdown(kill=False) # send the shutdown flag to the thread


def pause_resume_button_event(logger: Logger, window, thread: PausableThread) -> None:
"""method for temporarily stopping the main bot thread
args:
logger, the logger object for for stats storage and printing
window, the gui window
thread: the main bot thread
returns:
None
"""
if thread.toggle_pause():
logger.change_status(status="Pausing")
window["-Pause-Resume-Button-"].update(text="Resume")
else:
logger.change_status(status="Resuming")
window["-Pause-Resume-Button-"].update(text="Pause")


def update_layout(window: sg.Window, logger: Logger) -> None:
"""method for updaing the values in the gui's window
args:
Expand Down Expand Up @@ -442,8 +425,11 @@ def main_gui(start_on_run=False, settings: None | dict[str, str] = None) -> None
stop_button_event(logger, window, thread)

# on pause/resume event, pause/resume the thread
elif event == "-Pause-Resume-Button-" and thread is not None:
pause_resume_button_event(logger, window, thread)
elif event == "-Collapse-Button-":
window["-Collapse-Button-"].update(
text="Expand" if window["-tab-group-"].visible else "Collapse"
)
window["-tab-group-"].update(visible=not window["-tab-group-"].visible)

# upon changing any user settings, save the current settings
elif event in user_config_keys:
Expand Down
133 changes: 77 additions & 56 deletions src/pyclashbot/interface/layout.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,16 +84,18 @@ def get_random_donate_image_path():
DONATE_BUTTON_LAYOUTS = [
[
[
sg.Button(
image_source=RANDOM_DONATE_IMAGE,
size=(70, 7),
key=DONATE_BUTTON_KEY,
)
if RANDOM_DONATE_IMAGE is not None
else sg.Button(
"Donate",
size=(70, 7),
key=DONATE_BUTTON_KEY,
(
sg.Button(
image_source=RANDOM_DONATE_IMAGE,
size=(70, 7),
key=DONATE_BUTTON_KEY,
)
if RANDOM_DONATE_IMAGE is not None
else sg.Button(
"Donate",
size=(70, 7),
key=DONATE_BUTTON_KEY,
)
),
]
],
Expand All @@ -106,11 +108,7 @@ def get_random_donate_image_path():
[
sg.Frame(layout=controls, title="Controls", expand_x=True, expand_y=True),
sg.Frame(layout=jobs_checklist, title="Jobs", expand_x=True, expand_y=True),
]
]


account_switching_layout = [
],
[
sg.Frame(
layout=[
Expand Down Expand Up @@ -149,7 +147,7 @@ def get_random_donate_image_path():
],
],
title="Account Switching",
# expand_x=True,
expand_x=True,
),
sg.Frame(
layout=[
Expand All @@ -162,18 +160,33 @@ def get_random_donate_image_path():
],
],
title="Memu Docking",
expand_x=True,
expand_y=True,
expand_x=True,
),
sg.Frame(layout=bot_stats, title="Bot Stats", expand_x=True, expand_y=True),
]
],
]


stats_tab_layout = [
[
sg.Column(
[[sg.Frame(layout=battle_stats, title="Battle Stats", expand_x=True)]],
[
[
sg.Frame(
layout=battle_stats,
title="Battle Stats",
expand_x=True,
expand_y=True,
)
],
[
sg.Frame(
layout=bot_stats,
title="Bot Stats",
expand_x=True,
),
],
],
expand_x=True,
expand_y=True,
),
Expand All @@ -184,12 +197,13 @@ def get_random_donate_image_path():
layout=collection_stats,
title="Collection Stats",
expand_x=True,
)
expand_y=True,
),
],
],
expand_x=True,
expand_y=True,
justification="right",
expand_y=True,
),
]
]
Expand Down Expand Up @@ -228,69 +242,76 @@ def get_random_donate_image_path():
main_layout = [
[
# layout:List[List[Tab]]
sg.TabGroup(
layout=[
[sg.Tab("Controls", controls_layout)],
[sg.Tab("Stats", stats_tab_layout)],
]
),
sg.pin(
sg.Column(
[
[
sg.TabGroup(
layout=[
[sg.Tab("Controls", controls_layout)],
[sg.Tab("Stats", stats_tab_layout)],
],
),
],
],
key="-tab-group-",
)
)
],
[account_switching_layout],
[
sg.Button(
"Start",
# expand_x=True,
expand_x=True,
button_color="Lime Green",
border_width=3,
size=(23, 1),
# size=(23, 1),
),
sg.Button(
"Stop",
disabled=True,
# expand_x=True,
expand_x=True,
border_width=2,
size=(23, 1),
# size=(23, 1),
),
sg.Button(
"Pause",
disabled=True,
key="-Pause-Resume-Button-",
# expand_x=True,
"Collapse",
key="-Collapse-Button-",
expand_x=True,
border_width=2,
size=(23, 1),
# size=(23, 1),
),
],
[
sg.Button(
"Discord",
key="discord",
# expand_x=True,
expand_x=True,
button_color="#7289da",
border_width=2,
size=(17, 1),
),
sg.Button(
"Upload Log",
key="upload-log",
# expand_x=True,
size=(17, 1),
border_width=2,
# size=(17, 1),
),
sg.Button(
"Refresh Emulator",
key="refresh_emualtor_key",
# expand_x=True,
expand_x=True,
button_color="#FFD700",
border_width=2,
size=(17, 1),
# size=(17, 1),
),
sg.Button(
"Upload Log",
key="upload-log",
expand_x=True,
# size=(17, 1),
border_width=2,
),
sg.Button(
"Report Bug",
key="bug-report",
# expand_x=True,
expand_x=True,
button_color="#FF0000",
border_width=2,
size=(16, 1),
# size=(16, 1),
),
],
[donate_button_layout_tab],
Expand Down Expand Up @@ -320,8 +341,8 @@ def get_random_donate_image_path():
"daily_rewards_user_toggle",
"random_plays_user_toggle",
"skip_fight_if_full_chests_user_toggle",
'trophy_road_rewards_user_toggle',
'upgrade_all_cards_user_toggle',
"trophy_road_rewards_user_toggle",
"upgrade_all_cards_user_toggle",
# job increment controls keys
"request_increment_user_input",
"donate_increment_user_input",
Expand All @@ -334,9 +355,9 @@ def get_random_donate_image_path():
"war_attack_increment_user_input",
"battlepass_collect_increment_user_input",
"account_switching_increment_user_input",
'level_up_chest_increment_user_input',
'level_up_chest_user_toggle',
'trophy_road_reward_increment_user_input',
"level_up_chest_increment_user_input",
"level_up_chest_user_toggle",
"trophy_road_reward_increment_user_input",
# account switching stuff
"account_switching_toggle",
"account_switching_slider",
Expand Down
6 changes: 2 additions & 4 deletions src/pyclashbot/interface/stats.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
"""pysimplegui layout for stats tab"""

import PySimpleGUI as sg
from PySimpleGUI.PySimpleGUI import Text
from pyclashbot.interface.theme import THEME

sg.theme(THEME)


def stat_box(stat_name: str, size=(5, 1)) -> sg.Text:
def stat_box(stat_name: str, size=(4, 1)) -> sg.Text:
"""Returns a pysimplegui text box object for stats layout"""
return sg.Text(
"0",
Expand Down Expand Up @@ -144,21 +145,18 @@ def stat_box(stat_name: str, size=(5, 1)) -> sg.Text:
[
stat_box("losses"),
],

[
stat_box("winrate"),
],
[
stat_box("cards_played"),
],

[
stat_box("path_of_legends_1v1_fights"),
],
[
stat_box("trophy_road_1v1_fights"),
],

[
stat_box("2v2_fights"),
],
Expand Down

0 comments on commit d04cb1e

Please sign in to comment.