A row of split windows

We'll make a little viewmanager class will arrange the views separated by splitter bars. That class will be based on the QSplitter class. I would advise you never to use a splitter to separate documents (in contrast to BlackAdder, which does use this paradigm) — it's so uncommon that people will get confused. Building the class is a useful little introduction to QSplitter, though. A splitter is best used if you have a list of items or icons on the left, and a document pane to the right. Indeed, you might want to use one of the other arrangements for showing more than one window in the document pane, and separate the workspace from a selection list using a QSplitter. If you do this, the selection list functions as a kind of always-visible windows menu.

"""
splitspace.py - splitter 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 SplitSpace(QSplitter):

    def __init__(self, *args):
        apply(QSplitter.__init__,(self, ) + args)
        self.views=[]
        
    def addView(self, view):
        self.views.append(view)
    

Clever and clean as Qt might be, it is not immune to the inevitable inconsistencies caused by prolonged development. Some classes, such as the QTabWidget we saw above, have special insert or add methods for the insertion or addition of child widgets; others, like QWorkspace take care of their children if those children are created with them as the parent. This also holds for QSplitter — create a widget with a QSplitter object as a parent, and it will be automatically managed by the splitter. Therefore the addView() function has little to do.

    def removeView(self, view): pass

    def activeWindow(self):
        for view in self.views:
            if view.hasFocus():
                return view
        return self.views[0]
    

In order to be able to figure out which of the widgets managed by the splitter is the currently active one, we have to loop over the list and retrieve the one with focus. If that fails, we fall back on a hack: just return the first one.

    def cascade(self): pass

    def tile(self): pass

    def canCascade(self):
        return FALSE

    def canTile(self):
        return FALSE

    

Obviously, cascading nor tiling is relevant for this class.