Explorar o código

- fixed bug in Tools DB that crashed when a tool is copied
- in Tools Database added a Save Button whose color is changed in Red if the DB was modified and back to default when the DB is saved.
- fixed bug in Tool DB that crashed the app when the Tool Name was modified but there was no tree item (a tool in the list) selected in the Tree widget (list of tools)
- now on tool add and tool copy, the last item (tool, which is the one added) is autoselected; o tool delete always the first item (tool) is selected

Marius Stanciu %!s(int64=5) %!d(string=hai) anos
pai
achega
40535b9ffe
Modificáronse 4 ficheiros con 70 adicións e 2 borrados
  1. 4 0
      CHANGELOG.md
  2. 1 0
      FlatCAMApp.py
  3. 41 1
      FlatCAMDB.py
  4. 24 1
      flatcamGUI/FlatCAMGUI.py

+ 4 - 0
CHANGELOG.md

@@ -11,6 +11,10 @@ CHANGELOG for FlatCAM beta
 
 - made some corrections - due of recent refactoring PyCharm reported errors all over (not correct but it made programming difficult)
 - modified the requirements.txt file to force svg.path module to be at least version 4.0
+- fixed bug in Tools DB that crashed when a tool is copied
+- in Tools Database added a Save Button whose color is changed in Red if the DB was modified and back to default when the DB is saved.
+- fixed bug in Tool DB that crashed the app when the Tool Name was modified but there was no tree item (a tool in the list) selected in the Tree widget (list of tools)
+- now on tool add and tool copy, the last item (tool, which is the one added) is autoselected; o tool delete always the first item (tool) is selected
 
 29.04.2020
 

+ 1 - 0
FlatCAMApp.py

@@ -6022,6 +6022,7 @@ class App(QtCore.QObject):
         for idx in range(self.ui.plot_tab_area.count()):
             if self.ui.plot_tab_area.tabText(idx) == _("Tools Database"):
                 self.ui.plot_tab_area.tabBar.setTabTextColor(idx, QtGui.QColor('red'))
+                self.tools_db_tab.save_db_btn.setStyleSheet("QPushButton {color: red;}")
 
         self.tools_db_changed_flag = True
 

+ 41 - 1
FlatCAMDB.py

@@ -1672,6 +1672,12 @@ class ToolsDB2(QtWidgets.QWidget):
         )
         self.buttons_box.addWidget(import_db_btn)
 
