Changeset 997

Show
Ignore:
Timestamp:
09/06/06 02:24:06 (2 years ago)
Author:
arjanmol
Message:

Updated item removal.

Files:

Legend:

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

    r984 r997  
     12006-09-06  Arjan Molenaar  <arjan_at_yirdis_dot_nl> 
     2 
     3        * There have been several fixes from within the gaphas tree. 
     4        * util.py: new file. 
     5        * canvas.py: fixed remove behavior up to some degree (should still 
     6        handle handles and constraints). 
     7 
    182006-08-26  Arjan Molenaar  <arjan_at_yirdis_dot_nl> 
    29 
  • gaphas/trunk/demo.py

    r978 r997  
    212212    v.add(b) 
    213213 
     214    b = gtk.Button('Delete focused') 
     215 
     216    def on_clicked(button): 
     217        if view.focused_item: 
     218            canvas.remove(view.focused_item) 
     219            print 'items:', canvas.get_all_items() 
     220 
     221    b.connect('clicked', on_clicked) 
     222    v.add(b) 
     223 
    214224#    b = gtk.Button('Cursor') 
    215225# 
  • gaphas/trunk/gaphas/canvas.py

    r991 r997  
    7979            [] 
    8080            >>> i._canvas 
     81         
     82        TODO: Remove constraints on items connected to the removed item 
    8183        """ 
    8284        self._tree.remove(item) 
    8385        item.canvas = None 
     86 
     87        self._update_views((item,)) 
    8488        self._dirty_items.discard(item) 
    8589        self._dirty_matrix_items.discard(item) 
    8690         
    87  
    8891    def get_all_items(self): 
    8992        """Get a list of all items 
     
    164167            [<gaphas.item.Item ...>] 
    165168            >>> list(c.get_children(i)) 
    166             [<gaphas.item.Item ...>, <gaphas.item.Item ...>
     169            [<gaphas.item.Item ...>
    167170        """ 
    168171        return self._tree.get_children(item) 
     172 
     173    def get_connected_items(self, item): 
     174        """Return a set of items that are connected to @item. 
     175        The list contains tuples (item, handle). As a result an item may be 
     176        in the list more than once (depending on the number of handles that 
     177        are connected). If @item is connected to itself it will also appear 
     178        in the list. 
     179 
     180            >>> c = Canvas() 
     181            >>> from gaphas import item 
     182            >>> i = item.Line() 
     183            >>> c.add(i) 
     184            >>> ii = item.Line() 
     185            >>> c.add(ii) 
     186            >>> iii = item.Line() 
     187            >>> c.add (iii) 
     188            >>> i.handles()[0].connected_to = ii 
     189            >>> list(c.get_connected_items(i)) 
     190            [] 
     191            >>> ii.handles()[0].connected_to = iii 
     192            >>> list(c.get_connected_items(ii)) 
     193            [(<gaphas.item.Line ...>, <Handle object on (0, 0)>)] 
     194            >>> list(c.get_connected_items(iii)) 
     195            [(<gaphas.item.Line ...>, <Handle object on (0, 0)>)] 
     196        """ 
     197        connected_items = set() 
     198        for i in self.get_all_items(): 
     199            for h in i.handles(): 
     200                if h.connected_to is item: 
     201                    connected_items.add((i, h)) 
     202        return connected_items 
    169203 
    170204    def get_matrix_i2w(self, item, calculate=False): 
     
    254288    @async(single=True, priority=PRIORITY_HIGH_IDLE) 
    255289    def update(self): 
     290        """Update the canavs, if called from within a gtk-mainloop, the 
     291        update job is scheduled as idle job. 
     292        """ 
    256293        if not self._in_update: 
    257294            self.update_now() 
     
    405442if __name__ == '__main__': 
    406443    import doctest 
    407     doctest.testmod(
     444    doctest.testmod(optionflags=doctest.ELLIPSIS
    408445 
    409446# vim:sw=4:et 
  • gaphas/trunk/gaphas/constraint.py

    r989 r997  
    3232 
    3333    def variables(self): 
     34        """return an iterator which iterates over the variables that are 
     35        held by this constraint. 
     36        """ 
    3437        raise NotImplemented 
    3538 
    3639    def solve_for(self, var): 
     40        """Solve the constraint for a given variable. 
     41        The variable itself is updated. 
     42        """ 
    3743        raise NotImplemented 
    3844 
  • gaphas/trunk/gaphas/item.py

    r995 r997  
    381381        """ 
    382382        for c in self._orthogonal: 
    383             self.canvas.solver.remove(c) 
     383            self.canvas.solver.remove_constraint(c) 
    384384 
    385385    def split_segment(self, segment, parts=2): 
  • gaphas/trunk/gaphas/tree.py

    r945 r997  
    9797        """ 
    9898        # First remove children: 
    99         children = self._children[node] 
     99        children = list(self._children[node]) 
    100100        for c in children: 
    101101            self.remove(c) 
  • gaphas/trunk/gaphas/view.py

    r967 r997  
    328328 
    329329        # Make sure everything's updated 
    330         self.request_update(self.canvas.get_all_items()) 
     330        self.request_update(self._canvas.get_all_items()) 
    331331        a = self.allocation 
    332332        super(View, self).queue_draw_area(0, 0, a.width, a.height) 
     
    385385        assert self.canvas 
    386386        wx, wy = self.transform_point_c2w(x, y) 
    387         return self.canvas.get_matrix_w2i(item).transform_point(wx, wy) 
     387        return self._canvas.get_matrix_w2i(item).transform_point(wx, wy) 
    388388 
    389389    def transform_point_i2c(self, item, x, y): 
     
    391391        """ 
    392392        assert self.canvas 
    393         wx, wy = self.canvas.get_matrix_i2w(item).transform_point(x, y) 
     393        wx, wy = self._canvas.get_matrix_i2w(item).transform_point(x, y) 
    394394        return self.transform_point_w2c(wx, wy) 
    395395 
     
    473473        with_handles.add(self._focused_item) 
    474474 
     475        all_items = self._canvas.get_all_items() 
     476        removed = [i for i in items if i not in all_items] 
     477         
    475478        for i in items: 
    476479            self.queue_draw_item(i, handles=(i in with_handles)) 
     480 
     481        # Remove removed items: 
     482        for i in removed: 
     483            self.selected_items.discard(i) 
     484            if i is self.focused_item: 
     485                self.focused_item = None 
     486            if i is self.hovered_item: 
     487                self.hovered_item = None 
    477488 
    478489        # Pseudo-draw 
     
    552563 
    553564        # Force recalculation of the bounding boxes: 
    554         self.request_update(self.canvas.get_all_items()) 
     565        self.request_update(self._canvas.get_all_items()) 
    555566 
    556567        a = self.allocation