Ejemplo n.º 1
0
def test_option_will_not_be_set_to_None(mock_label, mock_var, mock_option):
    value = None
    field = GridOptionMenu(PANEL, ROW, COLUMN, LABEL_TEXT, CHOICES,
                           EVENT_FUNCTION)
    field.set(value)
    var_instance = mock_var.return_value
    var_instance.set.assert_not_called()
Ejemplo n.º 2
0
def test_option_will_properly_set(mock_label, mock_var, mock_option):
    value = CHOICES[0]
    field = GridOptionMenu(PANEL, ROW, COLUMN, LABEL_TEXT, CHOICES,
                           EVENT_FUNCTION)
    field.set(value)
    var_instance = mock_var.return_value
    var_instance.set.assert_called_with(value)
Ejemplo n.º 3
0
def test_option_updates_function(mock_label, mock_var, mock_option):
    function = mock.MagicMock()
    field = GridOptionMenu(PANEL, ROW, COLUMN, LABEL_TEXT, CHOICES,
                           EVENT_FUNCTION)
    expected_value = '5'
    mock_var.return_value.get.return_value = expected_value
    field.update(function, UNLOCKED)
    function.assert_called_with(expected_value)
Ejemplo n.º 4
0
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()
Ejemplo n.º 5
0
 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()
Ejemplo n.º 6
0
def test_option_will_properly_be_updated_by_entry(mock_label, mock_var,
                                                  mock_option):
    field = GridOptionMenu(PANEL, ROW, COLUMN, LABEL_TEXT, CHOICES,
                           EVENT_FUNCTION)
    var_instance = mock_var.return_value
    var_instance.trace.assert_called_with('w', EVENT_FUNCTION)
Ejemplo n.º 7
0
def test_option_positioned_on_grid(mock_label, mock_var, mock_option):
    field = GridOptionMenu(PANEL, ROW, COLUMN, LABEL_TEXT, CHOICES,
                           EVENT_FUNCTION)
    mock_option.return_value.grid.assert_called_with(row=ROW,
                                                     column=(COLUMN * 2) + 2,
                                                     sticky=EW)
Ejemplo n.º 8
0
def test_option_properly_composed(mock_label, mock_var, mock_option):
    field = GridOptionMenu(PANEL, ROW, COLUMN, LABEL_TEXT, CHOICES,
                           EVENT_FUNCTION)
    var_instance = mock_var.return_value
    mock_label.assert_called_with(PANEL, ROW, COLUMN * 2, LABEL_TEXT)
    mock_option.assert_called_with(PANEL, var_instance, *CHOICES)