Просмотр исходного кода

- repurposed shortcut key 'Delete' to delete tools in tooltable when the mouse is over the Seleted tab (with Geometry inside) or in Tools tab (when NCC Tool or Paint Tool is inside). Or in Excellon Editor when mouse is hovering the Selected tab selecting a tool, 'Delete' key will delete that tool, if on canvas 'Delete' key will delete a selected shape (drill). In rest, will delete selected objects.

Marius Stanciu 7 лет назад
Родитель
Сommit
f35994a712
4 измененных файлов с 128 добавлено и 69 удалено
  1. 94 60
      FlatCAMApp.py
  2. 28 9
      FlatCAMGUI.py
  3. 4 0
      FlatCAMObj.py
  4. 2 0
      README.md

+ 94 - 60
FlatCAMApp.py

@@ -2782,66 +2782,6 @@ class App(QtCore.QObject):
 
         self.inform.emit("[success] A Geometry object was converted to SingleGeo type.")
 
-    def on_skey_tool_add(self):
-        ## Current application units in Upper Case
-        self.units = self.general_options_form.general_app_group.units_radio.get_value().upper()
-
-        # work only if the notebook tab on focus is the Selected_Tab and only if the object is Geometry
-        if self.ui.notebook.currentWidget().objectName() == 'selected_tab':
-            if str(type(self.collection.get_active())) == "<class 'FlatCAMObj.FlatCAMGeometry'>":
-                tool_add_popup = FCInputDialog(title="New Tool ...",
-                                               text='Enter a Tool Diameter:',
-                                               min=0.0000, max=99.9999, decimals=4)
-                tool_add_popup.setWindowIcon(QtGui.QIcon('share/letter_t_32.png'))
-
-                val, ok = tool_add_popup.get_value()
-                if ok:
-                    if float(val) == 0:
-                        self.inform.emit(
-                            "[WARNING_NOTCL] Please enter a tool diameter with non-zero value, in Float format.")
-                        return
-                    self.collection.get_active().on_tool_add(dia=float(val))
-                else:
-                    self.inform.emit(
-                        "[WARNING_NOTCL] Adding Tool cancelled ...")
-
-        # work only if the notebook tab on focus is the Tools_Tab
-        if self.ui.notebook.currentWidget().objectName() == 'tool_tab':
-            # and only if the tool is NCC Tool
-            if self.ui.tool_scroll_area.widget().objectName() == self.ncclear_tool.toolName:
-                tool_add_popup = FCInputDialog(title="New Tool ...",
-                                               text='Enter a Tool Diameter:',
-                                               min=0.0000, max=99.9999, decimals=4)
-                tool_add_popup.setWindowIcon(QtGui.QIcon('share/letter_t_32.png'))
-
-                val, ok = tool_add_popup.get_value()
-                if ok:
-                    if float(val) == 0:
-                        self.inform.emit(
-                            "[WARNING_NOTCL] Please enter a tool diameter with non-zero value, in Float format.")
-                        return
-                    self.ncclear_tool.on_tool_add(dia=float(val))
-                else:
-                    self.inform.emit(
-                        "[WARNING_NOTCL] Adding Tool cancelled ...")
-            # and only if the tool is Paint Area Tool
-            if self.ui.tool_scroll_area.widget().objectName() == self.paint_tool.toolName:
-                tool_add_popup = FCInputDialog(title="New Tool ...",
-                                               text='Enter a Tool Diameter:',
-                                               min=0.0000, max=99.9999, decimals=4)
-                tool_add_popup.setWindowIcon(QtGui.QIcon('share/letter_t_32.png'))
-
-                val, ok = tool_add_popup.get_value()
-                if ok:
-                    if float(val) == 0:
-                        self.inform.emit(
-                            "[WARNING_NOTCL] Please enter a tool diameter with non-zero value, in Float format.")
-                        return
-                    self.paint_tool.on_tool_add(dia=float(val))
-                else:
-                    self.inform.emit(
-                        "[WARNING_NOTCL] Adding Tool cancelled ...")
-
     def on_options_dict_change(self, field):
         self.options_write_form_field(field)
 
@@ -3585,6 +3525,100 @@ class App(QtCore.QObject):
             # Mark end of undo block
             cursor.endEditBlock()
 
