Exceptions typing in bastd ui

This commit is contained in:
Roman Trapeznikov 2020-05-21 19:20:29 +03:00
parent 9143415308
commit 976cf18247
No known key found for this signature in database
GPG Key ID: 827DD41DACE1E018
21 changed files with 45 additions and 49 deletions

View File

@ -627,7 +627,7 @@ class AccountSettingsWindow(ba.Window):
elif account_type == 'Game Circle': elif account_type == 'Game Circle':
account_type_name = ba.Lstr(resource='gameCircleText') account_type_name = ba.Lstr(resource='gameCircleText')
else: else:
raise Exception("unknown account type: '" + str(account_type) + raise ValueError("unknown account type: '" + str(account_type) +
"'") "'")
self._game_service_button = btn = ba.buttonwidget( self._game_service_button = btn = ba.buttonwidget(
parent=self._subcontainer, parent=self._subcontainer,
@ -1105,7 +1105,7 @@ class AccountSettingsWindow(ba.Window):
elif sel == self._scrollwidget: elif sel == self._scrollwidget:
sel_name = 'Scroll' sel_name = 'Scroll'
else: else:
raise Exception('unrecognized selection') raise ValueError('unrecognized selection')
ba.app.window_states[self.__class__.__name__] = sel_name ba.app.window_states[self.__class__.__name__] = sel_name
except Exception: except Exception:
ba.print_exception('exception saving state for', self.__class__) ba.print_exception('exception saving state for', self.__class__)

View File

@ -50,7 +50,7 @@ class ColorPicker(popup.PopupWindow):
c_raw = get_player_colors() c_raw = get_player_colors()
if len(c_raw) != 16: if len(c_raw) != 16:
raise Exception('expected 16 player colors') raise ValueError('expected 16 player colors')
self.colors = [c_raw[0:4], c_raw[4:8], c_raw[8:12], c_raw[12:16]] self.colors = [c_raw[0:4], c_raw[4:8], c_raw[8:12], c_raw[12:16]]
if scale is None: if scale is None:
@ -189,7 +189,7 @@ class ColorPickerExact(popup.PopupWindow):
from ba.internal import get_player_colors from ba.internal import get_player_colors
c_raw = get_player_colors() c_raw = get_player_colors()
if len(c_raw) != 16: if len(c_raw) != 16:
raise Exception('expected 16 player colors') raise ValueError('expected 16 player colors')
self.colors = [c_raw[0:4], c_raw[4:8], c_raw[8:12], c_raw[12:16]] self.colors = [c_raw[0:4], c_raw[4:8], c_raw[8:12], c_raw[12:16]]
if scale is None: if scale is None:

View File

@ -1555,7 +1555,7 @@ class CoopBrowserWindow(ba.Window):
elif sel == self._scrollwidget: elif sel == self._scrollwidget:
sel_name = 'Scroll' sel_name = 'Scroll'
else: else:
raise Exception('unrecognized selection') raise ValueError('unrecognized selection')
ba.app.window_states[self.__class__.__name__] = { ba.app.window_states[self.__class__.__name__] = {
'sel_name': sel_name 'sel_name': sel_name
} }

View File

@ -807,11 +807,8 @@ class GatherWindow(ba.Window):
color=(1, 0, 0)) color=(1, 0, 0))
ba.playsound(ba.getsound('error')) ba.playsound(ba.getsound('error'))
return return
try:
port = int(cast(str, ba.textwidget(query=port_textwidget))) port = int(cast(str, ba.textwidget(query=port_textwidget)))
if port > 65535 or port < 0: if port > 65535 or port < 0:
raise Exception()
except Exception:
ba.screenmessage( ba.screenmessage(
ba.Lstr(resource='internal.invalidPortErrorText'), ba.Lstr(resource='internal.invalidPortErrorText'),
color=(1, 0, 0)) color=(1, 0, 0))
@ -1958,7 +1955,7 @@ class GatherWindow(ba.Window):
elif sel == self._tab_container: elif sel == self._tab_container:
sel_name = 'TabContainer' sel_name = 'TabContainer'
else: else:
raise Exception('unrecognized selection: ' + str(sel)) raise ValueError(f'unrecognized selection: \'{sel}\'')
ba.app.window_states[self.__class__.__name__] = { ba.app.window_states[self.__class__.__name__] = {
'sel_name': sel_name, 'sel_name': sel_name,
'tab': self._current_tab, 'tab': self._current_tab,

View File

@ -321,7 +321,6 @@ class MainMenuWindow(ba.Window):
# we want back presses to quit our activity. # we want back presses to quit our activity.
if (not self._in_game and not self._have_quit_button if (not self._in_game and not self._have_quit_button
and ba.app.platform == 'android'): and ba.app.platform == 'android'):
def _do_quit() -> None: def _do_quit() -> None:
confirm.QuitWindow(swish=True, back=True) confirm.QuitWindow(swish=True, back=True)
@ -673,7 +672,7 @@ class MainMenuWindow(ba.Window):
if (not isinstance(cme, dict) or 'label' not in cme if (not isinstance(cme, dict) or 'label' not in cme
or not isinstance(cme['label'], (str, ba.Lstr)) or not isinstance(cme['label'], (str, ba.Lstr))
or 'call' not in cme or not callable(cme['call'])): or 'call' not in cme or not callable(cme['call'])):
raise Exception('invalid custom menu entry: ' + raise ValueError('invalid custom menu entry: ' +
str(cme)) str(cme))
except Exception: except Exception:
custom_menu_entries = [] custom_menu_entries = []

View File

@ -538,7 +538,7 @@ class PlayWindow(ba.Window):
elif sel == self._back_button: elif sel == self._back_button:
sel_name = 'Back' sel_name = 'Back'
else: else:
raise Exception('unrecognized selected widget') raise ValueError(f'unrecognized selection {sel}')
ba.app.window_states[self.__class__.__name__] = sel_name ba.app.window_states[self.__class__.__name__] = sel_name
except Exception: except Exception:
ba.print_exception('error saving state for', self.__class__) ba.print_exception('error saving state for', self.__class__)

View File

@ -58,7 +58,7 @@ class PlaylistTypeVars:
fallback_resource='freeForAllText') fallback_resource='freeForAllText')
self.sessiontype = ba.FreeForAllSession self.sessiontype = ba.FreeForAllSession
else: else:
raise Exception('playlist type vars undefined for session type: ' + raise TypeError('playlist type vars undefined for session type: ' +
str(sessiontype)) str(sessiontype))
self.default_list_name = ba.Lstr(resource='defaultGameListNameText', self.default_list_name = ba.Lstr(resource='defaultGameListNameText',
subs=[('${PLAYMODE}', play_mode_name) subs=[('${PLAYMODE}', play_mode_name)

View File

@ -62,7 +62,7 @@ class PlaylistBrowserWindow(ba.Window):
ba.app.main_window = 'Free-for-All Game Select' ba.app.main_window = 'Free-for-All Game Select'
ba.set_analytics_screen('FreeForAll Window') ba.set_analytics_screen('FreeForAll Window')
else: else:
raise Exception(f'invalid sessiontype: {sessiontype}') raise TypeError(f'invalid sessiontype: {sessiontype}')
self._pvars = playlist.PlaylistTypeVars(sessiontype) self._pvars = playlist.PlaylistTypeVars(sessiontype)
self._sessiontype = sessiontype self._sessiontype = sessiontype

View File

@ -264,19 +264,19 @@ class PlaylistEditGameWindow(ba.Window):
if 'choices' in setting: if 'choices' in setting:
for choice in setting['choices']: for choice in setting['choices']:
if len(choice) != 2: if len(choice) != 2:
raise Exception( raise ValueError(
"Expected 2-member tuples for 'choices'; got: " + "Expected 2-member tuples for 'choices'; got: " +
repr(choice)) repr(choice))
if not isinstance(choice[0], str): if not isinstance(choice[0], str):
raise Exception( raise TypeError(
'First value for choice tuple must be a str; got: ' 'First value for choice tuple must be a str; got: '
+ repr(choice)) + repr(choice))
if not isinstance(choice[1], value_type): if not isinstance(choice[1], value_type):
raise Exception( raise TypeError(
'Choice type does not match default value; choice:' 'Choice type does not match default value; choice:'
+ repr(choice) + '; setting:' + repr(setting)) + repr(choice) + '; setting:' + repr(setting))
if value_type not in (int, float): if value_type not in (int, float):
raise Exception( raise TypeError(
'Choice type setting must have int or float default; ' 'Choice type setting must have int or float default; '
'got: ' + repr(setting)) 'got: ' + repr(setting))
@ -509,5 +509,5 @@ class PlaylistEditGameWindow(ba.Window):
elif setting_type == int: elif setting_type == int:
ba.textwidget(edit=ctrl, text=str(int(val))) ba.textwidget(edit=ctrl, text=str(int(val)))
else: else:
raise Exception('invalid vartype: ' + str(setting_type)) raise TypeError('invalid vartype: ' + str(setting_type))
self._settings[setting_name] = val self._settings[setting_name] = val

View File

@ -93,7 +93,7 @@ class PlayOptionsWindow(popup.PopupWindow):
elif self._sessiontype is ba.DualTeamSession: elif self._sessiontype is ba.DualTeamSession:
plst = get_default_teams_playlist() plst = get_default_teams_playlist()
else: else:
raise Exception('unrecognized session-type: ' + raise TypeError('unrecognized session-type: ' +
str(self._sessiontype)) str(self._sessiontype))
else: else:
try: try:

View File

@ -153,7 +153,7 @@ class PopupMenuWindow(PopupWindow):
self._choices_disabled = list(choices_disabled) self._choices_disabled = list(choices_disabled)
self._done_building = False self._done_building = False
if not choices: if not choices:
raise Exception('Must pass at least one choice') raise TypeError('Must pass at least one choice')
self._width = width self._width = width
self._scale = scale self._scale = scale
if len(choices) > 8: if len(choices) > 8:
@ -302,7 +302,7 @@ class PopupMenu:
current_choice = None current_choice = None
self._choices = list(choices) self._choices = list(choices)
if not choices: if not choices:
raise Exception('no choices given') raise TypeError('no choices given')
self._choices_display = list(choices_display) self._choices_display = list(choices_display)
self._choices_disabled = list(choices_disabled) self._choices_disabled = list(choices_disabled)
self._width = width self._width = width
@ -313,7 +313,7 @@ class PopupMenu:
self._position = position self._position = position
self._parent = parent self._parent = parent
if not choices: if not choices:
raise Exception('Must pass at least one choice') raise TypeError('Must pass at least one choice')
self._parent = parent self._parent = parent
self._button_size = button_size self._button_size = button_size

View File

@ -546,7 +546,7 @@ class EditProfileWindow(ba.Window):
elif picker_type == 'highlight': elif picker_type == 'highlight':
initial_color = self._highlight initial_color = self._highlight
else: else:
raise Exception('invalid picker_type: ' + picker_type) raise ValueError('invalid picker_type: ' + picker_type)
colorpicker.ColorPicker( colorpicker.ColorPicker(
parent=self._root_widget, parent=self._root_widget,
position=origin, position=origin,

View File

@ -44,7 +44,7 @@ class PurchaseWindow(ba.Window):
header_text = ba.Lstr(resource='unlockThisText', header_text = ba.Lstr(resource='unlockThisText',
fallback_resource='unlockThisInTheStoreText') fallback_resource='unlockThisInTheStoreText')
if len(items) != 1: if len(items) != 1:
raise Exception('expected exactly 1 item') raise ValueError('expected exactly 1 item')
self._items = list(items) self._items = list(items)
self._width = 580 self._width = 580
self._height = 520 self._height = 520

View File

@ -596,11 +596,11 @@ class AdvancedSettingsWindow(ba.Window):
elif sel == self._language_inform_checkbox: elif sel == self._language_inform_checkbox:
sel_name = 'LangInform' sel_name = 'LangInform'
else: else:
raise Exception('unrecognized selection') raise ValueError(f'unrecognized selection \'{sel}\'')
elif sel == self._back_button: elif sel == self._back_button:
sel_name = 'Back' sel_name = 'Back'
else: else:
raise Exception('unrecognized selection') raise ValueError(f'unrecognized selection \'{sel}\'')
ba.app.window_states[self.__class__.__name__] = { ba.app.window_states[self.__class__.__name__] = {
'sel_name': sel_name 'sel_name': sel_name
} }

View File

@ -252,7 +252,7 @@ class AllSettingsWindow(ba.Window):
elif sel == self._back_button: elif sel == self._back_button:
sel_name = 'Back' sel_name = 'Back'
else: else:
raise Exception('unrecognized selection') raise ValueError(f'unrecognized selection \'{sel}\'')
ba.app.window_states[self.__class__.__name__] = { ba.app.window_states[self.__class__.__name__] = {
'sel_name': sel_name 'sel_name': sel_name
} }

View File

@ -266,7 +266,7 @@ class AudioSettingsWindow(ba.Window):
elif sel == self._vr_head_relative_audio_button: elif sel == self._vr_head_relative_audio_button:
sel_name = 'VRHeadRelative' sel_name = 'VRHeadRelative'
else: else:
raise Exception('unrecognized selected widget') raise ValueError(f'unrecognized selection \'{sel}\'')
ba.app.window_states[self.__class__.__name__] = sel_name ba.app.window_states[self.__class__.__name__] = sel_name
except Exception: except Exception:
ba.print_exception('error saving state for', self.__class__) ba.print_exception('error saving state for', self.__class__)

View File

@ -167,7 +167,7 @@ class TestingWindow(ba.Window):
for entry in self._entries: for entry in self._entries:
if entry['name'] == name: if entry['name'] == name:
return entry return entry
raise Exception(f'Entry not found: {name}') raise ba.NotFoundError(f'Entry not found: {name}')
def _on_reset_press(self) -> None: def _on_reset_press(self) -> None:
for entry in self._entries: for entry in self._entries:

View File

@ -485,7 +485,7 @@ class SoundtrackBrowserWindow(ba.Window):
elif sel == self._back_button: elif sel == self._back_button:
sel_name = 'Back' sel_name = 'Back'
else: else:
raise Exception('unrecognized selection') raise ValueError(f'unrecognized selection \'{sel}\'')
ba.app.window_states[self.__class__.__name__] = sel_name ba.app.window_states[self.__class__.__name__] = sel_name
except Exception: except Exception:
ba.print_exception('error saving state for', self.__class__) ba.print_exception('error saving state for', self.__class__)

View File

@ -1002,7 +1002,7 @@ class StoreBrowserWindow(ba.Window):
sel_name = 'Tab:' + list(self._tab_buttons.keys())[list( sel_name = 'Tab:' + list(self._tab_buttons.keys())[list(
self._tab_buttons.values()).index(sel)] self._tab_buttons.values()).index(sel)]
else: else:
raise Exception('unrecognized selection') raise ValueError(f'unrecognized selection \'{sel}\'')
ba.app.window_states[self.__class__.__name__] = { ba.app.window_states[self.__class__.__name__] = {
'sel_name': sel_name, 'sel_name': sel_name,
'tab': self._current_tab 'tab': self._current_tab

View File

@ -69,7 +69,7 @@ class TournamentEntryWindow(popup.PopupWindow):
self._purchase_price_name = 'price.tournament_entry_1' self._purchase_price_name = 'price.tournament_entry_1'
else: else:
if self._fee != 0: if self._fee != 0:
raise Exception('invalid fee: ' + str(self._fee)) raise ValueError('invalid fee: ' + str(self._fee))
self._purchase_name = 'tournament_entry_0' self._purchase_name = 'tournament_entry_0'
self._purchase_price_name = 'price.tournament_entry_0' self._purchase_price_name = 'price.tournament_entry_0'

View File

@ -482,7 +482,7 @@ class WatchWindow(ba.Window):
elif sel == self._tab_container: elif sel == self._tab_container:
sel_name = 'TabContainer' sel_name = 'TabContainer'
else: else:
raise Exception('unrecognized selection') raise ValueError(f'unrecognized selection {sel}')
ba.app.window_states[self.__class__.__name__] = { ba.app.window_states[self.__class__.__name__] = {
'sel_name': sel_name, 'sel_name': sel_name,
'tab': self._current_tab 'tab': self._current_tab