Layouts and Multiple Documents

In every dialog we have created so far, all the widgets have been visible at the same time. But in some cases, such as, complex configuration dialogs or property editors, so many widgets are required that showing them all at once could confuse the user. For such situations we can use tab widgets or stacked widgets that allow us to group related widgets together, and show only the relevant group, or we can use extension dialogs that can show extra options on demand. These techniques can help make dialogs smaller and easier for users to navigate and use; we will cover them in this chapter's second section.

In the main-window-style applications we have created, we had one central widget. But in some situations, we need to show two or more widgets in the central area, and often want to give the user some control over their relative sizes. One way to achieve this is to use a single central widget with dock windows; we saw this approach in Chapter 6. Another approach is to use splitters, the subject of this chapter's third section.

Another issue that arises with main-window-style applications is how we deal with multiple documents. There are four main approaches to this. One is to use multiple instances of the application. In this approach, the user launches one instance of the application for each document they wish to work on. In theory this requires no programming effort at all, but in practice, we might want to implement some kind of file-locking scheme or use interprocess communication to ensure that the user does not start the application two or more times on the same document. All the applications we have created so far are of this kind, although none of them has used file locking.*

A second approach is to use SDI (Single Document Interface). This means that the user is expected to run only one instance of the application, but can use that application instance to create as many main windows as they need to handle all the documents they wish to work on. (It is possible to ensure that the user can only have one instance of an application running at the same

★For file-locking code, see "File Locking Using a Cross-Platform API" in the Python Cookbook.

time, but the technique varies from platform to platform and is beyond the scope of this book.) This approach is quite fashionable, and is recommended by the Apple Human Interface Guidelines for "document-style" applications. It is covered in the fourth section.

A third approach is to use MDI (Multiple Document Interface). Again, the user is expected to run only one instance of the application, but here, all the documents are kept within a single "workspace", that is, in child windows inside the main window's central area. MDI is less fashionable than SDI, and is also less resource hungry. For MDI applications, there is just one main window, no matter how many documents are being worked on, whereas SDI has a main window with its menu bar, toolbars, and so on for every document. The final section of this chapter will show how to implement an MDI application.

A fourth alternative is to use a tab widget with each document occupying its own tab page. This approach is used by many modern Web browsers. We will only cover tab widgets in the context of dialogs, although in the exercise you will get the chance to create a tab-widget-based main window application, and perhaps surprisingly, the code required is very similar to that used for an MDI application.

But before looking at tab widgets and stacked widgets in dialogs, and handling multiple documents, we will take a brief diversion to discuss layouts in a bit more depth than when we first encountered them.

Was this article helpful?

0 -1
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