From d14e5d9445560f31e5b02ef180e5439347ab2351 Mon Sep 17 00:00:00 2001 From: Marius Stanciu Date: Mon, 6 Apr 2020 20:52:00 +0300 Subject: [PATCH] - fixed a bug in handling the UP/DOWN key shortcuts that caused a crash when no object was selected in the Project Tab; also made sure that the said keys are handled only for the Project Tab --- README.md | 1 + flatcamGUI/FlatCAMGUI.py | 41 ++++++++++++++++++++++++---------------- 2 files changed, 26 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index 5104b726..5e9d55b8 100644 --- a/README.md +++ b/README.md @@ -14,6 +14,7 @@ CAD program, and create G-Code for Isolation routing. - added key shortcuts (arrow up/down) that will select the objects in the Project tab if the focus is in that tab - added a minor change to the ListSys Tcl command - fixed an crash generated when running the Tool Database from the Menu -> Options menu entry +- fixed a bug in handling the UP/DOWN key shortcuts that caused a crash when no object was selected in the Project Tab; also made sure that the said keys are handled only for the Project Tab 5.04.2020 diff --git a/flatcamGUI/FlatCAMGUI.py b/flatcamGUI/FlatCAMGUI.py index 064d3d76..27c80913 100644 --- a/flatcamGUI/FlatCAMGUI.py +++ b/flatcamGUI/FlatCAMGUI.py @@ -16,8 +16,7 @@ from flatcamEditors.FlatCAMGeoEditor import FCShapeTool from matplotlib.backend_bases import KeyEvent as mpl_key_event import webbrowser -from copy import deepcopy -from datetime import datetime +from ObjectCollection import KeySensitiveListView import subprocess import os @@ -3134,23 +3133,33 @@ class FlatCAMGUI(QtWidgets.QMainWindow): # Select the object in the Tree above the current one if key == QtCore.Qt.Key_Up: - self.app.collection.set_all_inactive() - active_name = active.options['name'] - active_index = names_list.index(active_name) - if active_index == 0: - self.app.collection.set_active(names_list[-1]) - else: - self.app.collection.set_active(names_list[active_index-1]) + # make sure it works only for the Project Tab who is an instance of KeySensitiveListView + focused_wdg = QtWidgets.QApplication.focusWidget() + if isinstance(focused_wdg, KeySensitiveListView): + self.app.collection.set_all_inactive() + if active is None: + return + active_name = active.options['name'] + active_index = names_list.index(active_name) + if active_index == 0: + self.app.collection.set_active(names_list[-1]) + else: + self.app.collection.set_active(names_list[active_index-1]) # Select the object in the Tree bellow the current one if key == QtCore.Qt.Key_Down: - self.app.collection.set_all_inactive() - active_name = active.options['name'] - active_index = names_list.index(active_name) - if active_index == len(names_list) - 1: - self.app.collection.set_active(names_list[0]) - else: - self.app.collection.set_active(names_list[active_index+1]) + # make sure it works only for the Project Tab who is an instance of KeySensitiveListView + focused_wdg = QtWidgets.QApplication.focusWidget() + if isinstance(focused_wdg, KeySensitiveListView): + self.app.collection.set_all_inactive() + if active is None: + return + active_name = active.options['name'] + active_index = names_list.index(active_name) + if active_index == len(names_list) - 1: + self.app.collection.set_active(names_list[0]) + else: + self.app.collection.set_active(names_list[active_index+1]) # New Geometry