- minor PEP corrections

This commit is contained in:
Marius Stanciu 2020-10-31 18:46:20 +02:00 committed by Marius Stanciu
parent ffe4f0d641
commit e71a48ff5c
6 changed files with 52 additions and 68 deletions

View File

@ -12,7 +12,7 @@
# ########################################################## # ##########################################################
from PyQt5 import QtCore from PyQt5 import QtCore
from shapely.geometry import Polygon, Point, LineString, MultiPoint from shapely.geometry import Polygon, Point, LineString
from shapely.ops import unary_union from shapely.ops import unary_union
from appGUI.VisPyVisuals import ShapeCollection from appGUI.VisPyVisuals import ShapeCollection
@ -20,7 +20,6 @@ from appTool import AppTool
from copy import deepcopy from copy import deepcopy
import collections import collections
import traceback
import numpy as np import numpy as np
# from voronoi import Voronoi # from voronoi import Voronoi
@ -39,6 +38,7 @@ class GracefulException(Exception):
""" """
Graceful Exception raised when the user is requesting to cancel the current threaded task Graceful Exception raised when the user is requesting to cancel the current threaded task
""" """
def __init__(self): def __init__(self):
super().__init__() super().__init__()
@ -95,7 +95,7 @@ class LoudUniqueList(list, collections.MutableSequence):
super().__init__() super().__init__()
self.callback = lambda x: None self.callback = lambda x: None
if not arg is None: if arg is not None:
if isinstance(arg, list): if isinstance(arg, list):
self.extend(arg) self.extend(arg)
else: else:
@ -110,32 +110,32 @@ class LoudUniqueList(list, collections.MutableSequence):
def append(self, v): def append(self, v):
if v in self: if v in self:
raise ValueError("One of the added items is already in the list.") raise ValueError("One of the added items is already in the list.")
l = len(self) le = len(self)
self.callback(l) self.callback(le)
return super().append(v) return super().append(v)
def extend(self, t): def extend(self, t):
for v in t: for v in t:
if v in self: if v in self:
raise ValueError("One of the added items is already in the list.") raise ValueError("One of the added items is already in the list.")
l = len(self) le = len(self)
self.callback(l) self.callback(le)
return super().extend(t) return super().extend(t)
def __add__(self, t): # This is for something like `LoudUniqueList([1, 2, 3]) + list([4, 5, 6])`... def __add__(self, t): # This is for something like `LoudUniqueList([1, 2, 3]) + list([4, 5, 6])`...
for v in t: for v in t:
if v in self: if v in self:
raise ValueError("One of the added items is already in the list.") raise ValueError("One of the added items is already in the list.")
l = len(self) le = len(self)
self.callback(l) self.callback(le)
return super().__add__(t) return super().__add__(t)
def __iadd__(self, t): # This is for something like `l = LoudUniqueList(); l += [1, 2, 3]` def __iadd__(self, t): # This is for something like `l = LoudUniqueList(); l += [1, 2, 3]`
for v in t: for v in t:
if v in self: if v in self:
raise ValueError("One of the added items is already in the list.") raise ValueError("One of the added items is already in the list.")
l = len(self) le = len(self)
self.callback(l) self.callback(le)
return super().__iadd__(t) return super().__iadd__(t)
def __setitem__(self, i, v): def __setitem__(self, i, v):
@ -146,7 +146,7 @@ class LoudUniqueList(list, collections.MutableSequence):
except TypeError: except TypeError:
if v in self: if v in self:
raise ValueError("One of the modified items is already in the list.") raise ValueError("One of the modified items is already in the list.")
if not v is None: if v is not None:
self.callback(i) self.callback(i)
return super().__setitem__(i, v) return super().__setitem__(i, v)
@ -374,10 +374,10 @@ class ExclusionAreas(QtCore.QObject):
# "overz": float < - self.over_z_button # "overz": float < - self.over_z_button
# } # }
new_el = { new_el = {
"obj_type": self.obj_type, "obj_type": self.obj_type,
"shape": new_rectangle, "shape": new_rectangle,
"strategy": self.strategy_button.get_value(), "strategy": self.strategy_button.get_value(),
"overz": self.over_z_button.get_value() "overz": self.over_z_button.get_value()
} }
self.exclusion_areas_storage.append(new_el) self.exclusion_areas_storage.append(new_el)

View File