+        self.save_db_btn = FCButton(_("Save DB"))
+        self.save_db_btn.setToolTip(
+            _("Save the Tools Database information's.")
+        )
+        self.buttons_box.addWidget(self.save_db_btn)
+
         self.add_tool_from_db = FCButton(_("Add Tool from Tools DB"))
         self.add_tool_from_db.setToolTip(
             _("Add a new tool in the Tools Table of the\n"
@@ -1796,6 +1802,7 @@ class ToolsDB2(QtWidgets.QWidget):
         remove_entry_btn.clicked.connect(self.on_tool_delete)
         export_db_btn.clicked.connect(self.on_export_tools_db_file)
         import_db_btn.clicked.connect(self.on_import_tools_db_file)
+        self.save_db_btn.clicked.connect(self.on_save_db_btn_click)
         # closebtn.clicked.connect(self.accept)
 
         self.add_tool_from_db.clicked.connect(self.on_tool_requested_from_app)
@@ -2026,6 +2033,14 @@ class ToolsDB2(QtWidgets.QWidget):
         # add the new entry to the Tools DB table
         self.update_storage()
         self.build_db_ui()
+
+        # select the last Tree item just added
+        nr_items = self.tree_widget.topLevelItemCount()
+        if nr_items:
+            last_item = self.tree_widget.topLevelItem(nr_items - 1)
+            self.tree_widget.setCurrentItem(last_item)
+            last_item.setSelected(True)
+
         self.app.inform.emit('[success] %s' % _("Tool added to DB."))
 
     def on_tool_copy(self):
@@ -2050,6 +2065,15 @@ class ToolsDB2(QtWidgets.QWidget):
 
         self.update_storage()
         self.build_db_ui()
+
+        # select the last Tree item just added
+        nr_items = self.tree_widget.topLevelItemCount()
+        if nr_items:
+            last_item = self.tree_widget.topLevelItem(nr_items - 1)
+            self.tree_widget.setCurrentItem(last_item)
+            last_item.setSelected(True)
+
+        self.callback_app()
         self.app.inform.emit('[success] %s' % _("Tool copied from Tools DB."))
 
     def on_tool_delete(self):
@@ -2069,6 +2093,14 @@ class ToolsDB2(QtWidgets.QWidget):
 
         self.update_storage()
         self.build_db_ui()
+
+        # select the first Tree item
+        nr_items = self.tree_widget.topLevelItemCount()
+        if nr_items:
+            first_item = self.tree_widget.topLevelItem(0)
+            self.tree_widget.setCurrentItem(first_item)
+            first_item.setSelected(True)
+
         self.app.inform.emit('[success] %s' % _("Tool removed from Tools DB."))
 
     def on_export_tools_db_file(self):
@@ -2167,6 +2199,7 @@ class ToolsDB2(QtWidgets.QWidget):
         for idx in range(self.app.ui.plot_tab_area.count()):
             if self.app.ui.plot_tab_area.tabText(idx) == _("Tools Database"):
                 self.app.ui.plot_tab_area.tabBar.setTabTextColor(idx, QtGui.QColor('black'))
+                self.save_db_btn.setStyleSheet("")
 
                 # Save Tools DB in a file
                 try:
@@ -2181,6 +2214,10 @@ class ToolsDB2(QtWidgets.QWidget):
                 if not silent:
                     self.app.inform.emit('[success] %s' % _("Saved Tools DB."))
 
+    def on_save_db_btn_click(self):
+        self.app.tools_db_changed_flag = False
+        self.on_save_tools_db()
+
     def ui_connect(self):
         # make sure that we don't make multiple connections to the widgets
         self.ui_disconnect()
@@ -2258,6 +2295,8 @@ class ToolsDB2(QtWidgets.QWidget):
         val = self.name_entry.get_value()
 
         item = self.tree_widget.currentItem()
+        if item is None:
+            return
         # I'm setting the value for the second column (designated by 1) because first column holds the ID
         # and second column holds the Name (this behavior is set in the build_ui method)
         item.setData(1, QtCore.Qt.DisplayRole, val)
@@ -2272,7 +2311,8 @@ class ToolsDB2(QtWidgets.QWidget):
         try:
             wdg = self.sender()
 
-            assert isinstance(wdg, QtWidgets.QWidget), "Expected a QWidget got %s" % type(wdg)
+            assert isinstance(wdg, QtWidgets.QWidget) or isinstance(wdg, QtWidgets.QAction), \
+                "Expected a QWidget got %s" % type(wdg)
 
             if wdg is None:
                 return

+ 24 - 1
flatcamGUI/FlatCAMGUI.py

@@ -31,6 +31,7 @@ from flatcamObjects.ObjectCollection import KeySensitiveListView
 
 import subprocess
 import os
+import sys
 import gettext
 import FlatCAMTranslation as fcTranslate
 import builtins
@@ -2864,14 +2865,17 @@ class FlatCAMGUI(QtWidgets.QMainWindow):
             key = event.key
 
         if self.app.call_source == 'app':
+            # CTRL + ALT
             if modifiers == QtCore.Qt.ControlModifier | QtCore.Qt.AltModifier:
                 if key == QtCore.Qt.Key_X:
                     self.app.abort_all_tasks()
                     return
+            # CTRL + SHIFT
             if modifiers == QtCore.Qt.ControlModifier | QtCore.Qt.ShiftModifier:
                 if key == QtCore.Qt.Key_S:
                     self.app.on_file_saveprojectas()
                     return
+            # CTRL
             elif modifiers == QtCore.Qt.ControlModifier:
                 # Select All
                 if key == QtCore.Qt.Key_A:
@@ -2944,6 +2948,7 @@ class FlatCAMGUI(QtWidgets.QMainWindow):
                     self.app.on_toggle_plotarea()
 
                 return
+            # SHIFT
             elif modifiers == QtCore.Qt.ShiftModifier:
 
                 # Copy Object Name
@@ -2996,6 +3001,7 @@ class FlatCAMGUI(QtWidgets.QMainWindow):
                 if key == QtCore.Qt.Key_Y:
                     self.app.on_skewy()
                     return
+            # ALT
             elif modifiers == QtCore.Qt.AltModifier:
                 # Eanble all plots
                 if key == Qt.Key_1:
@@ -3114,6 +3120,7 @@ class FlatCAMGUI(QtWidgets.QMainWindow):
                 if key == QtCore.Qt.Key_F10 or key == 'F10':
                     self.app.on_fullscreen()
                     return
+            # NO MODIFIER
             elif modifiers == QtCore.Qt.NoModifier:
                 # Open Manual
                 if key == QtCore.Qt.Key_F1 or key == 'F1':
@@ -3311,6 +3318,7 @@ class FlatCAMGUI(QtWidgets.QMainWindow):
 
                 return
         elif self.app.call_source == 'geo_editor':
+            # CTRL
             if modifiers == QtCore.Qt.ControlModifier:
                 # save (update) the current geometry and return to the App
                 if key == QtCore.Qt.Key_S or key == 'S':
@@ -3340,6 +3348,7 @@ class FlatCAMGUI(QtWidgets.QMainWindow):
                         messagebox.setDefaultButton(QtWidgets.QMessageBox.Ok)
                         messagebox.exec_()
                     return
+            # SHIFT
             elif modifiers == QtCore.Qt.ShiftModifier:
                 # Run Distance Minimum Tool
                 if key == QtCore.Qt.Key_M or key == 'M':
@@ -3355,6 +3364,7 @@ class FlatCAMGUI(QtWidgets.QMainWindow):
                 if key == QtCore.Qt.Key_Y or key == 'Y':
                     self.app.geo_editor.transform_tool.on_skewy_key()
                     return
+            # ALT
             elif modifiers == QtCore.Qt.AltModifier:
 
                 # Transformation Tool
@@ -3371,6 +3381,7 @@ class FlatCAMGUI(QtWidgets.QMainWindow):
                 if key == QtCore.Qt.Key_Y or key == 'Y':
                     self.app.geo_editor.transform_tool.on_offy_key()
                     return
+            # NO MODIFIER
             elif modifiers == QtCore.Qt.NoModifier:
                 # toggle display of Notebook area
                 if key == QtCore.Qt.Key_QuoteLeft or key == '`':
@@ -3578,6 +3589,7 @@ class FlatCAMGUI(QtWidgets.QMainWindow):
                 if key == 'F3':
                     self.app.on_shortcut_list()
         elif self.app.call_source == 'grb_editor':
+            # CTRL
             if modifiers == QtCore.Qt.ControlModifier:
                 # Eraser Tool
                 if key == QtCore.Qt.Key_E or key == 'E':
@@ -3593,11 +3605,13 @@ class FlatCAMGUI(QtWidgets.QMainWindow):
                 if key == QtCore.Qt.Key_M or key == 'M':
                     self.app.distance_tool.run()
                     return
+            # SHIFT
             elif modifiers == QtCore.Qt.ShiftModifier:
                 # Run Distance Minimum Tool
                 if key == QtCore.Qt.Key_M or key == 'M':
                     self.app.distance_min_tool.run()
                     return
+            # ALT
             elif modifiers == QtCore.Qt.AltModifier:
                 # Mark Area Tool
                 if key == QtCore.Qt.Key_A or key == 'A':
@@ -3612,6 +3626,7 @@ class FlatCAMGUI(QtWidgets.QMainWindow):
                 if key == QtCore.Qt.Key_R or key == 'R':
                     self.app.grb_editor.on_transform()
                     return
+            # NO MODIFIER
             elif modifiers == QtCore.Qt.NoModifier:
                 # Abort the current action
                 if key == QtCore.Qt.Key_Escape or key == 'Escape':
@@ -3807,6 +3822,7 @@ class FlatCAMGUI(QtWidgets.QMainWindow):
                     self.app.on_shortcut_list()
                     return
         elif self.app.call_source == 'exc_editor':
+            # CTRL
             if modifiers == QtCore.Qt.ControlModifier:
                 # save (update) the current geometry and return to the App
                 if key == QtCore.Qt.Key_S or key == 'S':
@@ -3817,13 +3833,16 @@ class FlatCAMGUI(QtWidgets.QMainWindow):
                 if key == QtCore.Qt.Key_M or key == 'M':
                     self.app.distance_tool.run()
                     return
+            # SHIFT
             elif modifiers == QtCore.Qt.ShiftModifier:
                 # Run Distance Minimum Tool
                 if key == QtCore.Qt.Key_M or key == 'M':
                     self.app.distance_min_tool.run()
                     return
+            # ALT
             elif modifiers == QtCore.Qt.AltModifier:
                 pass
+            # NO MODIFIER
             elif modifiers == QtCore.Qt.NoModifier:
                 # Abort the current action
                 if key == QtCore.Qt.Key_Escape or key == 'Escape':
@@ -4036,6 +4055,7 @@ class FlatCAMGUI(QtWidgets.QMainWindow):
                 pass
             elif modifiers == QtCore.Qt.ShiftModifier:
                 pass
+            # NO MODIFIER
             elif modifiers == QtCore.Qt.NoModifier:
                 if key == QtCore.Qt.Key_Escape or key == 'Escape':
                     # abort the measurement action
@@ -4051,6 +4071,7 @@ class FlatCAMGUI(QtWidgets.QMainWindow):
                 if key == QtCore.Qt.Key_J or key == 'J':
                     self.app.on_jump_to()
         elif self.app.call_source == 'qrcode_tool':
+            # CTRL + ALT
             if modifiers == QtCore.Qt.ControlModifier | QtCore.Qt.AltModifier:
                 if key == QtCore.Qt.Key_X:
                     self.app.abort_all_tasks()
@@ -4062,6 +4083,7 @@ class FlatCAMGUI(QtWidgets.QMainWindow):
                 pass
             elif modifiers == QtCore.Qt.AltModifier:
                 pass
+            # NO MODIFIER
             elif modifiers == QtCore.Qt.NoModifier:
                 # Escape = Deselect All
                 if key == QtCore.Qt.Key_Escape or key == 'Escape':
@@ -4075,17 +4097,18 @@ class FlatCAMGUI(QtWidgets.QMainWindow):
                 if key == QtCore.Qt.Key_J:
                     self.app.on_jump_to()
         elif self.app.call_source == 'copper_thieving_tool':
+            # CTRL + ALT
             if modifiers == QtCore.Qt.ControlModifier | QtCore.Qt.AltModifier:
                 if key == QtCore.Qt.Key_X:
                     self.app.abort_all_tasks()
                     return
-
             elif modifiers == QtCore.Qt.ControlModifier:
                 pass
             elif modifiers == QtCore.Qt.ShiftModifier:
                 pass
             elif modifiers == QtCore.Qt.AltModifier:
                 pass
+            # NO MODIFIER
             elif modifiers == QtCore.Qt.NoModifier:
                 # Escape = Deselect All
                 if key == QtCore.Qt.Key_Escape or key == 'Escape':