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?
Discover How You Can Quickly And Easily Dominate Google and YouTube... With Simple Cash Generating Videos. Did you know that YouTube is the second largest search website on the entire Internet? YouTube gets more daily searches than Bing and Yahoo. In fact, there is only one search engine that gets more action.