@ -71,10 +71,10 @@ class BilinearInterpolation(object):
self.y_length = y_length self.y_length = y_length
self.extrapolate = True self.extrapolate = True
#slopes = self.slopes = [] # slopes = self.slopes = []
#for j in range(y_length): # for j in range(y_length):
#intervals = zip(x_index, x_index[1:], values[j], values[j][1:]) # intervals = zip(x_index, x_index[1:], values[j], values[j][1:])
#slopes.append([(y2 - y1) / (x2 - x1) for x1, x2, y1, y2 in intervals]) # slopes.append([(y2 - y1) / (x2 - x1) for x1, x2, y1, y2 in intervals])
def __call__(self, x, y): def __call__(self, x, y):
# local lookups # local lookups

View File

@ -2046,7 +2046,8 @@ class AppExcEditor(QtCore.QObject):
try: try:
if dia is None or dia is False: if dia is None or dia is False:
# deleted_tool_dia = float(self.e_ui.tools_table_exc.item(self.e_ui.tools_table_exc.currentRow(), 1).text()) # deleted_tool_dia = float(
# self.e_ui.tools_table_exc.item(self.e_ui.tools_table_exc.currentRow(), 1).text())
for index in self.e_ui.tools_table_exc.selectionModel().selectedRows(): for index in self.e_ui.tools_table_exc.selectionModel().selectedRows():
row = index.row() row = index.row()
deleted_tool_dia_list.append(float(self.e_ui.tools_table_exc.item(row, 1).text())) deleted_tool_dia_list.append(float(self.e_ui.tools_table_exc.item(row, 1).text()))
@ -2803,11 +2804,7 @@ class AppExcEditor(QtCore.QObject):
def update_options(obj): def update_options(obj):
try: try:
if not obj.options: if not obj.options:
obj.options = {} obj.options = {'xmin': 0, 'ymin': 0, 'xmax': 0, 'ymax': 0}
obj.options['xmin'] = 0
obj.options['ymin'] = 0
obj.options['xmax'] = 0
obj.options['ymax'] = 0
return True return True
else: else:
return False return False
@ -3229,7 +3226,8 @@ class AppExcEditor(QtCore.QObject):
# if the row to be selected is not already in the selected rows then select it # if the row to be selected is not already in the selected rows then select it
# otherwise don't do it as it seems that we have a toggle effect # otherwise don't do it as it seems that we have a toggle effect
if row_to_sel not in set(index.row() for index in self.e_ui.tools_table_exc.selectedIndexes()): if row_to_sel not in set(
index.row() for index in self.e_ui.tools_table_exc.selectedIndexes()):
self.e_ui.tools_table_exc.selectRow(row_to_sel) self.e_ui.tools_table_exc.selectRow(row_to_sel)
self.last_tool_selected = int(key_tool_nr) self.last_tool_selected = int(key_tool_nr)

View File

@ -1266,7 +1266,7 @@ class TransformEditorTool(AppTool):
""" """
Rotate geometry Rotate geometry
:param num: Rotate with a known angle value, val :param val: Rotate with a known angle value, val
:param point: Reference point for rotation: tuple :param point: Reference point for rotation: tuple
:return: :return:
""" """
@ -1326,6 +1326,7 @@ class TransformEditorTool(AppTool):
""" """
Skew geometry Skew geometry
:param point:
:param axis: Axis on which to deform, skew :param axis: Axis on which to deform, skew
:param xval: Skew value on X axis :param xval: Skew value on X axis
:param yval: Skew value on Y axis :param yval: Skew value on Y axis
@ -1888,7 +1889,8 @@ class DrawTool(object):
def utility_geometry(self, data=None): def utility_geometry(self, data=None):
return None return None
def bounds(self, obj): @staticmethod
def bounds(obj):
def bounds_rec(o): def bounds_rec(o):
if type(o) is list: if type(o) is list:
minx = np.Inf minx = np.Inf
@ -3688,7 +3690,6 @@ class AppGeoEditor(QtCore.QObject):
self.clear() self.clear()
self.app.ui.geo_edit_toolbar.setDisabled(True) self.app.ui.geo_edit_toolbar.setDisabled(True)
settings = QSettings("Open Source", "FlatCAM")
self.app.ui.corner_snap_btn.setVisible(False) self.app.ui.corner_snap_btn.setVisible(False)
self.app.ui.snap_magnet.setVisible(False) self.app.ui.snap_magnet.setVisible(False)

View File

