GeometryGenPrefGroupUI.py 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. from PyQt5 import QtWidgets, QtCore, QtGui
  2. from PyQt5.QtCore import QSettings
  3. from AppGUI.GUIElements import FCCheckBox, FCSpinner, FCEntry
  4. from AppGUI.preferences.OptionsGroupUI import OptionsGroupUI
  5. import gettext
  6. import AppTranslation as fcTranslate
  7. import builtins
  8. fcTranslate.apply_language('strings')
  9. if '_' not in builtins.__dict__:
  10. _ = gettext.gettext
  11. settings = QSettings("Open Source", "FlatCAM")
  12. if settings.contains("machinist"):
  13. machinist_setting = settings.value('machinist', type=int)
  14. else:
  15. machinist_setting = 0
  16. class GeometryGenPrefGroupUI(OptionsGroupUI):
  17. def __init__(self, decimals=4, parent=None):
  18. # OptionsGroupUI.__init__(self, "Geometry General Preferences", parent=parent)
  19. super(GeometryGenPrefGroupUI, self).__init__(self, parent=parent)
  20. self.setTitle(str(_("Geometry General")))
  21. self.decimals = decimals
  22. # ## Plot options
  23. self.plot_options_label = QtWidgets.QLabel("<b>%s:</b>" % _("Plot Options"))
  24. self.layout.addWidget(self.plot_options_label)
  25. # Plot CB
  26. self.plot_cb = FCCheckBox(label=_('Plot'))
  27. self.plot_cb.setToolTip(
  28. _("Plot (show) this object.")
  29. )
  30. self.layout.addWidget(self.plot_cb)
  31. grid0 = QtWidgets.QGridLayout()
  32. self.layout.addLayout(grid0)
  33. grid0.setColumnStretch(0, 0)
  34. grid0.setColumnStretch(1, 1)
  35. # Number of circle steps for circular aperture linear approximation
  36. self.circle_steps_label = QtWidgets.QLabel('%s:' % _("Circle Steps"))
  37. self.circle_steps_label.setToolTip(
  38. _("The number of circle steps for <b>Geometry</b> \n"
  39. "circle and arc shapes linear approximation.")
  40. )
  41. self.circle_steps_entry = FCSpinner()
  42. self.circle_steps_entry.set_range(0, 999)
  43. grid0.addWidget(self.circle_steps_label, 1, 0)
  44. grid0.addWidget(self.circle_steps_entry, 1, 1)
  45. # Tools
  46. self.tools_label = QtWidgets.QLabel("<b>%s:</b>" % _("Tools"))
  47. grid0.addWidget(self.tools_label, 2, 0, 1, 2)
  48. # Tooldia
  49. tdlabel = QtWidgets.QLabel('<b><font color="green">%s:</font></b>' % _('Tools Dia'))
  50. tdlabel.setToolTip(
  51. _("Diameters of the tools, separated by comma.\n"
  52. "The value of the diameter has to use the dot decimals separator.\n"
  53. "Valid values: 0.3, 1.0")
  54. )
  55. self.cnctooldia_entry = FCEntry()
  56. grid0.addWidget(tdlabel, 3, 0)
  57. grid0.addWidget(self.cnctooldia_entry, 3, 1)
  58. separator_line = QtWidgets.QFrame()
  59. separator_line.setFrameShape(QtWidgets.QFrame.HLine)
  60. separator_line.setFrameShadow(QtWidgets.QFrame.Sunken)
  61. grid0.addWidget(separator_line, 9, 0, 1, 2)
  62. # Geometry Object Color
  63. self.gerber_color_label = QtWidgets.QLabel('<b>%s</b>' % _('Geometry Object Color'))
  64. grid0.addWidget(self.gerber_color_label, 10, 0, 1, 2)
  65. # Plot Line Color
  66. self.line_color_label = QtWidgets.QLabel('%s:' % _('Outline'))
  67. self.line_color_label.setToolTip(
  68. _("Set the line color for plotted objects.")
  69. )
  70. self.line_color_entry = FCEntry()
  71. self.line_color_button = QtWidgets.QPushButton()
  72. self.line_color_button.setFixedSize(15, 15)
  73. self.form_box_child_2 = QtWidgets.QHBoxLayout()
  74. self.form_box_child_2.addWidget(self.line_color_entry)
  75. self.form_box_child_2.addWidget(self.line_color_button)
  76. self.form_box_child_2.setAlignment(QtCore.Qt.AlignLeft | QtCore.Qt.AlignVCenter)
  77. grid0.addWidget(self.line_color_label, 11, 0)
  78. grid0.addLayout(self.form_box_child_2, 11, 1)
  79. self.layout.addStretch()
  80. # Setting plot colors signals
  81. self.line_color_entry.editingFinished.connect(self.on_line_color_entry)
  82. self.line_color_button.clicked.connect(self.on_line_color_button)
  83. def on_line_color_entry(self):
  84. self.app.defaults['geometry_plot_line'] = self.line_color_entry.get_value()[:7] + 'FF'
  85. self.line_color_button.setStyleSheet("background-color:%s" % str(self.app.defaults['geometry_plot_line'])[:7])
  86. def on_line_color_button(self):
  87. current_color = QtGui.QColor(self.app.defaults['geometry_plot_line'][:7])
  88. # print(current_color)
  89. c_dialog = QtWidgets.QColorDialog()
  90. plot_line_color = c_dialog.getColor(initial=current_color)
  91. if plot_line_color.isValid() is False:
  92. return
  93. self.line_color_button.setStyleSheet("background-color:%s" % str(plot_line_color.name()))
  94. new_val_line = str(plot_line_color.name()) + str(self.app.defaults['geometry_plot_line'][7:9])
  95. self.line_color_entry.set_value(new_val_line)