move the excellon export settings sync code out of FlatCAMApp

This commit is contained in:
David Robertson 2020-05-10 22:43:50 +01:00
parent 5d3f4ee038
commit 3a1089c277
2 changed files with 26 additions and 135 deletions

View File

@ -1011,15 +1011,6 @@ class App(QtCore.QObject):
self.object_status_changed.connect(self.on_collection_updated)
# Make sure that when the Excellon loading parameters are changed, the change is reflected in the
# Export Excellon parameters.
self.ui.excellon_defaults_form.excellon_gen_group.update_excellon_cb.stateChanged.connect(
self.on_update_exc_export
)
# call it once to make sure it is updated at startup
self.on_update_exc_export(state=self.defaults["excellon_update"])
# when there are arguments at application startup this get launched
self.args_at_startup[list].connect(self.on_startup_args)
@ -4623,133 +4614,7 @@ class App(QtCore.QObject):
self.app_cursor.enabled = True
self.app_cursor.enabled = False
def on_update_exc_export(self, state):
"""
This is handling the update of Excellon Export parameters based on the ones in the Excellon General but only
if the update_excellon_cb checkbox is checked
:param state: state of the checkbox whose signals is tied to his slot
:return:
"""
if state:
# first try to disconnect
try:
self.ui.excellon_defaults_form.excellon_gen_group.excellon_format_upper_in_entry.returnPressed. \
disconnect(self.on_excellon_format_changed)
except TypeError:
pass
try:
self.ui.excellon_defaults_form.excellon_gen_group.excellon_format_lower_in_entry.returnPressed. \
disconnect(self.on_excellon_format_changed)
except TypeError:
pass
try:
self.ui.excellon_defaults_form.excellon_gen_group.excellon_format_upper_mm_entry.returnPressed. \
disconnect(self.on_excellon_format_changed)
except TypeError:
pass
try:
self.ui.excellon_defaults_form.excellon_gen_group.excellon_format_lower_mm_entry.returnPressed. \
disconnect(self.on_excellon_format_changed)
except TypeError:
pass
try:
self.ui.excellon_defaults_form.excellon_gen_group.excellon_zeros_radio.activated_custom. \
disconnect(self.on_excellon_zeros_changed)
except TypeError:
pass
try:
self.ui.excellon_defaults_form.excellon_gen_group.excellon_units_radio.activated_custom. \
disconnect(self.on_excellon_zeros_changed)
except TypeError:
pass
# the connect them
self.ui.excellon_defaults_form.excellon_gen_group.excellon_format_upper_in_entry.returnPressed.connect(
self.on_excellon_format_changed)
self.ui.excellon_defaults_form.excellon_gen_group.excellon_format_lower_in_entry.returnPressed.connect(
self.on_excellon_format_changed)
self.ui.excellon_defaults_form.excellon_gen_group.excellon_format_upper_mm_entry.returnPressed.connect(
self.on_excellon_format_changed)
self.ui.excellon_defaults_form.excellon_gen_group.excellon_format_lower_mm_entry.returnPressed.connect(
self.on_excellon_format_changed)
self.ui.excellon_defaults_form.excellon_gen_group.excellon_zeros_radio.activated_custom.connect(
self.on_excellon_zeros_changed)
self.ui.excellon_defaults_form.excellon_gen_group.excellon_units_radio.activated_custom.connect(
self.on_excellon_units_changed)
else:
# disconnect the signals
try:
self.ui.excellon_defaults_form.excellon_gen_group.excellon_format_upper_in_entry.returnPressed. \
disconnect(self.on_excellon_format_changed)
except TypeError:
pass
try:
self.ui.excellon_defaults_form.excellon_gen_group.excellon_format_lower_in_entry.returnPressed. \
disconnect(self.on_excellon_format_changed)
except TypeError:
pass
try:
self.ui.excellon_defaults_form.excellon_gen_group.excellon_format_upper_mm_entry.returnPressed. \
disconnect(self.on_excellon_format_changed)
except TypeError:
pass
try:
self.ui.excellon_defaults_form.excellon_gen_group.excellon_format_lower_mm_entry.returnPressed. \
disconnect(self.on_excellon_format_changed)
except TypeError:
pass
try:
self.ui.excellon_defaults_form.excellon_gen_group.excellon_zeros_radio.activated_custom. \
disconnect(self.on_excellon_zeros_changed)
except TypeError:
pass
try:
self.ui.excellon_defaults_form.excellon_gen_group.excellon_units_radio.activated_custom. \
disconnect(self.on_excellon_zeros_changed)
except TypeError:
pass
def on_excellon_format_changed(self):
"""
Slot activated when the user changes the Excellon format values in Preferences -> Excellon -> Excellon General
:return: None
"""
if self.ui.excellon_defaults_form.excellon_gen_group.excellon_units_radio.get_value().upper() == 'METRIC':
self.ui.excellon_defaults_form.excellon_exp_group.format_whole_entry.set_value(
self.ui.excellon_defaults_form.excellon_gen_group.excellon_format_upper_mm_entry.get_value()
)
self.ui.excellon_defaults_form.excellon_exp_group.format_dec_entry.set_value(
self.ui.excellon_defaults_form.excellon_gen_group.excellon_format_lower_mm_entry.get_value()
)
else:
self.ui.excellon_defaults_form.excellon_exp_group.format_whole_entry.set_value(
self.ui.excellon_defaults_form.excellon_gen_group.excellon_format_upper_in_entry.get_value()
)
self.ui.excellon_defaults_form.excellon_exp_group.format_dec_entry.set_value(
self.ui.excellon_defaults_form.excellon_gen_group.excellon_format_lower_in_entry.get_value()
)
def on_excellon_zeros_changed(self):
"""
Slot activated when the user changes the Excellon zeros values in Preferences -> Excellon -> Excellon General
:return: None
"""
self.ui.excellon_defaults_form.excellon_exp_group.zeros_radio.set_value(
self.ui.excellon_defaults_form.excellon_gen_group.excellon_zeros_radio.get_value() + 'Z'
)
def on_excellon_units_changed(self):
"""
Slot activated when the user changes the Excellon unit values in Preferences -> Excellon -> Excellon General
:return: None
"""
self.ui.excellon_defaults_form.excellon_exp_group.excellon_units_radio.set_value(
self.ui.excellon_defaults_form.excellon_gen_group.excellon_units_radio.get_value()
)
self.on_excellon_format_changed()
def on_film_color_entry(self):
self.defaults['tools_film_color'] = \

