Add a new method to the ShipTableModel, sortByTEU(). Use any sorting technique you like; we have used DSU. Then use this method in MainForm.sort-Table(). In total this should take just half a dozen lines.

Extend the ShipTableModel.data() method to provide tooltips. The tip should simply be the text of the data item, except for TEUs, where the text should be the (localized) number followed by "twenty foot equivalents". Notice that HTML is correctly formatted in the tooltip. This is easy and takes only a dozen lines.

Modify ShipTableDelegate.setModelData() so that it will change the name, owner, or country, only if the new text is at least three characters long. Extend the tooltips for these columns with the text "(minimum of 3 characters)". This can be done in about half a dozen lines.

Add an Export button that, when pressed, prompts the user for a filename with the suffix .txt, and saves the data using the UTF-8 encoding, one ship per line, in the form:

name|owner|country|teu|description with a bar "I" (pipe) as a separator. The data should be accessed through the model's data() method and output in country/owner order, with no HTML tags in the description and with TEUs output with digits only (no commas, periods, or spaces). Pop up a message box at the end, either to report an error or to report success. Use Python or PyQt for writing the file; we have used PyQt. If you write using a version of PyQt prior to 4.1, you will need to convert the TEU to a QString before writing it to the text stream. The export() method can be written in less than 50 lines.

A solution is provided in chap14/ships_ans.py and chap14/ships-delegate-_ans.py.

This page intentionally left blank

• Connecting to the Database

• Executing SQL Queries

• Using Database Form Views

• Using Database Table Views

Was this article helpful?

0 0
Tube Jacker

Tube Jacker

Download Tube Jacker And Discover Everything You Need To Know About Jacking Unlimited Traffic From The Video Giant. The drop dead easy way to create winning video campaigns that will FLOOD your website with unstoppable FREE traffic, all on complete and total autopilot. How to exploit a sneaky method of boosting exposure and getting your videos to the top of Google within 72 hours, guaranteed.

Get My Free Ebook

Post a comment