Changeset 1680

Show
Ignore:
Timestamp:
07/19/07 11:28:34 (1 year ago)
Author:
wrobe..@pld-linux.org
Message:

- it is up to application to create an item and add it to canvas, therefore

do not add an item onto canvas in PlacementTool?

- create item factory for demo application

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • gaphas/trunk/demo.py

    r1670 r1680  
    4343 
    4444 
     45def factory(view, cls): 
     46    """ 
     47    Simple canvas item factory. 
     48    """ 
     49    def wrapper(): 
     50        item = cls() 
     51        view.canvas.add(item) 
     52        return item 
     53    return wrapper 
     54 
     55 
    4556class MyBox(Box): 
    4657    """Box with an example connection protocol. 
     
    109120    def on_clicked(button, view): 
    110121        #view.window.set_cursor(gtk.gdk.Cursor(gtk.gdk.CROSSHAIR)) 
    111         view.tool.grab(PlacementTool(MyBox, HandleTool(), 2)) 
     122        view.tool.grab(PlacementTool(factory(view, MyBox), HandleTool(), 2)) 
    112123 
    113124    b.connect('clicked', on_clicked, view) 
     
    117128 
    118129    def on_clicked(button): 
    119         view.tool.grab(PlacementTool(MyLine, HandleTool(), 1)) 
     130        view.tool.grab(PlacementTool(factory(view, MyLine), HandleTool(), 1)) 
    120131 
    121132    b.connect('clicked', on_clicked) 
  • gaphas/trunk/gaphas/tool.py

    r1670 r1680  
    589589        canvas = view.canvas 
    590590        item = self._factory() 
    591         if item not in canvas.get_all_items(): 
    592             canvas.add(item) 
    593             x, y = view.get_matrix_v2i(item).transform_point(x, y) 
    594             item.matrix.translate(x, y) 
     591        x, y = view.get_matrix_v2i(item).transform_point(x, y) 
     592        item.matrix.translate(x, y) 
    595593        return item 
    596594