From f7ec3d750873324fce6d671418d89ccb7439a5e4 Mon Sep 17 00:00:00 2001 From: Silvris <58583688+Silvris@users.noreply.github.com> Date: Sun, 22 Sep 2024 09:24:14 -0500 Subject: [PATCH] kvui: abstract away client tab additions #3950 --- WargrooveClient.py | 4 +--- kvui.py | 13 ++++++++++--- worlds/sc2/ClientGui.py | 5 +---- 3 files changed, 12 insertions(+), 10 deletions(-) diff --git a/WargrooveClient.py b/WargrooveClient.py index 39da044d..f9971f7a 100644 --- a/WargrooveClient.py +++ b/WargrooveClient.py @@ -267,9 +267,7 @@ class WargrooveContext(CommonContext): def build(self): container = super().build() - panel = TabbedPanelItem(text="Wargroove") - panel.content = self.build_tracker() - self.tabs.add_widget(panel) + self.add_client_tab("Wargroove", self.build_tracker()) return container def build_tracker(self) -> TrackerLayout: diff --git a/kvui.py b/kvui.py index 65cf52c7..536dce12 100644 --- a/kvui.py +++ b/kvui.py @@ -536,9 +536,8 @@ class GameManager(App): # show Archipelago tab if other logging is present self.tabs.add_widget(panel) - hint_panel = TabbedPanelItem(text="Hints") - self.log_panels["Hints"] = hint_panel.content = HintLog(self.json_to_kivy_parser) - self.tabs.add_widget(hint_panel) + hint_panel = self.add_client_tab("Hints", HintLog(self.json_to_kivy_parser)) + self.log_panels["Hints"] = hint_panel.content if len(self.logging_pairs) == 1: self.tabs.default_tab_text = "Archipelago" @@ -572,6 +571,14 @@ class GameManager(App): return self.container + def add_client_tab(self, title: str, content: Widget) -> Widget: + """Adds a new tab to the client window with a given title, and provides a given Widget as its content. + Returns the new tab widget, with the provided content being placed on the tab as content.""" + new_tab = TabbedPanelItem(text=title) + new_tab.content = content + self.tabs.add_widget(new_tab) + return new_tab + def update_texts(self, dt): if hasattr(self.tabs.content.children[0], "fix_heights"): self.tabs.content.children[0].fix_heights() # TODO: remove this when Kivy fixes this upstream diff --git a/worlds/sc2/ClientGui.py b/worlds/sc2/ClientGui.py index fe62e616..51c55b43 100644 --- a/worlds/sc2/ClientGui.py +++ b/worlds/sc2/ClientGui.py @@ -111,13 +111,10 @@ class SC2Manager(GameManager): def build(self): container = super().build() - panel = TabbedPanelItem(text="Starcraft 2 Launcher") - panel.content = CampaignScroll() + panel = self.add_client_tab("Starcraft 2 Launcher", CampaignScroll()) self.campaign_panel = MultiCampaignLayout() panel.content.add_widget(self.campaign_panel) - self.tabs.add_widget(panel) - Clock.schedule_interval(self.build_mission_table, 0.5) return container