@ -815,9 +815,7 @@ class FCPoligonize(FCShapeTool):
except KeyError: except KeyError:
self.draw_app.on_aperture_add(apcode='0') self.draw_app.on_aperture_add(apcode='0')
current_storage = self.draw_app.storage_dict['0']['geometry'] current_storage = self.draw_app.storage_dict['0']['geometry']
new_el = {} new_el = {'solid': geo, 'follow': geo.exterior}
new_el['solid'] = geo
new_el['follow'] = geo.exterior
self.draw_app.on_grb_shape_complete(current_storage, specific_shape=DrawToolShape(deepcopy(new_el))) self.draw_app.on_grb_shape_complete(current_storage, specific_shape=DrawToolShape(deepcopy(new_el)))
else: else:
# clean-up the geo # clean-up the geo
@ -830,9 +828,7 @@ class FCPoligonize(FCShapeTool):
self.draw_app.on_aperture_add(apcode='0') self.draw_app.on_aperture_add(apcode='0')
current_storage = self.draw_app.storage_dict['0']['geometry'] current_storage = self.draw_app.storage_dict['0']['geometry']
new_el = {} new_el = {'solid': fused_geo, 'follow': fused_geo.exterior}
new_el['solid'] = fused_geo
new_el['follow'] = fused_geo.exterior
self.draw_app.on_grb_shape_complete(current_storage, specific_shape=DrawToolShape(deepcopy(new_el))) self.draw_app.on_grb_shape_complete(current_storage, specific_shape=DrawToolShape(deepcopy(new_el)))
self.draw_app.delete_selected() self.draw_app.delete_selected()
@ -840,8 +836,7 @@ class FCPoligonize(FCShapeTool):
self.draw_app.in_action = False self.draw_app.in_action = False
self.complete = True self.complete = True
self.draw_app.app.inform.emit('[success] %s' % self.draw_app.app.inform.emit('[success] %s' % _("Done. Poligonize completed."))
_("Done. Poligonize completed."))
# MS: always return to the Select Tool if modifier key is not pressed # MS: always return to the Select Tool if modifier key is not pressed
# else return to the current tool # else return to the current tool
@ -1052,12 +1047,11 @@ class FCRegion(FCShapeTool):
self.temp_points.append(self.inter_point) self.temp_points.append(self.inter_point)
self.temp_points.append(data) self.temp_points.append(data)
new_geo_el = {} new_geo_el = {
'solid': LinearRing(self.temp_points).buffer(self.buf_val,
new_geo_el['solid'] = LinearRing(self.temp_points).buffer(self.buf_val, resolution=int(self.steps_per_circle / 4),
resolution=int(self.steps_per_circle / 4), join_style=1),
join_style=1) 'follow': LinearRing(self.temp_points)}
new_geo_el['follow'] = LinearRing(self.temp_points)
return DrawToolUtilityShape(new_geo_el) return DrawToolUtilityShape(new_geo_el)
@ -1073,12 +1067,11 @@ class FCRegion(FCShapeTool):
else: else:
self.draw_app.last_aperture_selected = '0' self.draw_app.last_aperture_selected = '0'
new_geo_el = {} new_geo_el = {
'solid': Polygon(self.points).buffer(self.buf_val,
new_geo_el['solid'] = Polygon(self.points).buffer(self.buf_val, resolution=int(self.steps_per_circle / 4),
resolution=int(self.steps_per_circle / 4), join_style=2), 'follow': Polygon(self.points).exterior
join_style=2) }
new_geo_el['follow'] = Polygon(self.points).exterior
self.geometry = DrawToolShape(new_geo_el) self.geometry = DrawToolShape(new_geo_el)
self.draw_app.in_action = False self.draw_app.in_action = False
@ -2106,8 +2099,7 @@ class FCApertureMove(FCShapeTool):
geo_list.append(deepcopy(new_geo_el)) geo_list.append(deepcopy(new_geo_el))
return DrawToolUtilityShape(geo_list) return DrawToolUtilityShape(geo_list)
else: else:
ss_el = {} ss_el = {'solid': affinity.translate(self.selection_shape, xoff=dx, yoff=dy)}
ss_el['solid'] = affinity.translate(self.selection_shape, xoff=dx, yoff=dy)
return DrawToolUtilityShape(ss_el) return DrawToolUtilityShape(ss_el)
@ -3971,7 +3963,6 @@ class AppGerberEditor(QtCore.QObject):
else: else:
self.conversion_factor = 0.0393700787401575 self.conversion_factor = 0.0393700787401575
# Hide original geometry # Hide original geometry
orig_grb_obj.visible = False orig_grb_obj.visible = False
@ -4237,11 +4228,7 @@ class AppGerberEditor(QtCore.QObject):
def update_options(obj): def update_options(obj):
try: try:
if not obj.options: if not obj.options:
obj.options = {} obj.options = {'xmin': 0, 'ymin': 0, 'xmax': 0, 'ymax': 0}
obj.options['xmin'] = 0
obj.options['ymin'] = 0
obj.options['xmax'] = 0
obj.options['ymax'] = 0
return True return True
else: else:
return False return False
@ -5960,7 +5947,7 @@ class TransformEditorTool(AppTool):
""" """
Rotate geometry Rotate geometry
:param num: Rotate with a known angle value, val :param val: Rotate with a known angle value, val
:param point: Reference point for rotation: tuple :param point: Reference point for rotation: tuple
:return: :return:
""" """
@ -5969,7 +5956,7 @@ class TransformEditorTool(AppTool):
px, py = point px, py = point
if not elem_list: if not elem_list:
self.app.inform.emit('[WARNING_NOTCL] %s' %_("No shape selected.")) self.app.inform.emit('[WARNING_NOTCL] %s' % _("No shape selected."))
return return
with self.app.proc_container.new(_("Appying Rotate")): with self.app.proc_container.new(_("Appying Rotate")):
@ -6297,6 +6284,7 @@ class TransformEditorTool(AppTool):
return bounds_rec(shapelist) return bounds_rec(shapelist)
def get_shapely_list_bounds(geometry_list): def get_shapely_list_bounds(geometry_list):
xmin = np.Inf xmin = np.Inf
ymin = np.Inf ymin = np.Inf

