From 529148c60d6776b2038680dbef7150cc34d9f37c Mon Sep 17 00:00:00 2001 From: Marius Stanciu Date: Fri, 11 Feb 2022 11:06:08 +0200 Subject: [PATCH] - made sure that the `redraw_on_top_on_project_click` works properly and only on mouse click release in the Project list - made sure that the `redraw_on_top_on_project_click` works only on single object selections --- CHANGELOG.md | 2 ++ appGUI/MainGUI.py | 10 +++++----- appObjects/ObjectCollection.py | 25 ++++++++++++++++--------- app_Main.py | 10 +++++++--- 4 files changed, 30 insertions(+), 17 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 590a124c..4109d00b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,8 @@ CHANGELOG for FlatCAM beta - made sure that the new feature of redrawing Gerber on top is not activated when that Gerber object is disabled - added ability to turn off the outline plotting for Gerber objects (will speed up the plotting but the plotting visual quality will degrade); controlled from Preferences -> Gerber -> General - plotting visuals in 3d graphic mode will no longer create some unnecessary lists +- made sure that the `redraw_on_top_on_project_click` works properly and only on mouse click release in the Project list +- made sure that the `redraw_on_top_on_project_click` works only on single object selections 10.02.2022 diff --git a/appGUI/MainGUI.py b/appGUI/MainGUI.py index 9b340daa..51d8a5fb 100644 --- a/appGUI/MainGUI.py +++ b/appGUI/MainGUI.py @@ -32,7 +32,7 @@ from appGUI.preferences.tools.Plugins2PreferencesUI import Plugins2PreferencesUI from appGUI.preferences.tools.PluginsEngravingPreferencesUI import PluginsEngravingPreferencesUI from appGUI.preferences.utilities.UtilPreferencesUI import UtilPreferencesUI -from appObjects.ObjectCollection import KeySensitiveListView +from appObjects.ObjectCollection import EventSensitiveListView import subprocess import os @@ -3267,9 +3267,9 @@ class MainGUI(QtWidgets.QMainWindow): # Select the object in the Tree above the current one if key == QtCore.Qt.Key.Key_Up: - # make sure it works only for the Project Tab who is an instance of KeySensitiveListView + # make sure it works only for the Project Tab who is an instance of EventSensitiveListView focused_wdg = QtWidgets.QApplication.focusWidget() - if isinstance(focused_wdg, KeySensitiveListView): + if isinstance(focused_wdg, EventSensitiveListView): self.app.collection.set_all_inactive() if active is None: return @@ -3282,9 +3282,9 @@ class MainGUI(QtWidgets.QMainWindow): # Select the object in the Tree below the current one if key == QtCore.Qt.Key.Key_Down: - # make sure it works only for the Project Tab who is an instance of KeySensitiveListView + # make sure it works only for the Project Tab who is an instance of EventSensitiveListView focused_wdg = QtWidgets.QApplication.focusWidget() - if isinstance(focused_wdg, KeySensitiveListView): + if isinstance(focused_wdg, EventSensitiveListView): self.app.collection.set_all_inactive() if active is None: return diff --git a/appObjects/ObjectCollection.py b/appObjects/ObjectCollection.py index 2ebf2264..b77d1e86 100644 --- a/appObjects/ObjectCollection.py +++ b/appObjects/ObjectCollection.py @@ -42,13 +42,13 @@ if '_' not in builtins.__dict__: log = logging.getLogger('base') -class KeySensitiveListView(QtWidgets.QTreeView): +class EventSensitiveListView(QtWidgets.QTreeView): """ QtGui.QListView extended to emit a signal on key press. """ def __init__(self, app, parent=None): - super(KeySensitiveListView, self).__init__(parent) + super(EventSensitiveListView, self).__init__(parent) self.setHeaderHidden(True) # self.setRootIsDecorated(False) @@ -72,12 +72,17 @@ class KeySensitiveListView(QtWidgets.QTreeView): # self.dropped_obj = None keyPressed = QtCore.pyqtSignal(int) + mouseReleased = QtCore.pyqtSignal(int) def keyPressEvent(self, event): - # super(KeySensitiveListView, self).keyPressEvent(event) + # super(EventSensitiveListView, self).keyPressEvent(event) # print(QtGui.QKeySequence(event.key()).toString()) self.keyPressed.emit(event.key()) + def mouseReleaseEvent(self, event: QtGui.QMouseEvent) -> None: + self.mouseReleased.emit(event.button()) + super().mouseReleaseEvent(event) + def dragEnterEvent(self, event): # if event.source(): # self.current_idx = self.currentIndex() @@ -165,7 +170,7 @@ class KeySensitiveListView(QtWidgets.QTreeView): event.ignore() -class TreeItem(KeySensitiveListView): +class TreeItem(EventSensitiveListView): """ Item of a tree model """ @@ -307,7 +312,7 @@ class ObjectCollection(QtCore.QAbstractItemModel): self.plot_promises = set() # ## View - self.view = KeySensitiveListView(self.app) + self.view = EventSensitiveListView(self.app) self.view.setModel(self) self.view.setContextMenuPolicy(QtCore.Qt.ContextMenuPolicy.CustomContextMenu) @@ -338,6 +343,7 @@ class ObjectCollection(QtCore.QAbstractItemModel): self.view.selectionModel().selectionChanged.connect(self.on_list_selection_change) # self.view.activated.connect(self.on_item_activated) self.view.keyPressed.connect(self.app.ui.keyPressEvent) + self.view.mouseReleased.connect(self.on_list_click_release) # self.view.clicked.connect(self.on_mouse_down) self.view.customContextMenuRequested.connect(self.on_menu_request) @@ -999,15 +1005,16 @@ class ObjectCollection(QtCore.QAbstractItemModel): # make sure that if the Properties Tab is selected then the Object UI is updated (built) self.app.on_notebook_tab_changed() - # on Gerber object selection it will redrawn on top of the other Gerber objects - if self.app.defaults["gerber_plot_on_select"] is True: - self.app.gerber_redraw() - # don't emit the signal if there is more than one objects selected # this signal is intended to be emitted for a single selection in the collection view if len(self.get_selected()) == 1: self.app.proj_selection_changed.emit(current, previous) + def on_list_click_release(self): + # on Gerber object selection it will redrawn on top of the other Gerber objects + if self.app.defaults["gerber_plot_on_select"] is True: + self.app.gerber_redraw() + def on_item_activated(self, index): """ Double-click or Enter on item. diff --git a/app_Main.py b/app_Main.py index 96bf1b09..a9059286 100644 --- a/app_Main.py +++ b/app_Main.py @@ -8994,14 +8994,18 @@ class App(QtCore.QObject): self.clear_pool() def gerber_redraw(self): + # the Gerber redraw should work only if there is only one object of type Gerber and active in the selection + sel_gerb_objs = [o for o in self.collection.get_selected() if o.kind == 'gerber' and o.options['plot']] + if len(sel_gerb_objs) > 1: + return + obj = self.collection.get_active() - if obj.options['plot'] is False or obj.kind != 'gerber': + if not obj or (obj.options['plot'] is False or obj.kind != 'gerber'): # we don't replot something that is disabled or if it is not Gerber type return def worker_task(plot_obj): - with self.proc_container.new(''): - plot_obj.plot(visible=True) + plot_obj.plot(visible=True) self.worker_task.emit({'fcn': worker_task, 'params': [obj]})