I just started a new small python project on google code which goal is to easily create clickable graphs on a GKT+ goocanvas. The initial idea comes from this code snippet http://www.daniweb.com/software-development/python/code/323792 . I want to do about the same, but instead of simply drawing the graph, I want to display it on a goocanvas to make it interactive.

The project's page is here http://code.google.com/p/clickonpy/ , there is no code yet, but if some members of the python forum are ready to contribute, please let me know :)

7 Years
Discussion Span
Last Post by Gribouillis

Clickonpy produced its first clickable graphs. To do so, it only needs a sequence of pairs of "connected" arbitrary python objects, and a function to call when one of the objects is clicked. Here is an example code

from clickonpy.app import App

if __name__ == "__main__":
    def on_click(graph, obj, button):
        # this will be called when the user clicks on a graph node
        print "{0} was clicked with button {1}".format(repr(obj), button)

    def pairs():
        # example graph: take a series of words and connect those with at least 3 common letters
        words = "format frame framework function game generator grid gui help".split()
        for i, w0 in enumerate(words):
            for w1 in words[i+1:]:
                if sum(x in w1 for x in set(w0)) >= 3:
                    yield w0, w1
    app = App()
    app.create_graph(pairs(), node_click = on_click)
    for obj in app.graph:
        app.graph[obj].label = str(obj).capitalize()

""" my output --->
'framework' was clicked with button 1
'framework' was clicked with button 2
'generator' was clicked with button 3
'function' was clicked with button 2
'frame' was clicked with button 1
'format' was clicked with button 1
'game' was clicked with button 3
'game' was clicked with button 2
'game' was clicked with button 3
'generator' was clicked with button 1

This code displays a gtk window containing the graph, as shown in the attached screenshot.
The code was run in linux, it needs pygtk, pycairo, pygoocanvas, pygraphviz and pydot. I currently don't know if it will work in windows. The key point is to install pygoocanvas in windows.

You can currently download clickonpy by pulling its mercurial repository. I would appreciate if someone helps me with setuptools to write an installer ?

Attachments clickonpy.png 37.45 KB
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.