Demo.swing.TreeDemo.py Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jython-standalone Show documentation
Show all versions of jython-standalone Show documentation
Jython is an implementation of the high-level, dynamic, object-oriented
language Python written in 100% Pure Java, and seamlessly integrated with
the Java platform. It thus allows you to run Python on any Java platform.
"""\
A simple demonstration of creating a swing tree widget from a
Python dictionary.
"""
data = {
'PyObject': {
'PyInteger':None,
'PyFloat':None,
'PyComplex':None,
'PySequence': {
'PyArray':None,
'PyList':None,
'PyTuple':None,
'PyString':None,
},
'PyClass': {
'PyJavaClass':None,
},
},
'sys':None,
'Py':None,
'PyException':None,
'__builtin__':None,
'ThreadState':None,
}
from pawt import swing
Node = swing.tree.DefaultMutableTreeNode
def addNode(tree, key, value):
node = Node(key)
tree.add(node)
if value is not None:
addLeaves(node, value.items())
def addLeaves(node, items):
items.sort()
for key, value in items:
addNode(node, key, value)
def makeTree(name, data):
tree = Node('A Few JPython Classes')
addLeaves(tree, data.items())
return tree
if __name__ == '__main__':
tree = makeTree('Some JPython Classes', data)
swing.test(swing.JScrollPane(swing.JTree(tree)))