diff --git a/flatcamGUI/preferences/OptionUI.py b/flatcamGUI/preferences/OptionUI.py index a594f5cd..ce851d4f 100644 --- a/flatcamGUI/preferences/OptionUI.py +++ b/flatcamGUI/preferences/OptionUI.py @@ -97,7 +97,7 @@ class TextAreaOptionUI(OptionUI): self.textarea_widget = self.build_textarea_widget() def build_label_widget(self): - label = QtWidgets.QLabel(_(self.label_text)) + label = QtWidgets.QLabel("%s:" % _(self.label_text)) label.setToolTip(_(self.label_tooltip)) return label diff --git a/flatcamGUI/preferences/PreferencesUIManager.py b/flatcamGUI/preferences/PreferencesUIManager.py index a1b04eb0..e9eae026 100644 --- a/flatcamGUI/preferences/PreferencesUIManager.py +++ b/flatcamGUI/preferences/PreferencesUIManager.py @@ -141,13 +141,6 @@ class PreferencesUIManager: "excellon_editor_slot_circ_angle": self.ui.excellon_defaults_form.excellon_editor_group.slot_array_circular_angle_entry, - - # CNC Job Advanced Options - "cncjob_toolchange_macro": self.ui.cncjob_defaults_form.cncjob_adv_opt_group.toolchange_text, - "cncjob_toolchange_macro_enable": self.ui.cncjob_defaults_form.cncjob_adv_opt_group.toolchange_cb, - "cncjob_annotation_fontsize": self.ui.cncjob_defaults_form.cncjob_adv_opt_group.annotation_fontsize_sp, - "cncjob_annotation_fontcolor": self.ui.cncjob_defaults_form.cncjob_adv_opt_group.annotation_fontcolor_entry, - # NCC Tool "tools_ncctools": self.ui.tools_defaults_form.tools_ncc_group.ncc_tool_dia_entry, "tools_nccorder": self.ui.tools_defaults_form.tools_ncc_group.ncc_order_radio, @@ -532,17 +525,6 @@ class PreferencesUIManager: "background-color:%s;" "border-color: dimgray" % str(self.defaults['excellon_plot_line'])[:7]) - - - - - # Init the Annotation CNC Job color - self.ui.cncjob_defaults_form.cncjob_adv_opt_group.annotation_fontcolor_entry.set_value( - self.defaults['cncjob_annotation_fontcolor']) - self.ui.cncjob_defaults_form.cncjob_adv_opt_group.annotation_fontcolor_button.setStyleSheet( - "background-color:%s;" - "border-color: dimgray" % str(self.defaults['cncjob_annotation_fontcolor'])[:7]) - # Init the Tool Film color self.ui.tools_defaults_form.tools_film_group.film_color_entry.set_value( self.defaults['tools_film_color']) diff --git a/flatcamGUI/preferences/cncjob/CNCJobAdvOptPrefGroupUI.py b/flatcamGUI/preferences/cncjob/CNCJobAdvOptPrefGroupUI.py index 8d7a1cf0..5422e297 100644 --- a/flatcamGUI/preferences/cncjob/CNCJobAdvOptPrefGroupUI.py +++ b/flatcamGUI/preferences/cncjob/CNCJobAdvOptPrefGroupUI.py @@ -1,8 +1,7 @@ -from PyQt5 import QtWidgets, QtGui, QtCore -from PyQt5.QtCore import QSettings, Qt +from PyQt5.QtCore import Qt -from flatcamGUI.GUIElements import FCTextArea, FCCheckBox, FCComboBox, FCSpinner, FCEntry -from flatcamGUI.preferences.OptionsGroupUI import OptionsGroupUI +from flatcamGUI.preferences.OptionUI import * +from flatcamGUI.preferences.OptionsGroupUI import OptionsGroupUI2 import gettext import FlatCAMTranslation as fcTranslate import builtins @@ -11,93 +10,18 @@ fcTranslate.apply_language('strings') if '_' not in builtins.__dict__: _ = gettext.gettext -settings = QSettings("Open Source", "FlatCAM") -if settings.contains("machinist"): - machinist_setting = settings.value('machinist', type=int) -else: - machinist_setting = 0 +class CNCJobAdvOptPrefGroupUI(OptionsGroupUI2): -class CNCJobAdvOptPrefGroupUI(OptionsGroupUI): - def __init__(self, decimals=4, parent=None): - # OptionsGroupUI.__init__(self, "CNC Job Advanced Options Preferences", parent=None) - super(CNCJobAdvOptPrefGroupUI, self).__init__(self, parent=parent) + def __init__(self, decimals=4, **kwargs): self.decimals = decimals - + super().__init__(**kwargs) self.setTitle(str(_("CNC Job Adv. Options"))) - # ## Export G-Code - self.export_gcode_label = QtWidgets.QLabel("%s:" % _("Export CNC Code")) - self.export_gcode_label.setToolTip( - _("Export and save G-Code to\n" - "make this object to a file.") - ) - self.layout.addWidget(self.export_gcode_label) - - # Prepend to G-Code - toolchangelabel = QtWidgets.QLabel('%s' % _('Toolchange G-Code')) - toolchangelabel.setToolTip( - _( - "Type here any G-Code commands you would\n" - "like to be executed when Toolchange event is encountered.\n" - "This will constitute a Custom Toolchange GCode,\n" - "or a Toolchange Macro.\n" - "The FlatCAM variables are surrounded by '%' symbol.\n\n" - "WARNING: it can be used only with a preprocessor file\n" - "that has 'toolchange_custom' in it's name and this is built\n" - "having as template the 'Toolchange Custom' posprocessor file." - ) - ) - self.layout.addWidget(toolchangelabel) - - qsettings = QSettings("Open Source", "FlatCAM") - if qsettings.contains("textbox_font_size"): - tb_fsize = qsettings.value('textbox_font_size', type=int) - else: - tb_fsize = 10 - font = QtGui.QFont() - font.setPointSize(tb_fsize) - - self.toolchange_text = FCTextArea() - self.toolchange_text.setPlaceholderText( - _( - "Type here any G-Code commands you would " - "like to be executed when Toolchange event is encountered.\n" - "This will constitute a Custom Toolchange GCode, " - "or a Toolchange Macro.\n" - "The FlatCAM variables are surrounded by '%' symbol.\n" - "WARNING: it can be used only with a preprocessor file " - "that has 'toolchange_custom' in it's name." - ) - ) - self.layout.addWidget(self.toolchange_text) - self.toolchange_text.setFont(font) - - hlay = QtWidgets.QHBoxLayout() - self.layout.addLayout(hlay) - - # Toolchange Replacement GCode - self.toolchange_cb = FCCheckBox(label='%s' % _('Use Toolchange Macro')) - self.toolchange_cb.setToolTip( - _("Check this box if you want to use\n" - "a Custom Toolchange GCode (macro).") - ) - hlay.addWidget(self.toolchange_cb) - hlay.addStretch() - - hlay1 = QtWidgets.QHBoxLayout() - self.layout.addLayout(hlay1) - - # Variable list - self.tc_variable_combo = FCComboBox() - self.tc_variable_combo.setToolTip( - _("A list of the FlatCAM variables that can be used\n" - "in the Toolchange event.\n" - "They have to be surrounded by the '%' symbol") - ) - hlay1.addWidget(self.tc_variable_combo) + self.toolchange_text = self.option_dict()["cncjob_toolchange_macro"].get_field() # Populate the Combo Box + self.tc_variable_combo = self.option_dict()["__toolchange_variable"].get_field() variables = [_('Parameters'), 'tool', 'tooldia', 't_drills', 'x_toolchange', 'y_toolchange', 'z_toolchange', 'z_cut', 'z_move', 'z_depthpercut', 'spindlespeed', 'dwelltime'] self.tc_variable_combo.addItems(variables) @@ -126,83 +50,58 @@ class CNCJobAdvOptPrefGroupUI(OptionsGroupUI): _("dwelltime = time to dwell to allow the spindle to reach it's set RPM"), Qt.ToolTipRole) - # hlay1.addStretch() - - # Insert Variable into the Toolchange G-Code Text Box - # self.tc_insert_buton = FCButton("Insert") - # self.tc_insert_buton.setToolTip( - # "Insert the variable in the GCode Box\n" - # "surrounded by the '%' symbol." - # ) - # hlay1.addWidget(self.tc_insert_buton) - - grid0 = QtWidgets.QGridLayout() - self.layout.addLayout(grid0) - - grid0.addWidget(QtWidgets.QLabel(''), 1, 0, 1, 2) - - # Annotation Font Size - self.annotation_fontsize_label = QtWidgets.QLabel('%s:' % _("Annotation Size")) - self.annotation_fontsize_label.setToolTip( - _("The font size of the annotation text. In pixels.") - ) - grid0.addWidget(self.annotation_fontsize_label, 2, 0) - self.annotation_fontsize_sp = FCSpinner() - self.annotation_fontsize_sp.set_range(0, 9999) - - grid0.addWidget(self.annotation_fontsize_sp, 2, 1) - grid0.addWidget(QtWidgets.QLabel(''), 2, 2) - - # Annotation Font Color - self.annotation_color_label = QtWidgets.QLabel('%s:' % _('Annotation Color')) - self.annotation_color_label.setToolTip( - _("Set the font color for the annotation texts.") - ) - self.annotation_fontcolor_entry = FCEntry() - self.annotation_fontcolor_button = QtWidgets.QPushButton() - self.annotation_fontcolor_button.setFixedSize(15, 15) - - self.form_box_child = QtWidgets.QHBoxLayout() - self.form_box_child.setContentsMargins(0, 0, 0, 0) - self.form_box_child.addWidget(self.annotation_fontcolor_entry) - self.form_box_child.addWidget(self.annotation_fontcolor_button, alignment=Qt.AlignRight) - self.form_box_child.setAlignment(QtCore.Qt.AlignLeft | QtCore.Qt.AlignVCenter) - - color_widget = QtWidgets.QWidget() - color_widget.setLayout(self.form_box_child) - grid0.addWidget(self.annotation_color_label, 3, 0) - grid0.addWidget(color_widget, 3, 1) - grid0.addWidget(QtWidgets.QLabel(''), 3, 2) - - self.layout.addStretch() - self.tc_variable_combo.currentIndexChanged[str].connect(self.on_cnc_custom_parameters) - self.annotation_fontcolor_entry.editingFinished.connect(self.on_annotation_fontcolor_entry) - self.annotation_fontcolor_button.clicked.connect(self.on_annotation_fontcolor_button) + def build_options(self) -> [OptionUI]: + return [ + HeadingOptionUI( + label_text="Export CNC Code", + label_tooltip="Export and save G-Code to\n" + "make this object to a file." + ), + CheckboxOptionUI( + option="cncjob_toolchange_macro_enable", + label_text="Use Toolchange Macro", + label_tooltip="Check this box if you want to use\n" + "a Custom Toolchange GCode (macro)." + ), + TextAreaOptionUI( + option="cncjob_toolchange_macro", + label_text="Toolchange G-Code", + label_tooltip="Type here any G-Code commands you would " + "like to be executed when Toolchange event is encountered.\n" + "This will constitute a Custom Toolchange GCode, " + "or a Toolchange Macro.\n" + "The FlatCAM variables are surrounded by '%' symbol.\n" + "WARNING: it can be used only with a preprocessor file " + "that has 'toolchange_custom' in it's name." + ), + ComboboxOptionUI( + option="__toolchange_variable", + label_text="Insert variable", + label_tooltip="A list of the FlatCAM variables that can be used\n" + "in the Toolchange event.\n" + "They have to be surrounded by the '%' symbol", + choices=[] # see init. + ), + + SpinnerOptionUI( + option="cncjob_annotation_fontsize", + label_text="Annotation Size", + label_tooltip="The font size of the annotation text. In pixels.", + min_value=1, max_value=9999, step=1 + ), + ColorOptionUI( + option="cncjob_annotation_fontcolor", + label_text="Annotation Color", + label_tooltip="Set the font color for the annotation texts." + ) + ] def on_cnc_custom_parameters(self, signal_text): - if signal_text == 'Parameters': + if signal_text == _("Parameters"): return else: self.toolchange_text.insertPlainText('%%%s%%' % signal_text) + self.tc_variable_combo.set_value(_("Parameters")) - def on_annotation_fontcolor_entry(self): - self.app.defaults['cncjob_annotation_fontcolor'] = self.annotation_fontcolor_entry.get_value() - self.annotation_fontcolor_button.setStyleSheet( - "background-color:%s" % str(self.app.defaults['cncjob_annotation_fontcolor'])) - - def on_annotation_fontcolor_button(self): - current_color = QtGui.QColor(self.app.defaults['cncjob_annotation_fontcolor']) - - c_dialog = QtWidgets.QColorDialog() - annotation_color = c_dialog.getColor(initial=current_color) - - if annotation_color.isValid() is False: - return - - self.annotation_fontcolor_button.setStyleSheet("background-color:%s" % str(annotation_color.name())) - - new_val_sel = str(annotation_color.name()) - self.annotation_fontcolor_entry.set_value(new_val_sel) - self.app.defaults['cncjob_annotation_fontcolor'] = new_val_sel