user.py 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. # Copyright (c) 2026 Riverbank Computing Limited <info@riverbankcomputing.com>
  2. #
  3. # This file is part of PyQt6.
  4. #
  5. # This file may be used under the terms of the GNU General Public License
  6. # version 3.0 as published by the Free Software Foundation and appearing in
  7. # the file LICENSE included in the packaging of this file. Please review the
  8. # following information to ensure the GNU General Public License version 3.0
  9. # requirements will be met: http://www.gnu.org/copyleft/gpl.html.
  10. #
  11. # If you do not wish to use this file under the terms of the GPL version 3.0
  12. # then you may purchase a commercial license. For more information contact
  13. # info@riverbankcomputing.com.
  14. #
  15. # This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
  16. # WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  17. class UserException(Exception):
  18. """ Encapsulate an exception ultimate caused by the user. """
  19. pass
  20. class User:
  21. """ A mixin that provides methods for communicating with the user. """
  22. def __init__(self, verbose, **kwargs):
  23. """ Initialise the object. """
  24. super().__init__(**kwargs)
  25. self._verbose = verbose
  26. @staticmethod
  27. def pretty(text):
  28. """ Returns a pretty-fied version of some text suitable for displaying
  29. to the user.
  30. """
  31. return text.replace('\n', '\\n')
  32. def progress(self, message):
  33. """ Display a progress message. """
  34. if self._verbose:
  35. print(message)