View File

@ -1305,7 +1305,7 @@ class App(QtCore.QObject):
# ########################################################################################################### # ###########################################################################################################
if self.defaults["first_run"] is True: if self.defaults["first_run"] is True:
# ONLY AT FIRST STARTUP INIT THE GUI LAYOUT TO 'minimal' # ONLY AT FIRST STARTUP INIT THE GUI LAYOUT TO 'minimal'
self.log.debug("-> First Run: Setting up the first Layout" ) self.log.debug("-> First Run: Setting up the first Layout")
initial_lay = 'minimal' initial_lay = 'minimal'
self.on_layout(lay=initial_lay) self.on_layout(lay=initial_lay)
@ -5461,8 +5461,7 @@ class App(QtCore.QObject):
apertures[str(apid)] = {} apertures[str(apid)] = {}
apertures[str(apid)]['geometry'] = [] apertures[str(apid)]['geometry'] = []
for obj_orig in obj.solid_geometry: for obj_orig in obj.solid_geometry:
new_elem = {} new_elem = {'solid': obj_orig}
new_elem['solid'] = obj_orig
try: try:
new_elem['follow'] = obj_orig.exterior new_elem['follow'] = obj_orig.exterior
except AttributeError: except AttributeError:
@ -5486,9 +5485,7 @@ class App(QtCore.QObject):
apertures[str(apid)] = {} apertures[str(apid)] = {}
apertures[str(apid)]['geometry'] = [] apertures[str(apid)]['geometry'] = []
for geo in obj.tools[tool]['solid_geometry']: for geo in obj.tools[tool]['solid_geometry']:
new_el = {} new_el = {'solid': geo, 'follow': geo.exterior}
new_el['solid'] = geo
new_el['follow'] = geo.exterior
apertures[str(apid)]['geometry'].append(deepcopy(new_el)) apertures[str(apid)]['geometry'].append(deepcopy(new_el))
apertures[str(apid)]['size'] = float(obj.tools[tool]['tooldia']) apertures[str(apid)]['size'] = float(obj.tools[tool]['tooldia'])
@ -7635,8 +7632,7 @@ class App(QtCore.QObject):
# urllib.parse.urlencode(self.defaults["global_stats"]) # urllib.parse.urlencode(self.defaults["global_stats"])
else: else:
# no_stats dict; just so it won't break things on website # no_stats dict; just so it won't break things on website
no_ststs_dict = {} no_ststs_dict = {"global_ststs": {}}
no_ststs_dict["global_ststs"] = {}
full_url = App.version_url + "?s=" + str(self.defaults['global_serial']) + "&v=" + str(self.version) full_url = App.version_url + "?s=" + str(self.defaults['global_serial']) + "&v=" + str(self.version)
full_url += "&os=" + str(self.os) + "&" + urllib.parse.urlencode(no_ststs_dict["global_ststs"]) full_url += "&os=" + str(self.os) + "&" + urllib.parse.urlencode(no_ststs_dict["global_ststs"])
@ -8157,6 +8153,7 @@ class App(QtCore.QObject):
""" """
Shows a message on the FlatCAM Shell Shows a message on the FlatCAM Shell
:param new_line:
:param msg: Message to display. :param msg: Message to display.
:param show: Opens the shell. :param show: Opens the shell.
:param error: Shows the message as an error. :param error: Shows the message as an error.