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

- 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

Marius Stanciu 6 лет назад
Родитель
Сommit
127a78e06e
3 измененных файлов с 26 добавлено и 0 удалено
  1. 20 0
      FlatCAMApp.py
  2. 5 0
      ObjectCollection.py
  3. 1 0
      README.md

+ 20 - 0
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.

+ 5 - 0
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]<span style="color:{color};">{name}</span> selected').format(
@@ -799,6 +803,7 @@ class ObjectCollection(QtCore.QAbstractItemModel):
                 self.app.inform.emit(_('[selected]<span style="color:{color};">{name}</span> 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:

+ 1 - 0
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