I said I wouldn't do an emacs-like stack of documents without any surrounding GUI — but it was so easy. PyQt contains a very basic class, QWidgetStack, which can contain any number of widgets, though only one is shown at a time. This class is used in QWizard, QTabWidget and QTabDialog, but it can be very useful when used by itself, too.
"""
stackspace.py - stacked view manager for the mdi framework
copyright: (C) 2001, Boudewijn Rempt
email: boud@rempt.xs4all.nl
"""
from qt import *
from resources import TRUE, FALSE
class StackSpace(QWidgetStack):
def __init__(self, *args):
apply(QWidgetStack.__init__,(self, ) + args)
self.views=[]
def addView(self, view):
self.views.append(view)
self.addWidget(view, len(self.views) - 1)
self.raiseWidget(view)
def removeView(self, view):
if view in self.views:
self.views.remove(view)
self.removeWidget(view)
QWidgetStack is one of those classes that wants its children to be explicitly added and removed. You also have to give a numerical ID to identify the widget.
def activeWindow(self):
return self.visibleWidget()
def cascade(self): pass
def tile(self): pass
def canCascade(self):
return FALSE
def canTile(self):
return FALSE
def windowList(self):
return self.views
def activateView(self, view):
self.raiseWidget(view)
In contrast with all other view managers we have created up to now, QWidgetStack does not automatically raise a window when it gets focus. This means that we have to add a new method to the view manager interface— activateView. This has to be added to all other view managers, too, and there is a small change necessary in the application class MDIApp:
def slotWindowMenuActivated(self, index):
self.menuToWindowMap[index].setFocus()
becomes:
def slotWindowMenuActivated(self, index):
self.workspace.activateView(self.menuToWindowMap[index])
Of course, this is merely an example of the use of QWidgetStack. If you want to present your users with stacked document windows, you ought to offer more than a mere ‘window' menu for selecting windows— A keyboard interface, for instance, or perhaps a listview with icons for open documents to the left.