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


The main focus of this report is to show how to get involved in video marketing on the run, how to rank quickly on YouTube and Google using FREE semi-automatic tools and services. QUICKLY AND FREE. I will show methods and techniques I use to rank my videos, as well as free resources and tools to make video clips, to get backlinks and free traffic.

Get My Free Ebook

Post a comment