Fixed an issue with the gather tab not getting freed on first run

This commit is contained in:
Eric Froemling 2020-10-29 22:02:59 -05:00
parent f8e2df644c
commit 688a18eca0
5 changed files with 46 additions and 12 deletions

View File

@ -6,6 +6,7 @@ from __future__ import annotations
import weakref import weakref
from typing import TYPE_CHECKING, Generic, TypeVar from typing import TYPE_CHECKING, Generic, TypeVar
import _ba
from ba._team import Team from ba._team import Team
from ba._player import Player from ba._player import Player
from ba._error import (print_exception, SessionTeamNotFoundError, from ba._error import (print_exception, SessionTeamNotFoundError,
@ -13,7 +14,6 @@ from ba._error import (print_exception, SessionTeamNotFoundError,
from ba._dependency import DependencyComponent from ba._dependency import DependencyComponent
from ba._general import Call, verify_object_death from ba._general import Call, verify_object_death
from ba._messages import UNHANDLED from ba._messages import UNHANDLED
import _ba
if TYPE_CHECKING: if TYPE_CHECKING:
from weakref import ReferenceType from weakref import ReferenceType

View File

@ -165,6 +165,11 @@ class GameButton:
def _update(self) -> None: def _update(self) -> None:
# pylint: disable=too-many-boolean-expressions # pylint: disable=too-many-boolean-expressions
from ba.internal import getcampaign from ba.internal import getcampaign
# In case we stick around after our UI...
if not self._button:
return
game = self._game game = self._game
campaignname, levelname = game.split(':') campaignname, levelname = game.split(':')

View File

@ -240,6 +240,7 @@ class GatherWindow(ba.Window):
ba.print_exception(f'Error saving state for {self}.') ba.print_exception(f'Error saving state for {self}.')
def _restore_state(self) -> None: def _restore_state(self) -> None:
# pylint: disable=too-many-branches
try: try:
for tab in self._tabs.values(): for tab in self._tabs.values():
tab.restore_state() tab.restore_state()
@ -249,12 +250,25 @@ class GatherWindow(ba.Window):
sel_name = winstate.get('sel_name', None) sel_name = winstate.get('sel_name', None)
assert isinstance(sel_name, (str, type(None))) assert isinstance(sel_name, (str, type(None)))
current_tab = self.TabID.ABOUT current_tab = self.TabID.ABOUT
try: gather_tab_val = ba.app.config.get('Gather Tab')
stored_tab = self.TabID(ba.app.config.get('Gather Tab'))
if stored_tab in self._tab_row.tabs: if bool(False):
current_tab = stored_tab # EWWW: normally would just do this, but it seems to result in
except ValueError: # a reference to self sticking around somewhere. (presumably
pass # in the exception?). Should get to the bottom of this.
try:
stored_tab = self.TabID(gather_tab_val)
if stored_tab in self._tab_row.tabs:
current_tab = stored_tab
except ValueError:
pass
else:
# Falling back to this for now.
tab_vals = {t.value for t in self.TabID}
if gather_tab_val in tab_vals:
stored_tab = self.TabID(gather_tab_val)
if stored_tab in self._tab_row.tabs:
current_tab = stored_tab
self._set_tab(current_tab) self._set_tab(current_tab)
if sel_name == 'Back': if sel_name == 'Back':
sel = self._back_button sel = self._back_button
@ -270,7 +284,7 @@ class GatherWindow(ba.Window):
sel = self._tab_row.tabs[current_tab].button sel = self._tab_row.tabs[current_tab].button
ba.containerwidget(edit=self._root_widget, selected_child=sel) ba.containerwidget(edit=self._root_widget, selected_child=sel)
except Exception: except Exception:
ba.print_exception(f'Error restoring state for {self}.') ba.print_exception('Error restoring gather-win state.')
def _back(self) -> None: def _back(self) -> None:
from bastd.ui.mainmenu import MainMenuWindow from bastd.ui.mainmenu import MainMenuWindow

View File

@ -4,6 +4,7 @@
from __future__ import annotations from __future__ import annotations
import weakref
from typing import TYPE_CHECKING from typing import TYPE_CHECKING
import ba import ba
@ -18,8 +19,9 @@ if TYPE_CHECKING:
class NetScanner: class NetScanner:
"""Class for scanning for games on the lan.""" """Class for scanning for games on the lan."""
def __init__(self, scrollwidget: ba.Widget, tab_button: ba.Widget, def __init__(self, tab: GatherTab, scrollwidget: ba.Widget,
width: float): tab_button: ba.Widget, width: float):
self._tab = weakref.ref(tab)
self._scrollwidget = scrollwidget self._scrollwidget = scrollwidget
self._tab_button = tab_button self._tab_button = tab_button
self._columnwidget = ba.columnwidget(parent=self._scrollwidget, self._columnwidget = ba.columnwidget(parent=self._scrollwidget,
@ -46,10 +48,22 @@ class NetScanner:
self._last_selected_host = host self._last_selected_host = host
def _on_activate(self, host: Dict[str, Any]) -> None: def _on_activate(self, host: Dict[str, Any]) -> None:
# Sanity check: make sure our gather window gets freed after this.
tab = self._tab()
if tab:
ba.verify_object_death(tab.window)
_ba.connect_to_party(host['address']) _ba.connect_to_party(host['address'])
def update(self) -> None: def update(self) -> None:
"""(internal)""" """(internal)"""
# In case our UI was killed from under us.
if not self._columnwidget:
print(f'ERROR: NetScanner running without UI at time'
f' {ba.time(timetype=ba.TimeType.REAL)}.')
return
t_scale = 1.6 t_scale = 1.6
for child in self._columnwidget.get_children(): for child in self._columnwidget.get_children():
child.delete() child.delete()
@ -125,7 +139,8 @@ class NearbyGatherTab(GatherTab):
0.5, v), 0.5, v),
size=(sub_scroll_width, sub_scroll_height)) size=(sub_scroll_width, sub_scroll_height))
self._net_scanner = NetScanner(scrollw, self._net_scanner = NetScanner(self,
scrollw,
tab_button, tab_button,
width=sub_scroll_width) width=sub_scroll_width)

View File

@ -1,5 +1,5 @@
<!-- THIS FILE IS AUTO GENERATED; DO NOT EDIT BY HAND --> <!-- THIS FILE IS AUTO GENERATED; DO NOT EDIT BY HAND -->
<h4><em>last updated on 2020-10-29 for Ballistica version 1.5.27 build 20230</em></h4> <h4><em>last updated on 2020-10-29 for Ballistica version 1.5.27 build 20234</em></h4>
<p>This page documents the Python classes and functions in the 'ba' module, <p>This page documents the Python classes and functions in the 'ba' module,
which are the ones most relevant to modding in Ballistica. If you come across something you feel should be included here or could be better explained, please <a href="mailto:support@froemling.net">let me know</a>. Happy modding!</p> which are the ones most relevant to modding in Ballistica. If you come across something you feel should be included here or could be better explained, please <a href="mailto:support@froemling.net">let me know</a>. Happy modding!</p>
<hr> <hr>