Procházet zdrojové kódy

- minor PEP corrections

Marius Stanciu před 5 roky
rodič
revize
e71a48ff5c

+ 16 - 16
appCommon/Common.py

@@ -12,7 +12,7 @@
 # ##########################################################
 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 appGUI.VisPyVisuals import ShapeCollection
@@ -20,7 +20,6 @@ from appTool import AppTool
 
 from copy import deepcopy
 import collections
-import traceback
 
 import numpy as np
 # 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
     """
+
     def __init__(self):
         super().__init__()
 
@@ -95,7 +95,7 @@ class LoudUniqueList(list, collections.MutableSequence):
         super().__init__()
         self.callback = lambda x: None
 
-        if not arg is None:
+        if arg is not None:
             if isinstance(arg, list):
                 self.extend(arg)
             else:
@@ -110,32 +110,32 @@ class LoudUniqueList(list, collections.MutableSequence):
     def append(self, v):
         if v in self:
             raise ValueError("One of the added items is already in the list.")
-        l = len(self)
-        self.callback(l)
+        le = len(self)
+        self.callback(le)
         return super().append(v)
 
     def extend(self, t):
         for v in t:
             if v in self:
                 raise ValueError("One of the added items is already in the list.")
-        l = len(self)
-        self.callback(l)
+        le = len(self)
+        self.callback(le)
         return super().extend(t)
 
     def __add__(self, t):  # This is for something like `LoudUniqueList([1, 2, 3]) + list([4, 5, 6])`...
         for v in t:
             if v in self:
                 raise ValueError("One of the added items is already in the list.")
-        l = len(self)
-        self.callback(l)
+        le = len(self)
+        self.callback(le)
         return super().__add__(t)
 
     def __iadd__(self, t):  # This is for something like `l = LoudUniqueList(); l += [1, 2, 3]`
         for v in t:
             if v in self:
                 raise ValueError("One of the added items is already in the list.")
-        l = len(self)
-        self.callback(l)
+        le = len(self)
+        self.callback(le)
         return super().__iadd__(t)
 
     def __setitem__(self, i, v):
@@ -146,7 +146,7 @@ class LoudUniqueList(list, collections.MutableSequence):
         except TypeError:
             if v in self:
                 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)
         return super().__setitem__(i, v)
 
@@ -374,10 +374,10 @@ class ExclusionAreas(QtCore.QObject):
                     #     "overz":      float < - self.over_z_button
                     # }
                     new_el = {
-                        "obj_type":     self.obj_type,
-                        "shape":        new_rectangle,
-                        "strategy":     self.strategy_button.get_value(),
-                        "overz":        self.over_z_button.get_value()
+                        "obj_type": self.obj_type,
+                        "shape": new_rectangle,
+                        "strategy": self.strategy_button.get_value(),
+                        "overz": self.over_z_button.get_value()
                     }
                     self.exclusion_areas_storage.append(new_el)
 

+ 4 - 4
appCommon/bilinear.py

@@ -71,10 +71,10 @@ class BilinearInterpolation(object):
         self.y_length = y_length
         self.extrapolate = True
 
-        #slopes = self.slopes = []
-        #for j in range(y_length):
-            #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 = self.slopes = []
+        # for j in range(y_length):
+        #     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])
 
     def __call__(self, x, y):
         # local lookups

+ 5 - 7
appEditors/AppExcEditor.py

@@ -2046,7 +2046,8 @@ class AppExcEditor(QtCore.QObject):
 
         try:
             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():
                     row = index.row()
                     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):
         try:
             if not obj.options:
-                obj.options = {}
-                obj.options['xmin'] = 0
-                obj.options['ymin'] = 0
-                obj.options['xmax'] = 0
-                obj.options['ymax'] = 0
+                obj.options = {'xmin': 0, 'ymin': 0, 'xmax': 0, 'ymax': 0}
                 return True
             else:
                 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
                             # 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.last_tool_selected = int(key_tool_nr)
 

+ 4 - 3
appEditors/AppGeoEditor.py

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

+ 18 - 30
appEditors/AppGerberEditor.py

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

+ 5 - 8
app_Main.py

@@ -1305,7 +1305,7 @@ class App(QtCore.QObject):
         # ###########################################################################################################
         if self.defaults["first_run"] is True:
             # 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'
             self.on_layout(lay=initial_lay)
 
@@ -5461,8 +5461,7 @@ class App(QtCore.QObject):
             apertures[str(apid)] = {}
             apertures[str(apid)]['geometry'] = []
             for obj_orig in obj.solid_geometry:
-                new_elem = {}
-                new_elem['solid'] = obj_orig
+                new_elem = {'solid': obj_orig}
                 try:
                     new_elem['follow'] = obj_orig.exterior
                 except AttributeError:
@@ -5486,9 +5485,7 @@ class App(QtCore.QObject):
                 apertures[str(apid)] = {}
                 apertures[str(apid)]['geometry'] = []
                 for geo in obj.tools[tool]['solid_geometry']:
-                    new_el = {}
-                    new_el['solid'] = geo
-                    new_el['follow'] = geo.exterior
+                    new_el = {'solid': geo, 'follow': geo.exterior}
                     apertures[str(apid)]['geometry'].append(deepcopy(new_el))
 
                 apertures[str(apid)]['size'] = float(obj.tools[tool]['tooldia'])
@@ -7635,8 +7632,7 @@ class App(QtCore.QObject):
             #            urllib.parse.urlencode(self.defaults["global_stats"])
         else:
             # 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 += "&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
 
+        :param new_line:
         :param msg:         Message to display.
         :param show:        Opens the shell.
         :param error:       Shows the message as an error.