Surface NMR processing and inversion GUI
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

hooks.py 1.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. """
  2. This module contains the hooks load and our builtin hooks.
  3. """
  4. import re
  5. import pkg_resources
  6. from .utils import write_message
  7. #: Name of the entrypoint to use in setup.py
  8. ENTRYPOINT = 'pyqt_distutils_hooks'
  9. def load_hooks():
  10. """
  11. Load the exposed hooks.
  12. Returns a dict of hooks where the keys are the name of the hook and the
  13. values are the actual hook functions.
  14. """
  15. hooks = {}
  16. for entrypoint in pkg_resources.iter_entry_points(ENTRYPOINT):
  17. name = str(entrypoint).split('=')[0].strip()
  18. try:
  19. hook = entrypoint.load()
  20. except Exception as e:
  21. write_message('failed to load entry-point %r (error="%s")' % (name, e), 'yellow')
  22. else:
  23. hooks[name] = hook
  24. return hooks
  25. def hook(ui_file_path):
  26. """
  27. This is the prototype of a hook function.
  28. """
  29. pass
  30. def gettext(ui_file_path):
  31. """
  32. Let you use gettext instead of the Qt tools for l18n
  33. """
  34. with open(ui_file_path, 'r') as fin:
  35. content = fin.read()
  36. # replace ``_translate("context", `` by ``_(``
  37. content = re.sub(r'_translate\(".*",\s', '_(', content)
  38. content = content.replace(
  39. ' _translate = QtCore.QCoreApplication.translate', '')
  40. with open(ui_file_path, 'w') as fout:
  41. fout.write(content)