#!/usr/bin/env python
#
# $Id: TreeExplorer.py,v 1.4 2001/11/03 11:05:22 doughellmann Exp $
#
# Copyright 2001 Doug Hellmann.
#
#
# All Rights Reserved
#
# Permission to use, copy, modify, and distribute this software and
# its documentation for any purpose and without fee is hereby
# granted, provided that the above copyright notice appear in all
# copies and that both that copyright notice and this permission
# notice appear in supporting documentation, and that the name of Doug
# Hellmann not be used in advertising or publicity pertaining to
# distribution of the software without specific, written prior
# permission.
#
# DOUG HELLMANN DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
# INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN
# NO EVENT SHALL DOUG HELLMANN BE LIABLE FOR ANY SPECIAL, INDIRECT OR
# CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
# OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
# NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
# CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#
"""For exploring the contents of a tree data structure.
"""
__rcs_info__ = {
#
# Creation Information
#
'module_name' : '$RCSfile: TreeExplorer.py,v $',
'rcs_id' : '$Id: TreeExplorer.py,v 1.4 2001/11/03 11:05:22 doughellmann Exp $',
'creator' : 'Doug Hellmann <doug@hellfly.net>',
'project' : 'PmwContribD',
'created' : 'Sun, 01-Apr-2001 13:16:12 EDT',
#
# Current Information
#
'author' : '$Author: doughellmann $',
'version' : '$Revision: 1.4 $',
'date' : '$Date: 2001/11/03 11:05:22 $',
}
#
# Import system modules
#
import Tkinter, Canvas
import Pmw
import sys, os, string, math
#
# Import Local modules
#
import AnimatedFolder
import TreeNavigator
import NavigableTree
#
# Module
#
class TreeExplorer(Pmw.LabeledWidget):
"""A Pmw style widget for exploring the contents of a tree data structure.
"""
def __init__(self, parent=None, **kw):
"""Create a TreeExplorer widget.
Create a new instance with specified parent widget and the
treedata to be displayed.
Options
'ipadx' -- Internal X padding.
'ipady' -- Internal Y padding.
'indent=20' -- How much to indent each child node of the tree.
'activebackground' -- Color to use when displaying a node as
active.
'height' -- Height of the widget.
"""
optiondefs = (
('ipadx', 0, Pmw.INITOPT),
('ipady', 0, Pmw.INITOPT),
('indent', 20, Pmw.INITOPT),
('activebackground', 'slateblue', Pmw.INITOPT),
('height', 200, Pmw.INITOPT),
)
self.defineoptions(kw, optiondefs)
# Initialize the base class
Pmw.LabeledWidget.__init__(self, parent=parent)
# Create our interface
self._createInterior()
self.createInterior()
# Check for initialization options
# for this class
self.initialiseoptions(TreeExplorer)
return
def enter_node(self, node):
"""
Called when the mouse enters the node area.
"""
#print 'entering: %s' % node_name
pass
def leave_node(self, node):
"""
Called when the mouse leaves the node area.
"""
#print 'leaving: %s' % node_name
pass
def select_node(self, node):
"""
Called when a node is selected by clicking on the
text.
"""
#print 'selected %s' % node.name
pass
def _createInterior(self):
"""
Create the interior components of the widget.
"""
interior = Pmw.LabeledWidget.interior(self)
self.panes = self.createcomponent(
'panes',
(), None,
Pmw.PanedWidget,
(interior,),
orient='horizontal',
hull_height=self['height'],
)
self.panes.add('navigatorpane', min=200, size=200)
self.panes.add('datapane', min=.1)
self.navigator = self.createcomponent('navigator', (), None,
TreeNavigator.TreeNavigator,
(self.panes.pane('navigatorpane'),),
treedata=None,
command=self.select_node,
entercommand=self.enter_node,
leavecommand=self.leave_node,
)
self.navigator.pack(side=Tkinter.TOP,
expand=Tkinter.YES,
fill=Tkinter.Y,
)
self.childsite = self.createcomponent('childsite', (), None,
Tkinter.Frame,
(self.panes.pane('datapane'),),
)
self.childsite.pack(side=Tkinter.TOP,
expand=Tkinter.YES,
fill=Tkinter.BOTH,
)
self.panes.pack(side=Tkinter.TOP,
expand=Tkinter.YES,
fill=Tkinter.BOTH,
)
return
def createInterior(self):
"""
Create widgets in our interior.
"""
pass
def interior(self):
return self.childsite
if __name__ == '__main__':
import GuiAppD
class SimpleTreeExplorer(TreeExplorer):
def _createInterior(self):
TreeExplorer._createInterior(self)
self.datalabel = Tkinter.Label(
self.interior(),
text='Data display goes here')
self.datalabel.pack()
self.motionlabel = Tkinter.Label(
self.interior(),
text='Motion:')
self.motionlabel.pack()
def select_node(self, node):
if node:
#print 'selected ', str(node)
TreeExplorer.select_node(self, node)
self.datalabel.configure(text='Selected: %s' % node)
def enter_node(self, node):
TreeExplorer.enter_node(self, node)
self.motionlabel.configure(text='Motion: %s' % node)
def leave_node(self, node):
TreeExplorer.leave_node(self, node)
self.motionlabel.configure(text='Motion:')
class TETest(GuiAppD.GuiAppD):
appname = 'Test the TreeExplorer widget'
def createInterface(self):
data = NavigableTree.create_from_tuples(
('data', 'this is the data node',
[ ('sub1', 'this is sub1 node',
[ ('sub11', 'This is sub11 node', [])
]
),
('sub2', 'this is sub2 node',
[ ('sub21', 'this is sub21 node',
[ ('sub211', 'this is sub211 node', [])
]
),
('sub22', 'this is sub22 node', [] ),
('sub23', 'this is sub23 node', [] ),
]
),
('sub3', 'this is sub3 node', []),
]
)
)
self.explorer = SimpleTreeExplorer(
self.interior(),
labelpos = 'n',
label_text='TreeExplorer',
height=200,
)
self.explorer.pack(side=Tkinter.TOP,
expand=Tkinter.YES,
fill=Tkinter.BOTH)
self.explorer.component('navigator').configure(treedata=data)
TETest().run()
|