- added a new feature in Preferences -> Gerber: a Layer Color Manager where the user can set and edit predefined colors for the Gerber objects: loading order matter

This commit is contained in:
Marius Stanciu
2022-01-10 17:06:12 +02:00
committed by Marius
parent 747a2f0de4
commit ab3e610324
5 changed files with 301 additions and 27 deletions

View File

@@ -870,6 +870,13 @@ class NumericalEvalTupleEntry(EvalEntry):
class FCColorEntry(QtWidgets.QFrame):
def __init__(self, **kwargs):
"""
:param kwargs:
:type kwargs:
"""
self.icon = kwargs.pop('icon', None)
super().__init__(**kwargs)
self.entry = FCEntry()
@@ -909,16 +916,28 @@ class FCColorEntry(QtWidgets.QFrame):
current_color = QtGui.QColor(self._extract_color(value))
color_dialog = QtWidgets.QColorDialog()
selected_color = color_dialog.getColor(initial=current_color,
options=QtWidgets.QColorDialog.ColorDialogOption.ShowAlphaChannel)
color_dialog.setOption(QtWidgets.QColorDialog.ColorDialogOption.ShowAlphaChannel, True)
if self.icon:
color_dialog.setWindowIcon(self.icon)
# selected_color = color_dialog.getColor(initial=current_color,
# options=QtWidgets.QColorDialog.ColorDialogOption.ShowAlphaChannel)
if selected_color.isValid() is False:
return
current_color.setAlpha(int(self._extract_alpha(value), 16))
color_dialog.setCurrentColor(current_color)
new_value = str(selected_color.name()) + self._extract_alpha(value)
self.set_value(new_value)
if color_dialog.exec() == QtWidgets.QDialog.DialogCode.Accepted:
selected_color = color_dialog.selectedColor()
if selected_color.isValid() is False:
return
new_value = self.argb2rgba(selected_color.name(QtGui.QColor.NameFormat.HexArgb)).upper()
self.set_value(new_value)
self.editingFinished.emit()
@staticmethod
def argb2rgba(argb_color):
return '#%s%s' % (argb_color[3:], argb_color[1:3])
@staticmethod
def _extract_color(value: str) -> str:
return value[:7]