From 127a78e06e61c2ce0e8b33c4af21529cfe2db0c0 Mon Sep 17 00:00:00 2001 From: Marius Stanciu Date: Mon, 21 Oct 2019 15:55:49 +0300 Subject: [PATCH] - updated the Objects menu signals so whenever an object is (de)selected in the Project Tab, it's state will reflect the (un)checked state of the actions in the Object menu --- FlatCAMApp.py | 20 ++++++++++++++++++++ ObjectCollection.py | 5 +++++ README.md | 1 + 3 files changed, 26 insertions(+) diff --git a/FlatCAMApp.py b/FlatCAMApp.py index 29b8511e..8d9b3567 100644 --- a/FlatCAMApp.py +++ b/FlatCAMApp.py @@ -2123,6 +2123,7 @@ class App(QtCore.QObject): # Object list self.collection.view.activated.connect(self.on_row_activated) + self.collection.item_selected.connect(self.on_row_selected) self.object_status_changed.connect(self.on_collection_updated) @@ -7923,6 +7924,25 @@ class App(QtCore.QObject): self.ui.notebook.setCurrentWidget(self.ui.selected_tab) self.collection.on_item_activated(index) + def on_row_selected(self, obj_name): + # this is a special string; when received it will make all entries unchecked + # it mean we clicked outside of the items and deselected all + if obj_name =='none': + for act in self.ui.menuobjects.actions(): + act.setChecked(False) + return + + # get the name of the selected objects and add them to a list + name_list = list() + for obj in self.collection.get_selected(): + name_list.append(obj.options['name']) + + # set all actions as unchecked but the ones selected make them checked + for act in self.ui.menuobjects.actions(): + act.setChecked(False) + if act.text() in name_list: + act.setChecked(True) + def on_collection_updated(self, obj, state, old_name): """ Create a menu from the object loaded in the collection. diff --git a/ObjectCollection.py b/ObjectCollection.py index c3534f0f..b917ea47 100644 --- a/ObjectCollection.py +++ b/ObjectCollection.py @@ -219,6 +219,9 @@ class ObjectCollection(QtCore.QAbstractItemModel): "document": "share/notes16_1.png" } + # will emit the name of the object that was just selected + item_selected = QtCore.pyqtSignal(str) + root_item = None # app = None @@ -779,6 +782,7 @@ class ObjectCollection(QtCore.QAbstractItemModel): try: obj = current.indexes()[0].internalPointer().obj + self.item_selected.emit(obj.options['name']) if obj.kind == 'gerber': self.app.inform.emit(_('[selected]{name} selected').format( @@ -799,6 +803,7 @@ class ObjectCollection(QtCore.QAbstractItemModel): self.app.inform.emit(_('[selected]{name} selected').format( color='darkCyan', name=str(obj.options['name']))) except IndexError: + self.item_selected.emit('none') # FlatCAMApp.App.log.debug("on_list_selection_change(): Index Error (Nothing selected?)") self.app.inform.emit('') try: diff --git a/README.md b/README.md index d1a05ea1..7df801ed 100644 --- a/README.md +++ b/README.md @@ -13,6 +13,7 @@ CAD program, and create G-Code for Isolation routing. - the context menu for the Tabs in notebook and PlotTabArea is launched now on right mouse click on tabs themselves - fixed an error when trying to view the source file and there is no object selected +- updated the Objects menu signals so whenever an object is (de)selected in the Project Tab, it's state will reflect the (un)checked state of the actions in the Object menu 18.10.2019