Skip to content

Commit

Permalink
Allow to override event processing of DotWidget.
Browse files Browse the repository at this point in the history
Don't use fancy GTK+ events/signals, just allow subclasses of DotWidget
to override on_click() method and then inject instance into DotWindow.
  • Loading branch information
pfalcon authored and jrfonseca committed May 12, 2013
1 parent d9f2204 commit d4c9791
Showing 1 changed file with 25 additions and 12 deletions.
37 changes: 25 additions & 12 deletions xdot.py
Original file line number Diff line number Diff line change
Expand Up @@ -1770,20 +1770,33 @@ def is_click(self, event, click_fuzz=4, click_timeout=1.0):
return (time.time() < self.presstime + click_timeout
and math.hypot(deltax, deltay) < click_fuzz)

def on_click(self, element, event):
"""Override this method in subclass to process
click events. Note that element can be None
(click on empty space)."""
return False

def on_area_button_release(self, area, event):
self.drag_action.on_button_release(event)
self.drag_action = NullAction(self)
if event.button == 1 and self.is_click(event):
x, y = int(event.x), int(event.y)
url = self.get_url(x, y)
if url is not None:
self.emit('clicked', unicode(url.url), event)
else:
jump = self.get_jump(x, y)
if jump is not None:
self.animate_to(jump.x, jump.y)
x, y = int(event.x), int(event.y)
if self.is_click(event):
el = self.get_element(x, y)
print "clicked element:", el
if self.on_click(el, event):
return True

if event.button == 1:
url = self.get_url(x, y)
if url is not None:
self.emit('clicked', unicode(url.url), event)
else:
jump = self.get_jump(x, y)
if jump is not None:
self.animate_to(jump.x, jump.y)

return True

return True
if event.button == 1 or event.button == 2:
return True
return False
Expand Down Expand Up @@ -1863,7 +1876,7 @@ class DotWindow(gtk.Window):

base_title = 'Dot Viewer'

def __init__(self):
def __init__(self, widget=None):
gtk.Window.__init__(self)

self.graph = Graph()
Expand All @@ -1875,7 +1888,7 @@ def __init__(self):
vbox = gtk.VBox()
window.add(vbox)

self.widget = DotWidget()
self.widget = widget or DotWidget()

# Create a UIManager instance
uimanager = self.uimanager = gtk.UIManager()
Expand Down

0 comments on commit d4c9791

Please sign in to comment.