- Remove dead code.
- Remove debug code.
- Replace filterlist() with standard OOP.
| ... | ... |
@@ -45,8 +45,6 @@ import pangocairo |
| 45 | 45 |
# - http://mirageiv.berlios.de/ |
| 46 | 46 |
# - http://comix.sourceforge.net/ |
| 47 | 47 |
|
| 48 |
-def filterlist(l, expr): |
|
| 49 |
- return map(lambda i: l[i], filter(lambda i: isinstance(l[i], expr), range(len(l)))) |
|
| 50 | 48 |
|
| 51 | 49 |
class Pen: |
| 52 | 50 |
"""Store pen attributes.""" |
| ... | ... |
@@ -91,6 +89,9 @@ class Shape: |
| 91 | 89 |
else: |
| 92 | 90 |
return self.pen |
| 93 | 91 |
|
| 92 |
+ def search_text(self, regexp): |
|
| 93 |
+ return False |
|
| 94 |
+ |
|
| 94 | 95 |
|
| 95 | 96 |
class TextShape(Shape): |
| 96 | 97 |
|
| ... | ... |
@@ -192,6 +193,9 @@ class TextShape(Shape): |
| 192 | 193 |
cr.line_to(x+self.w, self.y) |
| 193 | 194 |
cr.stroke() |
| 194 | 195 |
|
| 196 |
+ def search_text(self, regexp): |
|
| 197 |
+ return regexp.search(self.t) is not None |
|
| 198 |
+ |
|
| 195 | 199 |
|
| 196 | 200 |
class ImageShape(Shape): |
| 197 | 201 |
|
| ... | ... |
@@ -329,6 +333,12 @@ class CompoundShape(Shape): |
| 329 | 333 |
for shape in self.shapes: |
| 330 | 334 |
shape.draw(cr, highlight=highlight) |
| 331 | 335 |
|
| 336 |
+ def search_text(self, regexp): |
|
| 337 |
+ for shape in self.shapes: |
|
| 338 |
+ if shape.search_text(regexp): |
|
| 339 |
+ return True |
|
| 340 |
+ return False |
|
| 341 |
+ |
|
| 332 | 342 |
|
| 333 | 343 |
class Url(object): |
| 334 | 344 |
|
| ... | ... |
@@ -1295,22 +1305,6 @@ class DragAction(object): |
| 1295 | 1305 |
self.startmousey = self.prevmousey = event.y |
| 1296 | 1306 |
self.start() |
| 1297 | 1307 |
|
| 1298 |
- dot_widget = self.dot_widget |
|
| 1299 |
- item = dot_widget.get_url(event.x, event.y) |
|
| 1300 |
- if item is None: |
|
| 1301 |
- item = dot_widget.get_jump(event.x, event.y) |
|
| 1302 |
- |
|
| 1303 |
- if item is not None and isinstance(item.item, Node): |
|
| 1304 |
- src = filterlist(item.item.shapes, TextShape) |
|
| 1305 |
- print "# src", src[0].t |
|
| 1306 |
- for edge in dot_widget.graph.edges: |
|
| 1307 |
- if edge.src == item.item: |
|
| 1308 |
- dst = filterlist(edge.dst.shapes, TextShape) |
|
| 1309 |
- print "dst", dst[0].t |
|
| 1310 |
- #dstitem = dot_widget.get_jump(edge.dst.x, edge.dst.y); |
|
| 1311 |
- #dot_widget.window.set_cursor(gtk.gdk.Cursor(gtk.gdk.HAND2)) |
|
| 1312 |
- #dot_widget.set_highlight(dstitem.highlight) |
|
| 1313 |
- |
|
| 1314 | 1308 |
def on_motion_notify(self, event): |
| 1315 | 1309 |
if event.is_hint: |
| 1316 | 1310 |
x, y, state = event.window.get_pointer() |
| ... | ... |
@@ -1791,16 +1785,6 @@ class DotWidget(gtk.DrawingArea): |
| 1791 | 1785 |
self.animation = ZoomToAnimation(self, x, y) |
| 1792 | 1786 |
self.animation.start() |
| 1793 | 1787 |
|
| 1794 |
- def graph2window(self, x, y): |
|
| 1795 |
- rect = self.get_allocation() |
|
| 1796 |
- x -= self.x |
|
| 1797 |
- y -= self.y |
|
| 1798 |
- x *= self.zoom_ratio |
|
| 1799 |
- y *= self.zoom_ratio |
|
| 1800 |
- x += 0.5 * rect.width |
|
| 1801 |
- y += 0.5 * rect.height |
|
| 1802 |
- return x, y |
|
| 1803 |
- |
|
| 1804 | 1788 |
def window2graph(self, x, y): |
| 1805 | 1789 |
rect = self.get_allocation() |
| 1806 | 1790 |
x -= 0.5*rect.width |
| ... | ... |
@@ -1919,10 +1903,9 @@ class DotWindow(gtk.Window): |
| 1919 | 1903 |
def find_text(self, entry_text): |
| 1920 | 1904 |
found_items = [] |
| 1921 | 1905 |
dot_widget = self.widget |
| 1906 |
+ regexp = re.compile(entry_text) |
|
| 1922 | 1907 |
for node in dot_widget.graph.nodes: |
| 1923 |
- text = filterlist(node.shapes, TextShape) |
|
| 1924 |
- if re.search (entry_text, text[0].t): |
|
| 1925 |
- #print "found:", entry_text ,"at", node, node.x, node.y |
|
| 1908 |
+ if node.search_text(regexp): |
|
| 1926 | 1909 |
found_items.append(node) |
| 1927 | 1910 |
return found_items |
| 1928 | 1911 |
|
| ... | ... |
@@ -1948,17 +1931,6 @@ class DotWindow(gtk.Window): |
| 1948 | 1931 |
if(len(found_items) == 1): |
| 1949 | 1932 |
dot_widget.animate_to(found_items[0].x, found_items[0].y) |
| 1950 | 1933 |
|
| 1951 |
- def update(self, filename): |
|
| 1952 |
- if not hasattr(self, "last_mtime"): |
|
| 1953 |
- self.last_mtime = None |
|
| 1954 |
- |
|
| 1955 |
- current_mtime = os.stat(filename).st_mtime |
|
| 1956 |
- if current_mtime != self.last_mtime: |
|
| 1957 |
- self.last_mtime = current_mtime |
|
| 1958 |
- self.open_file(filename) |
|
| 1959 |
- |
|
| 1960 |
- return True |
|
| 1961 |
- |
|
| 1962 | 1934 |
def set_filter(self, filter): |
| 1963 | 1935 |
self.widget.set_filter(filter) |
| 1964 | 1936 |
|