Merged in codeZonkey/flatcam/plotToggle (pull request #77)

PlotToggle - From the Project tab
This commit is contained in:
MARCO A QUEZADA 2018-05-19 01:56:36 +00:00 committed by jpcgt
commit bb3b07455c
5 changed files with 76 additions and 18 deletions

View File

@ -24,7 +24,7 @@ class DblSidedTool(FlatCAMTool):
## Layer to mirror
self.object_combo = QtGui.QComboBox()
self.object_combo.setModel(self.app.collection)
self.object_combo.setModel(self.app.collection.model)
self.botlay_label = QtGui.QLabel("Bottom Layer:")
self.botlay_label.setToolTip(
"Layer to be mirrorer."
@ -68,7 +68,7 @@ class DblSidedTool(FlatCAMTool):
self.point = EvalEntry()
self.point_box_container.addWidget(self.point)
self.box_combo = QtGui.QComboBox()
self.box_combo.setModel(self.app.collection)
self.box_combo.setModel(self.app.collection.model)
self.point_box_container.addWidget(self.box_combo)
self.box_combo.hide()
@ -180,6 +180,12 @@ class DblSidedTool(FlatCAMTool):
px = 0.5 * (xmin + xmax)
py = 0.5 * (ymin + ymax)
# Ensure that the selected object will display when it is mirrored.
# If an object's plot setting is False it will still be available in
# the combo box. If the plot is not enforced to True then the user
# gets no feedback of the operation.
fcobj.options["plot"] = True;
fcobj.mirror(axis, [px, py])
fcobj.plot()

View File

@ -554,6 +554,7 @@ class App(QtCore.QObject):
# Options
self.ui.options_combo.activated.connect(self.on_options_combo_change)
self.options_form.units_radio.group_toggle_fn = self.on_toggle_units
#Notebook tabs
####################
### Other setups ###

View File

@ -5,7 +5,6 @@
# Date: 2/5/2014 #
# MIT Licence #
############################################################
from PyQt4 import QtGui, QtCore, Qt
from GUIElements import *
@ -152,6 +151,7 @@ class FlatCAMGUI(QtGui.QMainWindow):
### Notebook ###
################
self.notebook = QtGui.QTabWidget()
# self.notebook.setMinimumWidth(250)
### Projet ###
@ -268,6 +268,7 @@ class FlatCAMGUI(QtGui.QMainWindow):
QtGui.qApp.quit()
class FlatCAMActivityView(QtGui.QWidget):
def __init__(self, parent=None):
@ -375,6 +376,7 @@ class GerberOptionsGroupUI(OptionsGroupUI):
self.plot_options_label.setToolTip(
"Plot (show) this object."
)
grid0.addWidget(self.plot_cb, 0, 0)
# Solid CB
@ -945,4 +947,4 @@ class GlobalOptionsUI(QtGui.QWidget):
#
#
# if __name__ == '__main__':
# main()
# main()

View File

@ -30,6 +30,8 @@ class FlatCAMObj(QtCore.QObject):
# Instance of the application to which these are related.
# The app should set this value.
app = None
option_changed = QtCore.pyqtSignal(QtCore.QObject, str)
def __init__(self, name):
"""
@ -79,7 +81,8 @@ class FlatCAMObj(QtCore.QObject):
setattr(self, attr, d[attr])
def on_options_change(self, key):
self.emit(QtCore.SIGNAL("optionChanged"), key)
#self.emit(QtCore.SIGNAL("optionChanged()"), key)
self.option_changed.emit(self, key)
def set_ui(self, ui):
self.ui = ui

View File

@ -25,7 +25,8 @@ class KeySensitiveListView(QtGui.QListView):
self.keyPressed.emit(event.key())
class ObjectCollection(QtCore.QAbstractListModel):
#class ObjectCollection(QtCore.QAbstractListModel):
class ObjectCollection():
"""
Object storage and management.
"""
@ -45,7 +46,7 @@ class ObjectCollection(QtCore.QAbstractListModel):
}
def __init__(self, parent=None):
QtCore.QAbstractListModel.__init__(self, parent=parent)
#QtCore.QAbstractListModel.__init__(self, parent=parent)
### Icons for the list view
self.icons = {}
for kind in ObjectCollection.icon_files:
@ -66,7 +67,10 @@ class ObjectCollection(QtCore.QAbstractListModel):
#self.view = QtGui.QListView()
self.view = KeySensitiveListView()
self.view.setSelectionMode(Qt.QAbstractItemView.ExtendedSelection)
self.view.setModel(self)
self.model = QtGui.QStandardItemModel(self.view)
self.view.setModel(self.model)
self.model.itemChanged.connect(self.on_item_changed)
#self.view.setModel(self)
self.click_modifier = None
@ -96,8 +100,13 @@ class ObjectCollection(QtCore.QAbstractListModel):
self.get_active().ui.plot_cb.toggle()
return
def print_list(self):
for obj in self.object_list:
print obj
def on_mouse_down(self, event):
FlatCAMApp.App.log.debug("Mouse button pressed on list")
#self.print_list()
def rowCount(self, parent=QtCore.QModelIndex(), *args, **kwargs):
return len(self.object_list)
@ -119,10 +128,6 @@ class ObjectCollection(QtCore.QAbstractListModel):
# else:
# return Qt.Qt.Unchecked
def print_list(self):
for obj in self.object_list:
print obj
def append(self, obj, active=False):
FlatCAMApp.App.log.debug(str(inspect.stack()[1][3]) + " --> OC.append()")
@ -151,13 +156,42 @@ class ObjectCollection(QtCore.QAbstractListModel):
obj.set_ui(obj.ui_type())
# Required before appending (Qt MVC)
self.beginInsertRows(QtCore.QModelIndex(), len(self.object_list), len(self.object_list))
#self.beginInsertRows(QtCore.QModelIndex(), len(self.object_list), len(self.object_list))
# Simply append to the python list
self.object_list.append(obj)
# Create the model item to insert into the QListView
icon = QtGui.QIcon(self.icons[obj.kind])#self.icons["gerber"])
item = QtGui.QStandardItem(icon, name)
item.setCheckable(True)
if obj.options["plot"] == True:
item.setCheckState(2)#Qt.Checked)
else:
item.setCheckState(0) #Qt.Unchecked)
self.model.appendRow(item)
obj.option_changed.connect(self.on_object_option_changed)
# Required after appending (Qt MVC)
self.endInsertRows()
#self.endInsertRows()
def on_object_option_changed(self, obj, key):
if key == "plot":
self.model.blockSignals(True)
name = obj.options["name"]
state = 0 #Qt.Unchecked
for index in range(self.model.rowCount()):
item = self.model.item(index)
if self.object_list[item.row()].options["name"] == name:
if obj.options["plot"] == True:
state = 2 #Qt.Checked
item.setCheckState(state)
obj.ui.plot_cb.set_value(state)
break
self.model.blockSignals(False)
def get_names(self):
"""
@ -220,11 +254,12 @@ class ObjectCollection(QtCore.QAbstractListModel):
return
row = selections[0].row()
self.beginRemoveRows(QtCore.QModelIndex(), row, row)
#self.beginRemoveRows(QtCore.QModelIndex(), row, row)
self.object_list.pop(row)
self.model.removeRow(row)
self.endRemoveRows()
#self.endRemoveRows()
def get_active(self):
"""
@ -289,6 +324,16 @@ class ObjectCollection(QtCore.QAbstractListModel):
self.object_list[selection_index].build_ui()
def on_item_changed(self, item):
FlatCAMApp.App.log.debug("on_item_changed(): " + str(item.row()) + " " + self.object_list[item.row()].options["name"])
if item.checkState() == QtCore.Qt.Checked:
self.object_list[item.row()].options["plot"] = True #(item.checkState() == QtCore.Qt.Checked)
else:
self.object_list[item.row()].options["plot"] = False #(item.checkState() == QtCore.Qt.Checked)
self.object_list[item.row()].plot()
return
def on_item_activated(self, index):
"""
Double-click or Enter on item.
@ -301,12 +346,13 @@ class ObjectCollection(QtCore.QAbstractListModel):
def delete_all(self):
FlatCAMApp.App.log.debug(str(inspect.stack()[1][3]) + "--> OC.delete_all()")
self.beginResetModel()
# self.beginResetModel()
self.model.removeRows(0, self.model.rowCount())
self.object_list = []
self.checked_indexes = []
self.endResetModel()
# self.endResetModel()
def get_list(self):
return self.object_list