hook-gi.repository.Gtk.py 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. #-----------------------------------------------------------------------------
  2. # Copyright (c) 2005-2023, PyInstaller Development Team.
  3. #
  4. # Distributed under the terms of the GNU General Public License (version 2
  5. # or later) with exception for distributing the bootloader.
  6. #
  7. # The full license is in the file COPYING.txt, distributed with this software.
  8. #
  9. # SPDX-License-Identifier: (GPL-2.0-or-later WITH Bootloader-exception)
  10. #-----------------------------------------------------------------------------
  11. import os
  12. import os.path
  13. from PyInstaller.compat import is_win
  14. from PyInstaller.utils.hooks import get_hook_config
  15. from PyInstaller.utils.hooks.gi import GiModuleInfo, collect_glib_etc_files, collect_glib_share_files, \
  16. collect_glib_translations
  17. def hook(hook_api):
  18. module_info = GiModuleInfo('Gtk', '3.0', hook_api=hook_api) # Pass hook_api to read version from hook config
  19. if not module_info.available:
  20. return
  21. binaries, datas, hiddenimports = module_info.collect_typelib_data()
  22. # Collect fontconfig data
  23. datas += collect_glib_share_files('fontconfig')
  24. # Icons, themes, translations
  25. icon_list = get_hook_config(hook_api, "gi", "icons")
  26. if icon_list is not None:
  27. for icon in icon_list:
  28. datas += collect_glib_share_files(os.path.join('icons', icon))
  29. else:
  30. datas += collect_glib_share_files('icons')
  31. # Themes
  32. theme_list = get_hook_config(hook_api, "gi", "themes")
  33. if theme_list is not None:
  34. for theme in theme_list:
  35. datas += collect_glib_share_files(os.path.join('themes', theme))
  36. else:
  37. datas += collect_glib_share_files('themes')
  38. # Translations
  39. lang_list = get_hook_config(hook_api, "gi", "languages")
  40. datas += collect_glib_translations(f'gtk{module_info.version[0]}0', lang_list)
  41. # These only seem to be required on Windows
  42. if is_win:
  43. datas += collect_glib_etc_files('fonts')
  44. datas += collect_glib_etc_files('pango')
  45. datas += collect_glib_share_files('fonts')
  46. hook_api.add_datas(datas)
  47. hook_api.add_binaries(binaries)
  48. hook_api.add_imports(*hiddenimports)