From b7023d8ef6da1d18018277ceff44d4964725f428 Mon Sep 17 00:00:00 2001 From: Marius Stanciu Date: Thu, 30 May 2019 21:15:09 +0300 Subject: [PATCH] - more PEP8 cleanup --- FlatCAMObj.py | 18 ++++++------------ ObjectCollection.py | 23 +++++++++++------------ README.md | 1 + 3 files changed, 18 insertions(+), 24 deletions(-) diff --git a/FlatCAMObj.py b/FlatCAMObj.py index e5dc3409..65f2c62c 100644 --- a/FlatCAMObj.py +++ b/FlatCAMObj.py @@ -3036,6 +3036,9 @@ class FlatCAMGeometry(FlatCAMObj, Geometry): self.old_pp_state = '' self.old_toolchangeg_state = '' + # store here the default data for Geometry Data + self.default_data = {} + # Attributes to be included in serialization # Always append to it because it carries contents # from predecessors. @@ -3394,11 +3397,11 @@ class FlatCAMGeometry(FlatCAMObj, Geometry): try: # works for CheckBoxes self.ui.grid3.itemAt(i).widget().stateChanged.connect(self.gui_form_to_storage) - except: + except Exception as e: # works for ComboBoxes try: self.ui.grid3.itemAt(i).widget().currentIndexChanged.connect(self.gui_form_to_storage) - except: + except Exception as e2: # works for Entry try: self.ui.grid3.itemAt(i).widget().editingFinished.connect(self.gui_form_to_storage) @@ -3495,13 +3498,6 @@ class FlatCAMGeometry(FlatCAMObj, Geometry): def on_tool_add(self, dia=None): self.ui_disconnect() - last_offset = None - last_offset_value = None - last_type = None - last_tool_type = None - last_data = None - last_solid_geometry = [] - # if a Tool diameter entered is a char instead a number the final message of Tool adding is changed # because the Default value for Tool is used. change_message = False @@ -3550,7 +3546,7 @@ class FlatCAMGeometry(FlatCAMObj, Geometry): self.tools.update({ self.tooluid: { 'tooldia': tooldia, - 'offset': ('Path'), + 'offset': 'Path', 'offset_value': 0.0, 'type': _('Rough'), 'tool_type': 'C1', @@ -3559,7 +3555,6 @@ class FlatCAMGeometry(FlatCAMObj, Geometry): } }) else: - # print("LAST", self.tools[maxuid]) last_data = self.tools[max_uid]['data'] last_offset = self.tools[max_uid]['offset'] last_offset_value = self.tools[max_uid]['offset_value'] @@ -3583,7 +3578,6 @@ class FlatCAMGeometry(FlatCAMObj, Geometry): 'solid_geometry': deepcopy(last_solid_geometry) } }) - # print("CURRENT", self.tools[-1]) self.ui.tool_offset_entry.hide() self.ui.tool_offset_lbl.hide() diff --git a/ObjectCollection.py b/ObjectCollection.py index 8454be93..862a4375 100644 --- a/ObjectCollection.py +++ b/ObjectCollection.py @@ -20,9 +20,9 @@ from PyQt5.QtCore import Qt import gettext import FlatCAMTranslation as fcTranslate +import builtins fcTranslate.apply_language('strings') -import builtins if '_' not in builtins.__dict__: _ = gettext.gettext @@ -526,8 +526,8 @@ class ObjectCollection(QtCore.QAbstractItemModel): ymin = min([ymin, gymin]) xmax = max([xmax, gxmax]) ymax = max([ymax, gymax]) - except: - FlatCAMApp.App.log.warning("DEV WARNING: Tried to get bounds of empty geometry.") + except Exception as e: + FlatCAMApp.App.log.warning("DEV WARNING: Tried to get bounds of empty geometry. %s" % str(e)) return [xmin, ymin, xmax, ymax] @@ -537,12 +537,12 @@ class ObjectCollection(QtCore.QAbstractItemModel): :param name: The name of the object. :type name: str + :param isCaseSensitive: whether searching of the object is done by name where the name is case sensitive :return: The requested object or None if no such object. :rtype: FlatCAMObj or None """ FlatCAMApp.App.log.debug(str(inspect.stack()[1][3]) + "--> OC.get_by_name()") - if isCaseSensitive is None or isCaseSensitive is True: for obj in self.get_list(): if obj.options['name'] == name: @@ -570,10 +570,9 @@ class ObjectCollection(QtCore.QAbstractItemModel): self.app.myKeywords.remove(name) self.app.shell._edit.set_model_data(self.app.myKeywords) self.app.ui.code_editor.set_model_data(self.app.myKeywords) - except: + except Exception as e: log.debug( - "delete_active() --> Could not remove the old object name from auto-completer model list") - + "delete_active() --> Could not remove the old object name from auto-completer model list. %s" % str(e)) self.beginRemoveRows(self.index(group.row(), 0, QtCore.QModelIndex()), active.row(), active.row()) @@ -650,12 +649,12 @@ class ObjectCollection(QtCore.QAbstractItemModel): :return: List of objects """ - l = self.get_list() + obj_list = self.get_list() for sel in self.get_selected(): - l.remove(sel) + obj_list.remove(sel) - return l + return obj_list def set_active(self, name): """ @@ -732,8 +731,8 @@ class ObjectCollection(QtCore.QAbstractItemModel): self.app.inform.emit('') try: self.app.ui.selected_scroll_area.takeWidget() - except: - FlatCAMApp.App.log.debug("Nothing to remove") + except Exception as e: + FlatCAMApp.App.log.debug("Nothing to remove. %s" % str(e)) self.app.setup_component_editor() return diff --git a/README.md b/README.md index 80dfca43..3fe39cc2 100644 --- a/README.md +++ b/README.md @@ -15,6 +15,7 @@ CAD program, and create G-Code for Isolation routing. - solved issue #292 where a new geometry renamed with many underscores failed to store the name in a saved project - the name for the saved projects are updated to the current time and not to the time of the app startup - some PEP8 changes related to comments starting with only one '#' symbol +- more PEP8 cleanup 24.05.2019