Changeset 1243

Show
Ignore:
Timestamp:
04/23/07 22:58:24 (2 years ago)
Author:
arj..@yirdis.nl
Message:
Files:

Legend:

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

    r1121 r1243  
     1 
     2[ for detailed log entries, see svn log ] 
     3 
    142006-11-20  arjan <arjan at yirdis dot nl> 
    25 
  • gaphor/trunk/gaphor/UML/tests/test_umllex.py

    r1121 r1243  
    22import unittest 
    33import gaphor 
     4from gaphor.UML.elementfactory import ElementFactory 
    45from gaphor.UML import * 
    56from gaphor.UML.umllex import * 
     
    89def dump_prop(prop): 
    910    m = attribute_pat.match(prop) 
    10     print m.groupdict() 
     11    #print m.groupdict() 
    1112 
    1213def dump_oper(oper): 
     
    1718        # set name to oper 
    1819        return 
    19     print g('vis'), g('name'), g('type'), g('mult_l'), g('mult_u'), g('tags') 
     20    #print g('vis'), g('name'), g('type'), g('mult_l'), g('mult_u'), g('tags') 
    2021    if g('params'): 
    2122        params = g('params') 
     
    2324            m = parameter_pat.match(params) 
    2425            g = m.group 
    25             print ' ', g('dir') or 'in', g('name'), g('type'), g('mult_l'), g('mult_u'), g('default'), g('tags') 
     26            #print ' ', g('dir') or 'in', g('name'), g('type'), g('mult_l'), g('mult_u'), g('default'), g('tags') 
    2627            params = g('rest') 
    2728 
     
    3435dump_oper('myfunc(aap:str[1] = "aap" { tag1, tag2 }, out two {tag3}): type') 
    3536 
     37 
     38element_factory = ElementFactory() 
     39element_factory.init(None) 
     40 
    3641class UmlLexTestCase(unittest.TestCase): 
    3742 
    38     def test_all(self): 
    39         element_factory = gaphor.resource(ElementFactory) 
     43    def setUp(self): 
     44        element_factory.flush() 
     45 
     46    def teardown(self): 
     47        element_factory.flush() 
     48 
     49    def test_parse_property_1(self): 
    4050        #log.set_log_level(log.INFO) 
    4151 
    42         print 'testing parse_property()...' 
     52        #print 'testing parse_property()...' 
    4353        a = element_factory.create(Property) 
    4454        assert len(element_factory.values()) == 1 
     
    5464        assert a.upperValue.value is None, a.upperValue.value  
    5565        assert a.defaultValue.value is None, a.defaultValue.value  
    56         assert a.taggedValue.value is None, a.taggedValue.value  
     66        assert not a.taggedValue, a.taggedValue 
    5767        s = render_property(a) 
    5868        parse_property(a, s) 
    5969        assert s == render_property(a) 
    6070 
     71        a.unlink() 
     72 
     73    def test_parse_property_2(self): 
    6174        # All features: 
    62         a.unlink() 
    6375        a = element_factory.create(Property) 
    6476 
     
    7183        assert a.upperValue.value == '*', a.upperValue.value  
    7284        assert a.defaultValue.value == '"aap"', a.defaultValue.value  
    73         assert a.taggedValue.value == 'static', a.taggedValue.value  
     85        assert a.taggedValue[0].value == 'static', a.taggedValue[0].value  
    7486        s = render_property(a) 
    7587        parse_property(a, s) 
    7688        assert s == render_property(a) 
    77         print render_property(a) 
    78  
     89        #print render_property(a) 
     90 
     91        a.unlink() 
     92 
     93    def test_parse_property_3(self): 
    7994        # Invalid syntax: 
    80         a.unlink() 
    8195        a = element_factory.create(Property) 
    8296 
     
    93107        parse_property(a, s) 
    94108        assert s == render_property(a) 
    95         print render_property(a) 
     109        #print render_property(a) 
    96110 
    97111        # Cleanup 
     
    100114        assert len(element_factory.values()) == 0 
    101115 
     116    def test_parse_property_4(self): 
    102117        # Association end: 
    103118 
     
    115130        assert not p.taggedValue or p.taggedValue.value is None, p.taggedValue.value  
    116131        p.unlink() 
    117  
     132        a.unlink() 
     133 
     134    def test_parse_property_5(self): 
     135        a = element_factory.create(Association) 
    118136        p = element_factory.create(Property) 
    119137        p.association = a 
     
    127145        assert not p.taggedValue or p.taggedValue.value is None, p.taggedValue.value  
    128146        p.unlink() 
    129  
     147        a.unlink() 
     148 
     149    def test_parse_property_6(self): 
     150        a = element_factory.create(Association) 
    130151        p = element_factory.create(Property) 
    131152        p.association = a 
     
    137158        assert p.upperValue.value == '2', p.upperValue.value  
    138159        assert not p.defaultValue or p.defaultValue.value is None, p.defaultValue.value  
    139         assert p.taggedValue.value == 'tag', p.taggedValue.value  
    140         p.unlink() 
    141  
     160        assert p.taggedValue[0].value == 'tag', p.taggedValue[0].value  
     161        p.unlink() 
     162        a.unlink() 
     163 
     164    def test_parse_property_7(self): 
     165        a = element_factory.create(Association) 
    142166        p = element_factory.create(Property) 
    143167        p.association = a 
     
    150174        assert p.upperValue.value == '2', p.upperValue.value  
    151175        assert not p.defaultValue or p.defaultValue.value is None, p.defaultValue.value  
    152         assert p.taggedValue.value == '''tag1, 
    153         tag2''', p.taggedValue.value  
    154         p.unlink() 
    155  
     176        assert p.taggedValue[0].value == 'tag1', p.taggedValue[0].value 
     177        assert p.taggedValue[1].value == 'tag2', p.taggedValue[1].value  
     178        p.unlink() 
     179        a.unlink() 
     180 
     181    def test_parse_property_8(self): 
     182        a = element_factory.create(Association) 
    156183        p = element_factory.create(Property) 
    157184        p.association = a 
     
    164191        assert p.upperValue.value == '*', p.upperValue.value  
    165192        assert not p.defaultValue or p.defaultValue.value is None, p.defaultValue.value  
    166         assert p.taggedValue.value == 'mytag', p.taggedValue.value  
    167         p.unlink() 
    168  
    169         # Cleanup 
    170         a.unlink() 
    171  
    172         print 'testing parse_operation()...' 
     193        assert p.taggedValue[0].value == 'mytag', p.taggedValue[0].value  
     194        p.unlink() 
     195 
     196        a.unlink() 
     197 
     198    def test_parse_operation_1(self): 
    173199        o = element_factory.create(Operation) 
    174200        assert len(element_factory.values()) == 1 
     
    182208        assert not o.formalParameter, o.formalParameter 
    183209        # 1 operation, 1 parameter, 4 literal strings. 
    184         assert len(element_factory.values()) == 6, len(element_factory.values()) 
    185         s = render_operation(o) 
    186         print render_operation(o) 
     210        assert len(element_factory.values()) == 5, len(element_factory.values()) 
     211        s = render_operation(o) 
     212        #print render_operation(o) 
    187213        parse_operation(o, s) 
    188214        assert s == render_operation(o) 
     
    195221        assert o.visibility == 'public' 
    196222        assert not o.formalParameter, o.formalParameter 
    197         assert len(element_factory.values()) == 6, len(element_factory.values()
    198         s = render_operation(o) 
    199         parse_operation(o, s) 
    200         assert s == render_operation(o) 
    201         print render_operation(o) 
    202  
     223        assert len(element_factory.values()) == 5, element_factory.values(
     224        s = render_operation(o) 
     225        parse_operation(o, s) 
     226        assert s == render_operation(o), render_operation(o) 
     227 
     228    def test_parse_operation_2_params(self): 
    203229        # Change the operation to support two parameters: 
    204230 
     231        o = element_factory.create(Operation) 
    205232        parse_operation(o, '# myfunc2 (a: str, b: int = 3 {  static}): myType2') 
    206233        assert o.name == 'myfunc2', o.name 
     
    211238        assert o.formalParameter[0].typeValue.value == 'str', o.formalParameter[0].typeValue.value 
    212239        assert o.formalParameter[0].defaultValue.value is None, o.formalParameter[0].defaultValue.value 
    213         assert o.formalParameter[0].taggedValue.value is None, o.formalParameter[0].taggedValue.value 
     240        assert not o.formalParameter[0].taggedValue, o.formalParameter[0].taggedValue 
    214241        assert o.formalParameter[1].name == 'b', o.formalParameter[1].name 
    215242        assert o.formalParameter[1].typeValue.value == 'int', o.formalParameter[1].typeValue.value 
    216243        assert o.formalParameter[1].defaultValue.value == '3', o.formalParameter[1].defaultValue.value 
    217         assert o.formalParameter[1].taggedValue.value == 'static', o.formalParameter[1].taggedValue.value 
     244        assert o.formalParameter[1].taggedValue[0].value == 'static', o.formalParameter[1].taggedValue[0].value 
    218245        # 1 operation, 3 parameters, 4 + 5*2 literal strings 
    219         assert len(element_factory.select(lambda e: isinstance(e, LiteralSpecification))) == 14, len(element_factory.select(lambda e: isinstance(e, LiteralSpecification))) 
    220         assert len(element_factory.values()) == 18, len(element_factory.values()) 
     246        assert len(element_factory.lselect(lambda e: isinstance(e, LiteralSpecification))) == 12, len(element_factory.lselect(lambda e: isinstance(e, LiteralSpecification))) 
     247        assert len(element_factory.values()) == 16, len(element_factory.values()) 
    221248        s = render_operation(o) 
    222249        parse_operation(o, s) 
    223250        assert s == render_operation(o) 
    224251 
    225         print render_operation(o) 
     252        #print render_operation(o) 
    226253 
    227254        # Change the operation to own one parameter: 
     
    235262        assert o.formalParameter[0].typeValue.value == 'node', o.formalParameter[0].typeValue.value 
    236263        assert o.formalParameter[0].defaultValue.value is None, o.formalParameter[0].defaultValue.value 
    237         assert o.formalParameter[0].taggedValue.value is None, o.formalParameter[0].taggedValue.value 
     264        assert not o.formalParameter[0].taggedValue, o.formalParameter[0].taggedValue 
    238265        # 1 operation, 2 parameters, 4 + 5 literal strings 
    239         assert len(element_factory.select(lambda e: isinstance(e, Operation))) == 1, len(element_factory.values()) 
    240         assert len(element_factory.select(lambda e: isinstance(e, Parameter))) == 2, len(element_factory.values()) 
    241         assert len(element_factory.select(lambda e: isinstance(e, LiteralSpecification))) == 9, len(element_factory.select(lambda e: isinstance(e, LiteralSpecification))) 
    242         assert len(element_factory.values()) == 12, len(element_factory.values()) 
    243         print render_operation(o) 
     266        assert len(element_factory.lselect(lambda e: isinstance(e, Operation))) == 1, len(element_factory.values()) 
     267        assert len(element_factory.lselect(lambda e: isinstance(e, Parameter))) == 2, len(element_factory.values()) 
     268        assert len(element_factory.lselect(lambda e: isinstance(e, LiteralSpecification))) == 7, len(element_factory.lselect(lambda e: isinstance(e, LiteralSpecification))) 
     269        assert len(element_factory.values()) == 10, len(element_factory.values()) 
     270        #print render_operation(o) 
    244271        s = render_operation(o) 
    245272        parse_operation(o, s) 
     
    250277        parse_operation(o, '- myfunc2: myType2') 
    251278 
    252         print 'done' 
    253  
     279        #print 'done' 
     280 
  • gaphor/trunk/gaphor/UML/umllex.py

    r1121 r1243  
    235235        p.upperValue.value = g('mult_u') 
    236236        # FIXME: Maybe add to Operation.ownedRule? 
    237         #if not p.taggedValue: 
    238         #    p.taggedValue = create(LiteralSpecification) 
    239         #p.taggedValue.value = g('tags') 
    240237        while self.taggedValue: 
    241238            self.taggedValue[0].unlink() 
     
    272269                p.defaultValue = create(LiteralSpecification) 
    273270            p.defaultValue.value = g('default') 
    274             while self.taggedValue: 
    275                 self.taggedValue[0].unlink() 
     271            while p.taggedValue: 
     272                p.taggedValue[0].unlink() 
     273            tags = g('tags') 
    276274            if tags: 
    277275                for t in map(str.strip, tags.split(',')): 
  • gaphor/trunk/gaphor/__init__.py

    r1219 r1243  
    2626# If the resource doesn't already exist, it is created, otherwise the existing 
    2727# resource is returned. 
    28 resource = Resource(initial_resources={ 
    29                         'Name': 'gaphor', 
    30                         'UserDataDir': user_data_dir, 
    31                         'ui.toolbox.classes': True, 
    32                     }) 
     28resource = Resource(initial_resources={ }) 
    3329 
    3430 
     
    5450    Application.init() 
    5551 
    56     main_window = resource('MainWindow') 
     52    main_window = Application.get_service('gui_manager').main_window 
     53    action_manager = Application.get_service('action_manager') 
    5754    if gaphor_file: 
    5855        main_window.set_filename(gaphor_file) 
    59         main_window.execute_action('FileRevert') 
     56        action_manager.execute('FileRevert') 
    6057    else: 
    61         main_window.execute_action('FileNew') 
     58        action_manager.execute('FileNew') 
    6259    Application.run() 
    6360    Application.shutdown() 
  • gaphor/trunk/gaphor/actions/diagramactions.py

    r1239 r1243  
    7777    id = 'ItemDiagramDrop' 
    7878 
     79    action_manager = inject('action_manager') 
     80 
    7981    def init(self, window): 
    8082        self._window = window 
    8183  
    8284    def execute(self): 
    83         self._window.execute_action('CreateLinks') 
     85        self.action_manager.execute('CreateLinks') 
    8486 
    8587register_action(DiagramDropAction) 
  • gaphor/trunk/gaphor/actions/itemactions.py

    r1241 r1243  
    711711    dependency_type = None 
    712712 
     713    action_manager = inject('action_manager') 
     714 
    713715    def init(self, window): 
    714716        self._window = window 
     
    728730            item.set_dependency_type(self.dependency_type) 
    729731            #item.auto_dependency = False 
    730             self._window.get_action_pool().execute('AutoDependency', active=False) 
     732            self.action_manager.execute('AutoDependency', active=False) 
    731733         
    732734 
     
    821823    Move attribute/operation down or up on the list. 
    822824    """ 
     825    action_manager = inject('action_manager') 
     826 
    823827    def _getItem(self): 
    824828        return self._window.get_current_diagram_view() \ 
     
    860864        move = getattr(self._getElements(cls, item), self.move_action) 
    861865        move(item.subject) 
    862         self._window.execute_action('ItemFocus') 
     866        self.action_manager.execute('ItemFocus') 
    863867 
    864868 
  • gaphor/trunk/gaphor/actions/mainactions.py

    r1239 r1243  
    7777 
    7878    element_factory = inject('element_factory') 
     79    action_manager = inject('action_manager') 
    7980 
    8081    def init(self, window): 
     
    107108 
    108109        self._window.select_element(diagram) 
    109         self._window.execute_action('OpenModelElement') 
     110        self.action_manager.execute('OpenModelElement') 
    110111 
    111112weave_method(NewAction.execute, ErrorHandlerAspect, message='Could not create a new model.') 
     
    120121 
    121122    element_factory = inject('element_factory') 
     123    action_manager = inject('action_manager') 
    122124 
    123125    def init(self, window): 
     
    134136 
    135137    def load(self, filename): 
    136         action_states = self._window.action_pool.get_action_states() 
     138        #action_states = self._window.action_pool.get_action_states() 
    137139        try: 
    138140            from gaphor import storage 
     
    143145            gc.collect() 
    144146            worker = GIdleThread(storage.load_generator(filename, self.element_factory), queue) 
    145             self._window.action_pool.insensivate_actions() 
     147            #self._window.action_pool.insensivate_actions() 
    146148            get_undo_manager().clear_undo_stack() 
    147149            get_undo_manager().clear_redo_stack() 
     
    163165 
    164166        finally: 
    165             self._window.action_pool.set_action_states(action_states) 
    166             self._window.action_pool.update_actions() 
     167            #self._window.action_pool.set_action_states(action_states) 
     168            self.action_manager.update_actions() 
    167169            try: 
    168170                win.destroy() 
     
    249251 
    250252                worker = GIdleThread(storage.save_generator(XMLWriter(out), self.element_factory), queue) 
    251                 action_states = self._window.action_pool.get_action_states() 
    252                 self._window.action_pool.insensivate_actions() 
     253                #action_states = self._window.action_pool.get_action_states() 
     254                #self._window.action_pool.insensivate_actions() 
    253255                worker.start() 
    254256                worker.wait() 
     
    261263 
    262264                # Restore states of actions 
    263                 self._window.action_pool.set_action_states(action_states) 
     265                #self._window.action_pool.set_action_states(action_states) 
    264266            finally: 
    265267                win.destroy() 
     
    397399 
    398400    def execute(self): 
    399         logo = gtk.gdk.pixbuf_new_from_file (resource('DataDir') + '/pixmaps/logo.png') 
     401        data_dir =  os.path.join(pkg_resources.get_distribution('gaphor').location, 'gaphor', 'data') 
     402        logo = gtk.gdk.pixbuf_new_from_file(os.path.join(data_dir, 'pixmaps', 'logo.png') 
    400403        version = Application.distribution.version 
    401404        about = gtk.Dialog("About Gaphor", self._window.get_window(), gtk.DIALOG_MODAL, (gtk.STOCK_OK, gtk.RESPONSE_OK)) 
     
    460463 
    461464    element_factory = inject('element_factory') 
     465    action_manager = inject('action_manager') 
    462466 
    463467    def init(self, window): 
     
    476480 
    477481        self._window.select_element(diagram) 
    478         self._window.execute_action('OpenModelElement') 
    479         self._window.execute_action('RenameModelElement') 
     482        self.action_manager.execute('OpenModelElement') 
     483        self.action_manager.execute('RenameModelElement') 
    480484 
    481485register_action(CreateDiagramAction, 'SelectRow') 
     
    628632 
    629633    # TODO: check if the diagram can undo. 
     634    action_manager = inject('action_manager') 
    630635 
    631636    def init(self, window): 
     
    638643        get_undo_manager().undo_transaction() 
    639644        self.update() 
    640         self._window.execute_action('UndoStack') 
     645        self.action_manager.execute('UndoStack') 
    641646 
    642647register_action(UndoAction, 'UndoStack') 
     
    649654    accel = 'C-r' 
    650655 
     656    action_manager = inject('action_manager') 
     657 
    651658    def init(self, window): 
    652659        self._window = window 
     
    658665        get_undo_manager().redo_transaction() 
    659666        #self.update() 
    660         self._window.execute_action('UndoStack') 
     667        self.action_manager.execute('UndoStack') 
    661668 
    662669register_action(RedoAction, 'UndoStack') 
     
    667674    """ 
    668675 
     676    action_manager = inject('action_manager') 
     677 
    669678    def init(self, window, filename): 
    670679        self._window = window 
     
    675684 
    676685    def execute(self): 
    677         revert_action = self._window.get_action_pool().get_action('FileRevert') 
     686        revert_action = self.action_manager.get_action('FileRevert') 
    678687        revert_action.load(self._filename) 
    679688 
     
    686695    gui_manager = inject('gui_manager') 
    687696    properties = inject('properties') 
    688      
     697    action_manager = inject('action_manager') 
     698 
    689699    def __init__(self, slot_id): 
    690700        DynamicMenu.__init__(self, slot_id) 
     
    697707            id = 'RecentFile_%d' % i 
    698708            try: 
    699                 action = window.get_action_pool().get_action(id) 
     709                action = self.action_manager.get_action(id) 
    700710                action._label='_%d. %s' % (i+1, f) 
    701711                action._tooltip='Load %s.' % f 
     
    705715                                          label='_%d. %s' % (i+1, f), 
    706716                                          tooltip='Load %s.' % f) 
    707                 window.get_action_pool().set_action(action) 
     717                self.action_manager.set_action(action) 
    708718            action.init(window, f) 
    709719            file_list.append(id) 
  • gaphor/trunk/gaphor/actions/tests/test_placementactions.py

    r1239 r1243  
    22import unittest 
    33from gaphor import resource 
    4 resource('DataDir', '') 
    54from gaphor.application import Application 
    65#from gaphor.ui.mainwindow import MainWindow 
  • gaphor/trunk/gaphor/data/plugins/checkmetamodel/checkmodel.py

    r1239 r1243  
    11# vim:sw=4:et 
    22 
    3 from gaphor import resource 
    43from gaphor import storage 
    54from gaphor import UML 
  • gaphor/trunk/gaphor/data/plugins/kidexport/xmi.kid

    r658 r1243  
    22 
    33<?python 
    4 import gaphor 
     4from gaphor.application import Application 
    55import time 
    6  
    7  
    8 elements = gaphor.resource('ElementFactory').select(
    9  
    10 topLevelPackage = [element for element in elements if not getattr(element, 'package', True)][0] 
     6import 
     7 
     8element_factory = Application.get_service('element_factory'
     9 
     10topLevelPackage = [element for element in element_factory.select() if not getattr(element, 'package', True)][0] 
    1111 
    1212def modelProcessNode(node): 
     
    1818     
    1919def getPackageChildNodes(package): 
    20     return [node for node in gaphor.resource('ElementFactory').select() if  
     20    return [node for node in element_factory.select() if  
    2121            hasattr(node, 'package') and node.package==package] 
    2222             
  • gaphor/trunk/gaphor/data/plugins/liveobjectbrowser/__init__.py

    r402 r1243  
    22 
    33import gaphor.plugin 
     4from gaphor.core import inject 
    45from browser import Browser 
    56import gaphor 
     
    78class LiveObjectBrowserAction(gaphor.plugin.Action): 
    89 
     10    element_factory = inject('element_factory') 
     11 
    912    def execute(self): 
    1013        browser = Browser() 
    11         browser.construct("resource", gaphor.resource('ElementFactory').select()) 
     14        browser.construct("resource", element_factory.lselect()) 
    1215        self.window.add_transient_window(browser) 
  • gaphor/trunk/gaphor/data/plugins/pynsource/__init__.py

    r402 r1243  
    99import gaphor 
    1010from gaphor.ui.abstractwindow import AbstractWindow 
     11from gaphor.core import inject 
    1112import gaphor.plugin 
    1213from gaphor.plugin import resource 
     
    1819 
    1920class PyNSourceAction(gaphor.plugin.Action): 
     21 
     22    action_manager = inject('action_manager') 
    2023 
    2124    def __init__(self): 
     
    5053        # Open and select the new diagram in the main window: 
    5154        main_window.select_element(engineer.diagram) 
    52         main_window.execute_action('OpenModelElement') 
     55        self.action_manager.execute('OpenModelElement') 
    5356 
    5457    def create_dialog(self): 
  • gaphor/trunk/gaphor/data/plugins/python/__init__.py

    r504 r1243  
    1111from gtk import FileSelection 
    1212 
    13 from gaphor import resource, plugin, UML 
     13from gaphor import plugin, UML 
     14from gaphor.core import inject 
    1415 
    1516from logilab.common.astng import astng, raw_building as builder, inspector, \ 
     
    1920class PythonReloadAction(plugin.Action): 
    2021     
     22    plugin_manager = inject('plugin_manager') 
     23 
    2124    def execute(self): 
    2225        reload(astng) 
     
    2427        reload(manager) 
    2528        reload(inspector) 
    26         resource('PluginManager').plugins['Python generator'].import_plugin() 
     29        self.plugin_manager.plugins['Python generator'].import_plugin() 
    2730 
    2831 
    2932class PythonExportAction(plugin.Action): 
     33 
     34    element_factory = inject('element_factory') 
    3035 
    3136    def __init__(self): 
     
    5257        pyconverter.reset(directory) 
    5358        # FIXME: should we export the root package ? 
    54         pyconverter.visit(root(resource(UML.ElementFactory))) 
     59        pyconverter.visit(root(self.element_factory)) 
    5560        print '**** done' 
    5661 
     
    5863class PythonImportAction(plugin.Action): 
    5964     
     65    element_factory = inject('element_factory') 
     66 
    6067    def execute(self): 
    6168        """gaphor's plugin main callback""" 
     
    7986        linker = inspector.Linker(module, tag=1) 
    8087        linker.visit(module) 
    81         fact = resource(UML.ElementFactory) 
     88        fact = self.element_factory 
    8289        root_package = root(fact) 
    8390        gapconverter.reset(fact, module) 
  • gaphor/trunk/gaphor/data/plugins/xmiexport/exportmodel.py

    r1121 r1243  
    33#from xml.sax.saxutils import XMLGenerator 
    44import time 
    5 import gaphor 
     5from gaphor.core import inject 
    66from gaphor import UML 
    77from gaphor.misc.xmlwriter import XMLWriter 
     
    2727class XMIExport(object): 
    2828     
     29    element_factory = inject('element_factory') 
     30 
    2931    # State diagram specific 
    3032    # ====================== 
     
    7274        xmi.startElement('UML:Package', attrs=attributes) 
    7375        xmi.startElement('UML:Namespace.ownedElement', attrs=XMLAttributes()) 
    74         classes = [element for element in gaphor.resource('ElementFactory').select()] 
     76        classes = [element for element in self.element_factory.select()] 
    7577        for item in classes: 
    7678            try: 
     
    395397        xmi.startElement('UML:Model', attrs=attributes) 
    396398        xmi.startElement('UML:Namespace.ownedElement', attrs=XMLAttributes()) 
    397         for element in gaphor.resource('ElementFactory').select(): 
     399        for element in self.element_factory.select(): 
    398400            #print element.__class__.__name__ 
    399401            try: 
  • gaphor/trunk/gaphor/diagram/tool.py

    r1241 r1243  
    245245        try: 
    246246            if Application.get_service('properties')('reset-tool-after-create', False): 
    247                 pool = Application.get_service('gui_manager').main_window.get_action_pool(
     247                pool = Application.get_service('action_manager'
    248248                pool.get_action('Pointer').active = True 
    249249            return gaphas.tool.PlacementTool.on_button_release(self, context, event) 
  • gaphor/trunk/gaphor/misc/action.py

    r1121 r1243  
    11#/usr/bin/env python 
    2 # vim: sw=4:et 
    3 """Handle menus in a MVC manner. 
     2""" 
     3Handle menus in a MVC manner. 
    44 
    55TODO: show tooltips in the status bar when a menu item is selected. 
     
    188188 
    189189class ActionPool(object): 
    190     """ActionPool contains a set of actions that can be executed. 
     190    """ 
     191    ActionPool contains a set of actions that can be executed. 
    191192    """ 
    192193 
     
    197198 
    198199    def get_action(self, action_id): 
    199         """Find the action, create a new one if not found. 
     200        """ 
     201        Find the action, create a new one if not found. 
    200202        """ 
    201203        global _registered_actions 
     
    226228 
    227229    def set_action(self, action): 
    228         """Force an action class into the action pool. This is mainly used 
     230        """ 
     231        Force an action class into the action pool. This is mainly used 
    229232        by Actions, which are instantiated from Slots. 
    230233        """ 
     
    232235 
    233236    def execute(self, action_id, active=_no_default): 
    234         """Run an action, identified by its action id. If the action does 
     237        """ 
     238        Run an action, identified by its action id. If the action does 
    235239        not yet exists, it is created. 
    236240 
     
    261265 
    262266    def get_actions(self): 
    263         """Return the actions currently in this action pool. These are only 
     267        """ 
     268        Return the actions currently in this action pool. These are only 
    264269        the actions that have been created through get_action(), not the 
    265270        actions registered by register_action(). 
     
    268273 
    269274    def get_action_states(self): 
    270         """Store the states (sensitivity) of each action currently in the pool. 
     275        """ 
     276        Store the states (sensitivity) of each action currently in the pool. 
    271277        States can be restored by calling set_action_states(). 
    272278        """ 
     
    278284 
    279285    def set_action_states(self, state): 
    280         """Restore state previously saved with get_action_states(). 
     286        """ 
     287        Restore state previously saved with get_action_states(). 
    281288        """ 
    282289        for action, sensitive in state.iteritems(): 
     
    284291 
    285292    def insensivate_actions(self): 
    286         """Make all actions insensitive. This can be used to ensure that 
     293        """ 
     294        Make all actions insensitive. This can be used to ensure that 
    287295        no actions occur during a special big (background) action, such as 
    288296        loading or saving a model. 
     
    292300 
    293301    def update_actions(self): 
    294         """Update all actions. 
     302        """ 
     303        Update all actions. 
    295304        """ 
    296305        for action in self.actions.itervalues(): 
     
    299308 
    300309def register_action(action, *dependency_ids): 
    301     """Register an action so it can be looked up for on demand menu creation. 
     310    """ 
     311    Register an action so it can be looked up for on demand menu creation. 
    302312    """ 
    303313    global _registered_actions 
     
    309319 
    310320def action_dependencies(action, *dependency_ids): 
    311     """Define a dependency for action. This means that if one of the 
     321    """ 
     322    Define a dependency for action. This means that if one of the 
    312323    dependency_ids actions is executed, action is requested to update its 
    313324    state. 
     
    326337 
    327338def register_slot(slot_id, slot_class=SlotMenu): 
    328     """Register a slot. If no slot_class is provided, the SlotMenu is used. 
     339    """ 
     340    Register a slot. If no slot_class is provided, the SlotMenu is used. 
    329341    """ 
    330342    global _registered_slots 
     
    333345 
    334346def register_action_for_slot(action, slot, *dependency_ids): 
    335     """Register an action class for a specific slot. 
     347    """ 
     348    Register an action class for a specific slot. 
    336349    """ 
    337350    global _registered_slot_actions 
     
    361374 
    362375def get_actions_for_slot(slot): 
    363     """Return a the action ids for a specific slot as a tuple-menu. 
     376    """ 
     377    Return a the action ids for a specific slot as a tuple-menu. 
    364378    E.g. 
    365379      ('DummyAction', 
     
    377391    return get_actions_tuple(_registered_slot_actions.get(slot) or {}) 
    378392 
     393 
     394# vim: sw=4:et 
  • gaphor/trunk/gaphor/services/pluginmanager.py

    r1239 r1243  
    3333from gaphor.interfaces import IService 
    3434 
    35 from gaphor import resource 
    3635from gaphor.parser import ParserException 
    3736from gaphor.misc.action import register_action_for_slot 
     
    376375        return self.plugins.values() 
    377376 
    378 # Make one default plugin manager 
    379 import gaphor 
    380 _default_plugin_manager = gaphor.resource(PluginManager) 
    381 del gaphor 
    382377 
    383378# vim:sw=4:et 
  • gaphor/trunk/gaphor/ui/abstractwindow.py

    r739 r1243  
    33import gobject, gtk 
    44import gaphor 
     5from gaphor.core import inject 
    56from gaphor.misc.signal import Signal 
    6 from gaphor.misc.logger import Logger 
    7 #from commandregistry import CommandRegistry 
    8 from gaphor.misc.action import Action, ActionPool, register_action 
     7#from gaphor.misc.logger import Logger 
     8from gaphor.misc.action import ActionPool 
    99from menufactory import MenuFactory 
    1010 
    11 class CloseAction(Action): 
    12     id = 'WindowClose' 
    13  
    14     def init(self, window): 
    15         pass 
    16  
    17 register_action(CloseAction) 
    1811 
    1912class AbstractWindow(object): 
     
    3730    toolbar = () 
    3831 
     32    action_manager = inject('action_manager') 
     33 
    3934    def __init__(self): 
    4035        self.__state = AbstractWindow.STATE_INIT 
     
    4540        self.statusbar = None 
    4641        self.accel_group = None 
    47         self.action_pool = ActionPool(self._action_initializer) 
    4842        self.menu_factory = None 
    4943 
     
    5650        return self.window 
    5751 
    58     def get_action_pool(self): 
    59         return self.action_pool 
     52#    def get_action_pool(self): 
     53#        return self.action_manager 
    6054 
    6155    def get_state(self): 
     
    6862        raise NotImplementedError, 'construct() should create GUI components.' 
    6963 
    70     def execute_action(self, action_id): 
    71         self.action_pool.execute(action_id) 
     64#    def execute_action(self, action_id): 
     65#        self.action_manager.execute(action_id) 
    7266 
    7367    def set_message(self, message): 
     
    118112#            #return True 
    119113 
    120     def _action_initializer(self, action): 
    121         try: 
    122             action.init(self) 
    123         except Exception, e: 
    124             lo