Surface NMR processing and inversion GUI
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

config.py 2.6KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. """
  2. Contains the config class (pyuic.cfg or pyuic.json)
  3. """
  4. import json
  5. from .utils import write_message
  6. class QtApi:
  7. pyqt4 = 0
  8. pyqt5 = 1
  9. pyside = 2
  10. class Config:
  11. def __init__(self):
  12. self.files = []
  13. self.pyuic = ''
  14. self.pyuic_options = ''
  15. self.pyrcc = ''
  16. self.pyrcc_options = ''
  17. self.hooks = []
  18. def uic_command(self):
  19. return self.pyuic + ' ' + self.pyuic_options + ' %s -o %s'
  20. def rcc_command(self):
  21. return self.pyrcc + ' ' + self.pyrcc_options + ' %s -o %s'
  22. def load(self):
  23. for ext in ['.cfg', '.json']:
  24. try:
  25. with open('pyuic' + ext, 'r') as f:
  26. self.__dict__ = json.load(f)
  27. except (IOError, OSError):
  28. pass
  29. else:
  30. break
  31. else:
  32. write_message('failed to open configuration file', 'yellow')
  33. if not hasattr(self, 'hooks'):
  34. self.hooks = []
  35. def save(self):
  36. with open('pyuic.json', 'w') as f:
  37. json.dump(self.__dict__, f, indent=4, sort_keys=True)
  38. def generate(self, api):
  39. if api == QtApi.pyqt4:
  40. self.pyrcc = 'pyrcc4'
  41. self.pyrcc_options = '-py3'
  42. self.pyuic = 'pyuic4'
  43. self.pyuic_options = '--from-import'
  44. self.files[:] = []
  45. elif api == QtApi.pyqt5:
  46. self.pyrcc = 'pyrcc5'
  47. self.pyrcc_options = ''
  48. self.pyuic = 'pyuic5'
  49. self.pyuic_options = '--from-import'
  50. self.files[:] = []
  51. elif api == QtApi.pyside:
  52. self.pyrcc = 'pyside-rcc'
  53. self.pyrcc_options = '-py3'
  54. self.pyuic = 'pyside-uic'
  55. self.pyuic_options = '--from-import'
  56. self.files[:] = []
  57. self.save()
  58. write_message('pyuic.json generated', 'green')
  59. def add(self, src, dst):
  60. self.load()
  61. for fn, _ in self.files:
  62. if fn == src:
  63. write_message('ui file already added: %s' % src)
  64. return
  65. self.files.append((src, dst))
  66. self.save()
  67. write_message('file added to pyuic.json: %s -> %s' % (src, dst), 'green')
  68. def remove(self, filename):
  69. self.load()
  70. to_remove = None
  71. for i, files in enumerate(self.files):
  72. src, dest = files
  73. if filename == src:
  74. to_remove = i
  75. break
  76. if to_remove is not None:
  77. self.files.pop(to_remove)
  78. self.save()
  79. write_message('file removed from pyuic.json: %s' % filename, 'green')