From 2c2bdf50025d68c9d65fe1f4e307d3a34f4a4dc2 Mon Sep 17 00:00:00 2001 From: Marius Stanciu Date: Sat, 7 Sep 2019 10:55:45 +0300 Subject: [PATCH] - remade the handlers for the Enable/Disable Project Tree context menu so they are threaded and activity is shown in the lower right corner of the main window --- FlatCAMApp.py | 53 +++++++++++++---- FlatCAMObj.py | 162 ++++++++++++++++++++++++++------------------------ README.md | 1 + 3 files changed, 125 insertions(+), 91 deletions(-) diff --git a/FlatCAMApp.py b/FlatCAMApp.py index 16912b03..a9c3b139 100644 --- a/FlatCAMApp.py +++ b/FlatCAMApp.py @@ -3465,14 +3465,14 @@ class App(QtCore.QObject): # here it is done the object plotting def worker_task(t_obj): - # with self.proc_container.new(_("Plotting")): - if isinstance(t_obj, FlatCAMCNCjob): - t_obj.plot(kind=self.defaults["cncjob_plot_kind"]) - else: - t_obj.plot() - t1 = time.time() # DEBUG - self.log.debug("%f seconds adding object and plotting." % (t1 - t0)) - self.object_plotted.emit(t_obj) + with self.proc_container.new(_("Plotting")): + if isinstance(t_obj, FlatCAMCNCjob): + t_obj.plot(kind=self.defaults["cncjob_plot_kind"]) + else: + t_obj.plot() + t1 = time.time() # DEBUG + self.log.debug("%f seconds adding object and plotting." % (t1 - t0)) + self.object_plotted.emit(t_obj) # Send to worker # self.worker.add_task(worker_task, [self]) @@ -9379,11 +9379,26 @@ The normal flow when working in FlatCAM is the following:

:return: """ log.debug("Enabling plots ...") - self.inform.emit(_("Working ...")) + # self.inform.emit(_("Working ...")) + for obj in objects: if obj.options['plot'] is False: + obj.options.set_change_callback(lambda x: None) obj.options['plot'] = True - self.plots_updated.emit() + obj.options.set_change_callback(obj.on_options_change) + + def worker_task(objects): + with self.proc_container.new(_("Enabling plots ...")): + for obj in objects: + # obj.options['plot'] = True + if isinstance(obj, FlatCAMCNCjob): + obj.plot(visible=True, kind=self.defaults["cncjob_plot_kind"]) + else: + obj.plot(visible=True) + + self.worker_task.emit({'fcn': worker_task, 'params': [objects]}) + + # self.plots_updated.emit() def disable_plots(self, objects): """ @@ -9397,11 +9412,25 @@ The normal flow when working in FlatCAM is the following:

