Creating the layouts
Creating the crop selection layout
Now that we have the
RadioButtonWidget() class we are ready to start thinking about the crop selection layout itself. Remember, the design is as follows:
The video below demonstrates how to construct the layout and to test to ensure that it displays correctly.
Use the above video to help you construct the crop selection layout.
Instantiating the crops
Now that we have created a the crop selection layout and tested it to ensure it displays correctly we must add the actual functionality to this interface.
When you click the Create Crop button, a crop of selected type should be instantiated. To do this we must connect the event of pressing the button to a method that will perform the necessary action to instantiate the crop.
The video below demonstrates how to do this.
Use the above video to add the ability to instantiate a crop from the user interface.
Creating the crop status view layout
The second layout our interface requires needs to monitor the status of the crop and to enable the user to grow the crop either automatically or manually. In our design it looks as follows:
It terms of layouts, a vertical layout would not be sufficient as there are two clear columns of widgets. We will need a grid layout for this interface.
In PyQt a grid layout is indexed from the top-left hand-side cell and the indexing begins at zero. In this grid we will have the following widgets:
- (0,0) - A picture (
- (1,0) - A button (
- (1,1) - A button (
Cell (0,1) is more interesting as it needs to contain six different widgets:
- Three labels (
QLabel) to indicate growth, number of growing days and current status
- Three text boxes (
QLineEdit) to give the values associated with the labels
To do this we will need to nest another grid:
This video demonstrates how to accomplish this:
Use the above video to construct the crop view layout.
- 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