treeable.py
Go to the documentation of this file.
00001 from PySide.QtCore import QPointF
00002 from PySide.QtGui import QGraphicsEllipseItem, QPen, QColor
00003 
00004 class GraphicsItemInfo(object):
00005     # __slots__ = ['item', 'uid', 'active', 'label', 'clicked']
00006     def __init__(self, item, uid, label='', active=False):
00007         self.item = item
00008         self.uid = uid
00009         self.active = active
00010         self.label = label
00011         self.clicked = False
00012 
00013         if label:
00014             intern(label) 
00015 
00016 
00017 class TreePoint(QPointF):
00018     def __len__(self):
00019         return self.toTuple().__len__()
00020 
00021     def __getslice__(self, i, j):
00022         return self.toTuple().__getslice__(i, j)
00023 
00024     def __getitem__(self, i):
00025         return self.toTuple().__getitem__(i)
00026 
00027 class TreeCircle(QGraphicsEllipseItem):
00028     def __init__(self, rect, pen, point3d):
00029         super(TreeCircle, self).__init__(rect)
00030         self.setPen(pen)
00031         self.point3d = point3d
00032         hilightRect = rect.adjusted((pen.width()-1),(pen.width()-1),-(pen.width()-1),-(pen.width()-1))
00033         self.hilight = QGraphicsEllipseItem(hilightRect, parent=self)
00034         self.hilight.hide()
00035 
00036     def showHilight(self, color):
00037         self.hilight.setPen(QPen(color, self.pen().width()))
00038         if not self.hilight.isVisible():
00039             self.hilight.show()
00040 
00041     def clearHilight(self):
00042         if self.hilight.isVisible(): 
00043             self.hilight.hide()
00044 
00045     def __len__(self):
00046         return self.point3d.__len__() 
00047 
00048     def __getslice__(self, i, j):
00049         return self.point3d.__getslice__(i, j)
00050 
00051     def __getitem__(self, i):
00052         return self.point3d.__getitem__(i)
00053 
00054 class TreeCircleInfo(TreeCircle, GraphicsItemInfo):
00055     def __init__(self, rect, pen, point3d):
00056         # super(TreeCircleInfo, self).__init__(rect, pen, point3d)
00057         TreeCircle.__init__(self, rect, pen, point3d)
00058         GraphicsItemInfo.__init__(self, self, None, None)
00059 
00060     def __repr__(self):
00061         return 'TreeCircleInfo: (%s, %s, %s) / (%s, %s)' % (tuple(self.point3d) + self.rect().center().toTuple())
00062 
00063 if __name__ == '__main__':
00064     import kdtree
00065     tree = kdtree.create(dimensions=2)
00066     tree.add(TreePoint(1,2))
00067     tree.add(TreePoint(3,4))
00068     tree.add(TreePoint(10,20))
00069 
00070     q = TreePoint(1,1)
00071     nodes = tree.search_nn_dist(q, 100)
00072     for n in nodes:
00073         print n.dist(q) 


projector_interface
Author(s): Daniel Lazewatsky
autogenerated on Mon Oct 6 2014 10:12:36