def test_classifier_editor(self): """ Test classifier editor """ klass = self.create(ClassItem, UML.Class) klass.subject.name = "Class1" self.diagram.canvas.update() attr = self.element_factory.create(UML.Property) attr.name = "blah" klass.subject.ownedAttribute = attr oper = self.element_factory.create(UML.Operation) oper.name = "method" klass.subject.ownedOperation = oper self.diagram.canvas.update() edit = Editor(klass) assert "ClassifiedItemEditor" == edit.__class__.__name__ assert edit.is_editable(10, 10) # Test the inner working of the editor self.assertEqual(klass, edit._edit) assert "Class1" == edit.get_text()
def test_classifier_editor(self): """ Test classifier editor """ klass = self.create(ClassItem, UML.Class) klass.subject.name = "Class1" self.diagram.canvas.update() attr = self.element_factory.create(UML.Property) attr.name = "blah" klass.subject.ownedAttribute = attr oper = self.element_factory.create(UML.Operation) oper.name = "method" klass.subject.ownedOperation = oper self.diagram.canvas.update() edit = Editor(klass) self.assertEqual("CompartmentItemEditor", edit.__class__.__name__) self.assertEqual(True, edit.is_editable(10, 10)) # Test the inner working of the editor self.assertEqual(klass, edit._edit) self.assertEqual("Class1", edit.get_text()) # The attribute: y = klass._header_size[1] + klass.style.compartment_padding[0] + 3 self.assertEqual(True, edit.is_editable(4, y)) self.assertEqual(attr, edit._edit.subject) self.assertEqual("+ blah", edit.get_text()) y += klass.compartments[0].height # The operation self.assertEqual(True, edit.is_editable(3, y)) self.assertEqual(oper, edit._edit.subject) self.assertEqual("+ method()", edit.get_text())
def on_double_click(self, event): view = self.view item = view.hovered_item if item: editor = Editor(item) if not editor: return False log.debug(f"Found editor {editor!r}") x, y = view.get_matrix_v2i(item).transform_point(event.x, event.y) if editor.is_editable(x, y): text = editor.get_text() root_coords = event.get_root_coords() self.create_edit_window(root_coords.x_root, root_coords.y_root, text, editor) return True
def on_double_click(self, event): view = self.view item = view.hovered_item if item: try: editor = Editor(item) except TypeError: # Could not adapt to Editor return False log.debug("Found editor %r" % editor) x, y = view.get_matrix_v2i(item).transform_point(event.x, event.y) if editor.is_editable(x, y): text = editor.get_text() root_coords = event.get_root_coords() self.create_edit_window(root_coords.x_root, root_coords.y_root, text, editor) return True