Esempio n. 1
0
 def OnEditNode(self, evt):
     if self.selected_node is None:
         return
         
     #new_text = wx.GetTextFromUser("Edit node content", "Edit node", self.selected_node.content.replace('\n', ' '))
     dlg = EditNodeDialog(self.selected_node.content, self.selected_node.properties, self.GetParent())
     dlg.Show()
     val = dlg.ShowModal()
     new_text = dlg.GetNewContent()
     new_props = dlg.GetNewProperties()
     dlg.Destroy()
     
     if val != wx.ID_OK:
         return
     
     if len(new_text) == 0:
         return
     
     points = justify.get_points(new_text)
     all_js = justify.justify_text(points, 2)
     j = all_js[0][1]
     new_text = justify.render_text(new_text, j)
     
     mutation = tree_editor.EditMutation(self.layout, self.selected_node, new_text, new_props)
     self.editor.perform(mutation)
     self.dirty = True
Esempio n. 2
0
 def OnAddNode(self, evt):
     if self.selected_node is None:
         return
     
     new_text = wx.GetTextFromUser("Enter new node content", "New node", '')
     if len(new_text) == 0:
         return
         
     points = justify.get_points(new_text)
     all_js = justify.justify_text(points, 2)
     j = all_js[0][1]
     new_text = justify.render_text(new_text, j)
     
     n = tree.Node(new_text)
     mutation = tree_editor.InsertMutation(self.layout, self.selected_node, n)
     self.editor.perform(mutation)
     self.dirty = True
     
     wx.PostEvent(self, evt)
Esempio n. 3
0
 def arrange_node(self, node):
     if self.changed is not None and node not in self.changed:
         return
     
     if '\n' not in node.content and len(node.content) > 0:
         points = justify.get_points(node.content)
         all_js = justify.justify_text(points, 2)
         j = all_js[0][1]
         node.content = justify.render_text(node.content, j)
     
     node.scale = 1.125**node.height
     margin = 10*node.scale
     node.inner_radius = (self.get_text_size(node.content, node.scale)+12)/2
     node.bounding_radius = node.inner_radius + margin
     node.inner_theta, node.inner_dist = 0,0
     node.in_theta = 0
     node.dist = 0
     node.theta = 0
     
     if len(node.children) == 0:
         return
     
     for c in node.children:
         self.arrange_node(c)
     
     queue = list(node.children)
     #queue.sort(key=lambda n: -n.bounding_radius)
     #if node.parent is None:
     #    #print >>sys.stderr, [c.bounding_radius for c in queue]
     #    queue = alternate(queue)
     #    #print >>sys.stderr, [c.bounding_radius for c in queue]
     
     check_rad = node.inner_radius
     while True:
         theta_up, theta_down = 0,1
         for c in queue:
             c.dist = check_rad + c.bounding_radius
             if theta_up < theta_down:
                 d = get_theta_delta(check_rad, c.bounding_radius, c.bounding_radius)
                 d1 = d
                 c.theta = theta_up
                 theta_down = theta_up
                 up_rad = c.bounding_radius
                 down_rad = c.bounding_radius
             #elif node.parent is not None and up_rad > down_rad:
             #    d = get_theta_delta(check_rad, up_rad, c.bounding_radius)
             #    theta_up += d
             #    c.theta = theta_up
             #    up_rad = c.bounding_radius
             else:
                 d = get_theta_delta(check_rad, down_rad, c.bounding_radius)
                 theta_down -= d
                 c.theta = theta_down
                 down_rad = c.bounding_radius
         
         if (theta_up + d) - (theta_down - d) < 2.0*math.pi:
         #if (theta_up) - (theta_down) < math.pi:
             break
         
         check_rad *= 1.1
         
     node.in_theta = (theta_up + theta_down) / 2
     
     if node.parent is None:
         tadj = 2*math.pi - (theta_up - theta_down) - d/2 - d1/2
         adj = tadj / len(queue)
         #print >>sys.stderr, theta_up, theta_down, tadj, adj
         sorted_queue = queue[:]
         sorted_queue.sort(key=lambda c: c.theta)
         cumadj = 0
         for c in sorted_queue:
             c.theta += cumadj
             cumadj += adj
     
     #print >>sys.stderr, "in_theta", node.in_theta
     
     circs = [(0,0,node.inner_radius)] + [(c.dist*math.cos(c.theta), c.dist*math.sin(c.theta), c.bounding_radius) for c in queue]
     #print >>sys.stderr, circs
     cx,cy,node.bounding_radius = circumscribe(circs)
     node.bounding_radius += margin
     #print >>sys.stderr, cx,cy
     node.inner_theta, node.inner_dist = angularise(cx,cy)