- 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

This commit is contained in:
Marius Stanciu
2019-09-07 10:55:45 +03:00
committed by Marius
parent 5d854a6f1b
commit 2c2bdf5002
3 changed files with 125 additions and 91 deletions

View File

@@ -3465,14 +3465,14 @@ class App(QtCore.QObject):
# here it is done the object plotting # here it is done the object plotting
def worker_task(t_obj): def worker_task(t_obj):
# with self.proc_container.new(_("Plotting")): with self.proc_container.new(_("Plotting")):
if isinstance(t_obj, FlatCAMCNCjob): if isinstance(t_obj, FlatCAMCNCjob):
t_obj.plot(kind=self.defaults["cncjob_plot_kind"]) t_obj.plot(kind=self.defaults["cncjob_plot_kind"])
else: else:
t_obj.plot() t_obj.plot()
t1 = time.time() # DEBUG t1 = time.time() # DEBUG
self.log.debug("%f seconds adding object and plotting." % (t1 - t0)) self.log.debug("%f seconds adding object and plotting." % (t1 - t0))
self.object_plotted.emit(t_obj) self.object_plotted.emit(t_obj)
# Send to worker # Send to worker
# self.worker.add_task(worker_task, [self]) # self.worker.add_task(worker_task, [self])
@@ -9379,11 +9379,26 @@ The normal flow when working in FlatCAM is the following:</span></p>
:return: :return:
""" """
log.debug("Enabling plots ...") log.debug("Enabling plots ...")
self.inform.emit(_("Working ...")) # self.inform.emit(_("Working ..."))
for obj in objects: for obj in objects:
if obj.options['plot'] is False: if obj.options['plot'] is False:
obj.options.set_change_callback(lambda x: None)
obj.options['plot'] = True 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): def disable_plots(self, objects):
""" """
@@ -9397,11 +9412,25 @@ The normal flow when working in FlatCAM is the following:</span></p>
return return
log.debug("Disabling plots ...") log.debug("Disabling plots ...")
self.inform.emit(_("Working ...")) # self.inform.emit(_("Working ..."))
for obj in objects: for obj in objects:
if obj.options['plot'] is True: if obj.options['plot'] is True:
obj.options.set_change_callback(lambda x: None)
obj.options['plot'] = False 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): def toggle_plots(self, objects):
""" """

View File

@@ -1162,6 +1162,11 @@ class FlatCAMGerber(FlatCAMObj, Gerber):
else: else:
face_color = self.app.defaults['global_plot_fill'] 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 the Follow Geometry checkbox is checked then plot only the follow geometry
if self.ui.follow_cb.get_value(): if self.ui.follow_cb.get_value():
geometry = self.follow_geometry geometry = self.follow_geometry
@@ -1179,40 +1184,39 @@ class FlatCAMGerber(FlatCAMObj, Gerber):
color[3] = 1 color[3] = 1
return color return color
with self.app.proc_container.new(_("Plotting")): try:
try: if self.options["solid"]:
if self.options["solid"]: for g in geometry:
for g in geometry: if type(g) == Polygon or type(g) == LineString:
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, self.add_shape(shape=g, color=color,
face_color=random_color() if self.options['multicolored'] face_color=random_color() if self.options['multicolored']
else face_color, visible=self.options['plot']) else face_color, visible=visible)
elif type(g) == Point: else:
pass for g in geometry:
else: if type(g) == Polygon or type(g) == LineString:
try: self.add_shape(shape=g, color=random_color() if self.options['multicolored'] else 'black',
for el in g: visible=visible)
self.add_shape(shape=el, color=color, elif type(g) == Point:
face_color=random_color() if self.options['multicolored'] pass
else face_color, visible=self.options['plot']) else:
except TypeError: for el in g:
self.add_shape(shape=g, color=color, self.add_shape(shape=el, color=random_color() if self.options['multicolored'] else 'black',
face_color=random_color() if self.options['multicolored'] visible=visible)
else face_color, visible=self.options['plot']) self.shapes.redraw()
else: except (ObjectDeleted, AttributeError):
for g in geometry: self.shapes.clear(update=True)
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)
# experimental plot() when the solid_geometry is stored in the self.apertures # experimental plot() when the solid_geometry is stored in the self.apertures
def plot_aperture(self, **kwargs): def plot_aperture(self, **kwargs):
@@ -2902,7 +2906,7 @@ class FlatCAMExcellon(FlatCAMObj, Excellon):
# except TypeError: # Element is not iterable... # except TypeError: # Element is not iterable...
# self.add_shape(shape=element, color=color, visible=visible, layer=0) # 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 # Does all the required setup and returns False
# if the 'ptint' option is set to False. # if the 'ptint' option is set to False.
@@ -2929,29 +2933,30 @@ class FlatCAMExcellon(FlatCAMObj, Excellon):
# except (ObjectDeleted, AttributeError, KeyError): # except (ObjectDeleted, AttributeError, KeyError):
# self.shapes.clear(update=True) # 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
# this stays for compatibility reasons, in case we try to open old projects try:
try: __ = iter(self.solid_geometry)
__ = iter(self.solid_geometry) except TypeError:
except TypeError: self.solid_geometry = [self.solid_geometry]
self.solid_geometry = [self.solid_geometry]
try: visible = visible if visible else self.options['plot']
# 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'])
self.shapes.redraw() try:
except (ObjectDeleted, AttributeError): # Plot Excellon (All polygons?)
self.shapes.clear(update=True) 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): class FlatCAMGeometry(FlatCAMObj, Geometry):
@@ -6071,33 +6076,32 @@ class FlatCAMCNCjob(FlatCAMObj, CNCjob):
if not FlatCAMObj.plot(self): if not FlatCAMObj.plot(self):
return 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(): if self.ui.annotation_cb.get_value() and self.ui.plot_cb.get_value():
self.text_col.enabled = True 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: else:
self.text_col.enabled = False # multiple tools usage
self.annotation.redraw() for tooluid_key in self.cnc_tools:
tooldia = float('%.4f' % float(self.cnc_tools[tooluid_key]['tooldia']))
try: gcode_parsed = self.cnc_tools[tooluid_key]['gcode_parsed']
if self.multitool is False: # single tool usage self.plot2(tooldia=tooldia, obj=self, visible=visible, gcode_parsed=gcode_parsed, kind=kind)
try: self.shapes.redraw()
dia_plot = float(self.options["tooldia"]) except (ObjectDeleted, AttributeError):
except ValueError: self.shapes.clear(update=True)
# we may have a tuple with only one element and a comma self.annotation.clear(update=True)
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)
def on_annotation_change(self): def on_annotation_change(self):
if self.ui.annotation_cb.get_value(): if self.ui.annotation_cb.get_value():

View File

@@ -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 - 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 - 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 6.09.2019