Changeset 1239
- Timestamp:
- 04/20/07 02:02:47 (1 year ago)
- Files:
-
- gaphor/trunk/gaphor/UML (modified) (1 prop)
- gaphor/trunk/gaphor/UML/__init__.py (modified) (4 diffs)
- gaphor/trunk/gaphor/actions/diagramactions.py (modified) (8 diffs)
- gaphor/trunk/gaphor/actions/itemactions.py (modified) (6 diffs)
- gaphor/trunk/gaphor/actions/mainactions.py (modified) (3 diffs)
- gaphor/trunk/gaphor/actions/placementactions.py (modified) (2 diffs)
- gaphor/trunk/gaphor/actions/tests/test_itemactions.py (modified) (2 diffs)
- gaphor/trunk/gaphor/actions/tests/test_placementactions.py (modified) (2 diffs)
- gaphor/trunk/gaphor/adapters/connectors.py (modified) (11 diffs)
- gaphor/trunk/gaphor/adapters/editors.py (modified) (3 diffs)
- gaphor/trunk/gaphor/adapters/tests/test_connector.py (modified) (2 diffs)
- gaphor/trunk/gaphor/application.py (modified) (2 diffs)
- gaphor/trunk/gaphor/data/plugins/checkmetamodel/checkmodel.py (modified) (1 diff)
- gaphor/trunk/gaphor/services/guimanager.py (modified) (3 diffs)
- gaphor/trunk/gaphor/services/pluginmanager.py (modified) (6 diffs)
- gaphor/trunk/gaphor/ui/diagramtab.py (modified) (1 diff)
- gaphor/trunk/gaphor/ui/mainwindow.py (modified) (2 diffs)
- gaphor/trunk/gaphor/ui/namespace.py (modified) (1 diff)
- gaphor/trunk/gaphor/ui/stock.py (modified) (3 diffs)
- gaphor/trunk/setup.py (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
gaphor/trunk/gaphor/UML
- Property svn:ignore set to
uml2.py
- Property svn:ignore set to
gaphor/trunk/gaphor/UML/__init__.py
r1121 r1239 4 4 from gaphor.UML.elementfactory import ElementFactory 5 5 6 # Make one ElementFactory instance an application-wide resource7 from gaphor import resource8 _default_element_factory = resource(ElementFactory)9 del resource10 6 11 7 # Make some elements of the default ElementFactory easely accessable … … 14 10 """Create a new model element in the default ElementFactory. 15 11 """ 16 return _default_element_factory.create(type) 12 from gaphor.application import Application 13 return Application.get_service('element_factory').create(type) 17 14 18 15 def lookup(id): 19 16 """Find the element with id in the default ElementFactory. 20 17 """ 21 return _default_element_factory.lookup(id) 18 from gaphor.application import Application 19 return Application.get_service('element_factory').lookup(id) 22 20 23 21 def select(expression=None): … … 25 23 Returns an iterator. 26 24 """ 27 return _default_element_factory.select(expression) 25 from gaphor.application import Application 26 return Application.get_service('element_factory').select(expression) 28 27 29 28 def lselect(expression=None): … … 31 30 Returns a list of elements. 32 31 """ 33 return _default_element_factory.lselect(expression) 32 from gaphor.application import Application 33 return Application.get_service('element_factory').lselect(expression) 34 34 35 35 def flush(): 36 _default_element_factory.flush() 36 from gaphor.application import Application 37 Application.get_service('element_factory').flush() 37 38 38 39 def swap_element(element, new_class): 39 40 """Swap the class for an element 40 41 """ 41 _default_element_factory.swap_element(element, new_class) 42 from gaphor.application import Application 43 Application.get_service('element_factory').swap_element(element, new_class) 42 44 43 45 if 0 and __debug__: gaphor/trunk/gaphor/actions/diagramactions.py
r1219 r1239 7 7 import gaphas 8 8 9 from gaphor import resource10 9 from gaphor import UML 10 from gaphor.core import inject 11 11 from gaphor.transaction import Transaction, transactional 12 12 from gaphor.misc.action import Action, CheckAction, RadioAction … … 192 192 193 193 194 copy_buffer = [] 195 194 196 class CopyAction(Action): 195 197 """Copy/Cut/Paste functionality required a lot of thinking: 196 198 197 Store a list of DiagramItems that have to be copied in resource199 Store a list of DiagramItems that have to be copied in a global 198 200 'copy-buffer'. 199 201 … … 227 229 #i.save(save_func) 228 230 if copy_items: 229 resource.set('copy-buffer', copy_items) 231 global copy_buffer 232 copy_buffer = copy_items 230 233 tab = self._window.get_current_diagram_tab() 231 234 … … 236 239 """Copy/Cut/Paste functionality required a lot of thinking: 237 240 238 Create a copy of DiagramItems that have to be copied in resource241 Create a copy of DiagramItems that have to be copied in a global 239 242 'copy-buffer'. 240 243 … … 252 255 stock_id = 'gtk-paste' 253 256 254 def init(self, window): 255 self._window = window 256 257 def update(self): 258 diagram_tab = self._window.get_current_diagram_tab() 259 self.sensitive = diagram_tab and resource('copy-buffer', []) 257 element_factory = inject('element_factory') 258 259 def init(self, window): 260 self._window = window 261 262 def update(self): 263 global copy_buffer 264 diagram_tab = self._window.get_current_diagram_tab() 265 self.sensitive = diagram_tab and copy_buffer 260 266 261 267 def _load_element(self, name, value): … … 268 274 self._item.load(name, item) 269 275 else: 270 item = self. _factory.lookup(value.id)276 item = self.element_factory.lookup(value.id) 271 277 if item: 272 278 self._item.load(name, item) … … 286 292 @transactional 287 293 def execute(self): 294 global copy_buffer 288 295 view = self._window.get_current_diagram_view() 289 296 diagram = self._window.get_current_diagram() … … 296 303 return 297 304 298 copy_items = [ c for c in resource('copy-buffer', [])if c.canvas ]305 copy_items = [ c for c in copy_buffer if c.canvas ] 299 306 300 307 # Mapping original id -> new item 301 308 self._new_items = {} 302 self._factory = resource(UML.ElementFactory)303 309 304 310 # Create new id's that have to be used to create the items: gaphor/trunk/gaphor/actions/itemactions.py
r1221 r1239 4 4 """ 5 5 6 from gaphor import GaphorError, resource7 6 from gaphor import UML 7 from gaphor.core import inject 8 8 from gaphor.diagram import items 9 9 from gaphor.transaction import transactional … … 12 12 import gaphas 13 13 14 class NoFocusItemError( GaphorError):14 class NoFocusItemError(Exception): 15 15 pass 16 16 … … 176 176 tooltip = 'Create a new attribute' 177 177 178 element_factory = inject('element_factory') 179 178 180 def init(self, window): 179 181 self._window = window … … 194 196 subject = focus_item.subject 195 197 assert isinstance(subject, (UML.Class, UML.Interface)) 196 elemfact = resource(UML.ElementFactory)197 198 198 attribute = elemfact.create(UML.Property)199 attribute = self.element_factory.create(UML.Property) 199 200 attribute.parse('new') 200 201 subject.ownedAttribute = attribute … … 219 220 tooltip = 'Create a new operation' 220 221 222 element_factory = inject('element_factory') 223 221 224 def init(self, window): 222 225 self._window = window … … 237 240 subject = focus_item.subject 238 241 assert isinstance(subject, UML.Classifier) 239 elemfact = resource(UML.ElementFactory) 240 241 operation = elemfact.create(UML.Operation) 242 243 operation = self.element_factory.create(UML.Operation) 242 244 operation.parse('new()') 243 245 subject.ownedOperation = operation gaphor/trunk/gaphor/actions/mainactions.py
r1237 r1239 227 227 228 228 def on_element_factory(self, *args): 229 #element_factory = resource(UML.ElementFactory)230 229 if self.element_factory.values(): 231 230 self.sensitive = True … … 460 459 stock_id = 'gaphor-diagram' 461 460 461 element_factory = inject('element_factory') 462 462 463 def init(self, window): 463 464 self._window = window … … 469 470 def execute(self): 470 471 element = self._window.get_tree_view().get_selected_element() 471 diagram = resource(UML.ElementFactory).create(UML.Diagram)472 diagram = self.element_factory.create(UML.Diagram) 472 473 diagram.package = element 473 474 gaphor/trunk/gaphor/actions/placementactions.py
r1233 r1239 80 80 group = 'placementtools' 81 81 82 element_factory = inject('element_factory') 83 82 84 def init(self, window): 83 85 self._window = window … … 90 92 subject = None 91 93 if self.subject_type: 92 subject = UML.create(self.subject_type)94 subject = self.element_factory.create(self.subject_type) 93 95 diagram = self._window.get_current_diagram() 94 96 return diagram.create(self.type, subject=subject) gaphor/trunk/gaphor/actions/tests/test_itemactions.py
r1121 r1239 3 3 4 4 from gaphor import resource, UML 5 from gaphor.application import Application 5 6 from gaphor.ui.mainwindow import MainWindow 6 7 from gaphor.diagram import items … … 11 12 class ItemActionTestCase(unittest.TestCase): 12 13 13 main_window = resource(MainWindow)14 try:15 main_window.construct()16 except:17 pass14 # main_window = resource(MainWindow) 15 # try: 16 # main_window.construct() 17 # except: 18 # pass 18 19 19 20 def setUp(self): 20 21 self.diagram = UML.create(UML.Diagram) 21 22 self.main_window.show_diagram(self.diagram) 23 Application.init() 24 self.main_window = Application.get_service('gui_manager').main_window 25 22 26 self.class_ = self.diagram.create(items.ClassItem, subject=UML.create(UML.Class)) 23 27 gaphor/trunk/gaphor/actions/tests/test_placementactions.py
r1121 r1239 2 2 import unittest 3 3 from gaphor import resource 4 from gaphor.ui.mainwindow import MainWindow 4 resource('DataDir', '') 5 from gaphor.application import Application 6 #from gaphor.ui.mainwindow import MainWindow 5 7 from gaphor.diagram.tool import PlacementTool 6 8 from gaphor.actions import placementactions … … 12 14 Event = Context 13 15 14 15 16 class PlacementToolTestCase(unittest.TestCase): 16 17 17 main_window = resource(MainWindow)18 try:19 main_window.construct()20 except:21 pass18 # main_window = MainWindow() 19 # try: 20 # main_window.construct() 21 # except: 22 # pass 22 23 23 24 def setUp(self): 24 pass 25 Application.init() 26 self.main_window = Application.get_service('gui_manager').main_window 25 27 26 28 def tearDown(self): 27 pass29 Application.shutdown() 28 30 29 31 def do_test_placement(self, action): gaphor/trunk/gaphor/adapters/connectors.py
r1126 r1239 9 9 from gaphas import constraint 10 10 from gaphor import UML 11 from gaphor.core import inject 11 12 from gaphor.diagram.interfaces import IConnect 12 13 from gaphor.diagram import items … … 307 308 """ 308 309 310 element_factory = inject('element_factory') 311 309 312 def relationship(self, required_type, head, tail): 310 313 """ … … 367 370 if not relation: 368 371 line = self.line 369 relation = UML.create(type)372 relation = self.element_factory.create(type) 370 373 setattr(relation, head[0], line.head.connected_to.subject) 371 374 setattr(relation, tail[0], line.tail.connected_to.subject) … … 737 740 # Find all associations and determine if the properties on 738 741 # the association ends have a type that points to the class. 739 for assoc in UML.select():742 for assoc in self.element_factory.select(): 740 743 if isinstance(assoc, UML.Extension): 741 744 end1 = assoc.memberEnd[0] … … 753 756 else: 754 757 # Create a new Extension relationship 755 relation = UML.create(UML.Extension)756 head_end = UML.create(UML.Property)757 tail_end = UML.create(UML.ExtensionEnd)758 relation = self.element_factory.create(UML.Extension) 759 head_end = self.element_factory.create(UML.Property) 760 tail_end = self.element_factory.create(UML.ExtensionEnd) 758 761 relation.package = element.canvas.diagram.namespace 759 762 relation.memberEnd = head_end … … 828 831 # Find all associations and determine if the properties on 829 832 # the association ends have a type that points to the class. 830 for assoc in UML.select():833 for assoc in self.element_factory.select(): 831 834 if isinstance(assoc, UML.Association): 832 835 end1 = assoc.memberEnd[0] … … 850 853 else: 851 854 # Create a new Extension relationship 852 relation = UML.create(UML.Association)853 head_end = UML.create(UML.Property)854 head_end.lowerValue = UML.create(UML.LiteralSpecification)855 tail_end = UML.create(UML.Property)856 tail_end.lowerValue = UML.create(UML.LiteralSpecification)855 relation = self.element_factory.create(UML.Association) 856 head_end = self.element_factory.create(UML.Property) 857 head_end.lowerValue = self.element_factory.create(UML.LiteralSpecification) 858 tail_end = self.element_factory.create(UML.Property) 859 tail_end.lowerValue = self.element_factory.create(UML.LiteralSpecification) 857 860 relation.package = element.canvas.diagram.namespace 858 861 relation.memberEnd = head_end … … 925 928 ('target', 'incoming')) 926 929 if not relation.guard: 927 relation.guard = UML.create(UML.LiteralSpecification)930 relation.guard = self.element_factory.create(UML.LiteralSpecification) 928 931 line.subject = relation 929 932 opposite = line.opposite(handle) … … 998 1001 subject = element.subject 999 1002 if len(subject.incoming) > 1 and len(subject.outgoing) < 2: 1000 UML.swap_element(subject, join_node_class)1003 self.element_factory.swap_element(subject, join_node_class) 1001 1004 element.request_update() 1002 1005 elif len(subject.incoming) < 2 and len(subject.outgoing) > 1: 1003 UML.swap_element(subject, fork_node_class)1006 self.element_factory.swap_element(subject, fork_node_class) 1004 1007 element.request_update() 1005 1008 elif not element.combined and len(subject.incoming) > 1 and len(subject.outgoing) > 1: … … 1012 1015 flow_class = UML.ControlFlow 1013 1016 1014 UML.swap_element(join_node, join_node_class)1015 fork_node = UML.create(fork_node_class)1017 self.element_factory.swap_element(join_node, join_node_class) 1018 fork_node = self.element_factory.create(fork_node_class) 1016 1019 for flow in list(join_node.outgoing): 1017 1020 flow.source = fork_node 1018 flow = UML.create(flow_class)1021 flow = self.element_factory.create(flow_class) 1019 1022 flow.source = join_node 1020 1023 flow.target = fork_node … … 1048 1051 if len(join_node.outgoing) > 1: 1049 1052 assert len(join_node.incoming) < 2 1050 UML.swap_element(join_node, fork_node_class)1053 self.element_factory.swap_element(join_node, fork_node_class) 1051 1054 element.combined = None 1052 1055 gaphor/trunk/gaphor/adapters/editors.py
r1211 r1239 9 9 from gaphas import constraint 10 10 from gaphor import UML 11 from gaphor.core import inject 11 12 from gaphor.UML.umllex import render_attribute 12 13 from gaphor.diagram.interfaces import IEditor … … 251 252 component.adapts(items.ForkNodeItem) 252 253 254 element_factory = inject('element_factory') 255 253 256 def __init__(self, item): 254 257 self._item = item … … 276 279 if not spec: 277 280 from gaphor import resource 278 factory = resource(UML.ElementFactory) 279 spec = self._item.subject.joinSpec = factory.create(UML.LiteralSpecification) 281 spec = self._item.subject.joinSpec = self.element_factory.create(UML.LiteralSpecification) 280 282 spec.value = text 281 283 gaphor/trunk/gaphor/adapters/tests/test_connector.py
r1233 r1239 6 6 from zope import component 7 7 from gaphor import UML 8 from gaphor.application import Application 8 9 from gaphor.diagram import items 9 10 from gaphor.diagram.interfaces import IConnect … … 11 12 # Ensure adapters are loaded 12 13 import gaphor.adapters 14 15 Application.load_services() 13 16 14 17 class ConnectorTestCase(unittest.TestCase): gaphor/trunk/gaphor/application.py
r1232 r1239 31 31 """ 32 32 self.load_services() 33 self.init_all_services() 33 34 34 35 def load_services(self): … … 49 50 50 51 # HACK: implicitly add UML.ElementFactory for now. 51 from gaphor import UML52 self._uninitialized_services['element_factory'] = resource(UML.ElementFactory)52 # from gaphor import UML 53 # self._uninitialized_services['element_factory'] = resource(UML.ElementFactory) 53 54 # /HACK 54 55 56 def init_all_services(self): 55 57 while self._uninitialized_services: 56 58 self.init_service(self._uninitialized_services.iterkeys().next()) gaphor/trunk/gaphor/data/plugins/checkmetamodel/checkmodel.py
r565 r1239 4 4 from gaphor import storage 5 5 from gaphor import UML 6 from gaphor.core import inject 6 7 from os import path 7 8 gaphor/trunk/gaphor/services/guimanager.py
r1221 r1239 34 34 # Load stock items 35 35 import gaphor.ui.stock 36 gaphor.ui.stock.load_stock_icons() 36 37 37 38 def init_main_window(self): … … 41 42 42 43 load_accel_map() 43 #self._main_window = MainWindow()44 self._main_window = MainWindow() 44 45 # Backwards compat 45 46 # TODO: remove 46 47 from gaphor import resource 47 self._main_window = resource(MainWindow) 48 resource.set(MainWindow, self._main_window) 49 resource.set('MainWindow', self._main_window) 48 50 self._main_window.construct() 49 51 … … 56 58 57 59 def shutdown(self): 60 #self._main_window.close() 58 61 from gaphor.ui.accelmap import save_accel_map 59 62 save_accel_map() gaphor/trunk/gaphor/services/pluginmanager.py
r1218 r1239 27 27 import glob 28 28 import sys 29 import pkg_resources 29 30 from xml.sax import handler, make_parser 30 31 … … 43 44 # Directories to look for plugins. These sirectories are added to the 44 45 # search path. User provided plugins overrule system plugins. 45 DEFAULT_PLUGIN_DIRS = [os.path.join(resource('DataDir'), 'plugins'), 46 os.path.join(resource('UserDataDir'), 'plugins')] 46 # TODO: fix: 47 #DEFAULT_PLUGIN_DIRS = [os.path.join(resource('DataDir'), 'plugins'), 48 # os.path.join(resource('UserDataDir'), 'plugins')] 47 49 48 50 #log.debug('sys.path=' + str(sys.path)) … … 93 95 return True 94 96 95 def import_plugin(self ):97 def import_plugin(self, importer): 96 98 """ 97 99 Do the actual import of the plugin module. … … 99 101 #mod = __import__(self.path.split(os.sep)[-1], globals(), locals(), []) 100 102 name = os.path.split(self.path)[1] 101 f, n, d = imp.find_module(name, DEFAULT_PLUGIN_DIRS) 102 mod = imp .load_module(MODULENS + name, f, n, d)103 104 mod = importer(name) 103 105 self.module = mod 104 106 self.initialized = True … … 323 325 return 324 326 327 plugin_dir = pkg_resources.resource_filename('gaphor', 'data/plugins') 328 325 329 # Load the plugins in reverse order, so the user plugins will 326 330 # overwrite the default plugins. (they are imported in sys.path as 327 331 # [user plugins, default plugins]). 328 for plugin_dir in DEFAULT_PLUGIN_DIRS: 329 self.load_plugins_from_dir(plugin_dir) 332 #for plugin_dir in plugin_dir: 333 self.load_plugins_from_dir(plugin_dir) 334 335 def plugin_importer(name): 336 f, n, d = imp.find_module(name, [plugin_dir]) 337 return imp.load_module(MODULENS + name, f, n, d) 330 338 331 339 import_done = True … … 335 343 if plugin.requirements_met(self): 336 344 try: 337 plugin.import_plugin( )345 plugin.import_plugin(plugin_importer) 338 346 except Exception, e: 339 347 plugin.status = 'Failed to load plugin %s: %s' % (plugin.name, e) gaphor/trunk/gaphor/ui/diagramtab.py
r1233 r1239 5 5 6 6 from gaphor import UML 7 from gaphor import resource8 7 from gaphor.core import inject 9 8 from gaphor.i18n import _ gaphor/trunk/gaphor/ui/mainwindow.py
r1233 r1239 4 4 import gtk 5 5 6 from gaphor import resource7 6 from gaphor import UML 8 7 from gaphor.core import inject … … 472 471 @component.adapter(IServiceEvent) 473 472 def on_undo(*args): 474 resource(MainWindow).execute_action('UndoStack') 473 from gaphor.application import Application 474 Application.get_service('gui_manager').main_window.execute_action('UndoStack') 475 475 476 476 component.provideHandler(on_undo) gaphor/trunk/gaphor/ui/namespace.py
r1233 r1239 12 12 13 13 from gaphor import UML 14 from gaphor import resource15 14 from gaphor.transaction import Transaction 16 15 gaphor/trunk/gaphor/ui/stock.py
r930 r1239 3 3 4 4 import os.path 5 import pkg_resources 5 6 from xml.sax import handler 6 7 import gtk 7 8 8 from gaphor import resource9 9 from gaphor import UML 10 10 from gaphor.parser import ParserException … … 117 117 from xml.sax import make_parser 118 118 parser = make_parser() 119 data_dir = resource('DataDir') 120 icon_dir = os.path.join(data_dir, 'pixmaps') 119 icon_dir = os.path.abspath(pkg_resources.resource_filename('gaphor', 'data/pixmaps')) 120 log.info('Icon dir: %s' % icon_dir) 121 #icon_dir = 'gaphor/data/pixmaps' 121 122 loader = StockIconLoader(icon_dir) 122 123 … … 124 125 parser.setContentHandler(loader) 125 126 126 filename = os.path.join(data_dir, 'icons.xml')127 filename = pkg_resources.resource_filename('gaphor', 'data/icons.xml') 127 128 if os.name == 'nt' and data_dir[1] == ':': 128 129 # Make the filename a full URL 129 130 filename = 'file:' + filename.replace('\\\\', '/') 131 #try: 130 132 parser.parse(filename) 133 #except IOError, e: 134 # log.error('Unable to load icons', e) 131 135 132 load_stock_icons()136 #load_stock_icons() 133 137 134 138 # vim:sw=4:et gaphor/trunk/setup.py
r1228 r1239 83 83 'gui_manager = gaphor.services.guimanager:GUIManager', 84 84 'adapter_loader = gaphor.services.adapterloader:AdapterLoader', 85 'element_factory = gaphor.UML.elementfactory:ElementFactory', 85 86 ], 86 87 'gaphor.adapters': [
