Changeset 1243
- Timestamp:
- 04/23/07 22:58:24 (2 years ago)
- Files:
-
- gaphor/trunk/ChangeLog (modified) (1 diff)
- gaphor/trunk/gaphor/UML/tests/test_umllex.py (modified) (19 diffs)
- gaphor/trunk/gaphor/UML/umllex.py (modified) (2 diffs)
- gaphor/trunk/gaphor/__init__.py (modified) (2 diffs)
- gaphor/trunk/gaphor/actions/diagramactions.py (modified) (1 diff)
- gaphor/trunk/gaphor/actions/itemactions.py (modified) (4 diffs)
- gaphor/trunk/gaphor/actions/mainactions.py (modified) (20 diffs)
- gaphor/trunk/gaphor/actions/tests/test_placementactions.py (modified) (1 diff)
- gaphor/trunk/gaphor/data/plugins/checkmetamodel/checkmodel.py (modified) (1 diff)
- gaphor/trunk/gaphor/data/plugins/kidexport/xmi.kid (modified) (2 diffs)
- gaphor/trunk/gaphor/data/plugins/liveobjectbrowser/__init__.py (modified) (2 diffs)
- gaphor/trunk/gaphor/data/plugins/pynsource/__init__.py (modified) (3 diffs)
- gaphor/trunk/gaphor/data/plugins/python/__init__.py (modified) (6 diffs)
- gaphor/trunk/gaphor/data/plugins/xmiexport/exportmodel.py (modified) (4 diffs)
- gaphor/trunk/gaphor/diagram/tool.py (modified) (1 diff)
- gaphor/trunk/gaphor/misc/action.py (modified) (16 diffs)
- gaphor/trunk/gaphor/services/pluginmanager.py (modified) (2 diffs)
- gaphor/trunk/gaphor/ui/abstractwindow.py (modified) (7 diffs)
- gaphor/trunk/gaphor/ui/diagramtab.py (modified) (4 diffs)
- gaphor/trunk/gaphor/ui/diagramview.py (modified) (2 diffs)
- gaphor/trunk/gaphor/ui/mainwindow.py (modified) (7 diffs)
- gaphor/trunk/setup.py (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
gaphor/trunk/ChangeLog
r1121 r1243 1 2 [ for detailed log entries, see svn log ] 3 1 4 2006-11-20 arjan <arjan at yirdis dot nl> 2 5 gaphor/trunk/gaphor/UML/tests/test_umllex.py
r1121 r1243 2 2 import unittest 3 3 import gaphor 4 from gaphor.UML.elementfactory import ElementFactory 4 5 from gaphor.UML import * 5 6 from gaphor.UML.umllex import * … … 8 9 def dump_prop(prop): 9 10 m = attribute_pat.match(prop) 10 print m.groupdict()11 #print m.groupdict() 11 12 12 13 def dump_oper(oper): … … 17 18 # set name to oper 18 19 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') 20 21 if g('params'): 21 22 params = g('params') … … 23 24 m = parameter_pat.match(params) 24 25 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') 26 27 params = g('rest') 27 28 … … 34 35 dump_oper('myfunc(aap:str[1] = "aap" { tag1, tag2 }, out two {tag3}): type') 35 36 37 38 element_factory = ElementFactory() 39 element_factory.init(None) 40 36 41 class UmlLexTestCase(unittest.TestCase): 37 42 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): 40 50 #log.set_log_level(log.INFO) 41 51 42 print 'testing parse_property()...'52 #print 'testing parse_property()...' 43 53 a = element_factory.create(Property) 44 54 assert len(element_factory.values()) == 1 … … 54 64 assert a.upperValue.value is None, a.upperValue.value 55 65 assert a.defaultValue.value is None, a.defaultValue.value 56 assert a.taggedValue.value is None, a.taggedValue.value66 assert not a.taggedValue, a.taggedValue 57 67 s = render_property(a) 58 68 parse_property(a, s) 59 69 assert s == render_property(a) 60 70 71 a.unlink() 72 73 def test_parse_property_2(self): 61 74 # All features: 62 a.unlink()63 75 a = element_factory.create(Property) 64 76 … … 71 83 assert a.upperValue.value == '*', a.upperValue.value 72 84 assert a.defaultValue.value == '"aap"', a.defaultValue.value 73 assert a.taggedValue .value == 'static', a.taggedValue.value85 assert a.taggedValue[0].value == 'static', a.taggedValue[0].value 74 86 s = render_property(a) 75 87 parse_property(a, s) 76 88 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): 79 94 # Invalid syntax: 80 a.unlink()81 95 a = element_factory.create(Property) 82 96 … … 93 107 parse_property(a, s) 94 108 assert s == render_property(a) 95 print render_property(a)109 #print render_property(a) 96 110 97 111 # Cleanup … … 100 114 assert len(element_factory.values()) == 0 101 115 116 def test_parse_property_4(self): 102 117 # Association end: 103 118 … … 115 130 assert not p.taggedValue or p.taggedValue.value is None, p.taggedValue.value 116 131 p.unlink() 117 132 a.unlink() 133 134 def test_parse_property_5(self): 135 a = element_factory.create(Association) 118 136 p = element_factory.create(Property) 119 137 p.association = a … … 127 145 assert not p.taggedValue or p.taggedValue.value is None, p.taggedValue.value 128 146 p.unlink() 129 147 a.unlink() 148 149 def test_parse_property_6(self): 150 a = element_factory.create(Association) 130 151 p = element_factory.create(Property) 131 152 p.association = a … … 137 158 assert p.upperValue.value == '2', p.upperValue.value 138 159 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) 142 166 p = element_factory.create(Property) 143 167 p.association = a … … 150 174 assert p.upperValue.value == '2', p.upperValue.value 151 175 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) 156 183 p = element_factory.create(Property) 157 184 p.association = a … … 164 191 assert p.upperValue.value == '*', p.upperValue.value 165 192 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): 173 199 o = element_factory.create(Operation) 174 200 assert len(element_factory.values()) == 1 … … 182 208 assert not o.formalParameter, o.formalParameter 183 209 # 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) 187 213 parse_operation(o, s) 188 214 assert s == render_operation(o) … … 195 221 assert o.visibility == 'public' 196 222 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): 203 229 # Change the operation to support two parameters: 204 230 231 o = element_factory.create(Operation) 205 232 parse_operation(o, '# myfunc2 (a: str, b: int = 3 { static}): myType2') 206 233 assert o.name == 'myfunc2', o.name … … 211 238 assert o.formalParameter[0].typeValue.value == 'str', o.formalParameter[0].typeValue.value 212 239 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.value240 assert not o.formalParameter[0].taggedValue, o.formalParameter[0].taggedValue 214 241 assert o.formalParameter[1].name == 'b', o.formalParameter[1].name 215 242 assert o.formalParameter[1].typeValue.value == 'int', o.formalParameter[1].typeValue.value 216 243 assert o.formalParameter[1].defaultValue.value == '3', o.formalParameter[1].defaultValue.value 217 assert o.formalParameter[1].taggedValue .value == 'static', o.formalParameter[1].taggedValue.value244 assert o.formalParameter[1].taggedValue[0].value == 'static', o.formalParameter[1].taggedValue[0].value 218 245 # 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()) == 1 8, 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()) 221 248 s = render_operation(o) 222 249 parse_operation(o, s) 223 250 assert s == render_operation(o) 224 251 225 print render_operation(o)252 #print render_operation(o) 226 253 227 254 # Change the operation to own one parameter: … … 235 262 assert o.formalParameter[0].typeValue.value == 'node', o.formalParameter[0].typeValue.value 236 263 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.value264 assert not o.formalParameter[0].taggedValue, o.formalParameter[0].taggedValue 238 265 # 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()) == 1 2, 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) 244 271 s = render_operation(o) 245 272 parse_operation(o, s) … … 250 277 parse_operation(o, '- myfunc2: myType2') 251 278 252 print 'done'253 279 #print 'done' 280 gaphor/trunk/gaphor/UML/umllex.py
r1121 r1243 235 235 p.upperValue.value = g('mult_u') 236 236 # FIXME: Maybe add to Operation.ownedRule? 237 #if not p.taggedValue:238 # p.taggedValue = create(LiteralSpecification)239 #p.taggedValue.value = g('tags')240 237 while self.taggedValue: 241 238 self.taggedValue[0].unlink() … … 272 269 p.defaultValue = create(LiteralSpecification) 273 270 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') 276 274 if tags: 277 275 for t in map(str.strip, tags.split(',')): gaphor/trunk/gaphor/__init__.py
r1219 r1243 26 26 # If the resource doesn't already exist, it is created, otherwise the existing 27 27 # resource is returned. 28 resource = Resource(initial_resources={ 29 'Name': 'gaphor', 30 'UserDataDir': user_data_dir, 31 'ui.toolbox.classes': True, 32 }) 28 resource = Resource(initial_resources={ }) 33 29 34 30 … … 54 50 Application.init() 55 51 56 main_window = resource('MainWindow') 52 main_window = Application.get_service('gui_manager').main_window 53 action_manager = Application.get_service('action_manager') 57 54 if gaphor_file: 58 55 main_window.set_filename(gaphor_file) 59 main_window.execute_action('FileRevert')56 action_manager.execute('FileRevert') 60 57 else: 61 main_window.execute_action('FileNew')58 action_manager.execute('FileNew') 62 59 Application.run() 63 60 Application.shutdown() gaphor/trunk/gaphor/actions/diagramactions.py
r1239 r1243 77 77 id = 'ItemDiagramDrop' 78 78 79 action_manager = inject('action_manager') 80 79 81 def init(self, window): 80 82 self._window = window 81 83 82 84 def execute(self): 83 self. _window.execute_action('CreateLinks')85 self.action_manager.execute('CreateLinks') 84 86 85 87 register_action(DiagramDropAction) gaphor/trunk/gaphor/actions/itemactions.py
r1241 r1243 711 711 dependency_type = None 712 712 713 action_manager = inject('action_manager') 714 713 715 def init(self, window): 714 716 self._window = window … … 728 730 item.set_dependency_type(self.dependency_type) 729 731 #item.auto_dependency = False 730 self. _window.get_action_pool().execute('AutoDependency', active=False)732 self.action_manager.execute('AutoDependency', active=False) 731 733 732 734 … … 821 823 Move attribute/operation down or up on the list. 822 824 """ 825 action_manager = inject('action_manager') 826 823 827 def _getItem(self): 824 828 return self._window.get_current_diagram_view() \ … … 860 864 move = getattr(self._getElements(cls, item), self.move_action) 861 865 move(item.subject) 862 self. _window.execute_action('ItemFocus')866 self.action_manager.execute('ItemFocus') 863 867 864 868 gaphor/trunk/gaphor/actions/mainactions.py
r1239 r1243 77 77 78 78 element_factory = inject('element_factory') 79 action_manager = inject('action_manager') 79 80 80 81 def init(self, window): … … 107 108 108 109 self._window.select_element(diagram) 109 self. _window.execute_action('OpenModelElement')110 self.action_manager.execute('OpenModelElement') 110 111 111 112 weave_method(NewAction.execute, ErrorHandlerAspect, message='Could not create a new model.') … … 120 121 121 122 element_factory = inject('element_factory') 123 action_manager = inject('action_manager') 122 124 123 125 def init(self, window): … … 134 136 135 137 def load(self, filename): 136 action_states = self._window.action_pool.get_action_states()138 #action_states = self._window.action_pool.get_action_states() 137 139 try: 138 140 from gaphor import storage … … 143 145 gc.collect() 144 146 worker = GIdleThread(storage.load_generator(filename, self.element_factory), queue) 145 self._window.action_pool.insensivate_actions()147 #self._window.action_pool.insensivate_actions() 146 148 get_undo_manager().clear_undo_stack() 147 149 get_undo_manager().clear_redo_stack() … … 163 165 164 166 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() 167 169 try: 168 170 win.destroy() … … 249 251 250 252 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() 253 255 worker.start() 254 256 worker.wait() … … 261 263 262 264 # Restore states of actions 263 self._window.action_pool.set_action_states(action_states)265 #self._window.action_pool.set_action_states(action_states) 264 266 finally: 265 267 win.destroy() … … 397 399 398 400 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') 400 403 version = Application.distribution.version 401 404 about = gtk.Dialog("About Gaphor", self._window.get_window(), gtk.DIALOG_MODAL, (gtk.STOCK_OK, gtk.RESPONSE_OK)) … … 460 463 461 464 element_factory = inject('element_factory') 465 action_manager = inject('action_manager') 462 466 463 467 def init(self, window): … … 476 480 477 481 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') 480 484 481 485 register_action(CreateDiagramAction, 'SelectRow') … … 628 632 629 633 # TODO: check if the diagram can undo. 634 action_manager = inject('action_manager') 630 635 631 636 def init(self, window): … … 638 643 get_undo_manager().undo_transaction() 639 644 self.update() 640 self. _window.execute_action('UndoStack')645 self.action_manager.execute('UndoStack') 641 646 642 647 register_action(UndoAction, 'UndoStack') … … 649 654 accel = 'C-r' 650 655 656 action_manager = inject('action_manager') 657 651 658 def init(self, window): 652 659 self._window = window … … 658 665 get_undo_manager().redo_transaction() 659 666 #self.update() 660 self. _window.execute_action('UndoStack')667 self.action_manager.execute('UndoStack') 661 668 662 669 register_action(RedoAction, 'UndoStack') … … 667 674 """ 668 675 676 action_manager = inject('action_manager') 677 669 678 def init(self, window, filename): 670 679 self._window = window … … 675 684 676 685 def execute(self): 677 revert_action = self. _window.get_action_pool().get_action('FileRevert')686 revert_action = self.action_manager.get_action('FileRevert') 678 687 revert_action.load(self._filename) 679 688 … … 686 695 gui_manager = inject('gui_manager') 687 696 properties = inject('properties') 688 697 action_manager = inject('action_manager') 698 689 699 def __init__(self, slot_id): 690 700 DynamicMenu.__init__(self, slot_id) … … 697 707 id = 'RecentFile_%d' % i 698 708 try: 699 action = window.get_action_pool().get_action(id)709 action = self.action_manager.get_action(id) 700 710 action._label='_%d. %s' % (i+1, f) 701 711 action._tooltip='Load %s.' % f … … 705 715 label='_%d. %s' % (i+1, f), 706 716 tooltip='Load %s.' % f) 707 window.get_action_pool().set_action(action)717 self.action_manager.set_action(action) 708 718 action.init(window, f) 709 719 file_list.append(id) gaphor/trunk/gaphor/actions/tests/test_placementactions.py
r1239 r1243 2 2 import unittest 3 3 from gaphor import resource 4 resource('DataDir', '')5 4 from gaphor.application import Application 6 5 #from gaphor.ui.mainwindow import MainWindow gaphor/trunk/gaphor/data/plugins/checkmetamodel/checkmodel.py
r1239 r1243 1 1 # vim:sw=4:et 2 2 3 from gaphor import resource4 3 from gaphor import storage 5 4 from gaphor import UML gaphor/trunk/gaphor/data/plugins/kidexport/xmi.kid
r658 r1243 2 2 3 3 <?python 4 import gaphor 4 from gaphor.application import Application 5 5 import time 6 7 8 element s = gaphor.resource('ElementFactory').select()9 10 topLevelPackage = [element for element in element sif not getattr(element, 'package', True)][0]6 import 7 8 element_factory = Application.get_service('element_factory') 9 10 topLevelPackage = [element for element in element_factory.select() if not getattr(element, 'package', True)][0] 11 11 12 12 def modelProcessNode(node): … … 18 18 19 19 def getPackageChildNodes(package): 20 return [node for node in gaphor.resource('ElementFactory').select() if20 return [node for node in element_factory.select() if 21 21 hasattr(node, 'package') and node.package==package] 22 22 gaphor/trunk/gaphor/data/plugins/liveobjectbrowser/__init__.py
r402 r1243 2 2 3 3 import gaphor.plugin 4 from gaphor.core import inject 4 5 from browser import Browser 5 6 import gaphor … … 7 8 class LiveObjectBrowserAction(gaphor.plugin.Action): 8 9 10 element_factory = inject('element_factory') 11 9 12 def execute(self): 10 13 browser = Browser() 11 browser.construct("resource", gaphor.resource('ElementFactory').select())14 browser.construct("resource", element_factory.lselect()) 12 15 self.window.add_transient_window(browser) gaphor/trunk/gaphor/data/plugins/pynsource/__init__.py
r402 r1243 9 9 import gaphor 10 10 from gaphor.ui.abstractwindow import AbstractWindow 11 from gaphor.core import inject 11 12 import gaphor.plugin 12 13 from gaphor.plugin import resource … … 18 19 19 20 class PyNSourceAction(gaphor.plugin.Action): 21 22 action_manager = inject('action_manager') 20 23 21 24 def __init__(self): … … 50 53 # Open and select the new diagram in the main window: 51 54 main_window.select_element(engineer.diagram) 52 main_window.execute_action('OpenModelElement')55 self.action_manager.execute('OpenModelElement') 53 56 54 57 def create_dialog(self): gaphor/trunk/gaphor/data/plugins/python/__init__.py
r504 r1243 11 11 from gtk import FileSelection 12 12 13 from gaphor import resource, plugin, UML 13 from gaphor import plugin, UML 14 from gaphor.core import inject 14 15 15 16 from logilab.common.astng import astng, raw_building as builder, inspector, \ … … 19 20 class PythonReloadAction(plugin.Action): 20 21 22 plugin_manager = inject('plugin_manager') 23 21 24 def execute(self): 22 25 reload(astng) … … 24 27 reload(manager) 25 28 reload(inspector) 26 resource('PluginManager').plugins['Python generator'].import_plugin()29 self.plugin_manager.plugins['Python generator'].import_plugin() 27 30 28 31 29 32 class PythonExportAction(plugin.Action): 33 34 element_factory = inject('element_factory') 30 35 31 36 def __init__(self): … … 52 57 pyconverter.reset(directory) 53 58 # FIXME: should we export the root package ? 54 pyconverter.visit(root( resource(UML.ElementFactory)))59 pyconverter.visit(root(self.element_factory)) 55 60 print '**** done' 56 61 … … 58 63 class PythonImportAction(plugin.Action): 59 64 65 element_factory = inject('element_factory') 66 60 67 def execute(self): 61 68 """gaphor's plugin main callback""" … … 79 86 linker = inspector.Linker(module, tag=1) 80 87 linker.visit(module) 81 fact = resource(UML.ElementFactory)88 fact = self.element_factory 82 89 root_package = root(fact) 83 90 gapconverter.reset(fact, module) gaphor/trunk/gaphor/data/plugins/xmiexport/exportmodel.py
r1121 r1243 3 3 #from xml.sax.saxutils import XMLGenerator 4 4 import time 5 import gaphor 5 from gaphor.core import inject 6 6 from gaphor import UML 7 7 from gaphor.misc.xmlwriter import XMLWriter … … 27 27 class XMIExport(object): 28 28 29 element_factory = inject('element_factory') 30 29 31 # State diagram specific 30 32 # ====================== … … 72 74 xmi.startElement('UML:Package', attrs=attributes) 73 75 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()] 75 77 for item in classes: 76 78 try: … … 395 397 xmi.startElement('UML:Model', attrs=attributes) 396 398 xmi.startElement('UML:Namespace.ownedElement', attrs=XMLAttributes()) 397 for element in gaphor.resource('ElementFactory').select():399 for element in self.element_factory.select(): 398 400 #print element.__class__.__name__ 399 401 try: gaphor/trunk/gaphor/diagram/tool.py
r1241 r1243 245 245 try: 246 246 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') 248 248 pool.get_action('Pointer').active = True 249 249 return gaphas.tool.PlacementTool.on_button_release(self, context, event) gaphor/trunk/gaphor/misc/action.py
r1121 r1243 1 1 #/usr/bin/env python 2 # vim: sw=4:et 3 """Handle menus in a MVC manner.2 """ 3 Handle menus in a MVC manner. 4 4 5 5 TODO: show tooltips in the status bar when a menu item is selected. … … 188 188 189 189 class 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. 191 192 """ 192 193 … … 197 198 198 199 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. 200 202 """ 201 203 global _registered_actions … … 226 228 227 229 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 229 232 by Actions, which are instantiated from Slots. 230 233 """ … … 232 235 233 236 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 235 239 not yet exists, it is created. 236 240 … … 261 265 262 266 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 264 269 the actions that have been created through get_action(), not the 265 270 actions registered by register_action(). … … 268 273 269 274 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. 271 277 States can be restored by calling set_action_states(). 272 278 """ … … 278 284 279 285 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(). 281 288 """ 282 289 for action, sensitive in state.iteritems(): … … 284 291 285 292 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 287 295 no actions occur during a special big (background) action, such as 288 296 loading or saving a model. … … 292 300 293 301 def update_actions(self): 294 """Update all actions. 302 """ 303 Update all actions. 295 304 """ 296 305 for action in self.actions.itervalues(): … … 299 308 300 309 def 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. 302 312 """ 303 313 global _registered_actions … … 309 319 310 320 def 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 312 323 dependency_ids actions is executed, action is requested to update its 313 324 state. … … 326 337 327 338 def 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. 329 341 """ 330 342 global _registered_slots … … 333 345 334 346 def 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. 336 349 """ 337 350 global _registered_slot_actions … … 361 374 362 375 def 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. 364 378 E.g. 365 379 ('DummyAction', … … 377 391 return get_actions_tuple(_registered_slot_actions.get(slot) or {}) 378 392 393 394 # vim: sw=4:et gaphor/trunk/gaphor/services/pluginmanager.py
r1239 r1243 33 33 from gaphor.interfaces import IService 34 34 35 from gaphor import resource36 35 from gaphor.parser import ParserException 37 36 from gaphor.misc.action import register_action_for_slot … … 376 375 return self.plugins.values() 377 376 378 # Make one default plugin manager379 import gaphor380 _default_plugin_manager = gaphor.resource(PluginManager)381 del gaphor382 377 383 378 # vim:sw=4:et gaphor/trunk/gaphor/ui/abstractwindow.py
r739 r1243 3 3 import gobject, gtk 4 4 import gaphor 5 from gaphor.core import inject 5 6 from 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 8 from gaphor.misc.action import ActionPool 9 9 from menufactory import MenuFactory 10 10 11 class CloseAction(Action):12 id = 'WindowClose'13 14 def init(self, window):15 pass16 17 register_action(CloseAction)18 11 19 12 class AbstractWindow(object): … … 37 30 toolbar = () 38 31 32 action_manager = inject('action_manager') 33 39 34 def __init__(self): 40 35 self.__state = AbstractWindow.STATE_INIT … … 45 40 self.statusbar = None 46 41 self.accel_group = None 47 self.action_pool = ActionPool(self._action_initializer)48 42 self.menu_factory = None 49 43 … … 56 50 return self.window 57 51 58 def get_action_pool(self):59 return self.action_pool 52 # def get_action_pool(self): 53 # return self.action_manager 60 54 61 55 def get_state(self): … … 68 62 raise NotImplementedError, 'construct() should create GUI components.' 69 63 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) 72 66 73 67 def set_message(self, message): … … 118 112 # #return True 119 113 120 def _action_initializer(self, action):121 try:122 action.init(self)123 except Exception, e:124 lo
