Geometry general prefs

This commit is contained in:
David Robertson
2020-05-09 16:21:21 +01:00
parent 31d0cfbdd7
commit 9f2991c003
5 changed files with 52 additions and 126 deletions

View File

@@ -31,12 +31,12 @@ class OptionUI:
class BasicOptionUI(OptionUI): class BasicOptionUI(OptionUI):
"""Abstract OptionUI that has a label on the left then some other widget on the right""" """Abstract OptionUI that has a label on the left then some other widget on the right"""
def __init__(self, option: str, label_text: str, label_tooltip: Union[str, None] = None, label_bold: bool = False, label_red: bool = False): def __init__(self, option: str, label_text: str, label_tooltip: Union[str, None] = None, label_bold: bool = False, label_color: Union[str, None] = None):
super().__init__(option=option) super().__init__(option=option)
self.label_text = label_text self.label_text = label_text
self.label_tooltip = label_tooltip self.label_tooltip = label_tooltip
self.label_bold = label_bold self.label_bold = label_bold
self.label_red = label_red self.label_color = label_color
self.label_widget = self.build_label_widget() self.label_widget = self.build_label_widget()
self.entry_widget = self.build_entry_widget() self.entry_widget = self.build_entry_widget()
@@ -44,8 +44,8 @@ class BasicOptionUI(OptionUI):
fmt = "%s:" fmt = "%s:"
if self.label_bold: if self.label_bold:
fmt = "<b>%s</b>" % fmt fmt = "<b>%s</b>" % fmt
if self.label_red: if self.label_color:
fmt = "<span style=\"color:red;\">%s</span>" % fmt fmt = "<span style=\"color:%s;\">%s</span>" % (self.label_color, fmt)
label_widget = QtWidgets.QLabel(fmt % _(self.label_text)) label_widget = QtWidgets.QLabel(fmt % _(self.label_text))
if self.label_tooltip is not None: if self.label_tooltip is not None:
label_widget.setToolTip(_(self.label_tooltip)) label_widget.setToolTip(_(self.label_tooltip))

View File

@@ -141,11 +141,6 @@ class PreferencesUIManager:
"excellon_editor_slot_circ_angle": "excellon_editor_slot_circ_angle":
self.ui.excellon_defaults_form.excellon_editor_group.slot_array_circular_angle_entry, self.ui.excellon_defaults_form.excellon_editor_group.slot_array_circular_angle_entry,
# Geometry General
"geometry_plot": self.ui.geometry_defaults_form.geometry_gen_group.plot_cb,
"geometry_circle_steps": self.ui.geometry_defaults_form.geometry_gen_group.circle_steps_entry,
"geometry_cnctooldia": self.ui.geometry_defaults_form.geometry_gen_group.cnctooldia_entry,
"geometry_plot_line": self.ui.geometry_defaults_form.geometry_gen_group.line_color_entry,
# Geometry Options # Geometry Options
"geometry_cutz": self.ui.geometry_defaults_form.geometry_opt_group.cutz_entry, "geometry_cutz": self.ui.geometry_defaults_form.geometry_opt_group.cutz_entry,
@@ -594,13 +589,6 @@ class PreferencesUIManager:
"background-color:%s;" "background-color:%s;"
"border-color: dimgray" % str(self.defaults['excellon_plot_line'])[:7]) "border-color: dimgray" % str(self.defaults['excellon_plot_line'])[:7])
# Init Geometry Plot Colors
self.ui.geometry_defaults_form.geometry_gen_group.line_color_entry.set_value(
self.defaults['geometry_plot_line'])
self.ui.geometry_defaults_form.geometry_gen_group.line_color_button.setStyleSheet(
"background-color:%s;"
"border-color: dimgray" % str(self.defaults['geometry_plot_line'])[:7])
# Init CNCJob Travel Line Colors # Init CNCJob Travel Line Colors
self.ui.cncjob_defaults_form.cncjob_gen_group.tfill_color_entry.set_value( self.ui.cncjob_defaults_form.cncjob_gen_group.tfill_color_entry.set_value(
self.defaults['cncjob_travel_fill']) self.defaults['cncjob_travel_fill'])

View File

