ExcellonPreferencesUI.py 3.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. from flatcamGUI.preferences.OptionsGroupUI import OptionsGroupUI
  2. from flatcamGUI.preferences.PreferencesSectionUI import PreferencesSectionUI
  3. from flatcamGUI.preferences.excellon.ExcellonEditorPrefGroupUI import ExcellonEditorPrefGroupUI
  4. from flatcamGUI.preferences.excellon.ExcellonExpPrefGroupUI import ExcellonExpPrefGroupUI
  5. from flatcamGUI.preferences.excellon.ExcellonAdvOptPrefGroupUI import ExcellonAdvOptPrefGroupUI
  6. from flatcamGUI.preferences.excellon.ExcellonOptPrefGroupUI import ExcellonOptPrefGroupUI
  7. from flatcamGUI.preferences.excellon.ExcellonGenPrefGroupUI import ExcellonGenPrefGroupUI
  8. import gettext
  9. import FlatCAMTranslation as fcTranslate
  10. import builtins
  11. fcTranslate.apply_language('strings')
  12. if '_' not in builtins.__dict__:
  13. _ = gettext.gettext
  14. class ExcellonPreferencesUI(PreferencesSectionUI):
  15. def __init__(self, decimals, **kwargs):
  16. self.decimals = decimals
  17. # FIXME: remove the need for external access to excellon_opt_group
  18. self.excellon_opt_group = ExcellonOptPrefGroupUI(decimals=self.decimals)
  19. self.excellon_editor_group = ExcellonEditorPrefGroupUI(decimals=self.decimals)
  20. super().__init__(**kwargs)
  21. self.init_sync_export()
  22. def build_groups(self) -> [OptionsGroupUI]:
  23. return [
  24. ExcellonGenPrefGroupUI(decimals=self.decimals),
  25. self.excellon_opt_group,
  26. ExcellonExpPrefGroupUI(decimals=self.decimals),
  27. ExcellonAdvOptPrefGroupUI(decimals=self.decimals),
  28. self.excellon_editor_group
  29. ]
  30. def get_tab_id(self):
  31. return "excellon_tab"
  32. def get_tab_label(self):
  33. return _("EXCELLON")
  34. def init_sync_export(self):
  35. self.option_dict()["excellon_update"].get_field().stateChanged.connect(self.sync_export)
  36. self.option_dict()["excellon_format_upper_in"].get_field().returnPressed.connect(self.sync_export)
  37. self.option_dict()["excellon_format_lower_in"].get_field().returnPressed.connect(self.sync_export)
  38. self.option_dict()["excellon_format_upper_mm"].get_field().returnPressed.connect(self.sync_export)
  39. self.option_dict()["excellon_format_lower_mm"].get_field().returnPressed.connect(self.sync_export)
  40. self.option_dict()["excellon_zeros"].get_field().activated_custom.connect(self.sync_export)
  41. self.option_dict()["excellon_units"].get_field().activated_custom.connect(self.sync_export)
  42. def sync_export(self):
  43. if not self.option_dict()["excellon_update"].get_field().get_value():
  44. # User has disabled sync.
  45. return
  46. zeros = self.option_dict()["excellon_zeros"].get_field().get_value() + 'Z'
  47. self.option_dict()["excellon_exp_zeros"].get_field().set_value(zeros)
  48. units = self.option_dict()["excellon_units"].get_field().get_value()
  49. self.option_dict()["excellon_exp_units"].get_field().set_value(units)
  50. if units.upper() == 'METRIC':
  51. whole = self.option_dict()["excellon_format_upper_mm"].get_field().get_value()
  52. dec = self.option_dict()["excellon_format_lower_mm"].get_field().get_value()
  53. else:
  54. whole = self.option_dict()["excellon_format_upper_in"].get_field().get_value()
  55. dec = self.option_dict()["excellon_format_lower_in"].get_field().get_value()
  56. self.option_dict()["excellon_exp_integer"].get_field().set_value(whole)
  57. self.option_dict()["excellon_exp_decimals"].get_field().set_value(dec)