- PEP8 changes

This commit is contained in:
Marius Stanciu 2020-04-01 18:59:53 +03:00 committed by Marius
parent 3d39916b5f
commit 280eb1dc3a
4 changed files with 72 additions and 90 deletions

View File

@ -13,6 +13,7 @@ CAD program, and create G-Code for Isolation routing.
- updated the SVG parser to take into consideration the 'Close' svg element and paths that are made from a single line (we may need to switch to svgpathtools module)
- minor changes to increase compatibility with Python 3.8
- PEP8 changes
30.03.2020

View File

@ -398,7 +398,7 @@ class FCSlot(FCShapeTool):
try:
QtGui.QGuiApplication.restoreOverrideCursor()
except Exception as e:
except Exception:
pass
self.cursor = QtGui.QCursor(QtGui.QPixmap(self.draw_app.app.resource_location + '/aero_slot.png'))
QtGui.QGuiApplication.setOverrideCursor(self.cursor)
@ -538,7 +538,7 @@ class FCSlot(FCShapeTool):
try:
QtGui.QGuiApplication.restoreOverrideCursor()
except Exception as e:
except Exception:
pass
try:
@ -600,7 +600,7 @@ class FCSlotArray(FCShapeTool):
try:
QtGui.QGuiApplication.restoreOverrideCursor()
except Exception as e:
except Exception:
pass
self.cursor = QtGui.QCursor(QtGui.QPixmap(self.draw_app.app.resource_location + '/aero_array.png'))
QtGui.QGuiApplication.setOverrideCursor(self.cursor)
@ -677,9 +677,8 @@ class FCSlotArray(FCShapeTool):
self.draw_app.app.inform.emit('[ERROR_NOTCL] %s' %
_("The value is not Float. Check for comma instead of dot separator."))
return
except Exception as e:
self.draw_app.app.inform.emit('[ERROR_NOTCL] %s' %
_("The value is mistyped. Check the value."))
except Exception:
self.draw_app.app.inform.emit('[ERROR_NOTCL] %s' % _("The value is mistyped. Check the value."))
return
if self.slot_array == 'Linear':
@ -829,7 +828,7 @@ class FCSlotArray(FCShapeTool):
try:
QtGui.QGuiApplication.restoreOverrideCursor()
except Exception as e:
except Exception:
pass
# add the point to slots if the diameter is a key in the dict, if not, create it add the drill location
@ -1340,7 +1339,7 @@ class FCDrillSelect(DrawTool):
try:
QtGui.QGuiApplication.restoreOverrideCursor()
except Exception as e:
except Exception:
pass
self.exc_editor_app = draw_app
@ -1739,7 +1738,7 @@ class FlatCAMExcEditor(QtCore.QObject):
self.linear_box.addLayout(self.linear_form)
# Linear Drill Array direction
self.drill_axis_label = QtWidgets.QLabel('%s:'% _('Direction'))
self.drill_axis_label = QtWidgets.QLabel('%s:' % _('Direction'))
self.drill_axis_label.setToolTip(
_("Direction on which the linear array is oriented:\n"
"- 'X' - horizontal axis \n"
@ -2037,22 +2036,14 @@ class FlatCAMExcEditor(QtCore.QObject):
# ## Toolbar events and properties
self.tools_exc = {
"drill_select": {"button": self.app.ui.select_drill_btn,
"constructor": FCDrillSelect},
"drill_add": {"button": self.app.ui.add_drill_btn,
"constructor": FCDrillAdd},
"drill_array": {"button": self.app.ui.add_drill_array_btn,
"constructor": FCDrillArray},
"slot_add": {"button": self.app.ui.add_slot_btn,
"constructor": FCSlot},
"slot_array": {"button": self.app.ui.add_slot_array_btn,
"constructor": FCSlotArray},
"drill_resize": {"button": self.app.ui.resize_drill_btn,
"constructor": FCDrillResize},
"drill_copy": {"button": self.app.ui.copy_drill_btn,
"constructor": FCDrillCopy},
"drill_move": {"button": self.app.ui.move_drill_btn,
"constructor": FCDrillMove},
"drill_select": {"button": self.app.ui.select_drill_btn, "constructor": FCDrillSelect},
"drill_add": {"button": self.app.ui.add_drill_btn, "constructor": FCDrillAdd},
"drill_array": {"button": self.app.ui.add_drill_array_btn, "constructor": FCDrillArray},
"slot_add": {"button": self.app.ui.add_slot_btn, "constructor": FCSlot},
"slot_array": {"button": self.app.ui.add_slot_array_btn, "constructor": FCSlotArray},
"drill_resize": {"button": self.app.ui.resize_drill_btn, "constructor": FCDrillResize},
"drill_copy": {"button": self.app.ui.copy_drill_btn, "constructor": FCDrillCopy},
"drill_move": {"button": self.app.ui.move_drill_btn, "constructor": FCDrillMove},
}
# ## Data
@ -2192,7 +2183,7 @@ class FlatCAMExcEditor(QtCore.QObject):
"operation": self.app.defaults["excellon_operation"],
"milling_type": self.app.defaults["excellon_milling_type"],
"milling_dia":self.app.defaults["excellon_milling_dia"],
"milling_dia": self.app.defaults["excellon_milling_dia"],
"cutz": self.app.defaults["excellon_cutz"],
"multidepth": self.app.defaults["excellon_multidepth"],
@ -2579,9 +2570,8 @@ class FlatCAMExcEditor(QtCore.QObject):
# each time a tool diameter is edited or added
self.olddia_newdia[tool_dia] = tool_dia
else:
self.app.inform.emit('[WARNING_NOTCL] %s' %
_("Tool already in the original or actual tool list.\n"
"Save and reedit Excellon if you need to add this tool. "))
self.app.inform.emit('[WARNING_NOTCL] %s' % _("Tool already in the original or actual tool list.\n"
"Save and reedit Excellon if you need to add this tool. "))
return
# since we add a new tool, we update also the initial state of the tool_table through it's dictionary
@ -2621,9 +2611,8 @@ class FlatCAMExcEditor(QtCore.QObject):
deleted_tool_dia_list.append(float('%.*f' % (self.decimals, dd)))
else:
deleted_tool_dia_list.append(float('%.*f' % (self.decimals, dia)))
except Exception as e:
self.app.inform.emit('[WARNING_NOTCL] %s' %
_("Select a tool in Tool Table"))
except Exception:
self.app.inform.emit('[WARNING_NOTCL] %s' % _("Select a tool in Tool Table"))
return
for deleted_tool_dia in deleted_tool_dia_list:
@ -2871,7 +2860,7 @@ class FlatCAMExcEditor(QtCore.QObject):
def deactivate(self):
try:
QtGui.QGuiApplication.restoreOverrideCursor()
except Exception as e:
except Exception:
pass
# adjust the status of the menu entries related to the editor
@ -3468,7 +3457,7 @@ class FlatCAMExcEditor(QtCore.QObject):
self.pos = self.canvas.translate_coords(event_pos)
if self.app.grid_status() == True:
if self.app.grid_status():
self.pos = self.app.geo_editor.snap(self.pos[0], self.pos[1])
else:
self.pos = (self.pos[0], self.pos[1])
@ -3613,7 +3602,7 @@ class FlatCAMExcEditor(QtCore.QObject):
pos_canvas = self.canvas.translate_coords(event_pos)
if self.app.grid_status() == True:
if self.app.grid_status():
pos = self.app.geo_editor.snap(pos_canvas[0], pos_canvas[1])
else:
pos = (pos_canvas[0], pos_canvas[1])
@ -3625,7 +3614,7 @@ class FlatCAMExcEditor(QtCore.QObject):
if self.app.ui.popMenu.mouse_is_panning is False:
try:
QtGui.QGuiApplication.restoreOverrideCursor()
except Exception as e:
except Exception:
pass
if self.active_tool.complete is False and not isinstance(self.active_tool, FCDrillSelect):
self.active_tool.complete = True
@ -3704,7 +3693,7 @@ class FlatCAMExcEditor(QtCore.QObject):
for storage in self.storage_dict:
for obj in self.storage_dict[storage].get_objects():
if (sel_type is True and poly_selection.contains(obj.geo)) or \
(sel_type is False and poly_selection.intersects(obj.geo)):
(sel_type is False and poly_selection.intersects(obj.geo)):
if obj in self.selected:
# remove the shape object from the selected shapes storage
@ -3724,7 +3713,7 @@ class FlatCAMExcEditor(QtCore.QObject):
try:
self.tools_table_exc.cellPressed.disconnect()
except Exception as e:
except Exception:
pass
# first deselect all rows (tools) in the Tools Table
@ -3801,7 +3790,7 @@ class FlatCAMExcEditor(QtCore.QObject):
return
# ## Snap coordinates
if self.app.grid_status() == True:
if self.app.grid_status():
x, y = self.app.geo_editor.snap(x, y)
# Update cursor

View File

@ -1805,7 +1805,7 @@ class DrawToolShape(object):
geoms.append(scale_recursion(local_geom))
return geoms
else:
return affinity.scale(geom, xfactor, yfactor, origin=(px, py))
return affinity.scale(geom, xfactor, yfactor, origin=(px, py))
try:
self.geo = scale_recursion(self.geo)
@ -3264,34 +3264,20 @@ class FlatCAMGeoEditor(QtCore.QObject):
# ## Toolbar events and properties
self.tools = {
"select": {"button": self.app.ui.geo_select_btn,
"constructor": FCSelect},
"arc": {"button": self.app.ui.geo_add_arc_btn,
"constructor": FCArc},
"circle": {"button": self.app.ui.geo_add_circle_btn,
"constructor": FCCircle},
"path": {"button": self.app.ui.geo_add_path_btn,
"constructor": FCPath},
"rectangle": {"button": self.app.ui.geo_add_rectangle_btn,
"constructor": FCRectangle},
"polygon": {"button": self.app.ui.geo_add_polygon_btn,
"constructor": FCPolygon},
"text": {"button": self.app.ui.geo_add_text_btn,
"constructor": FCText},
"buffer": {"button": self.app.ui.geo_add_buffer_btn,
"constructor": FCBuffer},
"paint": {"button": self.app.ui.geo_add_paint_btn,
"constructor": FCPaint},
"eraser": {"button": self.app.ui.geo_eraser_btn,
"constructor": FCEraser},
"move": {"button": self.app.ui.geo_move_btn,
"constructor": FCMove},
"transform": {"button": self.app.ui.geo_transform_btn,
"constructor": FCTransform},
"copy": {"button": self.app.ui.geo_copy_btn,
"constructor": FCCopy},
"explode": {"button": self.app.ui.geo_explode_btn,
"constructor": FCExplode}
"select": {"button": self.app.ui.geo_select_btn, "constructor": FCSelect},
"arc": {"button": self.app.ui.geo_add_arc_btn, "constructor": FCArc},
"circle": {"button": self.app.ui.geo_add_circle_btn, "constructor": FCCircle},
"path": {"button": self.app.ui.geo_add_path_btn, "constructor": FCPath},
"rectangle": {"button": self.app.ui.geo_add_rectangle_btn, "constructor": FCRectangle},
"polygon": {"button": self.app.ui.geo_add_polygon_btn, "constructor": FCPolygon},
"text": {"button": self.app.ui.geo_add_text_btn, "constructor": FCText},
"buffer": {"button": self.app.ui.geo_add_buffer_btn, "constructor": FCBuffer},
"paint": {"button": self.app.ui.geo_add_paint_btn, "constructor": FCPaint},
"eraser": {"button": self.app.ui.geo_eraser_btn, "constructor": FCEraser},
"move": {"button": self.app.ui.geo_move_btn, "constructor": FCMove},
"transform": {"button": self.app.ui.geo_transform_btn, "constructor": FCTransform},
"copy": {"button": self.app.ui.geo_copy_btn, "constructor": FCCopy},
"explode": {"button": self.app.ui.geo_explode_btn, "constructor": FCExplode}
}
# # ## Data
@ -3343,6 +3329,8 @@ class FlatCAMGeoEditor(QtCore.QObject):
# signal that there is an action active like polygon or path
self.in_action = False
self.units = None
# this will flag if the Editor "tools" are launched from key shortcuts (True) or from menu toolbar (False)
self.launched_from_shortcuts = False

View File

@ -423,7 +423,7 @@ class FCPadArray(FCShapeTool):
try:
QtGui.QGuiApplication.restoreOverrideCursor()
except Exception as e:
except Exception:
pass
self.cursor = QtGui.QCursor(QtGui.QPixmap(self.draw_app.app.resource_location + '/aero_array.png'))
QtGui.QGuiApplication.setOverrideCursor(self.cursor)
@ -515,9 +515,8 @@ class FCPadArray(FCShapeTool):
self.draw_app.app.inform.emit('[ERROR_NOTCL] %s' %
_("The value is not Float. Check for comma instead of dot separator."))
return
except Exception as e:
self.draw_app.app.inform.emit('[ERROR_NOTCL] %s' %
_("The value is mistyped. Check the value."))
except Exception:
self.draw_app.app.inform.emit('[ERROR_NOTCL] %s' % _("The value is mistyped. Check the value."))
return
if self.pad_array == 'Linear':
@ -3103,6 +3102,10 @@ class FlatCAMGrbEditor(QtCore.QObject):
self.conversion_factor = 1
self.apertures_row = 0
self.complete = True
self.set_ui()
log.debug("Initialization of the FlatCAM Gerber Editor is finished ...")
@ -3332,8 +3335,8 @@ class FlatCAMGrbEditor(QtCore.QObject):
self.storage_dict[ap_id]['geometry'] = []
# self.olddia_newdia dict keeps the evidence on current aperture codes as keys and gets updated on values
# each time a aperture code is edited or added
# self.olddia_newdia dict keeps the evidence on current aperture codes as keys and
# gets updated on values each time a aperture code is edited or added
self.olddia_newdia[ap_id] = ap_id
else:
if ap_id not in self.olddia_newdia:
@ -3945,9 +3948,9 @@ class FlatCAMGrbEditor(QtCore.QObject):
@staticmethod
def worker_job(app_obj):
with app_obj.app.proc_container.new('%s ...' % _("Loading Gerber into Editor")):
# ############################################################# ##
# ###############################################################
# APPLY CLEAR_GEOMETRY on the SOLID_GEOMETRY
# ############################################################# ##
# ###############################################################
# list of clear geos that are to be applied to the entire file
global_clear_geo = []
@ -3968,9 +3971,9 @@ class FlatCAMGrbEditor(QtCore.QObject):
# we subtract the big "negative" (clear) geometry from each solid polygon but only the part of
# clear geometry that fits inside the solid. otherwise we may loose the solid
for apid in app_obj.gerber_obj.apertures:
for ap_id in app_obj.gerber_obj.apertures:
temp_solid_geometry = []
if 'geometry' in app_obj.gerber_obj.apertures[apid]:
if 'geometry' in app_obj.gerber_obj.apertures[ap_id]:
# for elem in self.gerber_obj.apertures[apid]['geometry']:
# if 'solid' in elem:
# solid_geo = elem['solid']
@ -3998,7 +4001,7 @@ class FlatCAMGrbEditor(QtCore.QObject):
# if 'follow' in elem:
# new_elem['follow'] = solid_geo
# temp_elem.append(deepcopy(new_elem))
for elem in app_obj.gerber_obj.apertures[apid]['geometry']:
for elem in app_obj.gerber_obj.apertures[ap_id]['geometry']:
new_elem = {}
if 'solid' in elem:
solid_geo = elem['solid']
@ -4019,7 +4022,8 @@ class FlatCAMGrbEditor(QtCore.QObject):
new_elem['follow'] = elem['follow']
temp_solid_geometry.append(deepcopy(new_elem))
app_obj.gerber_obj.apertures[apid]['geometry'] = deepcopy(temp_solid_geometry)
app_obj.gerber_obj.apertures[ap_id]['geometry'] = deepcopy(temp_solid_geometry)
log.warning("Polygon difference done for %d apertures." % len(app_obj.gerber_obj.apertures))
try:
@ -4028,9 +4032,9 @@ class FlatCAMGrbEditor(QtCore.QObject):
app_obj.results.append(
app_obj.pool.apply_async(app_obj.add_apertures, args=(ap_id, ap_dict))
)
except Exception as e:
except Exception as ee:
log.debug(
"FlatCAMGrbEditor.edit_fcgerber.worker_job() Adding processes to pool --> %s" % str(e))
"FlatCAMGrbEditor.edit_fcgerber.worker_job() Adding processes to pool --> %s" % str(ee))
traceback.print_exc()
output = []
@ -4222,7 +4226,7 @@ class FlatCAMGrbEditor(QtCore.QObject):
except KeyError:
self.app.inform.emit('[ERROR_NOTCL] %s' %
_("There are no Aperture definitions in the file. Aborting Gerber creation."))
except Exception as e:
except Exception:
msg = '[ERROR] %s' % \
_("An internal error has occurred. See shell.\n")
msg += traceback.format_exc()
@ -4240,7 +4244,7 @@ class FlatCAMGrbEditor(QtCore.QObject):
self.results = []
return
self.app.inform.emit('[success] %s' % _("Done. Gerber editing finished."))
self.app.inform.emit('[success] %s' % _("Done. Gerber editing finished."))
# make sure to clean the previous results
self.results = []
@ -4395,7 +4399,7 @@ class FlatCAMGrbEditor(QtCore.QObject):
self.pos = self.canvas.translate_coords(event_pos)
if self.app.grid_status() == True:
if self.app.grid_status():
self.pos = self.app.geo_editor.snap(self.pos[0], self.pos[1])
else:
self.pos = (self.pos[0], self.pos[1])
@ -4462,7 +4466,7 @@ class FlatCAMGrbEditor(QtCore.QObject):
right_button = 3
pos_canvas = self.canvas.translate_coords(event_pos)
if self.app.grid_status() == True:
if self.app.grid_status():
pos = self.app.geo_editor.snap(pos_canvas[0], pos_canvas[1])
else:
pos = (pos_canvas[0], pos_canvas[1])
@ -4625,7 +4629,7 @@ class FlatCAMGrbEditor(QtCore.QObject):
return
# # ## Snap coordinates
if self.app.grid_status() == True:
if self.app.grid_status():
x, y = self.app.geo_editor.snap(x, y)
# Update cursor
@ -4755,7 +4759,7 @@ class FlatCAMGrbEditor(QtCore.QObject):
try:
self.shapes.add(shape=geometry.geo, color=color, face_color=color, layer=0, tolerance=self.tolerance)
except AttributeError as e:
except AttributeError:
if type(geometry) == Point:
return
if len(color) == 9:
@ -5069,12 +5073,12 @@ class FlatCAMGrbEditor(QtCore.QObject):
area = geo_el.geo['solid'].area
try:
upper_threshold_val = self.ma_upper_threshold_entry.get_value()
except Exception as e:
except Exception:
return
try:
lower_threshold_val = self.ma_lower_threshold_entry.get_value()
except Exception as e:
except Exception:
lower_threshold_val = 0.0
if float(upper_threshold_val) > area > float(lower_threshold_val):