Don't use fancy GTK+ events/signals, just allow subclasses of DotWidget
to override on_click() method and then inject instance into DotWindow.
| ... | ... |
@@ -1770,20 +1770,33 @@ class DotWidget(gtk.DrawingArea): |
| 1770 | 1770 |
return (time.time() < self.presstime + click_timeout |
| 1771 | 1771 |
and math.hypot(deltax, deltay) < click_fuzz) |
| 1772 | 1772 |
|
| 1773 |
+ def on_click(self, element, event): |
|
| 1774 |
+ """Override this method in subclass to process |
|
| 1775 |
+ click events. Note that element can be None |
|
| 1776 |
+ (click on empty space).""" |
|
| 1777 |
+ return False |
|
| 1778 |
+ |
|
| 1773 | 1779 |
def on_area_button_release(self, area, event): |
| 1774 | 1780 |
self.drag_action.on_button_release(event) |
| 1775 | 1781 |
self.drag_action = NullAction(self) |
| 1776 |
- if event.button == 1 and self.is_click(event): |
|
| 1777 |
- x, y = int(event.x), int(event.y) |
|
| 1778 |
- url = self.get_url(x, y) |
|
| 1779 |
- if url is not None: |
|
| 1780 |
- self.emit('clicked', unicode(url.url), event)
|
|
| 1781 |
- else: |
|
| 1782 |
- jump = self.get_jump(x, y) |
|
| 1783 |
- if jump is not None: |
|
| 1784 |
- self.animate_to(jump.x, jump.y) |
|
| 1782 |
+ x, y = int(event.x), int(event.y) |
|
| 1783 |
+ if self.is_click(event): |
|
| 1784 |
+ el = self.get_element(x, y) |
|
| 1785 |
+ print "clicked element:", el |
|
| 1786 |
+ if self.on_click(el, event): |
|
| 1787 |
+ return True |
|
| 1788 |
+ |
|
| 1789 |
+ if event.button == 1: |
|
| 1790 |
+ url = self.get_url(x, y) |
|
| 1791 |
+ if url is not None: |
|
| 1792 |
+ self.emit('clicked', unicode(url.url), event)
|
|
| 1793 |
+ else: |
|
| 1794 |
+ jump = self.get_jump(x, y) |
|
| 1795 |
+ if jump is not None: |
|
| 1796 |
+ self.animate_to(jump.x, jump.y) |
|
| 1797 |
+ |
|
| 1798 |
+ return True |
|
| 1785 | 1799 |
|
| 1786 |
- return True |
|
| 1787 | 1800 |
if event.button == 1 or event.button == 2: |
| 1788 | 1801 |
return True |
| 1789 | 1802 |
return False |
| ... | ... |
@@ -1863,7 +1876,7 @@ class DotWindow(gtk.Window): |
| 1863 | 1876 |
|
| 1864 | 1877 |
base_title = 'Dot Viewer' |
| 1865 | 1878 |
|
| 1866 |
- def __init__(self): |
|
| 1879 |
+ def __init__(self, widget=None): |
|
| 1867 | 1880 |
gtk.Window.__init__(self) |
| 1868 | 1881 |
|
| 1869 | 1882 |
self.graph = Graph() |
| ... | ... |
@@ -1875,7 +1888,7 @@ class DotWindow(gtk.Window): |
| 1875 | 1888 |
vbox = gtk.VBox() |
| 1876 | 1889 |
window.add(vbox) |
| 1877 | 1890 |
|
| 1878 |
- self.widget = DotWidget() |
|
| 1891 |
+ self.widget = widget or DotWidget() |
|
| 1879 | 1892 |
|
| 1880 | 1893 |
# Create a UIManager instance |
| 1881 | 1894 |
uimanager = self.uimanager = gtk.UIManager() |