__init__.py 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. """
  2. ***************************************************************************
  3. __init__.py
  4. ---------------------
  5. Date : January 2016
  6. Copyright : (C) 2016 by Victor Olaya
  7. Email : volayaf at gmail dot com
  8. ***************************************************************************
  9. * *
  10. * This program is free software; you can redistribute it and/or modify *
  11. * it under the terms of the GNU General Public License as published by *
  12. * the Free Software Foundation; either version 2 of the License, or *
  13. * (at your option) any later version. *
  14. * *
  15. ***************************************************************************
  16. """
  17. __author__ = 'Victor Olaya'
  18. __date__ = 'January 2016'
  19. __copyright__ = '(C) 2016, Victor Olaya'
  20. import os
  21. import codecs
  22. import warnings
  23. with warnings.catch_warnings():
  24. warnings.filterwarnings("ignore", category=DeprecationWarning)
  25. import yaml
  26. from qgis.core import QgsSettings, Qgis
  27. from qgis.PyQt.QtCore import QLocale, QCoreApplication
  28. def loadShortHelp():
  29. h = {}
  30. path = os.path.dirname(__file__)
  31. for f in os.listdir(path):
  32. if f.endswith("yaml"):
  33. filename = os.path.join(path, f)
  34. with codecs.open(filename, encoding='utf-8') as stream:
  35. with warnings.catch_warnings():
  36. warnings.filterwarnings("ignore", category=DeprecationWarning)
  37. for k, v in yaml.load(stream, Loader=yaml.SafeLoader).items():
  38. if v is None:
  39. continue
  40. h[k] = QCoreApplication.translate(f"{f[:-5].upper()}Algorithm", v)
  41. version = ".".join(Qgis.QGIS_VERSION.split(".")[0:2])
  42. overrideLocale = QgsSettings().value('locale/overrideFlag', False, bool)
  43. if not overrideLocale:
  44. locale = QLocale.system().name()[:2]
  45. else:
  46. locale = QgsSettings().value('locale/userLocale', '')
  47. locale = locale.split("_")[0]
  48. def replace(s):
  49. if s is not None:
  50. return s.replace("{qgisdocs}", f"https://docs.qgis.org/{version}/{locale}/docs")
  51. else:
  52. return None
  53. h = {k: replace(v) for k, v in list(h.items())}
  54. return h
  55. shortHelp = loadShortHelp()