Also move to center of the destination node, not to the destination
endpoint.
Includes changes that allow highlighting multiple items.
From: Marius Gedminas <marius@gedmin.as>
| ... | ... |
@@ -280,17 +280,23 @@ class CompoundShape(Shape): |
| 280 | 280 |
|
| 281 | 281 |
class Url(object): |
| 282 | 282 |
|
| 283 |
- def __init__(self, item, url): |
|
| 283 |
+ def __init__(self, item, url, highlight=None): |
|
| 284 | 284 |
self.item = item |
| 285 | 285 |
self.url = url |
| 286 |
+ if highlight is None: |
|
| 287 |
+ highlight = set([item]) |
|
| 288 |
+ self.highlight = highlight |
|
| 286 | 289 |
|
| 287 | 290 |
|
| 288 | 291 |
class Jump(object): |
| 289 | 292 |
|
| 290 |
- def __init__(self, item, x, y): |
|
| 293 |
+ def __init__(self, item, x, y, highlight=None): |
|
| 291 | 294 |
self.item = item |
| 292 | 295 |
self.x = x |
| 293 | 296 |
self.y = y |
| 297 |
+ if highlight is None: |
|
| 298 |
+ highlight = set([item]) |
|
| 299 |
+ self.highlight = highlight |
|
| 294 | 300 |
|
| 295 | 301 |
|
| 296 | 302 |
class Element(CompoundShape): |
| ... | ... |
@@ -356,9 +362,9 @@ class Edge(Element): |
| 356 | 362 |
|
| 357 | 363 |
def get_jump(self, x, y): |
| 358 | 364 |
if square_distance(x, y, *self.points[0]) <= self.RADIUS*self.RADIUS: |
| 359 |
- return Jump(self, *self.points[-1]) |
|
| 365 |
+ return Jump(self, self.dst.x, self.dst.y, highlight=set([self, self.dst])) |
|
| 360 | 366 |
if square_distance(x, y, *self.points[-1]) <= self.RADIUS*self.RADIUS: |
| 361 |
- return Jump(self, *self.points[0]) |
|
| 367 |
+ return Jump(self, self.src.x, self.src.y, highlight=set([self, self.src])) |
|
| 362 | 368 |
return None |
| 363 | 369 |
|
| 364 | 370 |
|
| ... | ... |
@@ -375,16 +381,18 @@ class Graph(Shape): |
| 375 | 381 |
def get_size(self): |
| 376 | 382 |
return self.width, self.height |
| 377 | 383 |
|
| 378 |
- def draw(self, cr, highlight_item=None): |
|
| 384 |
+ def draw(self, cr, highlight_items=None): |
|
| 385 |
+ if highlight_items is None: |
|
| 386 |
+ highlight_items = () |
|
| 379 | 387 |
cr.set_source_rgba(0.0, 0.0, 0.0, 1.0) |
| 380 | 388 |
|
| 381 | 389 |
cr.set_line_cap(cairo.LINE_CAP_BUTT) |
| 382 | 390 |
cr.set_line_join(cairo.LINE_JOIN_MITER) |
| 383 | 391 |
|
| 384 | 392 |
for edge in self.edges: |
| 385 |
- edge.draw(cr, highlight=(edge is highlight_item)) |
|
| 393 |
+ edge.draw(cr, highlight=(edge in highlight_items)) |
|
| 386 | 394 |
for node in self.nodes: |
| 387 |
- node.draw(cr, highlight=(node is highlight_item)) |
|
| 395 |
+ node.draw(cr, highlight=(node in highlight_items)) |
|
| 388 | 396 |
|
| 389 | 397 |
def get_url(self, x, y): |
| 390 | 398 |
for node in self.nodes: |
| ... | ... |
@@ -774,7 +782,7 @@ class NullAction(DragAction): |
| 774 | 782 |
item = dot_widget.get_jump(event.x, event.y) |
| 775 | 783 |
if item is not None: |
| 776 | 784 |
dot_widget.window.set_cursor(gtk.gdk.Cursor(gtk.gdk.HAND2)) |
| 777 |
- dot_widget.set_highlight(item.item) |
|
| 785 |
+ dot_widget.set_highlight(item.highlight) |
|
| 778 | 786 |
else: |
| 779 | 787 |
dot_widget.window.set_cursor(gtk.gdk.Cursor(gtk.gdk.ARROW)) |
| 780 | 788 |
dot_widget.set_highlight(None) |
| ... | ... |
@@ -904,7 +912,7 @@ class DotWidget(gtk.DrawingArea): |
| 904 | 912 |
cr.scale(self.zoom_ratio, self.zoom_ratio) |
| 905 | 913 |
cr.translate(-self.x, -self.y) |
| 906 | 914 |
|
| 907 |
- self.graph.draw(cr, highlight_item=self.highlight) |
|
| 915 |
+ self.graph.draw(cr, highlight_items=self.highlight) |
|
| 908 | 916 |
cr.restore() |
| 909 | 917 |
|
| 910 | 918 |
self.drag_action.draw(cr) |
| ... | ... |
@@ -919,9 +927,9 @@ class DotWidget(gtk.DrawingArea): |
| 919 | 927 |
self.y = y |
| 920 | 928 |
self.queue_draw() |
| 921 | 929 |
|
| 922 |
- def set_highlight(self, item): |
|
| 923 |
- if self.highlight != item: |
|
| 924 |
- self.highlight = item |
|
| 930 |
+ def set_highlight(self, items): |
|
| 931 |
+ if self.highlight != items: |
|
| 932 |
+ self.highlight = items |
|
| 925 | 933 |
self.queue_draw() |
| 926 | 934 |
|
| 927 | 935 |
def zoom_image(self, zoom_ratio, center=False): |