summaryrefslogtreecommitdiff
path: root/cad/src/modelTree/ModelTree.py
blob: 142788186700645ebb33b975ead7deb49290c7e7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
# Copyright 2004-2008 Nanorex, Inc.  See LICENSE file for details.
"""
ModelTree.py -- owner and external interface to the NE1 model tree
(which is implemented as several objects by the modules in this
modelTree package)

@version: $Id$
@copyright: 2004-2008 Nanorex, Inc.  See LICENSE file for details.

History:

modelTree.py was originally written by some combination of
Huaicai, Josh, and Mark. Bruce (Jan 2005) reorganized its interface with
Node and Group and their subclasses (Utility.py and other modules)
and rewrote a lot of the model-tree code (mainly to fix bugs),
and split it into three modules:

- TreeView.py (display and update),

- TreeWidget.py (event handling, and some conventions suitable for
  all our tree widgets, if we define other ones), and

- modelTree.py (customized for showing "the NE1 model tree" per se).

After that, Will ported it to Qt4, and since the Q3 compatibility
classes were unsupported by PyQt4, rewrote much of it, in the process
replacing TreeView.py and TreeWidget.py by a new file, modelTreeGui.py,
and adding a standalone prototype file modelTreePrototype.py (functional
as a separate test program, but not used by NE1). The current organization
might therefore be:

- modelTreeGui.py (display and update, event handling, and some
  conventions suitable for all our tree widgets, if we define other ones), and

- modelTree.py (customized for showing "the NE1 model tree" per se).

Bruce later rewrote much of modelTreeGui.py, and has added lots
of context menu commands to modelTree.py at various times.

Bruce 081216 is doing some cleanup and refactoring, including splitting
ModelTree and TreeModel into separate objects with separate classes and
_api classes, and splitting some code into separate files.
"""

from PyQt4 import QtCore

from modelTree.modelTreeGui import ModelTreeGui
from modelTree.TreeModel import TreeModel

# ===

class ModelTree(object):
    """
    NE1's main model tree, serving as public owner of the model tree widget
    (self.modelTreeGui, class ModelTreeGui) and private owner of the tree
    model shown by that (class TreeModel).

    @note: ModelTree is a public class name, and self.modelTreeGui
           is a public member, accessed by MWsemantics (or a subobject)
           for use in building the Qt widget layout. For public access
           purposes it can be considered "the Qt widget containing the model
           tree".
    """
    def __init__(self, parent, win, name = "modelTreeView", size = (200, 560)):
        """
        #doc
        """
        self._treemodel = TreeModel(self, win)

        self.modelTreeGui = ModelTreeGui(win, name, self._treemodel, parent)
            # public member; review: maybe it ought to have a special name
            # (or get-method) just for its public purpose, so this attr could
            # be made private for internal use

        self.mt_update()
        return

    def mt_update(self):
        return self.modelTreeGui.mt_update()

    def repaint_some_nodes(self, nodes): #bruce 080507, for cross-highlighting
        """
        For each node in nodes, repaint that node, if it was painted the last
        time we repainted self as a whole. (Not an error if it wasn't.)
        """
        self.modelTreeGui.repaint_some_nodes(nodes)
        return

    def setMinimumSize(self, h, w):
        return self.modelTreeGui.setMinimumSize(h, w)

    def setMaximumWidth(self, w): #k might not be needed
        return self.modelTreeGui.setMaximumWidth(w)

    def setColumnWidth(self, column, w):
        return self.modelTreeGui.setColumnWidth(column, w)

    def setGeometry(self, w, h): #k might not be needed
        return self.modelTreeGui.setGeometry(QtCore.QRect(0,0,w,h))

    pass # end of class ModelTree

# end