return log.debug("Disabling plots ...") - self.inform.emit(_("Working ...")) + # self.inform.emit(_("Working ...")) + for obj in objects: if obj.options['plot'] is True: + obj.options.set_change_callback(lambda x: None) obj.options['plot'] = False - self.plots_updated.emit() + obj.options.set_change_callback(obj.on_options_change) + + # self.plots_updated.emit() + def worker_task(objects): + with self.proc_container.new(_("Disabling plots ...")): + for obj in objects: + # obj.options['plot'] = True + if isinstance(obj, FlatCAMCNCjob): + obj.plot(visible=False, kind=self.defaults["cncjob_plot_kind"]) + else: + obj.plot(visible=False) + + self.worker_task.emit({'fcn': worker_task, 'params': [objects]}) def toggle_plots(self, objects): """ diff --git a/FlatCAMObj.py b/FlatCAMObj.py index 68f3c05c..1c4de08f 100644 --- a/FlatCAMObj.py +++ b/FlatCAMObj.py @@ -1162,6 +1162,11 @@ class FlatCAMGerber(FlatCAMObj, Gerber): else: face_color = self.app.defaults['global_plot_fill'] + if 'visible' not in kwargs: + visible = self.options['plot'] + else: + visible = kwargs['visible'] + # if the Follow Geometry checkbox is checked then plot only the follow geometry if self.ui.follow_cb.get_value(): geometry = self.follow_geometry @@ -1179,40 +1184,39 @@ class FlatCAMGerber(FlatCAMObj, Gerber): color[3] = 1 return color - with self.app.proc_container.new(_("Plotting")): - try: - if self.options["solid"]: - for g in geometry: - if type(g) == Polygon or type(g) == LineString: + try: + if self.options["solid"]: + for g in geometry: + if type(g) == Polygon or type(g) == LineString: + self.add_shape(shape=g, color=color, + face_color=random_color() if self.options['multicolored'] + else face_color, visible=visible) + elif type(g) == Point: + pass + else: + try: + for el in g: + self.add_shape(shape=el, color=color, + face_color=random_color() if self.options['multicolored'] + else face_color, visible=visible) + except TypeError: self.add_shape(shape=g, color=color, face_color=random_color() if self.options['multicolored'] - else face_color, visible=self.options['plot']) - elif type(g) == Point: - pass - else: - try: - for el in g: - self.add_shape(shape=el, color=color, - face_color=random_color() if self.options['multicolored'] - else face_color, visible=self.options['plot']) - except TypeError: - self.add_shape(shape=g, color=color, - face_color=random_color() if self.options['multicolored'] - else face_color, visible=self.options['plot']) - else: - for g in geometry: - if type(g) == Polygon or type(g) == LineString: - self.add_shape(shape=g, color=random_color() if self.options['multicolored'] else 'black', - visible=self.options['plot']) - elif type(g) == Point: - pass - else: - for el in g: - self.add_shape(shape=el, color=random_color() if self.options['multicolored'] else 'black', - visible=self.options['plot']) - self.shapes.redraw() - except (ObjectDeleted, AttributeError): - self.shapes.clear(update=True) + else face_color, visible=visible) + else: + for g in geometry: + if type(g) == Polygon or type(g) == LineString: + self.add_shape(shape=g, color=random_color() if self.options['multicolored'] else 'black', + visible=visible) + elif type(g) == Point: + pass + else: + for el in g: + self.add_shape(shape=el, color=random_color() if self.options['multicolored'] else 'black', + visible=visible) + self.shapes.redraw() + except (ObjectDeleted, AttributeError): + self.shapes.clear(update=True) # experimental plot() when the solid_geometry is stored in the self.apertures def plot_aperture(self, **kwargs): @@ -2902,7 +2906,7 @@ class FlatCAMExcellon(FlatCAMObj, Excellon): # except TypeError: # Element is not iterable... # self.add_shape(shape=element, color=color, visible=visible, layer=0) - def plot(self, kind=None): + def plot(self, visible=None, kind=None): # Does all the required setup and returns False # if the 'ptint' option is set to False. @@ -2929,29 +2933,30 @@ class FlatCAMExcellon(FlatCAMObj, Excellon): # except (ObjectDeleted, AttributeError, KeyError): # self.shapes.clear(update=True) - with self.app.proc_container.new(_("Plotting")): - # this stays for compatibility reasons, in case we try to open old projects - try: - __ = iter(self.solid_geometry) - except TypeError: - self.solid_geometry = [self.solid_geometry] + # this stays for compatibility reasons, in case we try to open old projects + try: + __ = iter(self.solid_geometry) + except TypeError: + self.solid_geometry = [self.solid_geometry] - try: - # Plot Excellon (All polygons?) - if self.options["solid"]: - for geo in self.solid_geometry: - self.add_shape(shape=geo, color='#750000BF', face_color='#C40000BF', - visible=self.options['plot'], - layer=2) - else: - for geo in self.solid_geometry: - self.add_shape(shape=geo.exterior, color='red', visible=self.options['plot']) - for ints in geo.interiors: - self.add_shape(shape=ints, color='orange', visible=self.options['plot']) + visible = visible if visible else self.options['plot'] - self.shapes.redraw() - except (ObjectDeleted, AttributeError): - self.shapes.clear(update=True) + try: + # Plot Excellon (All polygons?) + if self.options["solid"]: + for geo in self.solid_geometry: + self.add_shape(shape=geo, color='#750000BF', face_color='#C40000BF', + visible=visible, + layer=2) + else: + for geo in self.solid_geometry: + self.add_shape(shape=geo.exterior, color='red', visible=visible) + for ints in geo.interiors: + self.add_shape(shape=ints, color='orange', visible=visible) + + self.shapes.redraw() + except (ObjectDeleted, AttributeError): + self.shapes.clear(update=True) class FlatCAMGeometry(FlatCAMObj, Geometry): @@ -6071,33 +6076,32 @@ class FlatCAMCNCjob(FlatCAMObj, CNCjob): if not FlatCAMObj.plot(self): return - with self.app.proc_container.new(_("Plotting")): - visible = visible if visible else self.options['plot'] + visible = visible if visible else self.options['plot'] - if self.ui.annotation_cb.get_value() and self.ui.plot_cb.get_value(): - self.text_col.enabled = True + if self.ui.annotation_cb.get_value() and self.ui.plot_cb.get_value(): + self.text_col.enabled = True + else: + self.text_col.enabled = False + self.annotation.redraw() + + try: + if self.multitool is False: # single tool usage + try: + dia_plot = float(self.options["tooldia"]) + except ValueError: + # 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] + self.plot2(dia_plot, obj=self, visible=visible, kind=kind) else: - self.text_col.enabled = False - self.annotation.redraw() - - try: - if self.multitool is False: # single tool usage - try: - dia_plot = float(self.options["tooldia"]) - except ValueError: - # 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] - self.plot2(dia_plot, obj=self, visible=visible, kind=kind) - else: - # multiple tools usage - for tooluid_key in self.cnc_tools: - tooldia = float('%.4f' % float(self.cnc_tools[tooluid_key]['tooldia'])) - gcode_parsed = self.cnc_tools[tooluid_key]['gcode_parsed'] - self.plot2(tooldia=tooldia, obj=self, visible=visible, gcode_parsed=gcode_parsed, kind=kind) - self.shapes.redraw() - except (ObjectDeleted, AttributeError): - self.shapes.clear(update=True) - self.annotation.clear(update=True) + # multiple tools usage + for tooluid_key in self.cnc_tools: + tooldia = float('%.4f' % float(self.cnc_tools[tooluid_key]['tooldia'])) + gcode_parsed = self.cnc_tools[tooluid_key]['gcode_parsed'] + self.plot2(tooldia=tooldia, obj=self, visible=visible, gcode_parsed=gcode_parsed, kind=kind) + self.shapes.redraw() + except (ObjectDeleted, AttributeError): + self.shapes.clear(update=True) + self.annotation.clear(update=True) def on_annotation_change(self): if self.ui.annotation_cb.get_value(): diff --git a/README.md b/README.md index 2d0c5713..2f15c867 100644 --- a/README.md +++ b/README.md @@ -13,6 +13,7 @@ CAD program, and create G-Code for Isolation routing. - added a method to gracefully exit from threaded tasks and implemented it for the NCC Tool and for the Paint Tool - modified the on_about() function to reflect the reality in 2019 - FlatCAM it is an Open Source contributed software +- remade the handlers for the Enable/Disable Project Tree context menu so they are threaded and activity is shown in the lower right corner of the main window 6.09.2019