View File

@ -19,12 +19,23 @@ class ExcellonPreferencesUI(PreferencesSectionUI):
def __init__(self, decimals, **kwargs):
self.decimals = decimals
self.excellon_gen_group = ExcellonGenPrefGroupUI(decimals=self.decimals)
# FIXME: remove the need for external access to excellon_opt_group
self.excellon_opt_group = ExcellonOptPrefGroupUI(decimals=self.decimals)
self.excellon_exp_group = ExcellonExpPrefGroupUI(decimals=self.decimals)
self.excellon_adv_opt_group = ExcellonAdvOptPrefGroupUI(decimals=self.decimals)
self.excellon_editor_group = ExcellonEditorPrefGroupUI(decimals=self.decimals)
super().__init__(**kwargs)
self.excellon_gen_group.excellon_format_upper_in_entry.returnPressed.connect(self.sync_export)
self.excellon_gen_group.excellon_format_lower_in_entry.returnPressed.connect(self.sync_export)
self.excellon_gen_group.excellon_format_upper_mm_entry.returnPressed.connect(self.sync_export)
self.excellon_gen_group.excellon_format_lower_mm_entry.returnPressed.connect(self.sync_export)
self.excellon_gen_group.excellon_zeros_radio.activated_custom.connect(self.sync_export)
self.excellon_gen_group.excellon_units_radio.activated_custom.connect(self.sync_export)
def build_groups(self) -> [OptionsGroupUI]:
return [
self.excellon_gen_group,
@ -40,3 +51,18 @@ class ExcellonPreferencesUI(PreferencesSectionUI):
def get_tab_label(self):
return _("EXCELLON")
def sync_export(self):
if not self.excellon_gen_group.update_excellon_cb.get_value():
# User has disabled sync.
return
self.excellon_exp_group.zeros_radio.set_value(self.excellon_gen_group.excellon_zeros_radio.get_value() + 'Z')
self.excellon_exp_group.excellon_units_radio.set_value(self.excellon_gen_group.excellon_units_radio.get_value())
if self.excellon_gen_group.excellon_units_radio.get_value().upper() == 'METRIC':
self.excellon_exp_group.format_whole_entry.set_value(self.excellon_gen_group.excellon_format_upper_mm_entry.get_value())
self.excellon_exp_group.format_dec_entry.set_value(self.excellon_gen_group.excellon_format_lower_mm_entry.get_value())
else:
self.excellon_exp_group.format_whole_entry.set_value(self.excellon_gen_group.excellon_format_upper_in_entry.get_value())
self.excellon_exp_group.format_dec_entry.set_value(self.excellon_gen_group.excellon_format_lower_in_entry.get_value())