Changeset 999

Show
Ignore:
Timestamp:
09/06/06 23:13:25 (2 years ago)
Author:
arjanmol
Message:

--

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • gaphas/trunk/ChangeLog

    r997 r999  
     12006-09-07  Arjan Molenaar  <arjan_at_yirdis_dot_nl> 
     2 
     3        * item.py, canvas.py: item removal (with connected handles) solved, 
     4        use a callback method on the handle. 
     5 
    162006-09-06  Arjan Molenaar  <arjan_at_yirdis_dot_nl> 
    27 
  • gaphas/trunk/README.txt

    r929 r999  
    3636 
    3737Stage 3: 
    38  - make double and triple click work. 
    39  - text edit tool (gtk.Edit in popup window?) 
     38 v make double and triple click work. 
     39 v text edit tool (gtk.Edit in popup window?) 
    4040 
    4141Stage n: 
     
    130130 
    131131 
     132Interaction 
     133----------- 
     134Interaction with the canvas view (visual component) is handled by tools. 
     135Although the default tools do a fair amount of work, in most cases you'll 
     136see that especially the way items connect with each other is not the way 
     137you want it. That's okay. HandleTool provides some hooks (connect, disconnect and glue) to implement custom connection behavior (in fact, the default implementation doesn't do any connecting at all. 
     138 
     139One of the problems you'll face is what to do when an item is removed from the 
     140canvas and there are other items (lines) connected to. This problem can be 
     141solved by providing a disconnect handler to the handle instance ones it is 
     142connected. A callable object (e.g. function) can be assigned to the handle. It 
     143is called at the moment the item it's connected to is removed from the canvas. 
     144 
     145 
    132146Files 
    133147===== 
  • gaphas/trunk/demo.py

    r997 r999  
    8787        handle._connect_constraint = LineConstraint(view.canvas, glue_item, glue_item.handles()[s], glue_item.handles()[(s+1)%4], item, handle) 
    8888        view.canvas.solver.add_constraint(handle._connect_constraint) 
     89        def handle_disconnect(): 
     90            view.canvas.solver.remove_constraint(handle._connect_constraint) 
     91            handle._connect_constraint = None 
     92        handle.disconnect = handle_disconnect 
    8993        return 
    9094 
  • gaphas/trunk/gaphas/canvas.py

    r998 r999  
    9595        by items, those references are not cleaned up). 
    9696 
    97         So far, this is not the way to do it... 
    98         """ 
    99         def disconnect(var): 
    100             for c in self._solver.constraints_with_variable(var): 
    101                 self._solver.remove_constraint(c) 
    102  
    103         #for i, h in self.get_connected_items(item): 
    104         #for h in item.handles(): 
    105         #    disconnect(h.x) 
    106         #    disconnect(h.y) 
    107         #    h.connected_to = None 
     97        This method implies the constraint used to keep the handle in place 
     98        is connected to Handle.connect_constraint. 
     99        """ 
     100        for i, h in self.get_connected_items(item): 
     101            #self._solver.remove_constraint(h.connect_constraint) 
     102            h.disconnect() 
     103            # Never mind.. 
     104            h.connected_to = None 
     105            h.disconnect = lambda: 0 
    108106 
    109107    def get_all_items(self): 
  • gaphas/trunk/gaphas/item.py

    r997 r999  
    1212class Handle(object): 
    1313    """Handles are used to support modifications of Items. 
     14 
     15    If the handle is connected to an item, the connected_to property should 
     16    refer to the item. A disconnect handler should be provided that handles 
     17    all disconnect behavior (e.g. clean up constraints and connected_to). 
    1418    """ 
    15  
     19     
    1620    x = solvable() 
    1721    y = solvable() 
     
    2731        self.visible = True 
    2832        self.connected_to = None 
     33        # The constraint used to keep the handle visually connected 
     34        self.disconnect = lambda: 0 
    2935 
    3036    def _set_pos(self, pos):