# o 2.5 compatability update.
# o I'm a little nervous about some of it though.
#
+# 12/20/2003 - Jeff Grimmett (grimmtooth@softhome.net)
+#
+# o wxTreeModel -> TreeModel
+# o wxMVCTree -> MVCTree
+# o wxMVCTreeEvent -> MVCTreeEvent
+# o wxMVCTreeNotifyEvent -> MVCTreeNotifyEvent
+#
"""
-wxMVCTree is a control which handles hierarchical data. It is constructed
+MVCTree is a control which handles hierarchical data. It is constructed
in model-view-controller architecture, so the display of that data, and
the content of the data can be changed greatly without affecting the other parts.
-wxMVCTree actually is even more configurable than MVC normally implies, because
+MVCTree actually is even more configurable than MVC normally implies, because
almost every aspect of it is pluggable:
- wxMVCTree - Overall controller, and the window that actually gets placed
+ MVCTree - Overall controller, and the window that actually gets placed
in the GUI.
Painter - Paints the control. The 'view' part of MVC.
NodePainter - Paints just the nodes
class MVCTreeNode:
"""
- Used internally by wxMVCTree to manage its data. Contains information about
+ Used internally by MVCTree to manage its data. Contains information about
screen placement, the actual data associated with it, and more. These are
the nodes passed to all the other helper parts to do their work with.
"""
class Painter:
"""
- This is the interface that wxMVCTree expects from painters. All painters should
+ This is the interface that MVCTree expects from painters. All painters should
be Painter subclasses.
"""
def __init__(self, tree):
evt.Skip()
-class wxTreeModel:
+class TreeModel:
"""
Interface for tree models
"""
raise NotImplementedError
-class BasicTreeModel(wxTreeModel):
+class BasicTreeModel(TreeModel):
"""
A very simple treemodel implementation, but flexible enough for many needs.
"""
if not self.children.has_key(parent):
self.children[parent]=[]
self.children[parent].append(child)
- wxTreeModel.AddChild(self, parent, child)
+ TreeModel.AddChild(self, parent, child)
return child
def RemoveNode(self, node):
parent = self.parents[node]
del self.parents[node]
self.children[parent].remove(node)
- wxTreeModel.RemoveNode(self, node)
+ TreeModel.RemoveNode(self, node)
def InsertChild(self, parent, child, index):
self.parents[child]=parent
if not self.children.has_key(parent):
self.children[parent]=[]
self.children[parent].insert(child, index)
- wxTreeModel.InsertChild(self, parent, child, index)
+ TreeModel.InsertChild(self, parent, child, index)
return child
def IsLeaf(self, node):
mem_dc.SelectObject(self.GetBuffer())
mem_dc.SetPen(self.GetBackgroundPen())
mem_dc.SetBrush(self.GetBackgroundBrush())
- mem_dc.DrawRectangle((0, 0), (size[0], size[1]))
+ mem_dc.DrawRectangle(0, 0, size[0], size[1])
mem_dc.SetFont(self.tree.GetFont())
self.paintWalk(node, mem_dc)
else:
mem_dc.SelectObject(self.GetBuffer())
xstart, ystart = self.tree.CalcUnscrolledPosition(0,0)
size = self.tree.GetClientSizeTuple()
- dc.Blit((xstart, ystart), (size[0], size[1]), mem_dc, (xstart, ystart))
+ dc.Blit(xstart, ystart, size[0], size[1], mem_dc, xstart, ystart)
else:
if node == self.tree.currentRoot:
self.knobs = []
dc.SetBrush(self.GetBackgroundBrush())
dc.SetFont(self.tree.GetFont())
if paintBackground:
- dc.DrawRectangle((0, 0), (size[0], size[1]))
+ dc.DrawRectangle(0, 0, size[0], size[1])
if node:
#Call with not paintBackground because if we are told not to paint the
#whole background, we have to paint in parts to undo selection coloring.
if (not self.tree.model.IsLeaf(kid.data)) or ((kid.expanded or self.tree._assumeChildren) and len(kid.kids)):
dc.SetPen(self.linepen)
dc.SetBrush(self.bgbrush)
- dc.DrawRectangle((px -4, py-4), (9, 9))
+ dc.DrawRectangle(px -4, py-4, 9, 9)
self.knobs.append( (kid, Rect(px -4, py -4, 9, 9)) )
dc.SetPen(self.textpen)
if not kid.expanded:
- dc.DrawLine((px, py -2), (px, py + 3))
- dc.DrawLine((px -2, py), (px + 3, py))
+ dc.DrawLine(px, py -2, px, py + 3)
+ dc.DrawLine(px -2, py, px + 3, py)
if node == self.tree.currentRoot:
px = (node.projx - self.tree.layout.NODE_STEP) + 5
py = node.projy + node.height/2
dc.SetPen(self.linepen)
dc.SetBrush(self.bgbrush)
- dc.DrawRectangle((px -4, py-4), (9, 9))
+ dc.DrawRectangle(px -4, py-4, 9, 9)
self.knobs.append( (node, Rect(px -4, py -4, 9, 9)) )
dc.SetPen(self.textpen)
if not node.expanded:
- dc.DrawLine((px, py -2), (px, py + 3))
- dc.DrawLine((px -2, py), (px + 3, py))
+ dc.DrawLine(px, py -2, px, py + 3)
+ dc.DrawLine(px -2, py, px + 3, py)
return True
def OnMouse(self, evt):
dc.SetPen(self.painter.GetLinePen())
dc.SetBrush(self.painter.GetForegroundBrush())
dc.SetTextForeground(wx.NamedColour("WHITE"))
- dc.DrawRectangle((node.projx -1, node.projy -1), (node.width + 3, node.height + 3))
+ dc.DrawRectangle(node.projx -1, node.projy -1, node.width + 3, node.height + 3)
else:
if drawRects:
dc.SetBrush(self.painter.GetBackgroundBrush())
dc.SetPen(self.painter.GetBackgroundPen())
- dc.DrawRectangle((node.projx -1, node.projy -1), (node.width + 3, node.height + 3))
+ dc.DrawRectangle(node.projx -1, node.projy -1, node.width + 3, node.height + 3)
dc.SetTextForeground(self.painter.GetTextColour())
- dc.DrawText(text, (node.projx, node.projy))
+ dc.DrawText(text, node.projx, node.projy)
self.painter.rectangles.append((node, Rect(node.projx, node.projy, node.width, node.height)))
class TreeLinePainter(LinePainter):
py = child.projy + self.painter.tree.layout.NODE_HEIGHT/2 -2
cx = child.projx
cy = py
- dc.DrawLine((px, py), (cx, cy))
+ dc.DrawLine(px, py, cx, cy)
else:
px = parent.projx + 5
py = parent.projy + parent.height
cx = child.projx -5
cy = child.projy + self.painter.tree.layout.NODE_HEIGHT/2 -3
- dc.DrawLine((px, py), (px, cy))
- dc.DrawLine((px, cy), (cx, cy))
+ dc.DrawLine(px, py, px, cy)
+ dc.DrawLine(px, cy, cx, cy)
#>> Event defs
wxEVT_MVCTREE_BEGIN_EDIT = wx.NewEventType() #Start editing. Vetoable.
EVT_MVCTREE_DELETE_ITEM = wx.PyEventBinder(wxEVT_MVCTREE_DELETE_ITEM, 1)
EVT_MVCTREE_KEY_DOWN = wx.PyEventBinder(wxEVT_MVCTREE_KEY_DOWN, 1)
-class wxMVCTreeEvent(wx.PyCommandEvent):
+class MVCTreeEvent(wx.PyCommandEvent):
def __init__(self, type, id, node = None, nodes = None, keyEvent = None, **kwargs):
apply(wx.PyCommandEvent.__init__, (self, type, id), kwargs)
self.node = node
def getKeyEvent(self):
return self.keyEvent
-class wxMVCTreeNotifyEvent(wxMVCTreeEvent):
+class MVCTreeNotifyEvent(MVCTreeEvent):
def __init__(self, type, id, node = None, nodes = None, **kwargs):
- apply(wxMVCTreeEvent.__init__, (self, type, id, node, nodes), kwargs)
+ apply(MVCTreeEvent.__init__, (self, type, id, node, nodes), kwargs)
self.notify = wx.NotifyEvent(type, id)
def getNotifyEvent(self):
return self.notify
-class wxMVCTree(wx.ScrolledWindow):
+class MVCTree(wx.ScrolledWindow):
"""
The main mvc tree class.
"""
return self.transform
def __repr__(self):
- return "<wxMVCTree instance at %s>" % str(hex(id(self)))
+ return "<MVCTree instance at %s>" % str(hex(id(self)))
def __str__(self):
return self.__repr__()
def NodeAdded(self, parent, child):
- e = wxMVCTreeEvent(wxEVT_MVCTREE_ADD_ITEM, self.GetId(), node = child, nodes = [parent, child])
+ e = MVCTreeEvent(wxEVT_MVCTREE_ADD_ITEM, self.GetId(), node = child, nodes = [parent, child])
self.GetEventHandler().ProcessEvent(e)
self.painter.ClearBuffer()
def NodeInserted(self, parent, child, index):
- e = wxMVCTreeEvent(wxEVT_MVCTREE_ADD_ITEM, self.GetId(), node = child, nodes = [parent, child])
+ e = MVCTreeEvent(wxEVT_MVCTREE_ADD_ITEM, self.GetId(), node = child, nodes = [parent, child])
self.GetEventHandler().ProcessEvent(e)
self.painter.ClearBuffer()
def NodeRemoved(self, node):
- e = wxMVCTreeEvent(wxEVT_MVCTREE_DELETE_ITEM, self.GetId(), node = child, nodes = [parent, child])
+ e = MVCTreeEvent(wxEVT_MVCTREE_DELETE_ITEM, self.GetId(), node = child, nodes = [parent, child])
self.GetEventHandler().ProcessEvent(e)
self.painter.ClearBuffer()
def OnKeyDown(self, evt):
- e = wxMVCTreeEvent(wxEVT_MVCTREE_KEY_DOWN, self.GetId(), keyEvent = evt)
+ e = MVCTreeEvent(wxEVT_MVCTREE_KEY_DOWN, self.GetId(), keyEvent = evt)
self.GetEventHandler().ProcessEvent(e)
def SetFont(self, font):
def SetDoubleBuffered(self, bool):
"""
- By default wxMVCTree is double-buffered.
+ By default MVCTree is double-buffered.
"""
self.doubleBuffered = bool
def SetSelection(self, nodeTuple):
if type(nodeTuple) != type(()):
nodeTuple = (nodeTuple,)
- e = wxMVCTreeNotifyEvent(wxEVT_MVCTREE_SEL_CHANGING, self.GetId(), nodeTuple[0], nodes = nodeTuple)
+ e = MVCTreeNotifyEvent(wxEVT_MVCTREE_SEL_CHANGING, self.GetId(), nodeTuple[0], nodes = nodeTuple)
self.GetEventHandler().ProcessEvent(e)
if not e.notify.IsAllowed():
return
treenode = self.nodemap[node]
node.selected = False
self._selections = list(nodeTuple)
- e = wxMVCTreeEvent(wxEVT_MVCTREE_SEL_CHANGED, self.GetId(), nodeTuple[0], nodes = nodeTuple)
+ e = MVCTreeEvent(wxEVT_MVCTREE_SEL_CHANGED, self.GetId(), nodeTuple[0], nodes = nodeTuple)
self.GetEventHandler().ProcessEvent(e)
def IsMultiSelect(self):
return
for ed in self._editors:
if ed.CanEdit(node):
- e = wxMVCTreeNotifyEvent(wxEVT_MVCTREE_BEGIN_EDIT, self.GetId(), node)
+ e = MVCTreeNotifyEvent(wxEVT_MVCTREE_BEGIN_EDIT, self.GetId(), node)
self.GetEventHandler().ProcessEvent(e)
if not e.notify.IsAllowed():
return
self._currentEditor = None
def _EditEnding(self, node):
- e = wxMVCTreeNotifyEvent(wxEVT_MVCTREE_END_EDIT, self.GetId(), node)
+ e = MVCTreeNotifyEvent(wxEVT_MVCTREE_END_EDIT, self.GetId(), node)
self.GetEventHandler().ProcessEvent(e)
if not e.notify.IsAllowed():
return False
def SetExpanded(self, node, bool):
treenode = self.nodemap[node]
if bool:
- e = wxMVCTreeNotifyEvent(wxEVT_MVCTREE_ITEM_EXPANDING, self.GetId(), node)
+ e = MVCTreeNotifyEvent(wxEVT_MVCTREE_ITEM_EXPANDING, self.GetId(), node)
self.GetEventHandler().ProcessEvent(e)
if not e.notify.IsAllowed():
return
if not treenode.built:
self.LoadChildren(treenode)
else:
- e = wxMVCTreeNotifyEvent(wxEVT_MVCTREE_ITEM_COLLAPSING, self.GetId(), node)
+ e = MVCTreeNotifyEvent(wxEVT_MVCTREE_ITEM_COLLAPSING, self.GetId(), node)
self.GetEventHandler().ProcessEvent(e)
if not e.notify.IsAllowed():
return
treenode.expanded = bool
e = None
if treenode.expanded:
- e = wxMVCTreeEvent(wxEVT_MVCTREE_ITEM_EXPANDED, self.GetId(), node)
+ e = MVCTreeEvent(wxEVT_MVCTREE_ITEM_EXPANDED, self.GetId(), node)
else:
- e = wxMVCTreeEvent(wxEVT_MVCTREE_ITEM_COLLAPSED, self.GetId(), node)
+ e = MVCTreeEvent(wxEVT_MVCTREE_ITEM_COLLAPSED, self.GetId(), node)
self.GetEventHandler().ProcessEvent(e)
self.layout.Layout(self.currentRoot)
self.transform.Transform(self.currentRoot, self.offset, self.rotation)
nodeTuple = nodeOrTuple
if type(nodeOrTuple)!= type(()):
nodeTuple = (nodeOrTuple,)
- e = wxMVCTreeNotifyEvent(wxEVT_MVCTREE_SEL_CHANGING, self.GetId(), nodeTuple[0], nodes = nodeTuple)
+ e = MVCTreeNotifyEvent(wxEVT_MVCTREE_SEL_CHANGING, self.GetId(), nodeTuple[0], nodes = nodeTuple)
self.GetEventHandler().ProcessEvent(e)
if not e.notify.IsAllowed():
return
treenode = self.nodemap[node]
treenode.selected = True
changeparents.append(treenode)
- e = wxMVCTreeEvent(wxEVT_MVCTREE_SEL_CHANGED, self.GetId(), nodeTuple[0], nodes = nodeTuple)
+ e = MVCTreeEvent(wxEVT_MVCTREE_SEL_CHANGED, self.GetId(), nodeTuple[0], nodes = nodeTuple)
self.GetEventHandler().ProcessEvent(e)
dc = wx.ClientDC(self)
self.PrepareDC(dc)
treenode = self.nodemap[node]
changeparents.append(treenode)
treenode.selected = False
- e = wxMVCTreeEvent(wxEVT_MVCTREE_SEL_CHANGED, self.GetId(), node, nodes = nodeTuple)
+ e = MVCTreeEvent(wxEVT_MVCTREE_SEL_CHANGED, self.GetId(), node, nodes = nodeTuple)
self.GetEventHandler().ProcessEvent(e)
dc = wx.ClientDC(self)
self.PrepareDC(dc)