+    def on_tool_add_keypress(self):
+        ## Current application units in Upper Case
+        self.units = self.general_options_form.general_app_group.units_radio.get_value().upper()
+
+        notebook_widget_name = self.ui.notebook.currentWidget().objectName()
+
+        # work only if the notebook tab on focus is the Selected_Tab and only if the object is Geometry
+        if notebook_widget_name == 'selected_tab':
+            if str(type(self.collection.get_active())) == "<class 'FlatCAMObj.FlatCAMGeometry'>":
+                tool_add_popup = FCInputDialog(title="New Tool ...",
+                                               text='Enter a Tool Diameter:',
+                                               min=0.0000, max=99.9999, decimals=4)
+                tool_add_popup.setWindowIcon(QtGui.QIcon('share/letter_t_32.png'))
+
+                val, ok = tool_add_popup.get_value()
+                if ok:
+                    if float(val) == 0:
+                        self.inform.emit(
+                            "[WARNING_NOTCL] Please enter a tool diameter with non-zero value, in Float format.")
+                        return
+                    self.collection.get_active().on_tool_add(dia=float(val))
+                else:
+                    self.inform.emit(
+                        "[WARNING_NOTCL] Adding Tool cancelled ...")
+
+        # work only if the notebook tab on focus is the Tools_Tab
+        if notebook_widget_name == 'tool_tab':
+            tool_widget = self.ui.tool_scroll_area.widget().objectName()
+
+            # and only if the tool is NCC Tool
+            if tool_widget == self.ncclear_tool.toolName:
+                tool_add_popup = FCInputDialog(title="New Tool ...",
+                                               text='Enter a Tool Diameter:',
+                                               min=0.0000, max=99.9999, decimals=4)
+                tool_add_popup.setWindowIcon(QtGui.QIcon('share/letter_t_32.png'))
+
+                val, ok = tool_add_popup.get_value()
+                if ok:
+                    if float(val) == 0:
+                        self.inform.emit(
+                            "[WARNING_NOTCL] Please enter a tool diameter with non-zero value, in Float format.")
+                        return
+                    self.ncclear_tool.on_tool_add(dia=float(val))
+                else:
+                    self.inform.emit(
+                        "[WARNING_NOTCL] Adding Tool cancelled ...")
+            # and only if the tool is Paint Area Tool
+            elif tool_widget == self.paint_tool.toolName:
+                tool_add_popup = FCInputDialog(title="New Tool ...",
+                                               text='Enter a Tool Diameter:',
+                                               min=0.0000, max=99.9999, decimals=4)
+                tool_add_popup.setWindowIcon(QtGui.QIcon('share/letter_t_32.png'))
+
+                val, ok = tool_add_popup.get_value()
+                if ok:
+                    if float(val) == 0:
+                        self.inform.emit(
+                            "[WARNING_NOTCL] Please enter a tool diameter with non-zero value, in Float format.")
+                        return
+                    self.paint_tool.on_tool_add(dia=float(val))
+                else:
+                    self.inform.emit(
+                        "[WARNING_NOTCL] Adding Tool cancelled ...")
+
+    # It's meant to delete tools in tool tables via a 'Delete' shortcut key but only if certain conditions are met
+    # See description bellow.
+    def on_delete_keypress(self):
+        notebook_widget_name = self.ui.notebook.currentWidget().objectName()
+
+        # work only if the notebook tab on focus is the Selected_Tab and only if the object is Geometry
+        if notebook_widget_name == 'selected_tab':
+            if str(type(self.collection.get_active())) == "<class 'FlatCAMObj.FlatCAMGeometry'>":
+                self.collection.get_active().on_tool_delete()
+
+        # work only if the notebook tab on focus is the Tools_Tab
+        elif notebook_widget_name == 'tool_tab':
+            tool_widget = self.ui.tool_scroll_area.widget().objectName()
+
+            # and only if the tool is NCC Tool
+            if tool_widget == self.ncclear_tool.toolName:
+                self.ncclear_tool.on_tool_delete()
+
+            # and only if the tool is Paint Tool
+            elif tool_widget == self.paint_tool.toolName:
+                self.paint_tool.on_tool_delete()
+
+        else:
+            self.on_delete()
+
+    # It's meant to delete selected objects. It work also activated by a shortcut key 'Delete' same as above so in
+    # some screens you have to be careful where you hover with your mouse.
+    # Hovering over Selected tab, if the selected tab is a Geometry it will delete tools in tool table. But even if
+    # there is a Selected tab in focus with a Geometry inside, if you hover over canvas it will delete an object.
+    # Complicated, I know :)
     def on_delete(self):
         """
         Delete the currently selected FlatCAMObjs.

+ 28 - 9
FlatCAMGUI.py

@@ -991,7 +991,11 @@ class FlatCAMGUI(QtWidgets.QMainWindow):
 		</tr>
 		<tr height="20">
 			<td height="20"><strong>Del</strong></td>
-			<td>&nbsp;Delete Obj</td>
+			<td>&nbsp;Delete Object</td>
+		</tr>
+		<tr height="20">
+			<td height="20"><strong>Del</strong></td>
+			<td>&nbsp;Alternate: Delete Tool</td>
 		</tr>
         <tr height="20">
 			<td height="20"><strong>'`'</strong></td>
@@ -1150,6 +1154,10 @@ class FlatCAMGUI(QtWidgets.QMainWindow):
 			<td height="20"><strong>Del</strong></td>
 			<td>&nbsp;Delete Drill(s)</td>
 		</tr>
+		<tr height="20">
+			<td height="20"><strong>Del</strong></td>
+			<td>&nbsp;Alternate: Delete Tool(s)</td>
+		</tr>
 		<tr height="20">
 			<td height="20">&nbsp;</td>
 			<td>&nbsp;</td>
@@ -1616,7 +1624,6 @@ class FlatCAMGUI(QtWidgets.QMainWindow):
                 if key == QtCore.Qt.Key_Y:
                     self.app.on_skewy()
                     return
-
             elif modifiers == QtCore.Qt.AltModifier:
                 # Eanble all plots
                 if key == Qt.Key_1:
@@ -1698,11 +1705,17 @@ class FlatCAMGUI(QtWidgets.QMainWindow):
                 if key == QtCore.Qt.Key_3:
                     self.app.on_select_tab('tool')
 
-                # Delete
-                if key == QtCore.Qt.Key_Delete or key == 'Delete':
+                # Delete from PyQt
+                # It's meant to make a difference between delete objects and delete tools in
+                # Geometry Selected tool table
+                if key == QtCore.Qt.Key_Delete:
+                    self.app.on_delete_keypress()
+
+                # Delete from canvas
+                if key == 'Delete':
+                    # Delete via the application to
+                    # ensure cleanup of the GUI
                     if active:
-                        # Delete via the application to
-                        # ensure cleanup of the GUI
                         active.app.on_delete()
 
                 # Escape = Deselect All
@@ -1768,7 +1781,7 @@ class FlatCAMGUI(QtWidgets.QMainWindow):
 
                 # Add a Tool from shortcut
                 if key == QtCore.Qt.Key_T:
-                    self.app.on_skey_tool_add()
+                    self.app.on_tool_add_keypress()
 
                 # Zoom Fit
                 if key == QtCore.Qt.Key_V:
@@ -2055,8 +2068,8 @@ class FlatCAMGUI(QtWidgets.QMainWindow):
                     self.app.exc_editor.select_tool('select')
                     return
 
-                # Delete selected object
-                if key == QtCore.Qt.Key_Delete or key == 'Delete':
+                # Delete selected object if delete key event comes out of canvas
+                if key == 'Delete':
                     self.app.exc_editor.launched_from_shortcuts = True
                     if self.app.exc_editor.selected:
                         self.app.exc_editor.delete_selected()
@@ -2065,6 +2078,12 @@ class FlatCAMGUI(QtWidgets.QMainWindow):
                         self.app.inform.emit("[WARNING_NOTCL]Cancelled. Nothing selected to delete.")
                     return
 
+                # Delete tools in tools table if delete key event comes from the Selected Tab
+                if key == QtCore.Qt.Key_Delete:
+                    self.app.exc_editor.launched_from_shortcuts = True
+                    self.app.exc_editor.on_tool_delete()
+                    return
+
                 if key == QtCore.Qt.Key_Minus or key == '-':
                     self.app.exc_editor.launched_from_shortcuts = True
                     self.app.plotcanvas.zoom(1 / self.app.defaults['zoom_ratio'],

+ 4 - 0
FlatCAMObj.py

@@ -2688,6 +2688,10 @@ class FlatCAMGeometry(FlatCAMObj, Geometry):
                         temp_tools = copy.deepcopy(self.tools)
                         for tooluid_key in self.tools:
                             if int(tooluid_key) == tooluid_del:
+                                # if the self.tools has only one tool and we delete it then we move the solid_geometry
+                                # as a property of the object otherwise there will be nothing to hold it
+                                if len(self.tools) == 1:
+                                    self.solid_geometry = copy.deepcopy(self.tools[tooluid_key]['solid_geometry'])
                                 temp_tools.pop(tooluid_del, None)
                         self.tools = copy.deepcopy(temp_tools)
                         temp_tools.clear()

+ 2 - 0
README.md

@@ -13,6 +13,8 @@ CAD program, and create G-Code for Isolation routing.
 
 - the SELECTED type of messages are no longer printed to shell from 2 reasons: first, too much spam and second, issue with displaying html
 - on set_zero function and creation of new geometry or new excellon there is no longer a zoom fit 
+- repurposed shortcut key 'Delete' to delete tools in tooltable when the mouse is over the Seleted tab (with Geometry inside) or in Tools tab (when NCC Tool or Paint Tool is inside). Or in Excellon Editor when mouse is hovering the Selected tab selecting a tool, 'Delete' key will delete that tool, if on canvas 'Delete' key will delete a selected shape (drill). In rest, will delete selected objects.
+
 
 9.02.2019