BackwardsCompatibleMessage.py 813 B

1234567891011121314151617
  1. # Copyright (c) 2021 Ultimaker B.V.
  2. # Cura is released under the terms of the LGPLv3 or higher.
  3. from typing import Optional
  4. from cura.CuraApplication import CuraApplication
  5. from UM.Message import Message
  6. from UM.Version import Version
  7. def getBackwardsCompatibleMessage(text: str, title: str, message_type_str: str, lifetime: Optional[int] = 30) -> Message:
  8. if CuraApplication.getInstance().getAPIVersion() < Version("7.7.0"):
  9. return Message(text=text, title=title, lifetime=lifetime)
  10. else:
  11. message_type = Message.MessageType.NEUTRAL
  12. if ("MessageType." + message_type_str) in [str(item) for item in Message.MessageType]:
  13. message_type = Message.MessageType[message_type_str]
  14. return Message(text=text, title=title, lifetime=lifetime, message_type=message_type)