per page, with , order by , clip by
Results of 0 - 1 of about 0 (0.000 sec.)
Documentation
@author: Camille Huot
@digest: f700e49a4c076469bb549fa17cdd5edb
@id: 125736
@mdate: 2003-09-23T21:42:34Z
@size: 26177
@type: text/html
author: Camille Huot
description: GraphTool is a visual graph editor written in Python with DiaCanvas2, allowing us to run sophisticated algorithms on graphs
generator: Website XSL Stylesheet V2.5.0
keywords: graphtool, graph, manipulation, editor, generic, python, diacanvas, modular
#keywords: graphtool (135036), diacanvas2 (74779), graphxml (41443), diacanvas (32533), mynode (27999), mygraph (27250), montpellier (12718), specialisation (12162), arcs (11312), shapes (11157), graph (9204), arc (6010), toolbar (5872), ellipse (5749), edges (4581), constraint (4270), constraints (4152), universite (3726), self (3707), accessor (3608), redefine (3535), nodes (3435), customizing (2818), deletion (2622), shape (2482), buttons (1871), node (1842), canvas (1716), creation (1587), dictionary (1252), primitives (1243), python (1126)
Documentation GraphTool: The User's Guide Camille Huot E-Mail: < cam@cameuh.net > Copyright © 2003 Université Montpellier II This file is part of GraphTool. GraphTool is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. GraphTool is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with GraphTool; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Table of Contents Introduction Why a new graph editor ? The authors Installing GraphTool Getting GraphTool System requirements Patching DiaCanvas2 GraphTool Writing a simple graph extension Understanding the GraphTool layout A simple graph specialisation Using advanced facilities of GraphTool Customizing the Graph Customizing the Nodes Customizing the Arcs Constraints system [work in progress] Loading and saving files using GraphXML What is GraphXML Introduction GraphTool is a tool for the creation and visual edition of any kind of graph written in Python. It makes use of DiaCanvas2 , a diagramming library for GNOME. DiaCanvas2 provides a canvas on which we can put our nodes and arcs and change their visual aspect. Additionnaly, we automatically can have a SVG output of our graph. The official website is http://www.nongnu.org/graphtool/ . Why a new graph editor ? Before starting to create a new graph editor, we searched a long time for an editor that could use any kind of graph, In a completely generic way. We wanted a graph editor that could apply algorithms on a specific graph, without having to use a specific programm each time. The perfect (but entirely deprecated) model was GSS, an old generic graph editor written in C. This editor doesn't work on any actual system, so we were unable to test it. Other good stuff like Graphlet (very restrictive license) or Grace (an editor generator) have their owns problems and so we decided to write a new one. We hope you'll find it nice and easy to use. Feel free to ask us questions if you have. The authors GraphTool is written by Samuel Poujol , Camille Huot , Aurélien Campéas and Evelyne Zahn . It has started by a school project managed by Alain Jean-Marie at the Université Montpellier II. Thus, The Université Montpellier II is the copyright holder. Installing GraphTool Getting GraphTool You can download the latest version of GraphTool on Savannah (the official website) at http://www.nongnu.org/graphtool/ . Please note that GraphTool runs on a modified version of DiaCanvas2, so you have to patch Diacanvas before installing graphtool (I hope we will get rid of this patch some day). GraphTool DiaCanvas2 patch System requirements In order to run GraphTool, you have to install DiaCanvas2 + its bindings for Python. To install DiaCanvas2 (please report to DiaCanvas2 installation files) you have to get and install: Python 2.2 gnome-canvas PyGTK gnome-python Patching DiaCanvas2 Then we can install our patched version of DiaCanvas2: $ tar xzf diacanvas2-X.Y.Z.tar.gz $ cd diacanvas2-X.Y.Z $ gzip -dc ../diacanvas2-X.Y.Z-graphtool.patch.gz | patch -p1 $ automake $ autoconf Once we've got the patched diacanvas, we can process the usual way: $ ./configure --help $ ./configure [--your-options-here] --enable-python=yes At the end of the configure, be sure there is the line: Python wrapper: yes We can finish the installation: $ make # make install We only tested GraphTool on Linux, if you can run it under an other OS, please feed back (it shouldn't cause any problems). GraphTool There is no special installation instructions for GraphTool, simply untar it where you want. Note that you have to chdir into the directory containing the GraphTool script to make it work fine. Writing a simple graph extension When you use GraphTool, chances are you won't use the editor as is. You'll probably want to define your own graph to make use of your specifics algorithms. To do this, you have to make your own Python classes, that must inherit our bases classes: Graph, Node and Arc (or Edge for non-oriented edges). Understanding the GraphTool layout The graph model defined in GraphTool is quite simple. We have a Graph class that represents the canvas, it contains lists of all nodes and edges. You have to redefine it to make your own graph. Next we have the Node and Arc classes, which respectively represents a node and an arc on the graph. You can redefine these classes to add new properties/methods to the objects. You can also change the shape of the object, the color, etc. UML diagram of the generic GraphTool model. This diagram shows us relations between Graph, Node and Arc: a graph contains a list of nodes and arcs ; a node contains a list of arcs connected to it, and knows the graph ; an arc knows its originating node, its destination node and the graph. A simple graph specialisation To illustrate the theory, here is a simple graph specialisation. We'll write a specialized graph which counts its nodes and edges. Its specialized nodes and edges will name themselves. Example 1. A complete and usable example # we have to specify the location of GraphTool import sys sys.path.append('/nfs1/etu/info/mait/chuot/ter/cam/graphtool') # please change this # we import the modules containing the objects we'll extend import Graph import Node import Arc # the primitives module contains useful functions to interact with the user import primitives class MyGraph(Graph.Graph): def __init__(self): # mandatory call to superclass instance init func Graph.Graph.__init__(self) # set the node and arc default type self._node_type = MyNode self._arc_type = MyEdge # variable to count nodes self.nb_nodes = 0 # variable to count edges self.nb_edges = 0 # register methods to allow the user read theses values with GraphTool self.add_accessor('Number of nodes', self.get_nb_nodes, None) self.add_accessor('Number of edges', self.get_nb_edges, None) # we intercept the event to take action def on_node_creation(self, node): self.nb_nodes = self.nb_nodes + 1 def on_arc_creation(self, arc): self.nb_edges = self.nb_edges + 1 # we now have to write our method to read the values def get_nb_nodes(self): return self.nb_nodes def get_nb_edges(self): return self.nb_edges # we now make our node class (inherits Node of Node module) class MyNode(Node.Node): def __init__(self, graph, name): # mandatory Node.Node.__init__(self, graph, name) # we ask the user to name the node self.name = primitives.prompt_user(self._graph._frame, "Enter the node's name") # we add an accessor to be able to modify this name later self.make_default_accessors() # this method adds an accessor for each object's variable # that does not begin with a '_' # when the node is deleted def on_delete(self): self.graph.nb_nodes = self.nb_nodes - 1 # we have to return True so that the node will be really deleted return True # and finally our edge class class MyEdge(Arc.Arc): def __init__(self, graph): # mandatory Arc.Arc.__init__(self, graph) # we ask the user to name the arc self.name = primitives.prompt_user(self, "Enter the arc's name") # and we add the accessor self.make_default_accessors() def on_delete(self): self.graph.nb_edges = self.nb_edges - 1 return True # see how it is easy ? To install the newly created graph: run GraphTool, choose 'Types' then 'Add', choose the file MyGraph.py wherever it is, then click 'OK'. You can now create a new MyGraph by clicking 'File', 'New', 'MyGraph'. Fell free to try it, compare the utilisation with the base classes and modify this file to experiment or use it as a skeleton to create your own classes. Using advanced facilities of GraphTool As a graph developer, you should know some hints. Customizing the Graph You should take in consideration that our base graph contains oriented arcs. If you want to make a graph with non-oriented arcs, you have to make your own Edge class. The class Graph inherits from the diacanvas.Canvas class. For more information on this, please read the DiaCanvas2 documentation , and more precisely http://diacanvas.sourceforge.net/ref/DiaCanvas.html . At any time, if you want to force the screen refresh, you can apply an update_now() on the graph. Each node or arc in the graph has got an unique name, automatically generated at creation time. This name has to be read-only for implementation needs. Indeed this unique name acts as a key in the dictionary that contains all nodes or all arcs. In addition, the name acts as the "GraphXML id" and has to be unique for this purpose too. We now know that a graph has two Python dictionaries, one for nodes, another for arcs. The key of the dictionary is the unique name, and the value is the node or arc object himself. Customizing the toolbar When you create your graph, you have the possibility to redefine the buttons in the toolbars in an easy way. When a user open a new graph project, the GUI constructs the toolbar with informations gathered from the graph itself. The GUI does: items = graph.get_toolbar() And in the Graph class, there is a default get_toolbar method: def get_toolbar (self): return [['IN','add_node.png',self.make_node], ['IE','add_arc.png',self.make_arc]] In fact this method simply return a list of buttons. These buttons are represented by a list containing a string 'IN' or 'IE' (respectively "Instanciate Node" or "Instanciate Edge"), followed by an icon name and followed by a callback to use to instanciate the object. So you can customize this toolbar putting as many buttons you want, even non-creating buttons [work in progress]. Example 2. A custom toolbar example in a custom graph class def get_toolbar (self): tb = Graph.get_toolbar (self) tb = remove_toolbar_item (tb, 'IN') tb = add_toolbar_item (tb, 'IN','add_place.png', self.make_place) tb = add_toolbar_item (tb, 'IN','add_trans.png', self.make_trans) return tb Graph events When a node (the full story is OK for arcs too) is created, its constraints are checked ( see below ) and the object is put on the canvas. Then a user definable method is called: graph.on_node_creation(node) (for arcs it is graph.on_arc_creation(arc) . By default this method does nothing. You can customize it as you want to take action on node creation. (See A complete and usable example ). Customizing the Nodes Visual, shape You can modify the default shape of a Node object, or add new shapes, by modifying the _shapes list of shapes of the object. By default, _shapes[0] (the first shape of the list) contains an ellipse of 30 pixels width, filled with white color. The update X signal automatically refresh all the shapes contained in this list when requested by X. So you just have to add your shape to the list. For example, if you want to change the ellipse, and use a PNG picture instead, you have to do: mynode._shapes[0] = dia.shape.Image() mynode._shapes[0].image(gtk.gdk.pixbuf_new_from_file(filename='mypng.png')) To add a second ellipse: mynode._shapes.append(dia.shape.Ellipse()) mynode._shapes[-1].ellipse(center=(self.width/2, self.height/2), width=self.width, height=self.height)) mynode._shapes[-1] being the last shape of the list, so the one you just appended. This is the node.init_shapes() method that initializes the shape. If you redefine this method the default ellipse will go away and your shape will be shown. Example 3. Changing shape example from PetriNet's Transition node def init_shapes (self): self.set (height = 40, width = 40) self._shapes = [] self._shapes.append (dia.shape.Path ()) self._shapes[0].rectangle ((13,0), (27,self.height)) self._shapes[0].set_fill (1) self._shapes[0].set_fill_color (dia.color (250,250,250)) self._shapes[0].set_line_width (1) self.init_labels () Note that self.init_labels() is defined in the Petri_Node so you have to remove this line if you want to be able to use this code. Node events When a deletion for a node is requested, the node.on_delete() method is called. The deletion will continue only if node.on_delete() returns True . Note that the call is made before deleting the arcs, so the node deletion may fail because an arc doesn't want to be deleted. Customizing the Arcs We think the arcs are not yet very customizable. In fact they are not even finished (we can't do a loop with only one node). Arc events When a deletion for an arc is requested, the arc.on_delete() method is called. If this method returns True (default), the arc will be deleted. Constraints system [work in progress] Three types of constraints are defined in the Graph class.A Python dictionary exists for each of those types, to save the rlated constraints. Arc constraint: self._arcs_constraints Node constraint: self._nodes_constraints Global constraint: self._global_constraints A constraint in the dictionary is in the form: self._ type _constraint = { 'constraint_name' : [ constraint_function , (parameters)]} TODO: write an example and continue explanations Loading and saving files using GraphXML What is GraphXML GraphXML is a XML specialization designed to save graphs. It is generic enough to save graphs with attributes of virtually any type (for the moment only basic types: int, string, floats). About Documentation Screenshots Get it! Project page Authors Copyright Home Feedback ...
http://www.gnu.org/savannah-checkouts/non-gnu/graphtool/documentation.html - [detail] - [similar]
PREV NEXT
Powered by Hyper Estraier 1.4.13, with 213330 documents and 1081132 words.