- added a new menu category in the MenuBar named 'Objects'. It will hold the objects found in the Project tab. Useful when working in FullScreen
This commit is contained in:
118
FlatCAMApp.py
118
FlatCAMApp.py
@@ -201,7 +201,7 @@ class App(QtCore.QObject):
|
|||||||
object_plotted = QtCore.pyqtSignal(object)
|
object_plotted = QtCore.pyqtSignal(object)
|
||||||
|
|
||||||
# Emitted when a new object has been added or deleted from/to the collection
|
# Emitted when a new object has been added or deleted from/to the collection
|
||||||
object_status_changed = QtCore.pyqtSignal(object, str)
|
object_status_changed = QtCore.pyqtSignal(object, str, str)
|
||||||
|
|
||||||
message = QtCore.pyqtSignal(str, str, str)
|
message = QtCore.pyqtSignal(str, str, str)
|
||||||
|
|
||||||
@@ -2018,6 +2018,8 @@ class App(QtCore.QObject):
|
|||||||
# Object list
|
# Object list
|
||||||
self.collection.view.activated.connect(self.on_row_activated)
|
self.collection.view.activated.connect(self.on_row_activated)
|
||||||
|
|
||||||
|
self.object_status_changed.connect(self.on_collection_updated)
|
||||||
|
|
||||||
# Monitor the checkbox from the Application Defaults Tab and show the TCL shell or not depending on it's value
|
# Monitor the checkbox from the Application Defaults Tab and show the TCL shell or not depending on it's value
|
||||||
self.ui.general_defaults_form.general_gui_set_group.shell_startup_cb.clicked.connect(self.on_toggle_shell)
|
self.ui.general_defaults_form.general_gui_set_group.shell_startup_cb.clicked.connect(self.on_toggle_shell)
|
||||||
|
|
||||||
@@ -7583,6 +7585,120 @@ class App(QtCore.QObject):
|
|||||||
self.ui.notebook.setCurrentWidget(self.ui.selected_tab)
|
self.ui.notebook.setCurrentWidget(self.ui.selected_tab)
|
||||||
self.collection.on_item_activated(index)
|
self.collection.on_item_activated(index)
|
||||||
|
|
||||||
|
def on_collection_updated(self, obj, state, old_name):
|
||||||
|
"""
|
||||||
|
Create a menu from the object loaded in the collection.
|
||||||
|
TODO: should use the collection model to do this
|
||||||
|
|
||||||
|
:param obj: object that was changd (added, deleted, renamed)
|
||||||
|
:param state: what was done with the objectCand be: added, deleted, delete_all, renamed
|
||||||
|
:param old_name: the old name of the object before the action that triggered this slot happened
|
||||||
|
:return: None
|
||||||
|
"""
|
||||||
|
icon_files = {
|
||||||
|
"gerber": "share/flatcam_icon16.png",
|
||||||
|
"excellon": "share/drill16.png",
|
||||||
|
"cncjob": "share/cnc16.png",
|
||||||
|
"geometry": "share/geometry16.png",
|
||||||
|
"script": "share/script_new16.png",
|
||||||
|
"document": "share/notes16_1.png"
|
||||||
|
}
|
||||||
|
|
||||||
|
if state == 'append':
|
||||||
|
for act in self.ui.menuobjects.actions():
|
||||||
|
try:
|
||||||
|
act.triggered.disconnect()
|
||||||
|
except TypeError:
|
||||||
|
pass
|
||||||
|
self.ui.menuobjects.clear()
|
||||||
|
|
||||||
|
gerber_list = list()
|
||||||
|
exc_list = list()
|
||||||
|
cncjob_list = list()
|
||||||
|
geo_list = list()
|
||||||
|
script_list = list()
|
||||||
|
doc_list = list()
|
||||||
|
|
||||||
|
for name in self.collection.get_names():
|
||||||
|
obj_named = self.collection.get_by_name(name)
|
||||||
|
if obj_named.kind == 'gerber':
|
||||||
|
gerber_list.append(name)
|
||||||
|
elif obj_named.kind == 'excellon':
|
||||||
|
exc_list.append(name)
|
||||||
|
elif obj_named.kind == 'cncjob':
|
||||||
|
cncjob_list.append(name)
|
||||||
|
elif obj_named.kind == 'geometry':
|
||||||
|
geo_list.append(name)
|
||||||
|
elif obj_named.kind == 'script':
|
||||||
|
script_list.append(name)
|
||||||
|
elif obj_named.kind == 'document':
|
||||||
|
doc_list.append(name)
|
||||||
|
|
||||||
|
def add_act(name):
|
||||||
|
obj_for_icon = self.collection.get_by_name(name)
|
||||||
|
add_action = QtWidgets.QAction(parent=self.ui.menuobjects)
|
||||||
|
add_action.setText(name)
|
||||||
|
add_action.setIcon(QtGui.QIcon(icon_files[obj_for_icon.kind]))
|
||||||
|
add_action.triggered.connect(lambda: self.collection.set_exclusive_active(name))
|
||||||
|
self.ui.menuobjects.addAction(add_action)
|
||||||
|
|
||||||
|
for name in gerber_list:
|
||||||
|
add_act(name)
|
||||||
|
self.ui.menuobjects.addSeparator()
|
||||||
|
|
||||||
|
for name in exc_list:
|
||||||
|
add_act(name)
|
||||||
|
self.ui.menuobjects.addSeparator()
|
||||||
|
|
||||||
|
for name in cncjob_list:
|
||||||
|
add_act(name)
|
||||||
|
self.ui.menuobjects.addSeparator()
|
||||||
|
|
||||||
|
for name in geo_list:
|
||||||
|
add_act(name)
|
||||||
|
self.ui.menuobjects.addSeparator()
|
||||||
|
|
||||||
|
for name in script_list:
|
||||||
|
add_act(name)
|
||||||
|
self.ui.menuobjects.addSeparator()
|
||||||
|
|
||||||
|
for name in doc_list:
|
||||||
|
add_act(name)
|
||||||
|
|
||||||
|
|
||||||
|
elif state == 'delete':
|
||||||
|
for act in self.ui.menuobjects.actions():
|
||||||
|
if act.text() == obj.options['name']:
|
||||||
|
try:
|
||||||
|
act.triggered.disconnect()
|
||||||
|
except TypeError:
|
||||||
|
pass
|
||||||
|
self.ui.menuobjects.removeAction(act)
|
||||||
|
break
|
||||||
|
elif state == 'rename':
|
||||||
|
for act in self.ui.menuobjects.actions():
|
||||||
|
if act.text() == old_name:
|
||||||
|
add_action = QtWidgets.QAction(parent=self.ui.menuobjects)
|
||||||
|
add_action.setText(obj.options['name'])
|
||||||
|
add_action.setIcon(QtGui.QIcon(icon_files[obj.kind]))
|
||||||
|
add_action.triggered.connect(lambda: self.collection.set_exclusive_active(obj.options['name']))
|
||||||
|
|
||||||
|
self.ui.menuobjects.insertAction(act, add_action)
|
||||||
|
|
||||||
|
try:
|
||||||
|
act.triggered.disconnect()
|
||||||
|
except TypeError:
|
||||||
|
pass
|
||||||
|
self.ui.menuobjects.removeAction(act)
|
||||||
|
break
|
||||||
|
elif state =='delete_all':
|
||||||
|
for act in self.ui.menuobjects.actions():
|
||||||
|
try:
|
||||||
|
act.triggered.disconnect()
|
||||||
|
except TypeError:
|
||||||
|
pass
|
||||||
|
self.ui.menuobjects.clear()
|
||||||
|
|
||||||
def grid_status(self):
|
def grid_status(self):
|
||||||
if self.ui.grid_snap_btn.isChecked():
|
if self.ui.grid_snap_btn.isChecked():
|
||||||
return True
|
return True
|
||||||
|
|||||||
@@ -425,17 +425,17 @@ class ObjectCollection(QtCore.QAbstractItemModel):
|
|||||||
# rename the object
|
# rename the object
|
||||||
obj.options["name"] = deepcopy(data)
|
obj.options["name"] = deepcopy(data)
|
||||||
|
|
||||||
|
self.app.object_status_changed.emit(obj, 'rename', old_name)
|
||||||
|
|
||||||
# update the SHELL auto-completer model data
|
# update the SHELL auto-completer model data
|
||||||
try:
|
try:
|
||||||
self.app.myKeywords.remove(old_name)
|
self.app.myKeywords.remove(old_name)
|
||||||
self.app.myKeywords.append(new_name)
|
self.app.myKeywords.append(new_name)
|
||||||
self.app.shell._edit.set_model_data(self.app.myKeywords)
|
self.app.shell._edit.set_model_data(self.app.myKeywords)
|
||||||
self.app.ui.code_editor.set_model_data(self.app.myKeywords)
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
log.debug(
|
log.debug(
|
||||||
"setData() --> Could not remove the old object name from auto-completer model list. %s" %
|
"setData() --> Could not remove the old object name from auto-completer model list. %s" %
|
||||||
str(e))
|
str(e))
|
||||||
|
|
||||||
# obj.build_ui()
|
# obj.build_ui()
|
||||||
self.app.inform.emit(_("Object renamed from <b>{old}</b> to <b>{new}</b>").format(old=old_name,
|
self.app.inform.emit(_("Object renamed from <b>{old}</b> to <b>{new}</b>").format(old=old_name,
|
||||||
new=new_name))
|
new=new_name))
|
||||||
@@ -504,7 +504,7 @@ class ObjectCollection(QtCore.QAbstractItemModel):
|
|||||||
|
|
||||||
self.app.should_we_save = True
|
self.app.should_we_save = True
|
||||||
|
|
||||||
self.app.object_status_changed.emit(obj, 'append')
|
self.app.object_status_changed.emit(obj, 'append', name)
|
||||||
|
|
||||||
# decide if to show or hide the Notebook side of the screen
|
# decide if to show or hide the Notebook side of the screen
|
||||||
if self.app.defaults["global_project_autohide"] is True:
|
if self.app.defaults["global_project_autohide"] is True:
|
||||||
@@ -601,14 +601,16 @@ class ObjectCollection(QtCore.QAbstractItemModel):
|
|||||||
log.debug(
|
log.debug(
|
||||||
"delete_active() --> Could not remove the old object name from auto-completer model list. %s" % str(e))
|
"delete_active() --> Could not remove the old object name from auto-completer model list. %s" % str(e))
|
||||||
|
|
||||||
|
self.app.object_status_changed.emit(active.obj, 'delete', name)
|
||||||
|
|
||||||
|
# ############ OBJECT DELETION FROM MODEL STARTS HERE ####################
|
||||||
self.beginRemoveRows(self.index(group.row(), 0, QtCore.QModelIndex()), active.row(), active.row())
|
self.beginRemoveRows(self.index(group.row(), 0, QtCore.QModelIndex()), active.row(), active.row())
|
||||||
|
|
||||||
group.remove_child(active)
|
group.remove_child(active)
|
||||||
|
|
||||||
# after deletion of object store the current list of objects into the self.app.all_objects_list
|
# after deletion of object store the current list of objects into the self.app.all_objects_list
|
||||||
self.app.all_objects_list = self.get_list()
|
self.app.all_objects_list = self.get_list()
|
||||||
|
|
||||||
self.endRemoveRows()
|
self.endRemoveRows()
|
||||||
|
# ############ OBJECT DELETION FROM MODEL STOPS HERE ####################
|
||||||
|
|
||||||
if self.app.is_legacy is False:
|
if self.app.is_legacy is False:
|
||||||
self.app.plotcanvas.redraw()
|
self.app.plotcanvas.redraw()
|
||||||
|
|
||||||
@@ -626,6 +628,9 @@ class ObjectCollection(QtCore.QAbstractItemModel):
|
|||||||
|
|
||||||
def delete_all(self):
|
def delete_all(self):
|
||||||
FlatCAMApp.App.log.debug(str(inspect.stack()[1][3]) + "--> OC.delete_all()")
|
FlatCAMApp.App.log.debug(str(inspect.stack()[1][3]) + "--> OC.delete_all()")
|
||||||
|
|
||||||
|
self.app.object_status_changed.emit(None, 'delete_all', '')
|
||||||
|
|
||||||
try:
|
try:
|
||||||
self.app.all_objects_list.clear()
|
self.app.all_objects_list.clear()
|
||||||
|
|
||||||
@@ -709,6 +714,16 @@ class ObjectCollection(QtCore.QAbstractItemModel):
|
|||||||
log.error("[ERROR] Cause: %s" % str(e))
|
log.error("[ERROR] Cause: %s" % str(e))
|
||||||
raise
|
raise
|
||||||
|
|
||||||
|
def set_exclusive_active(self, name):
|
||||||
|
"""
|
||||||
|
Make the object with the name in parameters the only selected object
|
||||||
|
|
||||||
|
:param name: name of object to be selected and made the only active object
|
||||||
|
:return: None
|
||||||
|
"""
|
||||||
|
self.set_all_inactive()
|
||||||
|
self.set_active(name)
|
||||||
|
|
||||||
def set_inactive(self, name):
|
def set_inactive(self, name):
|
||||||
"""
|
"""
|
||||||
Unselect object by name from the project list. This triggers the
|
Unselect object by name from the project list. This triggers the
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ CAD program, and create G-Code for Isolation routing.
|
|||||||
- some PEP8 corrections
|
- some PEP8 corrections
|
||||||
- some code annotations to make it easier to navigate in the FlatCAMGUI.py
|
- some code annotations to make it easier to navigate in the FlatCAMGUI.py
|
||||||
- fixed exit FullScreen with Escape key
|
- fixed exit FullScreen with Escape key
|
||||||
|
- added a new menu category in the MenuBar named 'Objects'. It will hold the objects found in the Project tab. Useful when working in FullScreen
|
||||||
|
|
||||||
3.10.2019
|
3.10.2019
|
||||||
|
|
||||||
|
|||||||
@@ -404,7 +404,7 @@ class FlatCAMGUI(QtWidgets.QMainWindow):
|
|||||||
# ########################################################################
|
# ########################################################################
|
||||||
# ########################## Objects # ###################################
|
# ########################## Objects # ###################################
|
||||||
# ########################################################################
|
# ########################################################################
|
||||||
self.menufile = self.menu.addMenu(_('Objects'))
|
self.menuobjects = self.menu.addMenu(_('Objects'))
|
||||||
|
|
||||||
# ########################################################################
|
# ########################################################################
|
||||||
# ########################## Tool # ######################################
|
# ########################## Tool # ######################################
|
||||||
|
|||||||
Reference in New Issue
Block a user