Guest User

Untitled

a guest
Jul 16th, 2018
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.74 KB | None | 0 0
  1. from functor import Functor
  2. from category_diagram import CategoryDiagram
  3. from category_arrow import CategoryArrow
  4.  
  5. class OpFunctor(Functor):
  6. def __init__(self, new=True):
  7. super().__init__(new)
  8. self.setLabelText(0, "op")
  9. self.label(0).setEditable(False)
  10. self.setContravariant(True)
  11.  
  12. def setDomain(self, dom, undoable=False):
  13. if dom is not self.domain():
  14. super().setDomain(dom, undoable)
  15. cod = self.codomain()
  16. if cod and dom:
  17. cod.setSymbol(self.imageString(dom))
  18. cod.categoryLabel().addConstraint(lambda: cod.category() == self.imageString(dom))
  19.  
  20. def setCodomain(self, cod, undoable=False):
  21. prev_cod = self.codomain()
  22. if cod is not prev_cod:
  23. if prev_cod: prev_cod.symbolLabel().setEditable(True)
  24. super().setCodomain(cod, undoable)
  25. dom = self.domain()
  26. if dom and cod:
  27. cod.categoryLabel().setEditable(False)
  28. cod.setCategory(self.imageString(dom))
  29. cod.symbolLabel().addConstraint(lambda: cod.category() == self.imageString(dom))
  30.  
  31. def canConnectTo(self, item, at_tail):
  32. if super().canConnectTo(item, at_tail) == False:
  33. return False
  34. if at_tail == False:
  35. if isinstance(item, CategoryDiagram) and not item.categoryLabel().isConstrained():
  36. return True
  37. return True
  38.  
  39. def takeImage(self, dom=None, cod=None, contra=False):
  40. super().takeImage(dom, cod, not contra) # This is flag to invert the arrows in the image
  41.  
  42. def imageString(self, x):
  43. if isinstance(x, (CategoryDiagram, CategoryArrow)):
  44. return str(x) + "^op"
  45. return str(x)
Add Comment
Please, Sign In to add comment