Funktionierender Prototyp des Serious Games zur Vermittlung von Wissen zu Software-Engineering-Arbeitsmodellen.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

object.py 2.1KB

1 year ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. # MFC base classes.
  2. import win32ui
  3. class Object:
  4. def __init__(self, initObj=None):
  5. self.__dict__["_obj_"] = initObj
  6. # self._obj_ = initObj
  7. if initObj is not None:
  8. initObj.AttachObject(self)
  9. def __del__(self):
  10. self.close()
  11. def __getattr__(
  12. self, attr
  13. ): # Make this object look like the underlying win32ui one.
  14. # During cleanup __dict__ is not available, causing recursive death.
  15. if not attr.startswith("__"):
  16. try:
  17. o = self.__dict__["_obj_"]
  18. if o is not None:
  19. return getattr(o, attr)
  20. # Only raise this error for non "internal" names -
  21. # Python may be calling __len__, __nonzero__, etc, so
  22. # we dont want this exception
  23. if attr[0] != "_" and attr[-1] != "_":
  24. raise win32ui.error("The MFC object has died.")
  25. except KeyError:
  26. # No _obj_ at all - dont report MFC object died when there isnt one!
  27. pass
  28. raise AttributeError(attr)
  29. def OnAttachedObjectDeath(self):
  30. # print "object", self.__class__.__name__, "dieing"
  31. self._obj_ = None
  32. def close(self):
  33. if "_obj_" in self.__dict__:
  34. if self._obj_ is not None:
  35. self._obj_.AttachObject(None)
  36. self._obj_ = None
  37. class CmdTarget(Object):
  38. def __init__(self, initObj):
  39. Object.__init__(self, initObj)
  40. def HookNotifyRange(self, handler, firstID, lastID):
  41. oldhandlers = []
  42. for i in range(firstID, lastID + 1):
  43. oldhandlers.append(self.HookNotify(handler, i))
  44. return oldhandlers
  45. def HookCommandRange(self, handler, firstID, lastID):
  46. oldhandlers = []
  47. for i in range(firstID, lastID + 1):
  48. oldhandlers.append(self.HookCommand(handler, i))
  49. return oldhandlers
  50. def HookCommandUpdateRange(self, handler, firstID, lastID):
  51. oldhandlers = []
  52. for i in range(firstID, lastID + 1):
  53. oldhandlers.append(self.HookCommandUpdate(handler, i))
  54. return oldhandlers