diff --git a/CHANGELOG.md b/CHANGELOG.md index 7be425a5..7a92006a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,9 @@ CHANGELOG for FlatCAM beta - fixed issues in the 'millslots' and 'milldrills' Tcl commands for the case when some parameters are not used - made sure that in Tcl commands deleting argument keys will not raise an error - fixed the 'isolate' Tcl command: updated to the new tools data structure elements +- fixing an issue with not building the UI for the generated objects when running a script and then trying to enable/disable the plots +- attempting to add a feature in the text editors to autoselect all words in a document that are the same as the one that was clicked +- all the colors set in Preferences now have to be in the 8digits format RGBA (including the alpha channel as a suffix) - it is required to delete the current preferences files 15.01.2022 diff --git a/appEditors/AppExcEditor.py b/appEditors/AppExcEditor.py index 27944881..5976b256 100644 --- a/appEditors/AppExcEditor.py +++ b/appEditors/AppExcEditor.py @@ -3673,7 +3673,7 @@ class AppExcEditor(QtCore.QObject): for sub_geo in el.geoms: self.tool_shape.add( shape=sub_geo, - color=(self.app.defaults["global_draw_color"] + '80'), + color=(self.app.defaults["global_draw_color"]), update=False, layer=0, tolerance=None @@ -3681,14 +3681,14 @@ class AppExcEditor(QtCore.QObject): else: self.tool_shape.add( shape=el, - color=(self.app.defaults["global_draw_color"] + '80'), + color=(self.app.defaults["global_draw_color"]), update=False, layer=0, tolerance=None) except TypeError: self.tool_shape.add( shape=util_geo, - color=(self.app.defaults["global_draw_color"] + '80'), + color=(self.app.defaults["global_draw_color"]), update=False, layer=0, tolerance=None) @@ -3717,7 +3717,7 @@ class AppExcEditor(QtCore.QObject): self.plot_shape(geometry=shape_plus.geo, color=self.app.defaults['global_sel_draw_color'] + 'FF', linewidth=2) continue - self.plot_shape(geometry=shape_plus.geo, color=self.app.defaults['global_draw_color'] + 'FF') + self.plot_shape(geometry=shape_plus.geo, color=self.app.defaults['global_draw_color'][:-2] + 'FF') for shape_form in self.utility: self.plot_shape(geometry=shape_form.geo, linewidth=1) diff --git a/appEditors/AppGeoEditor.py b/appEditors/AppGeoEditor.py index 8537b4a4..fc4e3ff3 100644 --- a/appEditors/AppGeoEditor.py +++ b/appEditors/AppGeoEditor.py @@ -4975,7 +4975,7 @@ class AppGeoEditor(QtCore.QObject): for poly in el: self.tool_shape.add( shape=poly, - color=(self.app.defaults["global_draw_color"] + '80'), + color=(self.app.defaults["global_draw_color"]), update=False, layer=0, tolerance=None @@ -4984,7 +4984,7 @@ class AppGeoEditor(QtCore.QObject): for linestring in el: self.tool_shape.add( shape=linestring, - color=(self.app.defaults["global_draw_color"] + '80'), + color=(self.app.defaults["global_draw_color"]), update=False, layer=0, tolerance=None @@ -4992,14 +4992,14 @@ class AppGeoEditor(QtCore.QObject): else: self.tool_shape.add( shape=el, - color=(self.app.defaults["global_draw_color"] + '80'), + color=(self.app.defaults["global_draw_color"]), update=False, layer=0, tolerance=None ) except TypeError: self.tool_shape.add( - shape=geo.geo, color=(self.app.defaults["global_draw_color"] + '80'), + shape=geo.geo, color=(self.app.defaults["global_draw_color"]), update=False, layer=0, tolerance=None) self.tool_shape.redraw() @@ -5118,8 +5118,8 @@ class AppGeoEditor(QtCore.QObject): self.shapes.clear(update=True) - draw_color = self.app.defaults['global_draw_color'] + "FF" - sel_color = self.app.defaults['global_sel_draw_color'] + 'FF' + draw_color = self.app.defaults['global_draw_color'][:-2] + "FF" + sel_color = self.app.defaults['global_sel_draw_color'][:-2] + 'FF' for shape in self.storage.get_objects(): if shape.geo and not shape.geo.is_empty and shape.geo.is_valid: diff --git a/appEditors/AppGerberEditor.py b/appEditors/AppGerberEditor.py index fbd32c01..1dfc64ed 100644 --- a/appEditors/AppGerberEditor.py +++ b/appEditors/AppGerberEditor.py @@ -5516,7 +5516,7 @@ class AppGerberEditor(QtCore.QObject): geometric_data = el['solid'] # Add the new utility shape self.tool_shape.add( - shape=geometric_data, color=(self.app.defaults["global_draw_color"] + '80'), + shape=geometric_data, color=(self.app.defaults["global_draw_color"]), # face_color=self.app.defaults['global_alt_sel_fill'], update=False, layer=0, tolerance=None ) @@ -5525,7 +5525,7 @@ class AppGerberEditor(QtCore.QObject): # Add the new utility shape self.tool_shape.add( shape=geometric_data, - color=(self.app.defaults["global_draw_color"] + '80'), + color=(self.app.defaults["global_draw_color"]), # face_color=self.app.defaults['global_alt_sel_fill'], update=False, layer=0, tolerance=None ) @@ -5557,7 +5557,7 @@ class AppGerberEditor(QtCore.QObject): linewidth=2) else: self.plot_shape(geometry=geometric_data, - color=self.app.defaults['global_draw_color'] + 'FF') + color=self.app.defaults['global_draw_color'][:-2] + 'FF') if self.utility: for elem in self.utility: diff --git a/appGUI/GUIElements.py b/appGUI/GUIElements.py index 2169cf21..924e8440 100644 --- a/appGUI/GUIElements.py +++ b/appGUI/GUIElements.py @@ -2019,6 +2019,7 @@ class FCPlainTextAreaExtended(QtWidgets.QPlainTextEdit): super().__init__(parent) self.completer = MyCompleter() + self.previous_selected_word = '' self.model = QtCore.QStringListModel() self.completer.setModel(self.model) @@ -2295,6 +2296,50 @@ class FCPlainTextAreaExtended(QtWidgets.QPlainTextEdit): else: self.completer.popup().hide() + def mouseReleaseEvent(self, e: QtGui.QMouseEvent) -> None: + super().mouseReleaseEvent(e) + # self.select_word_instances(e.pos()) + + def select_word_instances(self, pos): + cursor = self.textCursor() + cursor.select(QtGui.QTextCursor.SelectionType.WordUnderCursor) + sel_word = cursor.selectedText() + + if sel_word != self.previous_selected_word or sel_word == '': + cs = self.cursorForPosition(pos) + position = cs.position() + # first clear a possible previous highlight + cursor.select(QtGui.QTextCursor.SelectionType.Document) + cursor.setCharFormat(QtGui.QTextCharFormat()) + cursor.clearSelection() + self.setTextCursor(cursor) + cursor.setPosition(position, QtGui.QTextCursor.MoveMode.MoveAnchor) + # cursor.movePosition(QtGui.QTextCursor.MoveOperation.StartOfWord, QtGui.QTextCursor.MoveMode.KeepAnchor, 1) + self.setTextCursor(cursor) + + self.previous_selected_word = sel_word + if sel_word == '': + return + + # Setup the desired format for matches + fmt = QtGui.QTextCharFormat() + fmt.setBackground(Qt.GlobalColor.lightGray) + text = self.toPlainText() + + pattern = re.compile(r'%s' % sel_word) + start = pattern.search(text, 0) + idx = 0 + + while start and idx < len(text): + idx = start.start() + # Select the matched text and apply the desired format + cursor.setPosition(idx, QtGui.QTextCursor.MoveMode.MoveAnchor) + cursor.movePosition(QtGui.QTextCursor.MoveOperation.EndOfWord, QtGui.QTextCursor.MoveMode.KeepAnchor ,1) + cursor.mergeCharFormat(fmt) + start = pattern.search(text, idx+1) + + cursor.select(QtGui.QTextCursor.SelectionType.WordUnderCursor) + def comment(self): """ Got it from here: diff --git a/appObjects/FlatCAMCNCJob.py b/appObjects/FlatCAMCNCJob.py index 45e11a7c..bb1523a8 100644 --- a/appObjects/FlatCAMCNCJob.py +++ b/appObjects/FlatCAMCNCJob.py @@ -1219,12 +1219,16 @@ class CNCJobObject(FlatCAMObj, CNCjob): self.ui_disconnect() cb_flag = self.ui.plot_cb.isChecked() - for row in range(self.ui.cnc_tools_table.rowCount()): - table_cb = self.ui.cnc_tools_table.cellWidget(row, 6) - if cb_flag: - table_cb.setChecked(True) - else: - table_cb.setChecked(False) + try: + for row in range(self.ui.cnc_tools_table.rowCount()): + table_cb = self.ui.cnc_tools_table.cellWidget(row, 6) + if cb_flag: + table_cb.setChecked(True) + else: + table_cb.setChecked(False) + except AttributeError: + # TODO from Tcl commands - should fix it sometime + pass self.ui_connect() def on_plot_cb_click_table(self): @@ -1307,13 +1311,14 @@ class CNCJobObject(FlatCAMObj, CNCjob): # we may have a tuple with only one element and a comma dia_plot = [float(el) for el in self.options["tooldia"].split(',') if el != ''][0] else: - try: - dia_plot = float(self.options["tools_mill_tooldia"]) - except ValueError: - # we may have a tuple with only one element and a comma - dia_plot = [ - float(el) for el in self.options["tools_mill_tooldia"].split(',') if el != '' - ][0] + # try: + # dia_plot = float(self.options["tools_mill_tooldia"]) + # except ValueError: + # # we may have a tuple with only one element and a comma + # dia_plot = [ + # float(el) for el in self.options["tools_mill_tooldia"].split(',') if el != '' + # ][0] + dia_plot = float(self.options["cncjob_tooldia"]) self.plot2(tooldia=dia_plot, obj=self, visible=visible, kind=kind) else: diff --git a/appObjects/FlatCAMGeometry.py b/appObjects/FlatCAMGeometry.py index 96827bcd..ad49e958 100644 --- a/appObjects/FlatCAMGeometry.py +++ b/appObjects/FlatCAMGeometry.py @@ -1584,8 +1584,9 @@ class GeometryObject(FlatCAMObj, Geometry): geo_final.multigeo = True try: - new_solid_geometry += deepcopy(geo_obj.solid_geometry) + new_solid_geometry += deepcopy(geo_obj.solid_geometry.geoms) except Exception as e: + new_solid_geometry.append(geo_obj.solid_geometry) log.error("GeometryObject.merge() --> %s" % str(e)) # find the tool_uid maximum value in the geo_final diff --git a/appObjects/ObjectCollection.py b/appObjects/ObjectCollection.py index 484ddf0f..effe4019 100644 --- a/appObjects/ObjectCollection.py +++ b/appObjects/ObjectCollection.py @@ -476,8 +476,8 @@ class ObjectCollection(QtCore.QAbstractItemModel): return index.internalPointer().data(index.column()) if role == Qt.ItemDataRole.ForegroundRole: - color = QColor(self.app.defaults['global_proj_item_color']) - color_disabled = QColor(self.app.defaults['global_proj_item_dis_color']) + color = QColor(self.app.defaults['global_proj_item_color'][:-2]) + color_disabled = QColor(self.app.defaults['global_proj_item_dis_color'][:-2]) obj = index.internalPointer().obj if obj: return QtGui.QBrush(color) if obj.options["plot"] else QtGui.QBrush(color_disabled) diff --git a/appPlugins/ToolCutOut.py b/appPlugins/ToolCutOut.py index af99cee1..39bceab2 100644 --- a/appPlugins/ToolCutOut.py +++ b/appPlugins/ToolCutOut.py @@ -1964,7 +1964,7 @@ class CutOut(AppTool): def draw_utility_geometry(self, geo): self.app.geo_editor.tool_shape.add( shape=geo, - color=(self.app.defaults["global_draw_color"] + '80'), + color=(self.app.defaults["global_draw_color"]), update=False, layer=0, tolerance=None) diff --git a/app_Main.py b/app_Main.py index 72765469..af4346c8 100644 --- a/app_Main.py +++ b/app_Main.py @@ -8261,7 +8261,14 @@ class App(QtCore.QObject): for plot_obj in self.collection.get_list(): def worker_task(obj): with self.proc_container.new("Plotting"): - obj.plot(kind=self.defaults["cncjob_plot_kind"]) + if obj.kind == 'cncjob': + try: + dia = obj.ui.tooldia_entry.get_value() + except AttributeError: + dia = self.defaults["cncjob_tooldia"] + obj.plot(kind=self.defaults["cncjob_plot_kind"], dia=dia) + else: + obj.plot() if fit_view is True: self.app_obj.object_plotted.emit(obj) @@ -8803,21 +8810,27 @@ class App(QtCore.QObject): for obj in objects: if obj.options['plot'] is False: obj.options.set_change_callback(lambda x: None) - obj.options['plot'] = True try: - # only the Gerber obj has on_plot_cb_click() method + obj.options['plot'] = True obj.ui.plot_cb.stateChanged.disconnect(obj.on_plot_cb_click) # disable this cb while disconnected, # in case the operation takes time the user is not allowed to change it obj.ui.plot_cb.setDisabled(True) except AttributeError: - pass + # try to build the ui + obj.build_ui() + # and try again + self.enable_plots(objects) + obj.set_form_item("plot") try: obj.ui.plot_cb.stateChanged.connect(obj.on_plot_cb_click) obj.ui.plot_cb.setDisabled(False) except AttributeError: - pass + # try to build the ui + obj.build_ui() + # and try again + self.enable_plots(objects) obj.options.set_change_callback(obj.on_options_change) self.collection.update_view() @@ -8846,19 +8859,25 @@ class App(QtCore.QObject): for obj in objects: if obj.options['plot'] is True: obj.options.set_change_callback(lambda x: None) - obj.options['plot'] = False try: - # only the Gerber obj has on_plot_cb_click() method + obj.options['plot'] = False obj.ui.plot_cb.stateChanged.disconnect(obj.on_plot_cb_click) obj.ui.plot_cb.setDisabled(True) except (AttributeError, TypeError): - pass + # try to build the ui + obj.build_ui() + # and try again + self.disable_plots(objects) + obj.set_form_item("plot") try: obj.ui.plot_cb.stateChanged.connect(obj.on_plot_cb_click) obj.ui.plot_cb.setDisabled(False) except (AttributeError, TypeError): - pass + # try to build the ui + obj.build_ui() + # and try again + self.disable_plots(objects) obj.options.set_change_callback(obj.on_options_change) try: diff --git a/defaults.py b/defaults.py index fed2b7b2..0837a3ca 100644 --- a/defaults.py +++ b/defaults.py @@ -120,10 +120,10 @@ class FlatCAMDefaults: "global_sel_line": '#0000ffbf', "global_alt_sel_fill": '#BBF268BF', "global_alt_sel_line": '#006E20BF', - "global_draw_color": '#FF0000', - "global_sel_draw_color": '#0000FF', - "global_proj_item_color": '#000000', - "global_proj_item_dis_color": '#b7b7cb', + "global_draw_color": '#FF000080', + "global_sel_draw_color": '#0000FF80', + "global_proj_item_color": '#000000FF', + "global_proj_item_dis_color": '#b7b7cbFF', "global_project_autohide": True, # General App Settings @@ -317,7 +317,7 @@ class FlatCAMDefaults: # CNC Job General "cncjob_plot": True, - "cncjob_tooldia": 1.0, + "cncjob_tooldia": 0.125, "cncjob_coords_type": "G90", "cncjob_coords_decimals": 4, "cncjob_fr_decimals": 2,