Dynamically Generating a Tree Structure

Hello,

I’d like to be able to generate a tree structure of morse code that looks like this:

I’m running into a few issues:

  1. Drawing lines in between the “treeNode” widgets

  2. Generating the tree algorithmically depending on branching factor rather than specifying where everything goes

Can anyone point me in the right direction towards solving these two problems?

Thanks,

Rishi Sharam

Rishi Sharma wrote:

Hello,

I'd like to be able to generate a tree structure of morse code that
looks like this:

What's the overall purpose for this? Unless people are going to be
clicking on the circles, why would you generate it dynamically? Why use
widgets at all? Just display it as a bitmap

I'm running into a few issues:
1) Drawing lines in between the "treeNode" widgets
2) Generating the tree algorithmically depending on branching factor
rather than specifying where everything goes

Can anyone point me in the right direction towards solving these two
problems?

To generate the positions algorithmically, you have to know the spacing
for the deepest level. Everything else follows from that. After you
place the 64 leaf nodes, then the nodes in the level above it are in the
center of each pair below, and that continues up.

···

--
Tim Roberts, timr@probo.com
Providenza & Boekelheide, Inc.

Rishi Sharma wrote:

I'd like to be able to generate a tree structure of morse code that
looks like this:
...
I'm running into a few issues:
1) Drawing lines in between the "treeNode" widgets
2) Generating the tree algorithmically depending on branching factor
rather than specifying where everything goes

Here's some code to place the balls recursively, although this is kind
of a silly solution. It'd be just as easy to figure out each level
directly.

rows = [,,,,,,]

class Node(object):
    def __init__(self,level,spot):
        if level < 6:
            self.left = Node(level+1,spot*2+0)
            self.right = Node(level+1,spot*2+1)
            self.x = (self.left.x + self.right.x) / 2
        else:
            self.x = spot * 10
        print "row %d spot %d is at %d" % (level,spot,self.x)
        rows[level].append( self )

x = Node( 0, 0 )

for no,row in enumerate(rows):
    print "Row %d:" % no,
    for ball in row:
        print ball.x,
    print

···

--
Tim Roberts, timr@probo.com
Providenza & Boekelheide, Inc.

1) Drawing lines in between the "treeNode" widgets

Here's some code to place the balls recursively, although this is kind
of a silly solution.

then to dsplay, plug it inot FloatCanvas. See:

http://svn.wxwidgets.org/viewvc/wx/wxPython/3rdParty/FloatCanvas/Demos/ProcessDiagram.py?view=markup

(if that link doesn't work well, it's the "ProcessDiagram.py" Demo, in
the wxPython 3rdParty svn.)

for an example.
(also enclosed)

That demo lets you move the nodes around, but you wouldn't have to enable that.

-Chris

It'd be just as easy to figure out each level

ProcessDiagram.py (11.7 KB)

···

On Tue, Jul 23, 2013 at 1:02 PM, Tim Roberts <timr@probo.com> wrote:

directly.

rows = [,,,,,,]

class Node(object):
    def __init__(self,level,spot):
        if level < 6:
            self.left = Node(level+1,spot*2+0)
            self.right = Node(level+1,spot*2+1)
            self.x = (self.left.x + self.right.x) / 2
        else:
            self.x = spot * 10
        print "row %d spot %d is at %d" % (level,spot,self.x)
        rows[level].append( self )

x = Node( 0, 0 )

for no,row in enumerate(rows):
    print "Row %d:" % no,
    for ball in row:
        print ball.x,
    print

--
Tim Roberts, timr@probo.com
Providenza & Boekelheide, Inc.

--
You received this message because you are subscribed to the Google Groups "wxPython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to wxpython-users+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

--

Christopher Barker, Ph.D.
Oceanographer

Emergency Response Division
NOAA/NOS/OR&R (206) 526-6959 voice
7600 Sand Point Way NE (206) 526-6329 fax
Seattle, WA 98115 (206) 526-6317 main reception

Chris.Barker@noaa.gov