Graphical representation of crops and animals
One of the questions our investigation list generated was:
- How can we combine the functionality of a crop or animal with a graphical representation?
There are two possible solutions to this problem:
- Multiple inheritance
Both of these solutions would result in a satisfactory outcome i.e. we would have a single class that could be used to instantiate objects that have functionality of our crops (or animals) and the functionality of a
QGraphicsPixmapItem, which we can place in a
In this situation we are going to use composition as multiple inheritance would add unnecessary complexity to our solution.
Representing the class structure
The diagram below represents the classes necessary to give us the required functionality for our graphical crops and animals:
Field item class and its sub-classes
The above diagram shows the
FieldItemGaphicsPixmapItem class which inherits from
QGraphicsPixmapItem. The field item class is necessary as a base class which sets some general properties for the graphical representation of either a crop or animal. This means that these properties are inherited by the sub-classes
AnimalGraphicsPixmapItem and if we need to change these properties in future we only need to do so in one place rather than several.
AnimalGraphicsPixmapItem are required as each has a different implementation of the
update_status() method which depends specifically status of the class relating to a crop or an animal.
The video below demonstrates how to create these classes.
Use the above video to create the graphical crop and animal item classes.
- 1. Installing PyQt on Mac OS X
- 2. Installing PyQt on Windows
- 3. Introduction to PyQt
- 4. Graphical crop simulation
- 5. Creating a basic PyQt application
- 6. Introduction to Layouts
- 7. Radio Button Widget
- 8. Creating the layouts
- 9. Switching layouts
- 10. Adding growth functionality
- 11. Graphics and resources
- 12. Summary
- 13. Field simulation
- 14. Designing the user interface
- 15. Graphical representation of crops and animals
- 16. Resources file
- 17. Crop and animal graphical sub-classes
- 18. Graphical representation of the field
- 19. Toolbars
- 20. Introduction to event handling
- 21. Adding the drag functionality to the toolbar labels
- 22. Adding the 'drop' functionality to the field
- 23. Context Menus
- 24. Automatically growing the field
- 25. Manually growing the field
- 26. Field Report
- 27. Final Summary
- 28. Distributing your application
- 29. Distributing your application on Mac OS X
- 30. Distributing your application on Windows