@@ -49,7 +49,7 @@ class GeneralAppPrefGroupUI(OptionsGroupUI2):
"Whatever is selected here is set every time\n" "Whatever is selected here is set every time\n"
"FlatCAM is started.", "FlatCAM is started.",
label_bold=True, label_bold=True,
label_red=True, label_color="red",
choices=[{'label': _('MM'), 'value': 'MM'}, choices=[{'label': _('MM'), 'value': 'MM'},
{'label': _('IN'), 'value': 'IN'}] {'label': _('IN'), 'value': 'IN'}]
), ),
@@ -94,7 +94,7 @@ class GeneralAppPrefGroupUI(OptionsGroupUI2):
"The choice here will influence the parameters in\n" "The choice here will influence the parameters in\n"
"the Selected Tab for all kinds of FlatCAM objects.", "the Selected Tab for all kinds of FlatCAM objects.",
label_bold=True, label_bold=True,
label_red=True, label_color="red",
choices=[{'label': _('Basic'), 'value': 'b'}, choices=[{'label': _('Basic'), 'value': 'b'},
{'label': _('Advanced'), 'value': 'a'}] {'label': _('Advanced'), 'value': 'a'}]
), ),

View File

@@ -1,8 +1,5 @@
from PyQt5 import QtWidgets, QtCore, QtGui from flatcamGUI.preferences.OptionUI import *
from PyQt5.QtCore import QSettings from flatcamGUI.preferences.OptionsGroupUI import OptionsGroupUI2
from flatcamGUI.GUIElements import FCCheckBox, FCSpinner, FCEntry
from flatcamGUI.preferences.OptionsGroupUI import OptionsGroupUI
import gettext import gettext
import FlatCAMTranslation as fcTranslate import FlatCAMTranslation as fcTranslate
@@ -12,112 +9,46 @@ fcTranslate.apply_language('strings')
if '_' not in builtins.__dict__: if '_' not in builtins.__dict__:
_ = gettext.gettext _ = gettext.gettext
settings = QSettings("Open Source", "FlatCAM")
if settings.contains("machinist"):
machinist_setting = settings.value('machinist', type=int)
else:
machinist_setting = 0
class GeometryGenPrefGroupUI(OptionsGroupUI2):
class GeometryGenPrefGroupUI(OptionsGroupUI): def __init__(self, decimals=4, **kwargs):
def __init__(self, decimals=4, parent=None):
# OptionsGroupUI.__init__(self, "Geometry General Preferences", parent=parent)
super(GeometryGenPrefGroupUI, self).__init__(self, parent=parent)
self.setTitle(str(_("Geometry General")))
self.decimals = decimals self.decimals = decimals
super().__init__(**kwargs)
self.setTitle(str(_("Geometry General")))
# ## Plot options def build_options(self) -> [OptionUI]:
self.plot_options_label = QtWidgets.QLabel("<b>%s:</b>" % _("Plot Options")) return [
self.layout.addWidget(self.plot_options_label) HeadingOptionUI(label_text="Plot Options"),
CheckboxOptionUI(
option="geometry_plot",
label_text="Plot",
label_tooltip="Plot (show) this object."
),
SpinnerOptionUI(
option="geometry_circle_steps",
label_text="Circle Steps",
label_tooltip="The number of circle steps for <b>Geometry</b> \n"
"circle and arc shapes linear approximation.",
min_value=0, max_value=9999, step=1
),
HeadingOptionUI(label_text="Tools"),
LineEntryOptionUI(
option="geometry_cnctooldia",
label_text="Tools Dia",
label_color="green",
label_bold=True,
label_tooltip="Diameters of the tools, separated by comma.\n"
"The value of the diameter has to use the dot decimals separator.\n"
"Valid values: 0.3, 1.0"
),
SeparatorOptionUI(),
# Plot CB HeadingOptionUI(label_text="Geometry Object Color"),
self.plot_cb = FCCheckBox(label=_('Plot')) ColorOptionUI(
self.plot_cb.setToolTip( option="geometry_plot_line",
_("Plot (show) this object.") label_text="Outline",
)
self.layout.addWidget(self.plot_cb)
grid0 = QtWidgets.QGridLayout() label_tooltip="Set the line color for plotted objects.",
self.layout.addLayout(grid0) ),
grid0.setColumnStretch(0, 0) ]
grid0.setColumnStretch(1, 1)
# Number of circle steps for circular aperture linear approximation
self.circle_steps_label = QtWidgets.QLabel('%s:' % _("Circle Steps"))
self.circle_steps_label.setToolTip(
_("The number of circle steps for <b>Geometry</b> \n"
"circle and arc shapes linear approximation.")
)
self.circle_steps_entry = FCSpinner()
self.circle_steps_entry.set_range(0, 999)
grid0.addWidget(self.circle_steps_label, 1, 0)
grid0.addWidget(self.circle_steps_entry, 1, 1)
# Tools
self.tools_label = QtWidgets.QLabel("<b>%s:</b>" % _("Tools"))
grid0.addWidget(self.tools_label, 2, 0, 1, 2)
# Tooldia
tdlabel = QtWidgets.QLabel('<b><font color="green">%s:</font></b>' % _('Tools Dia'))
tdlabel.setToolTip(
_("Diameters of the tools, separated by comma.\n"
"The value of the diameter has to use the dot decimals separator.\n"
"Valid values: 0.3, 1.0")
)
self.cnctooldia_entry = FCEntry()
grid0.addWidget(tdlabel, 3, 0)
grid0.addWidget(self.cnctooldia_entry, 3, 1)
separator_line = QtWidgets.QFrame()
separator_line.setFrameShape(QtWidgets.QFrame.HLine)
separator_line.setFrameShadow(QtWidgets.QFrame.Sunken)
grid0.addWidget(separator_line, 9, 0, 1, 2)
# Geometry Object Color
self.gerber_color_label = QtWidgets.QLabel('<b>%s</b>' % _('Geometry Object Color'))
grid0.addWidget(self.gerber_color_label, 10, 0, 1, 2)
# Plot Line Color
self.line_color_label = QtWidgets.QLabel('%s:' % _('Outline'))
self.line_color_label.setToolTip(
_("Set the line color for plotted objects.")
)
self.line_color_entry = FCEntry()
self.line_color_button = QtWidgets.QPushButton()
self.line_color_button.setFixedSize(15, 15)
self.form_box_child_2 = QtWidgets.QHBoxLayout()
self.form_box_child_2.addWidget(self.line_color_entry)
self.form_box_child_2.addWidget(self.line_color_button)
self.form_box_child_2.setAlignment(QtCore.Qt.AlignLeft | QtCore.Qt.AlignVCenter)
grid0.addWidget(self.line_color_label, 11, 0)
grid0.addLayout(self.form_box_child_2, 11, 1)
self.layout.addStretch()
# Setting plot colors signals
self.line_color_entry.editingFinished.connect(self.on_line_color_entry)
self.line_color_button.clicked.connect(self.on_line_color_button)
def on_line_color_entry(self):
self.app.defaults['geometry_plot_line'] = self.line_color_entry.get_value()[:7] + 'FF'
self.line_color_button.setStyleSheet("background-color:%s" % str(self.app.defaults['geometry_plot_line'])[:7])
def on_line_color_button(self):
current_color = QtGui.QColor(self.app.defaults['geometry_plot_line'][:7])
# print(current_color)
c_dialog = QtWidgets.QColorDialog()
plot_line_color = c_dialog.getColor(initial=current_color)
if plot_line_color.isValid() is False:
return
self.line_color_button.setStyleSheet("background-color:%s" % str(plot_line_color.name()))
new_val_line = str(plot_line_color.name()) + str(self.app.defaults['geometry_plot_line'][7:9])
self.line_color_entry.set_value(new_val_line)

View File

@@ -5,6 +5,13 @@ from flatcamGUI.preferences.geometry.GeometryAdvOptPrefGroupUI import GeometryAd
from flatcamGUI.preferences.geometry.GeometryOptPrefGroupUI import GeometryOptPrefGroupUI from flatcamGUI.preferences.geometry.GeometryOptPrefGroupUI import GeometryOptPrefGroupUI
from flatcamGUI.preferences.geometry.GeometryGenPrefGroupUI import GeometryGenPrefGroupUI from flatcamGUI.preferences.geometry.GeometryGenPrefGroupUI import GeometryGenPrefGroupUI
import gettext
import FlatCAMTranslation as fcTranslate
import builtins
fcTranslate.apply_language('strings')
if '_' not in builtins.__dict__:
_ = gettext.gettext
class GeometryPreferencesUI(PreferencesSectionUI): class GeometryPreferencesUI(PreferencesSectionUI):