Skip to content

Commit

Permalink
kvui: abstract away client tab additions #3950
Browse files Browse the repository at this point in the history
  • Loading branch information
Silvris authored Sep 22, 2024
1 parent 99c02a3 commit f7ec3d7
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 10 deletions.
4 changes: 1 addition & 3 deletions WargrooveClient.py
Original file line number Diff line number Diff line change
Expand Up @@ -267,9 +267,7 @@ class WargrooveManager(GameManager):

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:
Expand Down
13 changes: 10 additions & 3 deletions kvui.py
Original file line number Diff line number Diff line change
Expand Up @@ -536,9 +536,8 @@ def connect_bar_validate(sender):
# 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"
Expand Down Expand Up @@ -572,6 +571,14 @@ def connect_bar_validate(sender):

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
Expand Down
5 changes: 1 addition & 4 deletions worlds/sc2/ClientGui.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,13 +111,10 @@ def clear_tooltip(self) -> None:
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
Expand Down

0 comments on commit f7ec3d7

Please sign in to comment.