Modify the MDI Text Editor application (texteditor.pyw) so that instead of using MDI it uses a QTabWidget and becomes a tabbed editor.
The Window menu will not be required, so all the code associated with it can be removed. A new "file close tab" action will be needed, as will a corresponding method to handle it. Instead of using QWorkspace.windowList(), use a for loop to iterate from 0 to QTabWidget.count(), and use QTabWidget.widget() to access each window in turn.
The closeEvent() will need changing, and it is probably the trickiest to get right. Change loadFiles() to limit the number of files loaded on the command line to 10. fileNew() will need to create a TextEdit as before, and then add it to the tab widget using QTabWidget.addTab(), giving the widget and its window title as parameters. Instead of calling show() on the widget, use QTabWid-get.setCurrentWidget(). The fileOpen(), loadFile(), fileSave(), fileSaveAs(), and fileSaveAll() methods will need small changes. The edit methods need to change only their first line of code to use QTabWidget.currentWidget() instead of QWorkspace.activeWindow().
Once everything is working, add two keyboard shortcuts, one for QKey-Sequence.PreviousChild and the other for QKeySequence.NextChild, along with suitable methods, prevTab() and nextTab(), to make them work.
The changes amount to about a dozen lines, plus an extra twenty lines or so for the shortcuts and their methods; as always the emphasis is on thought and understanding rather than on typing.
A model solution is provided in the file chap09/tabbededitor.pyw.
This page intentionally left blank
• The Event-Handling Mechanism
• Reimplementing Event Handlers
• Using the Clipboard
Was this article helpful?
Uncover The Instant Traffic System That Will TRIPLE Your Income Overnight While Putting You In Direct Contact With THOUSANDS Of Hungry Buyers. How to generate instant traffic to your website, easily! Siphon high quality, ultra-targeted traffic to your offers. The easiest way to dominate your market with lase targeted video based campaigns. These video ads will suck in customers by the minute, driving your message out to a global audience of buyers.