NoValidPathException.py 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. #
  2. # This file is part of the LibreOffice project.
  3. #
  4. # This Source Code Form is subject to the terms of the Mozilla Public
  5. # License, v. 2.0. If a copy of the MPL was not distributed with this
  6. # file, You can obtain one at http://mozilla.org/MPL/2.0/.
  7. #
  8. # This file incorporates work covered by the following license notice:
  9. #
  10. # Licensed to the Apache Software Foundation (ASF) under one or more
  11. # contributor license agreements. See the NOTICE file distributed
  12. # with this work for additional information regarding copyright
  13. # ownership. The ASF licenses this file to you under the Apache
  14. # License, Version 2.0 (the "License"); you may not use this file
  15. # except in compliance with the License. You may obtain a copy of
  16. # the License at http://www.apache.org/licenses/LICENSE-2.0 .
  17. #
  18. class NoValidPathException(Exception):
  19. def __init__(self, xMSF, _sText):
  20. super(NoValidPathException,self).__init__(_sText)
  21. # TODO: NEVER open a dialog in an exception
  22. from .SystemDialog import SystemDialog
  23. if xMSF:
  24. import sys, os
  25. if sys.version_info < (3,4):
  26. import imp
  27. imp.load_source('strings', os.path.join(os.path.dirname(__file__), '../common/strings.hrc'))
  28. import strings
  29. elif sys.version_info < (3,7):
  30. # imp is deprecated since Python v.3.4
  31. from importlib.machinery import SourceFileLoader
  32. SourceFileLoader('strings', os.path.join(os.path.dirname(__file__), '../common/strings.hrc')).load_module()
  33. import strings
  34. else:
  35. # have to jump through hoops since 3.7, partly because python does not like loading modules that do have a .py extension
  36. import importlib
  37. import importlib.util
  38. import importlib.machinery
  39. module_name = 'strings'
  40. path = os.path.join(os.path.dirname(__file__), '../common/strings.hrc')
  41. spec = importlib.util.spec_from_loader(
  42. module_name,
  43. importlib.machinery.SourceFileLoader(module_name, path)
  44. )
  45. module = importlib.util.module_from_spec(spec)
  46. spec.loader.exec_module(module)
  47. sys.modules[module_name] = module
  48. strings = module
  49. SystemDialog.showErrorBox(xMSF, strings.RID_COMMON_START_21) #OfficePathnotavailable