- the application now uses only the default values from the app.options dict, the app.defaults dict holds the definitive default values

- fixed some outstanding issues from the PyQt6 port
- PEP8 fixes
- minor fixes
- updated the saving of Preferences to update the self.options too: the `Apply` action will update the self.options but the `Save` action will save the updated preferences to the file on disk
This commit is contained in:
Marius Stanciu
2022-02-18 23:06:58 +02:00
committed by Marius
parent 14d9ea5470
commit 65d8dcc0b2
92 changed files with 1881 additions and 1882 deletions

146
camlib.py
View File

@@ -565,7 +565,7 @@ class Geometry(object):
self.plot_temp_shapes(sub_el)
except TypeError: # Element is not iterable...
# self.add_shape(shape=element, color=color, visible=visible, layer=0)
self.temp_shapes.add(tolerance=float(self.app.defaults["global_tolerance"]),
self.temp_shapes.add(tolerance=float(self.app.options["global_tolerance"]),
shape=element, color=color, visible=True, layer=0)
def make_index(self):
@@ -1226,7 +1226,7 @@ class Geometry(object):
return
units = self.app.app_units if units is None else units
res = self.app.defaults['geometry_circle_steps']
res = self.app.options['geometry_circle_steps']
factor = svgparse_viewbox(svg_root)
if svg_units == 'cm':
@@ -1295,7 +1295,7 @@ class Geometry(object):
if geos_text_f:
self.solid_geometry = self.solid_geometry + geos_text_f
tooldia = float(self.app.defaults["tools_mill_tooldia"])
tooldia = float(self.app.options["tools_mill_tooldia"])
tooldia = float('%.*f' % (self.decimals, tooldia))
new_data = {k: v for k, v in self.obj_options.items()}
@@ -1364,7 +1364,7 @@ class Geometry(object):
else: # It's shapely geometry
self.solid_geometry = [self.solid_geometry, geos]
tooldia = float(self.app.defaults["tools_mill_tooldia"])
tooldia = float(self.app.options["tools_mill_tooldia"])
tooldia = float('%.*f' % (self.decimals, tooldia))
new_data = {k: v for k, v in self.obj_options.items()}
@@ -2726,7 +2726,7 @@ class CNCjob(Geometry):
# Used when parsing G-code arcs
self.steps_per_circle = steps_per_circle if steps_per_circle is not None else \
int(self.app.defaults['cncjob_steps_per_circle'])
int(self.app.options['cncjob_steps_per_circle'])
Geometry.__init__(self, geo_steps_per_circle=self.steps_per_circle)
@@ -2769,7 +2769,7 @@ class CNCjob(Geometry):
self.feedminutecode = "G94"
# self.absolutecode = "G90"
# self.incrementalcode = "G91"
self.coordinates_type = self.app.defaults["cncjob_coords_type"]
self.coordinates_type = self.app.options["cncjob_coords_type"]
self.gcode = ""
self.gcode_parsed = None
@@ -2809,13 +2809,13 @@ class CNCjob(Geometry):
self.input_geometry_bounds = None
# compensation for CNC bed not square
self._bed_limit_x = self.app.defaults["cncjob_bed_max_x"]
self._bed_limit_y = self.app.defaults["cncjob_bed_max_y"]
self._bed_limit_x = self.app.options["cncjob_bed_max_x"]
self._bed_limit_y = self.app.options["cncjob_bed_max_y"]
self._bed_offset_x = self.app.defaults["cncjob_bed_offset_x"]
self._bed_offset_y = self.app.defaults["cncjob_bed_offset_y"]
self._bed_skew_x = self.app.defaults["cncjob_bed_skew_x"]
self._bed_skew_y = self.app.defaults["cncjob_bed_skew_y"]
self._bed_offset_x = self.app.options["cncjob_bed_offset_x"]
self._bed_offset_y = self.app.options["cncjob_bed_offset_y"]
self._bed_skew_x = self.app.options["cncjob_bed_skew_x"]
self._bed_skew_y = self.app.options["cncjob_bed_skew_y"]
# coordinates used by the preprocessors position_code() method; updated when creating gcode
self.x = 0.0
@@ -3406,7 +3406,7 @@ class CNCjob(Geometry):
# if there are no locations then go to the next tool
if not locations:
return 'fail'
opt_time = self.app.defaults["excellon_search_time"]
opt_time = self.app.options["excellon_search_time"]
optimized_path = self.optimized_ortools_meta(locations=locations, opt_time=opt_time)
elif opt_type == 'B':
locations = self.create_tool_data_array(points=points)
@@ -3481,7 +3481,7 @@ class CNCjob(Geometry):
z_offset = 0
self.z_cut = z_offset + old_zcut
self.coordinates_type = self.app.defaults["cncjob_coords_type"]
self.coordinates_type = self.app.options["cncjob_coords_type"]
if self.coordinates_type == "G90":
# Drillling! for Absolute coordinates type G90
# variables to display the percentage of work done
@@ -3776,7 +3776,7 @@ class CNCjob(Geometry):
self.multidepth = tool_dict['tools_mill_multidepth']
self.z_depthpercut = float(tool_dict['tools_mill_depthperpass'])
self.z_move = float(tool_dict['tools_mill_travelz'])
self.f_plunge = self.app.defaults["tools_mill_f_plunge"]
self.f_plunge = self.app.options["tools_mill_f_plunge"]
self.feedrate = float(tool_dict['tools_mill_feedrate'])
self.z_feedrate = float(tool_dict['tools_mill_feedrate_z'])
@@ -3792,12 +3792,12 @@ class CNCjob(Geometry):
try:
self.spindledir = tool_dict['tools_mill_spindledir']
except KeyError:
self.spindledir = self.app.defaults["tools_mill_spindledir"]
self.spindledir = self.app.options["tools_mill_spindledir"]
try:
self.spindledir = tool_dict['tools_mill_spindledir']
except KeyError:
self.spindledir = self.app.defaults["tools_mill_spindledir"]
self.spindledir = self.app.options["tools_mill_spindledir"]
self.dwell = tool_dict['tools_mill_dwell']
self.dwelltime = float(tool_dict['tools_mill_dwelltime'])
@@ -4368,7 +4368,7 @@ class CNCjob(Geometry):
# if there are no locations then go to the next tool
if not locations:
continue
opt_time = self.app.defaults["excellon_search_time"]
opt_time = self.app.options["excellon_search_time"]
optimized_path = self.optimized_ortools_meta(locations=locations, opt_time=opt_time)
elif used_excellon_optimization_type == 'B':
if tool in points:
@@ -4439,7 +4439,7 @@ class CNCjob(Geometry):
z_offset = 0
self.z_cut = z_offset + old_zcut
self.coordinates_type = self.app.defaults["cncjob_coords_type"]
self.coordinates_type = self.app.options["cncjob_coords_type"]
if self.coordinates_type == "G90":
# Drillling! for Absolute coordinates type G90
# variables to display the percentage of work done
@@ -4627,7 +4627,7 @@ class CNCjob(Geometry):
# if there are no locations then go to the next tool
if not locations:
return 'fail'
opt_time = self.app.defaults["excellon_search_time"]
opt_time = self.app.options["excellon_search_time"]
optimized_path = self.optimized_ortools_meta(locations=locations, opt_time=opt_time)
elif used_excellon_optimization_type == 'B':
if all_points:
@@ -4690,7 +4690,7 @@ class CNCjob(Geometry):
z_offset = 0
self.z_cut = z_offset + old_zcut
self.coordinates_type = self.app.defaults["cncjob_coords_type"]
self.coordinates_type = self.app.options["cncjob_coords_type"]
if self.coordinates_type == "G90":
# Drillling! for Absolute coordinates type G90
# variables to display the percentage of work done
@@ -4920,7 +4920,7 @@ class CNCjob(Geometry):
# z_offset = 0
# self.z_cut = z_offset + old_zcut
#
# self.coordinates_type = self.app.defaults["cncjob_coords_type"]
# self.coordinates_type = self.app.options["cncjob_coords_type"]
# if self.coordinates_type == "G90":
# # Drillling! for Absolute coordinates type G90
# # variables to display the percentage of work done
@@ -5126,7 +5126,7 @@ class CNCjob(Geometry):
# z_offset = 0
# self.z_cut = z_offset + old_zcut
#
# self.coordinates_type = self.app.defaults["cncjob_coords_type"]
# self.coordinates_type = self.app.options["cncjob_coords_type"]
# if self.coordinates_type == "G90":
# # Drillling! for Absolute coordinates type G90
# # variables to display the percentage of work done
@@ -5330,7 +5330,7 @@ class CNCjob(Geometry):
# z_offset = 0
# self.z_cut = z_offset + old_zcut
#
# self.coordinates_type = self.app.defaults["cncjob_coords_type"]
# self.coordinates_type = self.app.options["cncjob_coords_type"]
# if self.coordinates_type == "G90":
# # Drillling! for Absolute coordinates type G90
# # variables to display the percentage of work done
@@ -5547,19 +5547,19 @@ class CNCjob(Geometry):
self.z_cut = float(z_cut) if z_cut else None
self.z_move = float(z_move) if z_move is not None else None
self.feedrate = float(feedrate) if feedrate else self.app.defaults["geometry_feedrate"]
self.z_feedrate = float(feedrate_z) if feedrate_z is not None else self.app.defaults["geometry_feedrate_z"]
self.feedrate_rapid = float(feedrate_rapid) if feedrate_rapid else self.app.defaults["geometry_feedrate_rapid"]
self.feedrate = float(feedrate) if feedrate else self.app.options["geometry_feedrate"]
self.z_feedrate = float(feedrate_z) if feedrate_z is not None else self.app.options["geometry_feedrate_z"]
self.feedrate_rapid = float(feedrate_rapid) if feedrate_rapid else self.app.options["geometry_feedrate_rapid"]
self.spindlespeed = int(spindlespeed) if spindlespeed != 0 else None
self.spindledir = spindledir
self.dwell = dwell
self.dwelltime = float(dwelltime) if dwelltime else self.app.defaults["geometry_dwelltime"]
self.dwelltime = float(dwelltime) if dwelltime else self.app.options["geometry_dwelltime"]
self.startz = float(startz) if startz is not None else self.app.defaults["geometry_startz"]
self.z_end = float(endz) if endz is not None else self.app.defaults["geometry_endz"]
self.startz = float(startz) if startz is not None else self.app.options["geometry_startz"]
self.z_end = float(endz) if endz is not None else self.app.options["geometry_endz"]
self.xy_end = re.sub('[()\[\]]', '', str(endxy)) if endxy else self.app.defaults["geometry_endxy"]
self.xy_end = re.sub('[()\[\]]', '', str(endxy)) if endxy else self.app.options["geometry_endxy"]
if self.xy_end and self.xy_end != '':
self.xy_end = [float(eval(a)) for a in self.xy_end.split(",")]
@@ -5569,10 +5569,10 @@ class CNCjob(Geometry):
"in the format (x, y) but now there is only one value, not two."))
return 'fail'
self.z_depthpercut = float(depthpercut) if depthpercut else self.app.defaults["geometry_depthperpass"]
self.z_depthpercut = float(depthpercut) if depthpercut else self.app.options["geometry_depthperpass"]
self.multidepth = multidepth
self.z_toolchange = float(toolchangez) if toolchangez is not None else self.app.defaults["geometry_toolchangez"]
self.z_toolchange = float(toolchangez) if toolchangez is not None else self.app.options["geometry_toolchangez"]
# it servers in the preprocessor file
self.tool = tool_no
@@ -5582,7 +5582,7 @@ class CNCjob(Geometry):
self.xy_toolchange = None
else:
self.xy_toolchange = re.sub('[()\[\]]', '', str(toolchangexy)) \
if toolchangexy else self.app.defaults["geometry_toolchangexy"]
if toolchangexy else self.app.options["geometry_toolchangexy"]
if self.xy_toolchange and self.xy_toolchange != '':
self.xy_toolchange = [float(eval(a)) for a in self.xy_toolchange.split(",")]
@@ -5597,7 +5597,7 @@ class CNCjob(Geometry):
pass
self.pp_geometry_name = pp_geometry_name if pp_geometry_name else 'default'
self.f_plunge = self.app.defaults["geometry_f_plunge"]
self.f_plunge = self.app.options["geometry_f_plunge"]
if self.z_cut is None:
if 'laser' not in self.pp_geometry_name:
@@ -5944,11 +5944,11 @@ class CNCjob(Geometry):
temp_solid_geometry = flat_geometry
default_dia = None
if isinstance(self.app.defaults["tools_mill_tooldia"], float):
default_dia = self.app.defaults["tools_mill_tooldia"]
if isinstance(self.app.options["tools_mill_tooldia"], float):
default_dia = self.app.options["tools_mill_tooldia"]
else:
try:
tools_string = self.app.defaults["tools_mill_tooldia"].split(",")
tools_string = self.app.options["tools_mill_tooldia"].split(",")
tools_diameters = [eval(a) for a in tools_string if a != '']
default_dia = tools_diameters[0] if tools_diameters else 0.0
except Exception as e:
@@ -5963,26 +5963,26 @@ class CNCjob(Geometry):
self.app.inform.emit('[ERROR] %s' % _("Failed."))
return 'fail'
self.z_cut = float(z_cut) if z_cut is not None else self.app.defaults["tools_mill_cutz"]
self.z_move = float(z_move) if z_move is not None else self.app.defaults["tools_mill_travelz"]
self.z_cut = float(z_cut) if z_cut is not None else self.app.options["tools_mill_cutz"]
self.z_move = float(z_move) if z_move is not None else self.app.options["tools_mill_travelz"]
self.feedrate = float(feedrate) if feedrate is not None else self.app.defaults["tools_mill_feedrate"]
self.z_feedrate = float(feedrate_z) if feedrate_z is not None else self.app.defaults["tools_mill_feedrate_z"]
self.feedrate = float(feedrate) if feedrate is not None else self.app.options["tools_mill_feedrate"]
self.z_feedrate = float(feedrate_z) if feedrate_z is not None else self.app.options["tools_mill_feedrate_z"]
self.feedrate_rapid = float(feedrate_rapid) if feedrate_rapid is not None else \
self.app.defaults["tools_mill_feedrate_rapid"]
self.app.options["tools_mill_feedrate_rapid"]
self.spindlespeed = int(spindlespeed) if spindlespeed != 0 and spindlespeed is not None else None
self.spindledir = spindledir
self.dwell = dwell
self.dwelltime = float(dwelltime) if dwelltime is not None else self.app.defaults["tools_mill_dwelltime"]
self.dwelltime = float(dwelltime) if dwelltime is not None else self.app.options["tools_mill_dwelltime"]
self.laser_min_power = int(laser_min_power)
self.startz = float(startz) if startz is not None and startz != '' else self.app.defaults["tools_mill_startz"]
self.startz = float(startz) if startz is not None and startz != '' else self.app.options["tools_mill_startz"]
self.z_end = float(endz) if endz is not None else self.app.defaults["tools_mill_endz"]
self.z_end = float(endz) if endz is not None else self.app.options["tools_mill_endz"]
self.xy_end = endxy if endxy != '' and endxy else self.app.defaults["tools_mill_endxy"]
self.xy_end = endxy if endxy != '' and endxy else self.app.options["tools_mill_endxy"]
self.xy_end = re.sub('[()\[\]]', '', str(self.xy_end)) if self.xy_end else None
if self.xy_end is not None and self.xy_end != '':
@@ -5998,9 +5998,9 @@ class CNCjob(Geometry):
self.z_depthpercut = abs(self.z_depthpercut)
self.multidepth = multidepth
self.z_toolchange = float(toolchangez) if toolchangez is not None else \
self.app.defaults["tools_mill_toolchangez"]
self.app.options["tools_mill_toolchangez"]
self.extracut_length = float(extracut_length) if extracut_length is not None else \
self.app.defaults["tools_mill_extracut_length"]
self.app.options["tools_mill_extracut_length"]
try:
if toolchangexy == '':
@@ -6019,7 +6019,7 @@ class CNCjob(Geometry):
pass
self.pp_geometry_name = pp_geometry_name if pp_geometry_name else 'default'
self.f_plunge = self.app.defaults["tools_mill_f_plunge"]
self.f_plunge = self.app.options["tools_mill_f_plunge"]
if self.z_cut is None:
if 'laser' not in self.pp_geometry_name:
@@ -6301,7 +6301,7 @@ class CNCjob(Geometry):
self.postdata['toolC'] = kwargs['tooldia']
self.pp_solderpaste_name = kwargs['data']['tools_solderpaste_pp'] if kwargs['data']['tools_solderpaste_pp'] \
else self.app.defaults['tools_solderpaste_pp']
else self.app.options['tools_solderpaste_pp']
p = self.app.preprocessors[self.pp_solderpaste_name]
# ## Flatten the geometry. Only linear elements (no polygons) remain.
@@ -6381,7 +6381,7 @@ class CNCjob(Geometry):
gcode = ''
path = geometry.coords
self.coordinates_type = self.app.defaults["cncjob_coords_type"]
self.coordinates_type = self.app.options["cncjob_coords_type"]
if self.coordinates_type == "G90":
# For Absolute coordinates type G90
first_x = path[0][0]
@@ -6675,8 +6675,8 @@ class CNCjob(Geometry):
current = {'X': 0.0, 'Y': 0.0, 'Z': 0.0, 'G': 0}
if tool_data is None:
toolchange_xy_mill = self.app.defaults["tools_mill_toolchangexy"]
toolchange_xy_drill = self.app.defaults["tools_drill_toolchangexy"]
toolchange_xy_mill = self.app.options["tools_mill_toolchangexy"]
toolchange_xy_drill = self.app.options["tools_drill_toolchangexy"]
else:
if "tools_drill_toolchange" in tool_data and tool_data["tools_mill_toolchange"] is True:
toolchange_xy_mill = tool_data["tools_mill_toolchangexy"]
@@ -7054,8 +7054,8 @@ class CNCjob(Geometry):
if color is None:
color = {
"T": [self.app.defaults["cncjob_travel_fill"], self.app.defaults["cncjob_travel_line"]],
"C": [self.app.defaults["cncjob_plot_fill"], self.app.defaults["cncjob_plot_line"]]
"T": [self.app.options["cncjob_travel_fill"], self.app.options["cncjob_travel_line"]],
"C": [self.app.options["cncjob_plot_fill"], self.app.options["cncjob_plot_line"]]
}
gcode_parsed = gcode_parsed if gcode_parsed else self.gcode_parsed
@@ -7080,7 +7080,7 @@ class CNCjob(Geometry):
else:
path_num = 0
self.coordinates_type = self.app.defaults["cncjob_coords_type"]
self.coordinates_type = self.app.options["cncjob_coords_type"]
if self.coordinates_type == "G90":
# For Absolute coordinates type G90
for geo in gcode_parsed:
@@ -7176,13 +7176,13 @@ class CNCjob(Geometry):
return
try:
if self.app.defaults['global_theme'] == 'white':
if self.app.options['global_theme'] == 'white':
obj.annotation.set(text=text, pos=pos, visible=obj.obj_options['plot'],
font_size=self.app.defaults["cncjob_annotation_fontsize"],
color=self.app.defaults["cncjob_annotation_fontcolor"])
font_size=self.app.options["cncjob_annotation_fontsize"],
color=self.app.options["cncjob_annotation_fontcolor"])
else:
# invert the color
old_color = self.app.defaults["cncjob_annotation_fontcolor"].lower()
old_color = self.app.options["cncjob_annotation_fontcolor"].lower()
new_color = ''
code = {}
l1 = "#;0123456789abcdef"
@@ -7194,7 +7194,7 @@ class CNCjob(Geometry):
new_color += code[old_color[x]]
obj.annotation.set(text=text, pos=pos, visible=obj.obj_options['plot'],
font_size=self.app.defaults["cncjob_annotation_fontsize"],
font_size=self.app.options["cncjob_annotation_fontsize"],
color=new_color)
except Exception as e:
self.app.log.error("CNCJob.plot2() --> annotations --> %s" % str(e))
@@ -7344,7 +7344,7 @@ class CNCjob(Geometry):
p = self.pp_geometry
self.coordinates_type = self.app.defaults["cncjob_coords_type"]
self.coordinates_type = self.app.options["cncjob_coords_type"]
if self.coordinates_type == "G90":
# For Absolute coordinates type G90
first_x = path[0][0]
@@ -7489,7 +7489,7 @@ class CNCjob(Geometry):
path = self.segment(target_linear.coords)
p = self.pp_geometry
self.coordinates_type = self.app.defaults["cncjob_coords_type"]
self.coordinates_type = self.app.options["cncjob_coords_type"]
if self.coordinates_type == "G90":
# For Absolute coordinates type G90
first_x = path[0][0]
@@ -7725,7 +7725,7 @@ class CNCjob(Geometry):
path = list(point.coords)
p = self.pp_geometry
self.coordinates_type = self.app.defaults["cncjob_coords_type"]
self.coordinates_type = self.app.options["cncjob_coords_type"]
if self.coordinates_type == "G90":
# For Absolute coordinates type G90
first_x = path[0][0]
@@ -8032,7 +8032,7 @@ class CNCjob(Geometry):
for nr in numbers_in_header:
new_nr = float(nr) * xfactor
# replace the updated string
line = line.replace(nr, ('%.*f' % (self.app.defaults["cncjob_coords_decimals"], new_nr))
line = line.replace(nr, ('%.*f' % (self.app.options["cncjob_coords_decimals"], new_nr))
)
# this scales all the X and Y and Z and F values and also the Tool Dia in the toolchange message
@@ -8052,7 +8052,7 @@ class CNCjob(Geometry):
# replace the updated string
line = line.replace(
match_x.group(1),
'X%.*f' % (self.app.defaults["cncjob_coords_decimals"], new_x)
'X%.*f' % (self.app.options["cncjob_coords_decimals"], new_x)
)
# find the Y group
match_y = self.g_y_re.search(line)
@@ -8061,7 +8061,7 @@ class CNCjob(Geometry):
new_y = float(match_y.group(1)[1:]) * yfactor
line = line.replace(
match_y.group(1),
'Y%.*f' % (self.app.defaults["cncjob_coords_decimals"], new_y)
'Y%.*f' % (self.app.options["cncjob_coords_decimals"], new_y)
)
# find the Z group
match_z = self.g_z_re.search(line)
@@ -8070,7 +8070,7 @@ class CNCjob(Geometry):
new_z = float(match_z.group(1)[1:]) * xfactor
line = line.replace(
match_z.group(1),
'Z%.*f' % (self.app.defaults["cncjob_coords_decimals"], new_z)
'Z%.*f' % (self.app.options["cncjob_coords_decimals"], new_z)
)
# find the F group
@@ -8080,7 +8080,7 @@ class CNCjob(Geometry):
new_f = float(match_f.group(1)[1:]) * xfactor
line = line.replace(
match_f.group(1),
'F%.*f' % (self.app.defaults["cncjob_fr_decimals"], new_f)
'F%.*f' % (self.app.options["cncjob_fr_decimals"], new_f)
)
# find the T group (tool dia on toolchange)
match_t = self.g_t_re.search(line)
@@ -8089,7 +8089,7 @@ class CNCjob(Geometry):
new_t = float(match_t.group(1)[1:]) * xfactor
line = line.replace(
match_t.group(1),
'= %.*f' % (self.app.defaults["cncjob_coords_decimals"], new_t)
'= %.*f' % (self.app.options["cncjob_coords_decimals"], new_t)
)
temp_gcode += line
@@ -8192,7 +8192,7 @@ class CNCjob(Geometry):
# replace the updated string
line = line.replace(
match_x.group(1),
'X%.*f' % (self.app.defaults["cncjob_coords_decimals"], new_x)
'X%.*f' % (self.app.options["cncjob_coords_decimals"], new_x)
)
match_y = self.g_y_re.search(line)
if match_y:
@@ -8200,7 +8200,7 @@ class CNCjob(Geometry):
new_y = float(match_y.group(1)[1:]) + dy
line = line.replace(
match_y.group(1),
'Y%.*f' % (self.app.defaults["cncjob_coords_decimals"], new_y)
'Y%.*f' % (self.app.options["cncjob_coords_decimals"], new_y)
)
temp_gcode += line
lines.close()