You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

118 lines
3.2 KiB

  1. import json
  2. import sys
  3. from collections import OrderedDict
  4. from uuid import uuid4
  5. from PyQt5.QtWidgets import QApplication
  6. from copy import deepcopy
  7. from rx.subjects import Subject
  8. from gooey.gui.lang import i18n
  9. def app_reducer(state, action):
  10. if action['type'] == 'pass':
  11. pass
  12. def gooey1to2(buildspec):
  13. '''
  14. Still figuring out exactly how I want everything arranged..
  15. '''
  16. root_commands = OrderedDict()
  17. widgets = []
  18. for parent_name, val in buildspec['widgets'].items():
  19. root_commands[parent_name] = val['command']
  20. for index, widget in enumerate(val['contents']):
  21. new_widget = deepcopy(widget)
  22. new_widget['parent'] = parent_name
  23. if widget['type'] == 'MultiDirChooser':
  24. print('Ignoring MultiDirChooser')
  25. continue
  26. if widget['type'] == 'RadioGroup':
  27. print('Ignoring RadioGroup')
  28. continue
  29. if not widget['type'] == 'RadioGroup':
  30. if new_widget['type'] == 'DirChooser':
  31. new_widget['type'] = 'DirectoryChooser'
  32. new_widget['value'] = widget['data']['default']
  33. else:
  34. new_widget['value'] = None
  35. new_widget['id'] = str(uuid4())
  36. new_widget['order'] = index
  37. widgets.append(new_widget)
  38. widget_map = OrderedDict((widget['id'], widget) for widget in widgets)
  39. new_buildspec = deepcopy(buildspec)
  40. new_buildspec['view'] = 'configuration'
  41. new_buildspec['activeGroup'] = list(root_commands.keys())[0]
  42. new_buildspec['groups'] = root_commands
  43. new_buildspec['widgets'] = widget_map
  44. new_buildspec['title'] = 'Settings'
  45. new_buildspec['subtitle'] = new_buildspec['program_description']
  46. new_buildspec['icon'] = '../images/config_icon.png'
  47. new_buildspec['gooey_state'] = {
  48. 'icon': '../images/config_icon.png',
  49. 'title': 'Settings',
  50. 'subtitle': new_buildspec['program_description'],
  51. 'window': 0,
  52. 'buttonGroup': 0
  53. }
  54. return new_buildspec
  55. def load_initial_state():
  56. with open('gooey_config.json', 'r') as f:
  57. data = json.loads(f.read(), object_pairs_hook=OrderedDict)
  58. return gooey1to2(data)
  59. class StateContainer(Subject):
  60. def __init__(self, initialState=None):
  61. super(StateContainer, self).__init__()
  62. self._state = initialState or {}
  63. def __getitem__(self, item):
  64. return self._state[item]
  65. def __setitem__(self, key, value):
  66. self._state[key] = value
  67. self.on_next(self._state)
  68. sys._excepthook = sys.excepthook
  69. def my_exception_hook(exctype, value, traceback):
  70. # Print the error and traceback
  71. print(exctype, value, traceback)
  72. # Call the normal Exception hook after
  73. sys._excepthook(exctype, value, traceback)
  74. sys.exit(1)
  75. # Set the exception hook to our wrapping function
  76. sys.excepthook = my_exception_hook
  77. state = StateContainer(load_initial_state())
  78. i18n.load(state['language_dir'], state['language'])
  79. from gooey.new_hotness.containers.application import MainWindow
  80. app = QApplication(sys.argv)
  81. form = MainWindow(state)
  82. state['title'] = 'Foobar'
  83. state['title'] = 'Settings'
  84. state['icon'] = '../images/config_icon.png'
  85. # show
  86. form.show()
  87. app.exec_()