Пример #1
0
    def press_add(self, name, country, priority):
        """
        Handler for pressing the add button
        :return: None
        """
        if (not name) or (not country) or (not priority):
            self.status_text = "All fields must be completed"
        else:

            try:
                priority = int(priority)
                if priority < 1:
                    self.status_text = "Priority must be > 0"
                else:
                    # Adding widget
                    p = Place(name=name,
                              country=country,
                              priority=priority,
                              visited_status=False)
                    temp_str = p.__str__(
                    ) + " (visited)" if p.visited_status else p.__str__()
                    temp_button = Button(text=temp_str)
                    temp_button.bind(on_release=self.press_entry)
                    temp_button.place = p
                    temp_button.state = "down" if p.visited_status else "normal"
                    # add the button to the "entries_box" using add_widget()
                    self.root.ids.entries_box.add_widget(temp_button)
                    self.clear_fields()
                    # Adding to place collection
                    self.pc.add_place(p)
            except:
                self.status_text = "Please enter a valid number"
Пример #2
0
def run_tests():
    """Test Place class."""

    # Test empty place (defaults)
    print("Test empty place:")
    default_place = Place()
    print(default_place)
    assert default_place.name == ""
    assert default_place.country == ""
    assert default_place.priority == 0
    assert not default_place.is_visited

    # Test initial-value place
    print("Test initial-value place:")
    new_place = Place("Malagar", "Spain", 1, False)
    # TODO: Write tests to show this initialisation works
    print(new_place)
    # TODO: Add more tests, as appropriate, for each method
    print(new_place.__str__())
    print(new_place.is_important())
    print(new_place.mark_visited())
    print(new_place.mark_unvisited())