class PlayerInfoTab(Tab): # pylint: disable=too-many-instance-attributes, too-few-public-methods def __init__(self, notebook): super(PlayerInfoTab, self).__init__(notebook) func = self._update_info self._stat_fields = [] self._money = GridField(self._panel, 0, 0, 'Money:', func) self._experience = GridField(self._panel, 0, 1, 'Experience:', func) self._alignment = GridOptionMenu(self._panel, 1, 0, 'Alignment:', ALIGNMENTS.keys(), func) self._instantiate_stats() self._portrait = None self._character = None self._party = None self._portraits = None self._expand() def load_info(self, party, character, save_dir): self._character = character self._party = party self._portraits = list_portrait_dirs(save_dir) self._portrait = GridPortraitMenu(self._panel, 1, 1, 'Portrait', self._portraits, self._update_info) self._dirty_lock = True self._money.set(party.money()) self._alignment.set(character.alignment.alignment()) self._experience.set(character.experience()) self._portrait.set(character.portrait()) _set_fields(character.stats, self._stat_fields) self._dirty_lock = False def _instantiate_stats(self): for stat in STATS: self._append_grid_field(stat, self._stat_fields, self._update_stats) def _update_stats(self, *args): # pylint: disable=unused-argument stats = self._character.stats for stat_field in self._stat_fields: _update_field(stat_field, stats, self._dirty_lock) def _update_info(self, *args): # pylint: disable=unused-argument alignment = self._character.alignment self._money.update(self._party.update_money, self._dirty_lock) self._experience.update(self._character.update_experience, self._dirty_lock) self._alignment.update(alignment.update_alignment, self._dirty_lock) self._portrait.update(self._character.update_portrait, self._dirty_lock) def _expand(self): self._notebook.add(self._panel, text="Player") self._panel.config()
def load_info(self, party, character, save_dir): self._character = character self._party = party self._portraits = list_portrait_dirs(save_dir) self._portrait = GridPortraitMenu(self._panel, 1, 1, 'Portrait', self._portraits, self._update_info) self._dirty_lock = True self._money.set(party.money()) self._alignment.set(character.alignment.alignment()) self._experience.set(character.experience()) self._portrait.set(character.portrait()) _set_fields(character.stats, self._stat_fields) self._dirty_lock = False
def test_portraits_will_do_nothing_for_set_when_no_choices(mock_options): field = GridPortraitMenu(PANEL, ROW, COLUMN, LABEL_TEXT, [], EVENT_FUNCTION) field.set(CHOICES[1]) options_instance = mock_options.return_value options_instance.set.assert_not_called()
def test_portraits_will_delegate_set_to_option_menu(mock_options): field = GridPortraitMenu(PANEL, ROW, COLUMN, LABEL_TEXT, CHOICES, EVENT_FUNCTION) field.set(CHOICES[1]) options_instance = mock_options.return_value options_instance.set.assert_called_with(CHOICES[1])
def test_portraits_will_do_nothing_for_update_when_no_choices(mock_options): field = GridPortraitMenu(PANEL, ROW, COLUMN, LABEL_TEXT, [], EVENT_FUNCTION) field.update(EVENT_FUNCTION, UNLOCKED) options_instance = mock_options.return_value options_instance.update.assert_not_called()
def test_portraits_will_delegate_update_to_option_menu(mock_options): field = GridPortraitMenu(PANEL, ROW, COLUMN, LABEL_TEXT, CHOICES, EVENT_FUNCTION) field.update(EVENT_FUNCTION, UNLOCKED) options_instance = mock_options.return_value options_instance.update.assert_called_with(EVENT_FUNCTION, UNLOCKED)
def test_portraits_will_not_render_options_when_options_None(mock_options): field = GridPortraitMenu(PANEL, ROW, COLUMN, LABEL_TEXT, None, EVENT_FUNCTION) mock_options.assert_not_called()
def test_portraits_will_render_options_when_options_exist(mock_options): field = GridPortraitMenu(PANEL, ROW, COLUMN, LABEL_TEXT, CHOICES, EVENT_FUNCTION) mock_options.assert_called_with(PANEL, ROW, COLUMN, LABEL_TEXT, CHOICES, EVENT_FUNCTION)