Changeset 1831

Show
Ignore:
Timestamp:
08/03/07 13:53:04 (1 year ago)
Author:
wrobe..@pld-linux.org
Message:

- implemented UMLAssociation model based on ListStore? model to manipulate

UML associations easily

- use UMLAssociation model for attributes GTK tree
- remove class attributes when 'backspace' is pressed

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • gaphor/trunk/gaphor/adapters/propertypages.py

    r1584 r1831  
    2020from gaphor.UML.umllex import parse_attribute, render_attribute 
    2121import gaphas.item 
     22 
     23 
     24class UMLAssociation(gtk.ListStore): 
     25    """ 
     26    UML association GTK model.  
     27    """ 
     28    def __init__(self, data): 
     29        """ 
     30        Create GTK model from UML association. 
     31 
     32        Parameters: 
     33 
     34            data: iterator of UML properties 
     35        """ 
     36        super(UMLAssociation, self).__init__(str, object) 
     37        for item in data: 
     38            self.append([item.render(), item]) 
     39        self.append(['', None]) 
     40 
     41 
     42    def remove(self, iter): 
     43        """ 
     44        Remove item from GTK model and destroy it. 
     45        """ 
     46        item = self[iter][1] 
     47        if item: 
     48            item.unlink() 
     49            super(UMLAssociation, self).remove(iter) 
     50 
     51 
     52def remove_on_keypress(tree, event): 
     53    """ 
     54    Remove selected items from GTK model on ``backspace`` keypress. 
     55    """ 
     56    k = gtk.gdk.keyval_name(event.keyval).lower() 
     57    if k == 'backspace': 
     58        model, iter = tree.get_selection().get_selected() 
     59        if iter: 
     60            model.remove(iter) 
     61 
    2262 
    2363class CommentItemPropertyPage(object): 
     
    268308 
    269309        # Attributes list store: 
    270         attributes = gtk.ListStore(str, object) 
    271          
    272         for attribute in self.context.subject.ownedAttribute: 
    273             if not attribute.association: 
    274                 attributes.append([attribute.render(), attribute]) 
    275         attributes.append(['', None]) 
    276          
     310        attrs = self.context.subject.ownedAttribute 
     311        attributes = UMLAssociation(a for a in attrs if not a.association) 
     312 
    277313        self.attributes = attributes 
    278314         
     
    285321        tag_column = gtk.TreeViewColumn('Attributes', renderer, text=0) 
    286322        tree_view.append_column(tag_column) 
     323 
     324        tree_view.connect('key_press_event', remove_on_keypress) 
    287325         
    288326        page.pack_start(tree_view) 
     
    306344 
    307345        # Delete attribute if both tag and value are empty 
    308         if not new_text and attr[1]: 
    309             attr[1].unlink() 
     346        if not new_text: 
    310347            self.attributes.remove(iter) 
    311348            return