- in Document Object UI - upgraded the UI and fixed the colors setting
This commit is contained in:
@@ -15,6 +15,7 @@ CHANGELOG for FlatCAM Evo beta
|
||||
- updated the FClabel widget with some more properties
|
||||
- updated the hack to make sure that the Editor sub-tools do not lose the stylesheet of the background
|
||||
- updated the disabled project item color default value for the dark theme
|
||||
- in Document Object UI - upgraded the UI and fixed the colors setting
|
||||
|
||||
10.05.2022
|
||||
|
||||
|
||||
@@ -963,6 +963,8 @@ class NumericalEvalTupleEntry(EvalEntry):
|
||||
|
||||
class FCColorEntry(QtWidgets.QFrame):
|
||||
|
||||
value_changed = pyqtSignal(str)
|
||||
|
||||
def __init__(self, **kwargs):
|
||||
"""
|
||||
|
||||
@@ -1004,6 +1006,7 @@ class FCColorEntry(QtWidgets.QFrame):
|
||||
def _sync_button_color(self):
|
||||
value = self.get_value()
|
||||
self.button.setStyleSheet("background-color:%s;" % self._extract_color(value))
|
||||
self.value_changed.emit(str(value))
|
||||
|
||||
def _on_button_clicked(self):
|
||||
value = self.entry.get_value()
|
||||
@@ -1030,7 +1033,7 @@ class FCColorEntry(QtWidgets.QFrame):
|
||||
|
||||
new_value = self.argb2rgba(selected_color.name(QtGui.QColor.NameFormat.HexArgb)).upper()
|
||||
self.set_value(new_value)
|
||||
self.editingFinished.emit()
|
||||
self.editingFinished.emit()
|
||||
|
||||
@staticmethod
|
||||
def argb2rgba(argb_color):
|
||||
|
||||
@@ -1563,8 +1563,8 @@ class DocumentObjectUI(ObjectUI):
|
||||
self.name_hlay.addWidget(name_label)
|
||||
self.name_hlay.addWidget(self.name_entry)
|
||||
|
||||
# Plot CB - this is added only for compatibility; other FlatCAM objects expect it and the mechanism is already
|
||||
# established and I don't want to changed it right now
|
||||
# Plot CB - this is added only for compatibility; other FlatCAM objects expect it, the mechanism is already
|
||||
# established, and I don't want to change it right now
|
||||
self.plot_cb = FCCheckBox()
|
||||
self.plot_cb.setLayoutDirection(QtCore.Qt.LayoutDirection.RightToLeft)
|
||||
self.custom_box.addWidget(self.plot_cb)
|
||||
@@ -1582,15 +1582,23 @@ class DocumentObjectUI(ObjectUI):
|
||||
h_lay.addWidget(self.autocomplete_cb)
|
||||
h_lay.addStretch()
|
||||
|
||||
# ##############################################################
|
||||
# ############ Grid LAYOUT #####################################
|
||||
# ##############################################################
|
||||
param_lbl = FCLabel('%s' % _("Parameters"), color='blue', bold=True)
|
||||
self.custom_box.addWidget(param_lbl)
|
||||
# #############################################################################################################
|
||||
# ################################################## Font Frame ###############################################
|
||||
# #############################################################################################################
|
||||
par_frame = FCFrame()
|
||||
self.custom_box.addWidget(par_frame)
|
||||
|
||||
# Grid Layout
|
||||
self.grid0 = GLay(v_spacing=5, h_spacing=3, c_stretch=[0, 1, 0])
|
||||
self.custom_box.addLayout(self.grid0)
|
||||
par_frame.setLayout(self.grid0)
|
||||
|
||||
font_lbl = FCLabel('%s' % _("Font"), bold=True)
|
||||
self.grid0.addWidget(font_lbl, 0, 0, 1, 2)
|
||||
|
||||
# Font
|
||||
self.font_type_label = FCLabel('%s:' % _("Font Type"))
|
||||
self.font_type_label = FCLabel('%s:' % _("Type"))
|
||||
|
||||
if sys.platform == "win32":
|
||||
f_current = QtGui.QFont("Arial")
|
||||
@@ -1604,26 +1612,20 @@ class DocumentObjectUI(ObjectUI):
|
||||
self.font_type_cb = QtWidgets.QFontComboBox(self)
|
||||
self.font_type_cb.setCurrentFont(f_current)
|
||||
|
||||
self.grid0.addWidget(self.font_type_label, 0, 0)
|
||||
self.grid0.addWidget(self.font_type_cb, 0, 1)
|
||||
self.grid0.addWidget(self.font_type_label, 2, 0)
|
||||
self.grid0.addWidget(self.font_type_cb, 2, 1)
|
||||
|
||||
# Font Size
|
||||
self.font_size_label = FCLabel('%s:' % _("Font Size"))
|
||||
self.font_size_label = FCLabel('%s:' % _("Size"))
|
||||
|
||||
size_hlay = QtWidgets.QHBoxLayout()
|
||||
|
||||
self.font_size_cb = FCComboBox()
|
||||
self.font_size_cb.setEditable(True)
|
||||
self.font_size_cb.setMinimumContentsLength(3)
|
||||
self.font_size_cb.setSizePolicy(QtWidgets.QSizePolicy.Policy.Minimum,
|
||||
QtWidgets.QSizePolicy.Policy.MinimumExpanding)
|
||||
# self.font_size_cb.setMaximumWidth(70)
|
||||
|
||||
font_sizes = ['6', '7', '8', '9', '10', '11', '12', '13', '14',
|
||||
'15', '16', '18', '20', '22', '24', '26', '28',
|
||||
'32', '36', '40', '44', '48', '54', '60', '66',
|
||||
'72', '80', '88', '96']
|
||||
|
||||
self.font_size_cb.addItems(font_sizes)
|
||||
|
||||
size_hlay.addWidget(self.font_size_cb)
|
||||
|
||||
self.font_bold_tb = QtWidgets.QToolButton()
|
||||
@@ -1640,8 +1642,42 @@ class DocumentObjectUI(ObjectUI):
|
||||
self.font_under_tb.setIcon(QtGui.QIcon(self.resource_loc + '/underline32.png'))
|
||||
size_hlay.addWidget(self.font_under_tb)
|
||||
|
||||
self.grid0.addWidget(self.font_size_label, 2, 0)
|
||||
self.grid0.addLayout(size_hlay, 2, 1)
|
||||
self.grid0.addWidget(self.font_size_label, 4, 0)
|
||||
self.grid0.addLayout(size_hlay, 4, 1)
|
||||
|
||||
# Font Color
|
||||
self.font_color_label = FCLabel('%s:' % _('Font Color'))
|
||||
self.font_color_label.setToolTip(
|
||||
_("Set the font color for the selected text")
|
||||
)
|
||||
|
||||
self.font_color_entry = FCColorEntry(icon=QtGui.QIcon(self.app.resource_location + '/set_colors64.png'))
|
||||
|
||||
self.grid0.addWidget(self.font_color_label, 6, 0)
|
||||
self.grid0.addWidget(self.font_color_entry, 6, 1)
|
||||
|
||||
# Selection Color
|
||||
self.sel_color_label = FCLabel('%s:' % _('Selection Color'))
|
||||
self.sel_color_label.setToolTip(
|
||||
_("Set the selection color when doing text selection.")
|
||||
)
|
||||
|
||||
self.sel_color_entry = FCColorEntry(icon=QtGui.QIcon(self.app.resource_location + '/set_colors64.png'))
|
||||
|
||||
self.grid0.addWidget(self.sel_color_label, 8, 0)
|
||||
self.grid0.addWidget(self.sel_color_entry, 8, 1)
|
||||
|
||||
alignment_title_lbl = FCLabel('%s' % _("Alignment"), bold=True, color='darkorange')
|
||||
self.custom_box.addWidget(alignment_title_lbl)
|
||||
# #############################################################################################################
|
||||
# Alignment Choices
|
||||
# #############################################################################################################
|
||||
a_frame = FCFrame()
|
||||
self.custom_box.addWidget(a_frame)
|
||||
|
||||
# Grid Layout
|
||||
a_grid = GLay(v_spacing=5, h_spacing=3)
|
||||
a_frame.setLayout(a_grid)
|
||||
|
||||
# Alignment Choices
|
||||
self.alignment_label = FCLabel('%s:' % _("Alignment"))
|
||||
@@ -1670,58 +1706,21 @@ class DocumentObjectUI(ObjectUI):
|
||||
|
||||
al_hlay.addStretch()
|
||||
|
||||
self.grid0.addWidget(self.alignment_label, 4, 0)
|
||||
self.grid0.addLayout(al_hlay, 4, 1)
|
||||
|
||||
# Font Color
|
||||
self.font_color_label = FCLabel('%s:' % _('Font Color'))
|
||||
self.font_color_label.setToolTip(
|
||||
_("Set the font color for the selected text")
|
||||
)
|
||||
|
||||
self.grid0_child_1 = QtWidgets.QHBoxLayout()
|
||||
|
||||
self.font_color_entry = FCEntry()
|
||||
self.font_color_button = FCButton()
|
||||
self.font_color_button.setFixedSize(15, 15)
|
||||
|
||||
self.grid0_child_1.addWidget(self.font_color_entry)
|
||||
self.grid0_child_1.addWidget(self.font_color_button)
|
||||
self.grid0_child_1.setAlignment(QtCore.Qt.AlignmentFlag.AlignLeft | QtCore.Qt.AlignmentFlag.AlignVCenter)
|
||||
|
||||
self.grid0.addWidget(self.font_color_label, 6, 0)
|
||||
self.grid0.addLayout(self.grid0_child_1, 6, 1)
|
||||
|
||||
# Selection Color
|
||||
self.sel_color_label = FCLabel('%s:' % _('Selection Color'))
|
||||
self.sel_color_label.setToolTip(
|
||||
_("Set the selection color when doing text selection.")
|
||||
)
|
||||
|
||||
self.grid0_child_2 = QtWidgets.QHBoxLayout()
|
||||
|
||||
self.sel_color_entry = FCEntry()
|
||||
self.sel_color_button = FCButton()
|
||||
self.sel_color_button.setFixedSize(15, 15)
|
||||
|
||||
self.grid0_child_2.addWidget(self.sel_color_entry)
|
||||
self.grid0_child_2.addWidget(self.sel_color_button)
|
||||
self.grid0_child_2.setAlignment(QtCore.Qt.AlignmentFlag.AlignLeft | QtCore.Qt.AlignmentFlag.AlignVCenter)
|
||||
|
||||
self.grid0.addWidget(self.sel_color_label, 8, 0)
|
||||
self.grid0.addLayout(self.grid0_child_2, 8, 1)
|
||||
a_grid.addWidget(self.alignment_label, 0, 0)
|
||||
a_grid.addLayout(al_hlay, 0, 1)
|
||||
|
||||
# Tab size
|
||||
self.tab_size_label = FCLabel('%s:' % _('Tab Size'))
|
||||
self.tab_size_label.setToolTip(
|
||||
_("Set the tab size. In pixels. Default value is 80 pixels.")
|
||||
_("Set the tab size. In pixels.")
|
||||
)
|
||||
self.tab_size_spinner = FCSpinner(callback=self.confirmation_message_int)
|
||||
self.tab_size_spinner.set_range(0, 1000)
|
||||
|
||||
self.grid0.addWidget(self.tab_size_label, 10, 0)
|
||||
self.grid0.addWidget(self.tab_size_spinner, 10, 1)
|
||||
a_grid.addWidget(self.tab_size_label, 2, 0)
|
||||
a_grid.addWidget(self.tab_size_spinner, 2, 1)
|
||||
|
||||
GLay.set_common_column_size([self.grid0, a_grid], 0)
|
||||
self.custom_box.addStretch(1)
|
||||
|
||||
# end of file
|
||||
|
||||
@@ -69,13 +69,6 @@ class DocumentObject(FlatCAMObj):
|
||||
self.change_level(app_mode)
|
||||
|
||||
self.document_editor_tab = AppTextEditor(app=self.app)
|
||||
stylesheet = """
|
||||
QTextEdit {selection-background-color:%s;
|
||||
selection-color:white;
|
||||
}
|
||||
""" % self.app.options["document_sel_color"]
|
||||
|
||||
self.document_editor_tab.code_editor.setStyleSheet(stylesheet)
|
||||
|
||||
self.document_editor_tab.buttonRun.hide()
|
||||
|
||||
@@ -83,8 +76,14 @@ class DocumentObject(FlatCAMObj):
|
||||
self.on_autocomplete_changed(state=self.app.options['document_autocompleter'])
|
||||
self.on_tab_size_change(val=self.app.options['document_tab_size'])
|
||||
|
||||
flt = "FlatCAM Docs (*.FlatDoc);;All Files (*.*)"
|
||||
self.ui.font_color_entry.set_value(self.app.options['document_font_color'])
|
||||
self.ui.sel_color_entry.set_value(self.app.options['document_sel_color'])
|
||||
self.ui.font_size_cb.setCurrentIndex(int(self.app.options['document_font_size']))
|
||||
|
||||
font_sizes = self.app.options['document_font_sizes']
|
||||
self.ui.font_size_cb.addItems(font_sizes)
|
||||
|
||||
flt = "FlatCAM Docs (*.FlatDoc);;All Files (*.*)"
|
||||
# ######################################################################
|
||||
# ######################## SIGNALS #####################################
|
||||
# ######################################################################
|
||||
@@ -103,10 +102,8 @@ class DocumentObject(FlatCAMObj):
|
||||
self.ui.font_italic_tb.clicked.connect(self.on_italic_button)
|
||||
self.ui.font_under_tb.clicked.connect(self.on_underline_button)
|
||||
|
||||
self.ui.font_color_entry.editingFinished.connect(self.on_font_color_entry)
|
||||
self.ui.font_color_button.clicked.connect(self.on_font_color_button)
|
||||
self.ui.sel_color_entry.editingFinished.connect(self.on_selection_color_entry)
|
||||
self.ui.sel_color_button.clicked.connect(self.on_selection_color_button)
|
||||
self.ui.font_color_entry.value_changed.connect(self.on_font_color_entry)
|
||||
self.ui.sel_color_entry.value_changed.connect(self.on_selection_color_entry)
|
||||
|
||||
self.ui.al_left_tb.clicked.connect(
|
||||
lambda: self.document_editor_tab.code_editor.setAlignment(Qt.AlignmentFlag.AlignLeft))
|
||||
@@ -122,16 +119,6 @@ class DocumentObject(FlatCAMObj):
|
||||
self.ui.tab_size_spinner.returnPressed.connect(self.on_tab_size_change)
|
||||
# #######################################################################
|
||||
|
||||
self.ui.font_color_entry.set_value(self.app.options['document_font_color'])
|
||||
self.ui.font_color_button.setStyleSheet(
|
||||
"background-color:%s" % str(self.app.options['document_font_color']))
|
||||
|
||||
self.ui.sel_color_entry.set_value(self.app.options['document_sel_color'])
|
||||
self.ui.sel_color_button.setStyleSheet(
|
||||
"background-color:%s" % self.app.options['document_sel_color'])
|
||||
|
||||
self.ui.font_size_cb.setCurrentIndex(int(self.app.options['document_font_size']))
|
||||
|
||||
# self.document_editor_tab.handleTextChanged()
|
||||
self.ser_attrs = ['options', 'kind', 'source_file']
|
||||
|
||||
@@ -146,6 +133,9 @@ class DocumentObject(FlatCAMObj):
|
||||
except AttributeError:
|
||||
self.document_editor_tab.load_text(self.source_file, move_to_start=True, clear_text=True, as_html=True)
|
||||
|
||||
self.on_selection_color_entry(self.app.options["document_sel_color"])
|
||||
# self.on_font_color_entry(self.app.options["document_font_color"])
|
||||
|
||||
self.build_ui()
|
||||
|
||||
# TODO does not work, why?
|
||||
@@ -274,40 +264,14 @@ class DocumentObject(FlatCAMObj):
|
||||
self.font_underline = False
|
||||
|
||||
# Setting font colors handlers
|
||||
def on_font_color_entry(self):
|
||||
self.app.options['document_font_color'] = self.ui.font_color_entry.get_value()
|
||||
self.ui.font_color_button.setStyleSheet("background-color:%s;" % str(self.app.options['document_font_color']))
|
||||
|
||||
def on_font_color_button(self):
|
||||
current_color = QtGui.QColor(self.app.options['document_font_color'])
|
||||
|
||||
c_dialog = QtWidgets.QColorDialog(parent=self.app.ui)
|
||||
font_color = c_dialog.getColor(initial=current_color)
|
||||
|
||||
if font_color.isValid() is False:
|
||||
return
|
||||
|
||||
self.document_editor_tab.code_editor.setTextColor(font_color)
|
||||
self.ui.font_color_button.setStyleSheet("background-color:%s;" % str(font_color.name()))
|
||||
|
||||
new_val = str(font_color.name())
|
||||
self.ui.font_color_entry.set_value(new_val)
|
||||
self.app.options['document_font_color'] = new_val
|
||||
def on_font_color_entry(self, val):
|
||||
self.app.options['document_font_color'] = val
|
||||
new_color = QtGui.QColor(val[:-2])
|
||||
self.document_editor_tab.code_editor.setTextColor(new_color)
|
||||
|
||||
# Setting selection colors handlers
|
||||
def on_selection_color_entry(self):
|
||||
self.app.options['document_sel_color'] = self.ui.sel_color_entry.get_value()
|
||||
self.ui.sel_color_button.setStyleSheet("background-color:%s;" % str(self.app.options['document_sel_color']))
|
||||
|
||||
def on_selection_color_button(self):
|
||||
current_color = QtGui.QColor(self.app.options['document_sel_color'])
|
||||
|
||||
c_dialog = QtWidgets.QColorDialog(parent=self.app.ui)
|
||||
sel_color = c_dialog.getColor(initial=current_color)
|
||||
|
||||
if sel_color.isValid() is False:
|
||||
return
|
||||
|
||||
def on_selection_color_entry(self, val):
|
||||
self.app.options['document_sel_color'] = val
|
||||
# p = QtGui.QPalette()
|
||||
# p.setColor(QtGui.QPalette.ColorRole.Highlight, sel_color)
|
||||
# p.setColor(QtGui.QPalette.ColorRole.HighlightedText, QtGui.QColor('white'))
|
||||
@@ -318,15 +282,9 @@ class DocumentObject(FlatCAMObj):
|
||||
QTextEdit {selection-background-color:%s;
|
||||
selection-color:white;
|
||||
}
|
||||
""" % sel_color.name()
|
||||
""" % QtGui.QColor(val[:-2]).name()
|
||||
)
|
||||
|
||||
self.ui.sel_color_button.setStyleSheet("background-color:%s;" % str(sel_color.name()))
|
||||
|
||||
new_val = str(sel_color.name())
|
||||
self.ui.sel_color_entry.set_value(new_val)
|
||||
self.app.options['document_sel_color'] = new_val
|
||||
|
||||
def mirror(self, axis, point):
|
||||
pass
|
||||
|
||||
|
||||
10
defaults.py
10
defaults.py
@@ -840,10 +840,16 @@ class AppDefaults:
|
||||
"document_text": "",
|
||||
"document_plot": True,
|
||||
"document_source_file": "",
|
||||
"document_font_color": '#000000',
|
||||
"document_sel_color": '#0055ff',
|
||||
"document_font_color": '#000000FF',
|
||||
"document_sel_color": '#0055ffFF',
|
||||
"document_font_size": 6,
|
||||
"document_tab_size": 80,
|
||||
"document_font_sizes": [
|
||||
'6', '7', '8', '9', '10', '11', '12', '13', '14',
|
||||
'15', '16', '18', '20', '22', '24', '26', '28',
|
||||
'32', '36', '40', '44', '48', '54', '60', '66',
|
||||
'72', '80', '88', '96'
|
||||
]
|
||||
}
|
||||
|
||||
@classmethod
|
||||
|
||||
Reference in New Issue
Block a user