CNCJobAdvOptPrefGroupUI.py 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. from PyQt5 import QtWidgets, QtGui, QtCore
  2. from PyQt5.QtCore import QSettings, Qt
  3. from flatcamGUI.GUIElements import FCTextArea, FCCheckBox, FCComboBox, FCSpinner, FCEntry
  4. from flatcamGUI.preferences.OptionsGroupUI import OptionsGroupUI
  5. class CNCJobAdvOptPrefGroupUI(OptionsGroupUI):
  6. def __init__(self, decimals=4, parent=None):
  7. # OptionsGroupUI.__init__(self, "CNC Job Advanced Options Preferences", parent=None)
  8. super(CNCJobAdvOptPrefGroupUI, self).__init__(self)
  9. self.decimals = decimals
  10. self.setTitle(str(_("CNC Job Adv. Options")))
  11. # ## Export G-Code
  12. self.export_gcode_label = QtWidgets.QLabel("<b>%s:</b>" % _("Export CNC Code"))
  13. self.export_gcode_label.setToolTip(
  14. _("Export and save G-Code to\n"
  15. "make this object to a file.")
  16. )
  17. self.layout.addWidget(self.export_gcode_label)
  18. # Prepend to G-Code
  19. toolchangelabel = QtWidgets.QLabel('%s' % _('Toolchange G-Code'))
  20. toolchangelabel.setToolTip(
  21. _(
  22. "Type here any G-Code commands you would\n"
  23. "like to be executed when Toolchange event is encountered.\n"
  24. "This will constitute a Custom Toolchange GCode,\n"
  25. "or a Toolchange Macro.\n"
  26. "The FlatCAM variables are surrounded by '%' symbol.\n\n"
  27. "WARNING: it can be used only with a preprocessor file\n"
  28. "that has 'toolchange_custom' in it's name and this is built\n"
  29. "having as template the 'Toolchange Custom' posprocessor file."
  30. )
  31. )
  32. self.layout.addWidget(toolchangelabel)
  33. qsettings = QSettings("Open Source", "FlatCAM")
  34. if qsettings.contains("textbox_font_size"):
  35. tb_fsize = qsettings.value('textbox_font_size', type=int)
  36. else:
  37. tb_fsize = 10
  38. font = QtGui.QFont()
  39. font.setPointSize(tb_fsize)
  40. self.toolchange_text = FCTextArea()
  41. self.toolchange_text.setPlaceholderText(
  42. _(
  43. "Type here any G-Code commands you would "
  44. "like to be executed when Toolchange event is encountered.\n"
  45. "This will constitute a Custom Toolchange GCode, "
  46. "or a Toolchange Macro.\n"
  47. "The FlatCAM variables are surrounded by '%' symbol.\n"
  48. "WARNING: it can be used only with a preprocessor file "
  49. "that has 'toolchange_custom' in it's name."
  50. )
  51. )
  52. self.layout.addWidget(self.toolchange_text)
  53. self.toolchange_text.setFont(font)
  54. hlay = QtWidgets.QHBoxLayout()
  55. self.layout.addLayout(hlay)
  56. # Toolchange Replacement GCode
  57. self.toolchange_cb = FCCheckBox(label='%s' % _('Use Toolchange Macro'))
  58. self.toolchange_cb.setToolTip(
  59. _("Check this box if you want to use\n"
  60. "a Custom Toolchange GCode (macro).")
  61. )
  62. hlay.addWidget(self.toolchange_cb)
  63. hlay.addStretch()
  64. hlay1 = QtWidgets.QHBoxLayout()
  65. self.layout.addLayout(hlay1)
  66. # Variable list
  67. self.tc_variable_combo = FCComboBox()
  68. self.tc_variable_combo.setToolTip(
  69. _("A list of the FlatCAM variables that can be used\n"
  70. "in the Toolchange event.\n"
  71. "They have to be surrounded by the '%' symbol")
  72. )
  73. hlay1.addWidget(self.tc_variable_combo)
  74. # Populate the Combo Box
  75. variables = [_('Parameters'), 'tool', 'tooldia', 't_drills', 'x_toolchange', 'y_toolchange', 'z_toolchange',
  76. 'z_cut', 'z_move', 'z_depthpercut', 'spindlespeed', 'dwelltime']
  77. self.tc_variable_combo.addItems(variables)
  78. self.tc_variable_combo.insertSeparator(1)
  79. self.tc_variable_combo.setItemData(0, _("FlatCAM CNC parameters"), Qt.ToolTipRole)
  80. fnt = QtGui.QFont()
  81. fnt.setBold(True)
  82. self.tc_variable_combo.setItemData(0, fnt, Qt.FontRole)
  83. self.tc_variable_combo.setItemData(2, 'tool = %s' % _("tool number"), Qt.ToolTipRole)
  84. self.tc_variable_combo.setItemData(3, 'tooldia = %s' % _("tool diameter"), Qt.ToolTipRole)
  85. self.tc_variable_combo.setItemData(4, 't_drills = %s' % _("for Excellon, total number of drills"),
  86. Qt.ToolTipRole)
  87. self.tc_variable_combo.setItemData(5, 'x_toolchange = %s' % _("X coord for Toolchange"), Qt.ToolTipRole)
  88. self.tc_variable_combo.setItemData(6, 'y_toolchange = %s' % _("Y coord for Toolchange"),
  89. Qt.ToolTipRole)
  90. self.tc_variable_combo.setItemData(7, 'z_toolchange = %s' % _("Z coord for Toolchange"), Qt.ToolTipRole)
  91. self.tc_variable_combo.setItemData(8, 'z_cut = %s' % _("Z depth for the cut"), Qt.ToolTipRole)
  92. self.tc_variable_combo.setItemData(9, 'z_move = %s' % _("Z height for travel"), Qt.ToolTipRole)
  93. self.tc_variable_combo.setItemData(10, 'z_depthpercut = %s' % _("the step value for multidepth cut"),
  94. Qt.ToolTipRole)
  95. self.tc_variable_combo.setItemData(11, 'spindlesspeed = %s' % _("the value for the spindle speed"),
  96. Qt.ToolTipRole)
  97. self.tc_variable_combo.setItemData(12,
  98. _("dwelltime = time to dwell to allow the spindle to reach it's set RPM"),
  99. Qt.ToolTipRole)
  100. # hlay1.addStretch()
  101. # Insert Variable into the Toolchange G-Code Text Box
  102. # self.tc_insert_buton = FCButton("Insert")
  103. # self.tc_insert_buton.setToolTip(
  104. # "Insert the variable in the GCode Box\n"
  105. # "surrounded by the '%' symbol."
  106. # )
  107. # hlay1.addWidget(self.tc_insert_buton)
  108. grid0 = QtWidgets.QGridLayout()
  109. self.layout.addLayout(grid0)
  110. grid0.addWidget(QtWidgets.QLabel(''), 1, 0, 1, 2)
  111. # Annotation Font Size
  112. self.annotation_fontsize_label = QtWidgets.QLabel('%s:' % _("Annotation Size"))
  113. self.annotation_fontsize_label.setToolTip(
  114. _("The font size of the annotation text. In pixels.")
  115. )
  116. grid0.addWidget(self.annotation_fontsize_label, 2, 0)
  117. self.annotation_fontsize_sp = FCSpinner()
  118. self.annotation_fontsize_sp.set_range(0, 9999)
  119. grid0.addWidget(self.annotation_fontsize_sp, 2, 1)
  120. grid0.addWidget(QtWidgets.QLabel(''), 2, 2)
  121. # Annotation Font Color
  122. self.annotation_color_label = QtWidgets.QLabel('%s:' % _('Annotation Color'))
  123. self.annotation_color_label.setToolTip(
  124. _("Set the font color for the annotation texts.")
  125. )
  126. self.annotation_fontcolor_entry = FCEntry()
  127. self.annotation_fontcolor_button = QtWidgets.QPushButton()
  128. self.annotation_fontcolor_button.setFixedSize(15, 15)
  129. self.form_box_child = QtWidgets.QHBoxLayout()
  130. self.form_box_child.setContentsMargins(0, 0, 0, 0)
  131. self.form_box_child.addWidget(self.annotation_fontcolor_entry)
  132. self.form_box_child.addWidget(self.annotation_fontcolor_button, alignment=Qt.AlignRight)
  133. self.form_box_child.setAlignment(QtCore.Qt.AlignLeft | QtCore.Qt.AlignVCenter)
  134. color_widget = QtWidgets.QWidget()
  135. color_widget.setLayout(self.form_box_child)
  136. grid0.addWidget(self.annotation_color_label, 3, 0)
  137. grid0.addWidget(color_widget, 3, 1)
  138. grid0.addWidget(QtWidgets.QLabel(''), 3, 2)
  139. self.layout.addStretch()
  140. self.tc_variable_combo.currentIndexChanged[str].connect(self.on_cnc_custom_parameters)
  141. self.annotation_fontcolor_entry.editingFinished.connect(self.on_annotation_fontcolor_entry)
  142. self.annotation_fontcolor_button.clicked.connect(self.on_annotation_fontcolor_button)
  143. def on_cnc_custom_parameters(self, signal_text):
  144. if signal_text == 'Parameters':
  145. return
  146. else:
  147. self.toolchange_text.insertPlainText('%%%s%%' % signal_text)
  148. def on_annotation_fontcolor_entry(self):
  149. self.app.defaults['cncjob_annotation_fontcolor'] = self.annotation_fontcolor_entry.get_value()
  150. self.annotation_fontcolor_button.setStyleSheet(
  151. "background-color:%s" % str(self.app.defaults['cncjob_annotation_fontcolor']))
  152. def on_annotation_fontcolor_button(self):
  153. current_color = QtGui.QColor(self.app.defaults['cncjob_annotation_fontcolor'])
  154. c_dialog = QtWidgets.QColorDialog()
  155. annotation_color = c_dialog.getColor(initial=current_color)
  156. if annotation_color.isValid() is False:
  157. return
  158. self.annotation_fontcolor_button.setStyleSheet("background-color:%s" % str(annotation_color.name()))
  159. new_val_sel = str(annotation_color.name())
  160. self.annotation_fontcolor_entry.set_value(new_val_sel)
  161. self.app.defaults['cncjob_annotation_fontcolor'] = new_val_sel