Changeset 2116
- Timestamp:
- 09/10/07 13:12:44 (8 months ago)
- Files:
-
- gaphor/trunk/gaphor/diagram/classifier.py (modified) (3 diffs)
- gaphor/trunk/gaphor/diagram/diagramitem.py (modified) (7 diffs)
- gaphor/trunk/gaphor/diagram/diagramline.py (modified) (1 diff)
- gaphor/trunk/gaphor/diagram/elementitem.py (modified) (3 diffs)
- gaphor/trunk/gaphor/diagram/klass.py (modified) (1 diff)
- gaphor/trunk/gaphor/diagram/nameditem.py (modified) (3 diffs)
- gaphor/trunk/gaphor/services/tests/test_filemanager.py (modified) (1 diff)
- gaphor/trunk/gaphor/tests/test_application.py (modified) (1 diff)
- gaphor/trunk/gaphor/tests/test_storage.py (modified) (1 diff)
- gaphor/trunk/gaphor/ui/mainwindow.py (modified) (1 diff)
- gaphor/trunk/gaphor/ui/namespace.py (modified) (26 diffs)
- gaphor/trunk/gaphor/ui/tests/test_handletool.py (modified) (1 diff)
- gaphor/trunk/gaphor/ui/tests/test_namespace.py (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
gaphor/trunk/gaphor/diagram/classifier.py
r2090 r2116 164 164 165 165 self._drawing_style = ClassifierItem.DRAW_NONE 166 self.add_watch(UML.Classifier.isAbstract, self.on_classifier_is_abstract) 166 167 167 168 … … 175 176 def postload(self): 176 177 NamedItem.postload(self) 177 self.on_ subject_notify__isAbstract(self.subject)178 self.on_classifier_is_abstract(None) 178 179 179 180 @observed … … 259 260 260 261 261 def on_subject_notify(self, pspec, notifiers=()): 262 #log.debug('Class.on_subject_notify(%s, %s)' % (pspec, notifiers)) 263 NamedItem.on_subject_notify(self, pspec, ('isAbstract',) + notifiers) 264 # Create already existing attributes and operations: 265 if self.subject: 266 self.on_subject_notify__isAbstract(self.subject) 267 self.request_update() 268 269 def on_subject_notify__isAbstract(self, subject, pspec=None): 270 self._name.font = subject.isAbstract \ 262 def on_classifier_is_abstract(self, event): 263 self._name.font = (self.subject and self.subject.isAbstract) \ 271 264 and font.FONT_ABSTRACT_NAME or font.FONT_NAME 272 265 self.request_update() gaphor/trunk/gaphor/diagram/diagramitem.py
r2009 r2116 4 4 """ 5 5 6 from zope import component 6 7 from gaphor import UML 8 from gaphor.application import Application 7 9 from gaphor.misc import uniqueid 8 10 from gaphor.diagram import DiagramItemMeta … … 279 281 # properties, which should be saved in file 280 282 self._persistent_props = set() 281 283 self._watched_properties = dict() 284 285 self.add_watch(UML.Element.appliedStereotype, self.on_element_applied_stereotype) 286 self.add_watch(UML.Presentation.subject, self.on_presentation_subject) 282 287 283 288 id = property(lambda self: self._id, doc='Id') … … 313 318 log.warning('%s has no property named %s (value %s)' % (self, name, value)) 314 319 320 315 321 def postload(self): 316 322 if self.subject: … … 324 330 save_func(name, getattr(self, name.replace('-', '_'))) 325 331 332 326 333 def save_properties(self, save_func, *names): 327 334 """ … … 330 337 for name in names: 331 338 self.save_property(save_func, name) 339 332 340 333 341 def unlink(self): … … 345 353 346 354 355 def request_update(self): 356 """ 357 Placeholder for gaphor.Item's request_update() method. 358 """ 359 pass 360 361 347 362 def draw(self, context): 348 363 EditableTextSupport.draw(self, context) … … 352 367 return self 353 368 354 def on_subject_notify__appliedStereotype(self, subject, pspec=None): 369 370 def on_subject_notify(self, pspec, notifiers=()): 371 SubjectSupport.on_subject_notify(self, pspec, notifiers) 372 373 def on_presentation_subject(self, event): 374 for prop, handler in self._watched_properties.iteritems(): 375 if handler: 376 # Provide event? 377 handler(None) 378 379 def on_element_applied_stereotype(self, event): 355 380 if self.subject: 356 381 self.update_stereotype() 357 382 self.request_update() 358 383 359 def request_update(self): 360 """ 361 Placeholder for gaphor.Item's request_update() method. 362 """ 363 pass 364 365 def on_subject_notify(self, pspec, notifiers=()): 366 SubjectSupport.on_subject_notify(self, pspec, notifiers + ('appliedStereotype',)) 384 385 def add_watch(self, property, handler=None): 386 """ 387 Add a property (umlproperty) to be watched. a handler may be provided 388 that will be called with the event as argument (handler(event)). 389 """ 390 assert isinstance(property, UML.properties.umlproperty) 391 self._watched_properties[property] = handler 392 393 394 def register_handlers(self): 395 Application.register_handler(self.on_element_change) 396 397 398 def unregister_handlers(self): 399 Application.unregister_handler(self.on_element_change) 400 401 402 @component.adapter(UML.interfaces.IElementChangeEvent) 403 def on_element_change(self, event): 404 """ 405 Called when a model element has changed. 406 """ 407 if event.property in self._watched_properties: 408 handler = self._watched_properties[event.property] 409 if handler: 410 handler(event) 411 elif self.subject: 412 log.debug('on_element_changed') 413 self.request_update() 367 414 368 415 gaphor/trunk/gaphor/diagram/diagramline.py
r2013 r2116 26 26 head = property(lambda self: self._handles[0]) 27 27 tail = property(lambda self: self._handles[-1]) 28 29 30 def setup_canvas(self): 31 gaphas.Line.setup_canvas() 32 self.register_handlers() 33 34 35 def teardown_canvas(self): 36 gaphas.Line.teardown_canvas() 37 self.unregister_handlers() 28 38 29 39 gaphor/trunk/gaphor/diagram/elementitem.py
r1747 r2116 24 24 self.auto_resize = 0 25 25 26 26 27 def save(self, save_func): 27 28 save_func('matrix', tuple(self.matrix)) … … 30 31 DiagramItem.save(self, save_func) 31 32 33 32 34 def load(self, name, value): 33 35 if name == 'matrix': … … 35 37 else: 36 38 DiagramItem.load(self, name, value) 39 40 41 def setup_canvas(self): 42 gaphas.Element.setup_canvas() 43 self.register_handlers() 44 45 46 def teardown_canvas(self): 47 gaphas.Element.teardown_canvas() 48 self.unregister_handlers() 49 37 50 38 51 def pre_update(self, context): gaphor/trunk/gaphor/diagram/klass.py
r2090 r2116 34 34 self._attributes = self.create_compartment('attributes') 35 35 self._operations = self.create_compartment('operations') 36 37 self.add_watch(UML.Class.ownedAttribute) 38 self.add_watch(UML.Class.ownedOperation) 36 39 37 40 def save(self, save_func): gaphor/trunk/gaphor/diagram/nameditem.py
r1998 r2116 35 35 # size of stereotype, namespace and name text 36 36 self._header_size = 0, 0 37 37 self.add_watch(UML.NamedElement.namespace, self.on_named_element_namespace) 38 self.add_watch(UML.Namespace.name, self.on_named_element_namespace) 38 39 39 40 def is_namespace_info_visible(self): … … 59 60 60 61 61 def on_subject_notify(self, pspec, notifiers=()): 62 #log.debug('Class.on_subject_notify(%s, %s)' % (pspec, notifiers)) 63 ElementItem.on_subject_notify(self, pspec, 64 ('namespace', 'namespace.name') + notifiers) 65 if self.subject: 66 self.on_subject_notify__namespace(self.subject) 67 68 69 def on_subject_notify__namespace(self, subject, pspec=None): 62 def on_named_element_namespace(self, event): 70 63 """ 71 64 Add a line '(from ...)' to the class item if subject's namespace … … 78 71 self._from.text = '' 79 72 self.request_update() 80 81 82 def on_subject_notify__namespace_name(self, subject, pspec=None):83 """84 Change the '(from ...)' line if the namespace's name changes.85 """86 self.on_subject_notify__namespace(subject, pspec)87 73 88 74 gaphor/trunk/gaphor/services/tests/test_filemanager.py
r2061 r2116 8 8 9 9 def setUp(self): 10 Application.init(services=['file_manager', 'element_factory', 'properties', 'gui_manager' ])10 Application.init(services=['file_manager', 'element_factory', 'properties', 'gui_manager', 'action_manager']) 11 11 self.recent_files_backup = Application.get_service('properties').get('recent-files') 12 12 gaphor/trunk/gaphor/tests/test_application.py
r2060 r2116 16 16 Load services. At lease the undo_manager should be available after that. 17 17 """ 18 Application.init(['undo_manager', 'file_manager' ])18 Application.init(['undo_manager', 'file_manager', 'properties']) 19 19 20 20 self.assertTrue(Application.get_service('undo_manager') is not None) gaphor/trunk/gaphor/tests/test_storage.py
r2052 r2116 15 15 from cStringIO import StringIO 16 16 17 __module__ = 'test_storage'17 #__module__ = 'test_storage' 18 18 19 19 class PseudoFile(object): gaphor/trunk/gaphor/ui/mainwindow.py
r2100 r2116 470 470 def quit(self): 471 471 self.ask_to_close() and gtk.main_quit() 472 self._tree_view.get_model().close() 473 Application.unregister_handler(self._action_executed) 472 474 473 475 @action(name='tree-view-open', label='_Open') gaphor/trunk/gaphor/ui/namespace.py
r2098 r2116 12 12 from zope import component 13 13 14 from gaphor.application import Application 14 15 from gaphor import UML 15 16 from gaphor.UML.event import ModelFactoryEvent, FlushFactoryEvent … … 76 77 self.filter = _default_filter_list 77 78 78 component.provideHandler(self.flush)79 component.provideHandler(self.refresh)80 component.provideHandler(self._on_element_change)81 component.provideHandler(self._on_element_create)82 component.provideHandler(self._on_element_delete)83 component.provideHandler(self._on_association_set)79 Application.register_handler(self.flush) 80 Application.register_handler(self.refresh) 81 Application.register_handler(self._on_element_change) 82 Application.register_handler(self._on_element_create) 83 Application.register_handler(self._on_element_delete) 84 Application.register_handler(self._on_association_set) 84 85 85 86 self._build_model() 87 88 89 def close(self): 90 """ 91 Close the namespace model, unregister handlers. 92 """ 93 Application.unregister_handler(self.flush) 94 Application.unregister_handler(self.refresh) 95 Application.unregister_handler(self._on_element_change) 96 Application.unregister_handler(self._on_element_create) 97 Application.unregister_handler(self._on_element_delete) 98 Application.unregister_handler(self._on_association_set) 99 86 100 87 101 def path_from_element(self, e): … … 96 110 return () 97 111 112 98 113 def element_from_path(self, path): 99 114 """ … … 109 124 return None 110 125 126 111 127 @component.adapter(IAttributeChangeEvent) 112 128 @catchall … … 148 164 [original] * len(parent_nodes), 149 165 parent_nodes)) 166 150 167 151 168 def _add_elements(self, element): … … 257 274 self._remove_element(element) 258 275 276 259 277 @component.adapter(ModelFactoryEvent) 260 278 def refresh(self, event=None): 261 279 self.flush() 262 280 self._build_model() 281 263 282 264 283 @component.adapter(FlushFactoryEvent) … … 268 287 self._nodes = {None: []} 269 288 289 270 290 def _build_model(self): 271 291 toplevel = self.factory.select(lambda e: isinstance(e, UML.Namespace) and not e.namespace) … … 274 294 self._add_elements(element) 275 295 296 276 297 # TreeModel methods: 277 298 … … 282 303 return 0 283 304 305 284 306 def on_get_n_columns(self): 285 307 """ … … 288 310 return 1 289 311 312 290 313 def on_get_column_type(self, index): 291 314 """ … … 293 316 """ 294 317 return gobject.TYPE_PYOBJECT 318 295 319 296 320 def on_get_path(self, node): … … 300 324 path = self.path_from_element(node) 301 325 return path 326 302 327 303 328 def on_get_iter(self, path): … … 309 334 return self.element_from_path(path) 310 335 336 311 337 def on_get_value(self, node, column): 312 338 """ … … 315 341 assert column == 0, 'column can only be 0' 316 342 return node 343 317 344 318 345 def on_iter_next(self, node): … … 327 354 except IndexError, e: 328 355 return None 356 329 357 330 358 def on_iter_has_child(self, node): … … 334 362 n = self._nodes.get(node) 335 363 return n or len(n) > 0 364 336 365 337 366 def on_iter_children(self, node): … … 344 373 pass 345 374 375 346 376 def on_iter_n_children(self, node): 347 377 """ … … 349 379 """ 350 380 return len(self._nodes[node]) 381 351 382 352 383 def on_iter_nth_child(self, node, n): … … 359 390 except TypeError, e: 360 391 return None 392 361 393 362 394 def on_iter_parent(self, node): … … 435 467 self.connect('drag-data-delete', NamespaceView.on_drag_data_delete) 436 468 469 437 470 def get_selected_element(self): 438 471 selection = self.get_selection() … … 442 475 return model.get_value(iter, 0) 443 476 477 444 478 def expand_root_nodes(self): 445 479 self.expand_row((0,), False) 480 446 481 447 482 def _set_pixbuf(self, column, cell, model, iter, data): … … 491 526 log.error('Could not create path from string "%s"' % path_str) 492 527 528 493 529 # def do_drag_begin (self, context): 494 530 # print 'do_drag_begin' 531 495 532 496 533 def on_drag_data_get(self, context, selection_data, info, time): … … 509 546 selection_data.set(selection_data.target, 8, element.name) 510 547 548 511 549 def on_drag_data_delete (self, context): 512 550 """ … … 514 552 """ 515 553 self.emit_stop_by_name('drag-data-delete') 554 516 555 517 556 # Drop … … 569 608 selection.select_path(path) 570 609 610 571 611 def on_drag_drop(self, context, x, y, time): 572 612 """ … … 577 617 return 1 578 618 619 579 620 gobject.type_register(NamespaceModel) 580 621 gobject.type_register(NamespaceView) gaphor/trunk/gaphor/ui/tests/test_handletool.py
r2051 r2116 21 21 22 22 def setUp(self): 23 Application.init(services=['adapter_loader', 'element_factory', 'gui_manager', 'properties_manager' ])23 Application.init(services=['adapter_loader', 'element_factory', 'gui_manager', 'properties_manager', 'action_manager', 'properties']) 24 24 self.main_window = Application.get_service('gui_manager').main_window 25 25 gaphor/trunk/gaphor/ui/tests/test_namespace.py
r1994 r2116 134 134 m.name = 'm' 135 135 assert ns._nodes.has_key(m) 136 assert ns.path_from_element(m) == ( 0,)137 assert ns.element_from_path(( 0,)) is m136 assert ns.path_from_element(m) == (1,) 137 assert ns.element_from_path((1,)) is m 138 138 139 139 a = factory.create(UML.Package) … … 142 142 assert a in ns._nodes[None] 143 143 assert m in ns._nodes 144 assert ns.path_from_element(a) == ( 0,), ns.path_from_element(a)145 assert ns.path_from_element(m) == ( 1,), ns.path_from_element(m)144 assert ns.path_from_element(a) == (1,), ns.path_from_element(a) 145 assert ns.path_from_element(m) == (2,), ns.path_from_element(m) 146 146 147 147 a.package = m … … 153 153 assert a in m.ownedMember 154 154 assert a.namespace is m 155 assert ns.path_from_element(a) == ( 0, 0), ns.path_from_element(a)155 assert ns.path_from_element(a) == (1, 0), ns.path_from_element(a) 156 156 157 157 c = factory.create(UML.Class) 158 158 c.name = 'c' 159 159 assert c in ns._nodes 160 assert ns.path_from_element(c) == ( 0,)161 assert ns.path_from_element(m) == ( 1,), ns.path_from_element(m)162 assert ns.path_from_element(a) == ( 1, 0), ns.path_from_element(a)160 assert ns.path_from_element(c) == (1,), ns.path_from_element(c) 161 assert ns.path_from_element(m) == (2,), ns.path_from_element(m) 162 assert ns.path_from_element(a) == (2, 0), ns.path_from_element(a) 163 163 164 164 c.package = m
