CNCJobAdvOptPrefGroupUI.py 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. from PyQt5.QtCore import Qt
  2. from flatcamGUI.preferences.OptionUI import *
  3. from flatcamGUI.preferences.OptionsGroupUI import OptionsGroupUI2
  4. import gettext
  5. import FlatCAMTranslation as fcTranslate
  6. import builtins
  7. fcTranslate.apply_language('strings')
  8. if '_' not in builtins.__dict__:
  9. _ = gettext.gettext
  10. class CNCJobAdvOptPrefGroupUI(OptionsGroupUI2):
  11. def __init__(self, decimals=4, **kwargs):
  12. self.decimals = decimals
  13. super().__init__(**kwargs)
  14. self.setTitle(str(_("CNC Job Adv. Options")))
  15. self.toolchange_text = self.option_dict()["cncjob_toolchange_macro"].get_field()
  16. # Populate the Combo Box
  17. self.tc_variable_combo = self.option_dict()["__toolchange_variable"].get_field()
  18. variables = [_('Parameters'), 'tool', 'tooldia', 't_drills', 'x_toolchange', 'y_toolchange', 'z_toolchange',
  19. 'z_cut', 'z_move', 'z_depthpercut', 'spindlespeed', 'dwelltime']
  20. self.tc_variable_combo.addItems(variables)
  21. self.tc_variable_combo.insertSeparator(1)
  22. self.tc_variable_combo.setItemData(0, _("FlatCAM CNC parameters"), Qt.ToolTipRole)
  23. fnt = QtGui.QFont()
  24. fnt.setBold(True)
  25. self.tc_variable_combo.setItemData(0, fnt, Qt.FontRole)
  26. self.tc_variable_combo.setItemData(2, 'tool = %s' % _("tool number"), Qt.ToolTipRole)
  27. self.tc_variable_combo.setItemData(3, 'tooldia = %s' % _("tool diameter"), Qt.ToolTipRole)
  28. self.tc_variable_combo.setItemData(4, 't_drills = %s' % _("for Excellon, total number of drills"),
  29. Qt.ToolTipRole)
  30. self.tc_variable_combo.setItemData(5, 'x_toolchange = %s' % _("X coord for Toolchange"), Qt.ToolTipRole)
  31. self.tc_variable_combo.setItemData(6, 'y_toolchange = %s' % _("Y coord for Toolchange"),
  32. Qt.ToolTipRole)
  33. self.tc_variable_combo.setItemData(7, 'z_toolchange = %s' % _("Z coord for Toolchange"), Qt.ToolTipRole)
  34. self.tc_variable_combo.setItemData(8, 'z_cut = %s' % _("Z depth for the cut"), Qt.ToolTipRole)
  35. self.tc_variable_combo.setItemData(9, 'z_move = %s' % _("Z height for travel"), Qt.ToolTipRole)
  36. self.tc_variable_combo.setItemData(10, 'z_depthpercut = %s' % _("the step value for multidepth cut"),
  37. Qt.ToolTipRole)
  38. self.tc_variable_combo.setItemData(11, 'spindlesspeed = %s' % _("the value for the spindle speed"),
  39. Qt.ToolTipRole)
  40. self.tc_variable_combo.setItemData(12,
  41. _("dwelltime = time to dwell to allow the spindle to reach it's set RPM"),
  42. Qt.ToolTipRole)
  43. self.tc_variable_combo.currentIndexChanged[str].connect(self.on_cnc_custom_parameters)
  44. def build_options(self) -> [OptionUI]:
  45. return [
  46. HeadingOptionUI(
  47. label_text="Export CNC Code",
  48. label_tooltip="Export and save G-Code to\n"
  49. "make this object to a file."
  50. ),
  51. CheckboxOptionUI(
  52. option="cncjob_toolchange_macro_enable",
  53. label_text="Use Toolchange Macro",
  54. label_tooltip="Check this box if you want to use\n"
  55. "a Custom Toolchange GCode (macro)."
  56. ),
  57. TextAreaOptionUI(
  58. option="cncjob_toolchange_macro",
  59. label_text="Toolchange G-Code",
  60. label_tooltip="Type here any G-Code commands you would "
  61. "like to be executed when Toolchange event is encountered.\n"
  62. "This will constitute a Custom Toolchange GCode, "
  63. "or a Toolchange Macro.\n"
  64. "The FlatCAM variables are surrounded by '%' symbol.\n"
  65. "WARNING: it can be used only with a preprocessor file "
  66. "that has 'toolchange_custom' in it's name."
  67. ),
  68. ComboboxOptionUI(
  69. option="__toolchange_variable",
  70. label_text="Insert variable",
  71. label_tooltip="A list of the FlatCAM variables that can be used\n"
  72. "in the Toolchange event.\n"
  73. "They have to be surrounded by the '%' symbol",
  74. choices=[] # see init.
  75. ),
  76. SpinnerOptionUI(
  77. option="cncjob_annotation_fontsize",
  78. label_text="Annotation Size",
  79. label_tooltip="The font size of the annotation text. In pixels.",
  80. min_value=1, max_value=9999, step=1
  81. ),
  82. ColorOptionUI(
  83. option="cncjob_annotation_fontcolor",
  84. label_text="Annotation Color",
  85. label_tooltip="Set the font color for the annotation texts."
  86. )
  87. ]
  88. def on_cnc_custom_parameters(self, signal_text):
  89. if signal_text == _("Parameters"):
  90. return
  91. else:
  92. self.toolchange_text.insertPlainText('%%%s%%' % signal_text)
  93. self.tc_variable_combo.set_value(_("Parameters"))