Changeset 1335

Show
Ignore:
Timestamp:
06/05/07 23:02:25 (1 year ago)
Author:
arj..@yirdis.nl
Message:

Added more property pages

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • gaphor/trunk/TODO

    r1322 r1335  
    66 - bug in zope.component package: in zope.component.globalregistry.py zope.testing is included.  This package is only a dependency for the [test] setting. zope.testing is not mandatory. 
    77 Use a more recent version 
     8 
     9 - Figure out how to allow users to split segments. 
    810 
    911 - allow comments to render multi-line. 
  • gaphor/trunk/gaphor/adapters/propertypages.py

    r1322 r1335  
    1818from zope import interface, component 
    1919from gaphor import UML 
     20import gaphas.item 
    2021 
    2122class NamedItemPropertyPage(object): 
     
    133134 
    134135 
    135 class AttributesPropertyPage(object): 
     136class AttributesPage(object): 
    136137    """ 
    137138    An editor for attributes associated with classes and interfaces 
     
    147148 
    148149    def __init__(self, context): 
    149         super(AttributesPropertyPage, self).__init__() 
     150        super(AttributesPage, self).__init__() 
    150151        self.context = context 
    151152         
     
    218219            attr[0] = attr[1].render() 
    219220 
    220 component.provideAdapter(AttributesPropertyPage, name='Attributes') 
    221  
    222  
    223 class OperationsPropertyPage(object): 
     221component.provideAdapter(AttributesPage, name='Attributes') 
     222 
     223 
     224class OperationsPage(object): 
    224225    """ 
    225226    An editor for operations associated with classes and interfaces 
     
    235236 
    236237    def __init__(self, context): 
    237         super(OperationsPropertyPage, self).__init__() 
     238        super(OperationsPage, self).__init__() 
    238239        self.context = context 
    239240         
     
    306307            attr[0] = attr[1].render() 
    307308 
    308 component.provideAdapter(OperationsPropertyPage, name='Operations') 
     309component.provideAdapter(OperationsPage, name='Operations') 
    309310 
    310311 
     
    383384 
    384385 
     386class DependencyPropertyPage(object): 
     387    """ 
     388    An editor for tagged values associated with elements. 
     389 
     390    Tagged values are stored in a ListSore: tag, value, taggedValue. taggedValue 
     391    is an UML model element (hidden). 
     392    """ 
     393 
     394    interface.implements(IPropertyPage) 
     395    component.adapts(items.DependencyItem) 
     396 
     397    dependency_types = ( 
     398        (_('Dependency'), UML.Dependency), 
     399        (_('Usage'), UML.Usage), 
     400        (_('Realization'), UML.Realization)) 
     401 
     402    def __init__(self, context): 
     403        super(DependencyPropertyPage, self).__init__() 
     404        self.context = context 
     405        self.size_group = gtk.SizeGroup(gtk.SIZE_GROUP_HORIZONTAL) 
     406         
     407    def construct(self): 
     408        page = gtk.VBox() 
     409 
     410        hbox = gtk.HBox() 
     411        label = gtk.Label(_('Dependency type')) 
     412        label.set_justify(gtk.JUSTIFY_LEFT) 
     413        self.size_group.add_widget(label) 
     414        hbox.pack_start(label, expand=False) 
     415 
     416        dependency_type = gtk.ListStore(str) 
     417         
     418        for t, l in self.dependency_types: 
     419            dependency_type.append([t]) 
     420         
     421        self.dependency_type = dependency_type 
     422         
     423        combo = gtk.ComboBox(dependency_type) 
     424        cell = gtk.CellRendererText() 
     425        combo.pack_start(cell, True) 
     426        combo.add_attribute(cell, 'text', 0) 
     427        combo.connect('changed', self._on_dependency_type_change) 
     428        self.combo = combo 
     429 
     430        hbox.pack_start(combo, expand=False) 
     431 
     432        page.pack_start(hbox, expand=False) 
     433 
     434        hbox = gtk.HBox() 
     435 
     436        label = gtk.Label(_('Automatic')) 
     437        label.set_justify(gtk.JUSTIFY_LEFT) 
     438        self.size_group.add_widget(label) 
     439        hbox.pack_start(label, expand=False) 
     440 
     441        button = gtk.CheckButton() 
     442        button.set_active(self.context.auto_dependency) 
     443        button.connect('toggled', self._on_auto_dependency_change) 
     444        hbox.pack_start(button) 
     445 
     446        page.pack_start(hbox, expand=False) 
     447 
     448        page.show_all() 
     449 
     450        self.update() 
     451 
     452        return page 
     453 
     454    def update(self): 
     455        for index, (_, dep_type) in enumerate(self.dependency_types): 
     456            if dep_type is self.context.dependency_type: 
     457                self.combo.set_active(index) 
     458                break 
     459 
     460    def _on_dependency_type_change(self, combo): 
     461        self.context.dependency_type = self.dependency_types[combo.get_active()][1] 
     462 
     463    def _on_auto_dependency_change(self, button): 
     464        self.context.auto_dependency = button.get_active() 
     465 
     466 
     467component.provideAdapter(DependencyPropertyPage, name='Properties') 
     468 
     469 
     470class AssociationPropertyPage(NamedItemPropertyPage): 
     471    """ 
     472    """ 
     473 
     474    interface.implements(IPropertyPage) 
     475    component.adapts(items.AssociationItem) 
     476 
     477    def __init__(self, context): 
     478        super(AssociationPropertyPage, self).__init__() 
     479        self.context = context 
     480        self.size_group = gtk.SizeGroup(gtk.SIZE_GROUP_HORIZONTAL) 
     481         
     482    def construct(self): 
     483        page = super(AssociationPropertyPage, self).construct() 
     484        return page 
     485 
     486        hbox = gtk.HBox() 
     487        label = gtk.Label(_('Dependency type')) 
     488        label.set_justify(gtk.JUSTIFY_LEFT) 
     489        self.size_group.add_widget(label) 
     490        hbox.pack_start(label, expand=False) 
     491 
     492        dependency_type = gtk.ListStore(str) 
     493         
     494        for t, l in self.dependency_types: 
     495            dependency_type.append([t]) 
     496         
     497        self.dependency_type = dependency_type 
     498         
     499        combo = gtk.ComboBox(dependency_type) 
     500        cell = gtk.CellRendererText() 
     501        combo.pack_start(cell, True) 
     502        combo.add_attribute(cell, 'text', 0) 
     503        combo.connect('changed', self._on_dependency_type_change) 
     504        self.combo = combo 
     505 
     506        hbox.pack_start(combo, expand=False) 
     507 
     508        page.pack_start(hbox, expand=False) 
     509 
     510        hbox = gtk.HBox() 
     511 
     512        label = gtk.Label(_('Automatic')) 
     513        label.set_justify(gtk.JUSTIFY_LEFT) 
     514        self.size_group.add_widget(label) 
     515        hbox.pack_start(label, expand=False) 
     516 
     517        button = gtk.CheckButton() 
     518        button.set_active(self.context.auto_dependency) 
     519        button.connect('toggled', self._on_auto_dependency_change) 
     520        hbox.pack_start(button) 
     521 
     522        page.pack_start(hbox, expand=False) 
     523 
     524        page.show_all() 
     525 
     526        self.update() 
     527 
     528        return page 
     529 
     530    def update(self): 
     531        for index, (_, dep_type) in enumerate(self.dependency_types): 
     532            if dep_type is self.context.dependency_type: 
     533                self.combo.set_active(index) 
     534                break 
     535 
     536    def _on_dependency_type_change(self, combo): 
     537        self.context.dependency_type = self.dependency_types[combo.get_active()][1] 
     538 
     539    def _on_auto_dependency_change(self, button): 
     540        self.context.auto_dependency = button.get_active() 
     541 
     542component.provideAdapter(AssociationPropertyPage, name='Properties') 
     543 
     544 
     545class LineStylePage(object): 
     546    """ 
     547    Basic line style properties: color, orthogonal, etc. 
     548    """ 
     549 
     550    interface.implements(IPropertyPage) 
     551    component.adapts(gaphas.item.Line) 
     552 
     553    def __init__(self, context): 
     554        super(LineStylePage, self).__init__() 
     555        self.context = context 
     556        self.size_group = gtk.SizeGroup(gtk.SIZE_GROUP_HORIZONTAL) 
     557         
     558    def construct(self): 
     559        page = gtk.VBox() 
     560 
     561        hbox = gtk.HBox() 
     562        label = gtk.Label(_('Orthogonal')) 
     563        label.set_justify(gtk.JUSTIFY_LEFT) 
     564        self.size_group.add_widget(label) 
     565        hbox.pack_start(label, expand=False) 
     566 
     567        button = gtk.CheckButton() 
     568        button.set_active(self.context.orthogonal) 
     569        button.connect('toggled', self._on_orthogonal_change) 
     570        hbox.pack_start(button) 
     571 
     572        page.pack_start(hbox, expand=False) 
     573 
     574        hbox = gtk.HBox() 
     575        label = gtk.Label(_('horizontal')) 
     576        label.set_justify(gtk.JUSTIFY_LEFT) 
     577        self.size_group.add_widget(label) 
     578        hbox.pack_start(label, expand=False) 
     579 
     580        button = gtk.CheckButton() 
     581        button.set_active(self.context.horizontal) 
     582        button.connect('toggled', self._on_horizontal_change) 
     583        hbox.pack_start(button) 
     584 
     585        page.pack_start(hbox, expand=False) 
     586 
     587        page.show_all() 
     588 
     589        return page 
     590 
     591    def _on_orthogonal_change(self, button): 
     592        self.context.orthogonal = button.get_active() 
     593 
     594    def _on_horizontal_change(self, button): 
     595        self.context.horizontal = button.get_active() 
     596 
     597component.provideAdapter(LineStylePage, name='Style') 
     598 
     599 
    385600# vim:sw=4:et:ai 
  • gaphor/trunk/gaphor/diagram/dependency.py

    r1241 r1335  
    5454    # we need to be very strict here 
    5555    __stereotype__ = { 
    56         'use':        lambda self: self.dependency_type == UML.Usage, 
    57         'realize':    lambda self: self.dependency_type == UML.Realization, 
    58         'implements': lambda self: self.dependency_type == UML.Implementation, 
     56        'use':        lambda self: self._dependency_type == UML.Usage, 
     57        'realize':    lambda self: self._dependency_type == UML.Realization, 
     58        'implements': lambda self: self._dependency_type == UML.Implementation, 
    5959    } 
    6060 
     
    7474        DiagramLine.__init__(self, id) 
    7575 
    76         self.dependency_type = UML.Dependency 
     76        self._dependency_type = UML.Dependency 
    7777        self.auto_dependency = True 
    7878        self._dash_style = True 
     
    8080    def save(self, save_func): 
    8181        DiagramLine.save(self, save_func) 
    82         save_func('dependency_type', self.dependency_type.__name__) 
     82        save_func('dependency_type', self._dependency_type.__name__) 
    8383        save_func('auto_dependency', self.auto_dependency) 
    8484 
     
    102102 
    103103    def get_dependency_type(self): 
    104         return self.dependency_type 
     104        return self._dependency_type 
    105105 
    106106 
     
    108108        if not dependency_type and self.auto_dependency: 
    109109            dependency_type = self.determine_dependency_type(self.head.connected_to, self.tail.connected_to) 
    110         self.dependency_type = dependency_type 
     110        self._dependency_type = dependency_type 
    111111        self.request_update() 
    112112 
     113    dependency_type = property(lambda s: s._dependency_type, 
     114                               set_dependency_type, set_dependency_type) 
    113115 
    114116    def update(self, context): 
     
    116118 
    117119        from interface import InterfaceItem 
    118         dependency_type = self.dependency_type 
     120        dependency_type = self._dependency_type 
    119121        c1 = self.head.connected_to 
    120122        if c1 and dependency_type is UML.Usage \