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

- 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 5 лет назад
Родитель
Сommit
40535b9ffe
4 измененных файлов с 70 добавлено и 2 удалено
  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)
 - 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
 - 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
 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()):
         for idx in range(self.ui.plot_tab_area.count()):
             if self.ui.plot_tab_area.tabText(idx) == _("Tools Database"):
             if self.ui.plot_tab_area.tabText(idx) == _("Tools Database"):
                 self.ui.plot_tab_area.tabBar.setTabTextColor(idx, QtGui.QColor('red'))
                 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
         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.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 = FCButton(_("Add Tool from Tools DB"))
         self.add_tool_from_db.setToolTip(
         self.add_tool_from_db.setToolTip(
             _("Add a new tool in the Tools Table of the\n"
             _("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)
         remove_entry_btn.clicked.connect(self.on_tool_delete)
         export_db_btn.clicked.connect(self.on_export_tools_db_file)
         export_db_btn.clicked.connect(self.on_export_tools_db_file)
         import_db_btn.clicked.connect(self.on_import_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)
         # closebtn.clicked.connect(self.accept)
 
 
         self.add_tool_from_db.clicked.connect(self.on_tool_requested_from_app)
         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
         # add the new entry to the Tools DB table
         self.update_storage()
         self.update_storage()
         self.build_db_ui()
         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."))
         self.app.inform.emit('[success] %s' % _("Tool added to DB."))
 
 
     def on_tool_copy(self):
     def on_tool_copy(self):
@@ -2050,6 +2065,15 @@ class ToolsDB2(QtWidgets.QWidget):
 
 
         self.update_storage()
         self.update_storage()
         self.build_db_ui()
         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."))
         self.app.inform.emit('[success] %s' % _("Tool copied from Tools DB."))
 
 
     def on_tool_delete(self):
     def on_tool_delete(self):
@@ -2069,6 +2093,14 @@ class ToolsDB2(QtWidgets.QWidget):
 
 
         self.update_storage()
         self.update_storage()
         self.build_db_ui()
         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."))
         self.app.inform.emit('[success] %s' % _("Tool removed from Tools DB."))
 
 
     def on_export_tools_db_file(self):
     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()):
         for idx in range(self.app.ui.plot_tab_area.count()):
             if self.app.ui.plot_tab_area.tabText(idx) == _("Tools Database"):
             if self.app.ui.plot_tab_area.tabText(idx) == _("Tools Database"):
                 self.app.ui.plot_tab_area.tabBar.setTabTextColor(idx, QtGui.QColor('black'))
                 self.app.ui.plot_tab_area.tabBar.setTabTextColor(idx, QtGui.QColor('black'))
+                self.save_db_btn.setStyleSheet("")
 
 
                 # Save Tools DB in a file
                 # Save Tools DB in a file
                 try:
                 try:
@@ -2181,6 +2214,10 @@ class ToolsDB2(QtWidgets.QWidget):
                 if not silent:
                 if not silent:
                     self.app.inform.emit('[success] %s' % _("Saved Tools DB."))
                     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):
     def ui_connect(self):
         # make sure that we don't make multiple connections to the widgets
         # make sure that we don't make multiple connections to the widgets
         self.ui_disconnect()
         self.ui_disconnect()
@@ -2258,6 +2295,8 @@ class ToolsDB2(QtWidgets.QWidget):
         val = self.name_entry.get_value()
         val = self.name_entry.get_value()
 
 
         item = self.tree_widget.currentItem()
         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
         # 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)
         # and second column holds the Name (this behavior is set in the build_ui method)
         item.setData(1, QtCore.Qt.DisplayRole, val)
         item.setData(1, QtCore.Qt.DisplayRole, val)
@@ -2272,7 +2311,8 @@ class ToolsDB2(QtWidgets.QWidget):
         try:
         try:
             wdg = self.sender()
             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:
             if wdg is None:
                 return
                 return

+ 24 - 1
flatcamGUI/FlatCAMGUI.py

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