added undo button to GUI

with icons that theoretically should look ok cross-platform
This commit is contained in:
tassaron 2017-08-20 22:04:57 -04:00
parent 6bf8a553d6
commit 9d9c4076ac
4 changed files with 51 additions and 8 deletions

View File

@ -823,7 +823,7 @@ class ComponentUpdate(QtWidgets.QUndoCommand):
'''Command object for making a component action undoable'''
def __init__(self, parent, oldWidgetVals, modifiedVals):
super().__init__(
'Changed %s component #%s' % (
'change %s component #%s' % (
parent.name, parent.compPos
)
)

View File

@ -15,7 +15,7 @@ from core import Core
class AddComponent(QUndoCommand):
def __init__(self, parent, compI, moduleI):
super().__init__(
"New %s component" %
"create new %s component" %
parent.core.modules[moduleI].Component.name
)
self.parent = parent
@ -39,7 +39,7 @@ class AddComponent(QUndoCommand):
class RemoveComponent(QUndoCommand):
def __init__(self, parent, selectedRows):
super().__init__('Remove component')
super().__init__('remove component')
self.parent = parent
componentList = self.parent.window.listWidget_componentList
self.selectedRows = [
@ -63,7 +63,7 @@ class RemoveComponent(QUndoCommand):
class MoveComponent(QUndoCommand):
def __init__(self, parent, row, newRow, tag):
super().__init__("Move component %s" % tag)
super().__init__("move component %s" % tag)
self.parent = parent
self.row = row
self.newRow = newRow
@ -107,7 +107,7 @@ class MoveComponent(QUndoCommand):
class ClearPreset(QUndoCommand):
def __init__(self, parent, compI):
super().__init__("Clear preset")
super().__init__("clear preset")
self.parent = parent
self.compI = compI
self.component = self.parent.core.selectedComponents[compI]
@ -125,7 +125,7 @@ class ClearPreset(QUndoCommand):
class OpenPreset(QUndoCommand):
def __init__(self, parent, presetName, compI):
super().__init__("Open %s preset" % presetName)
super().__init__("open %s preset" % presetName)
self.parent = parent
self.presetName = presetName
self.compI = compI
@ -145,7 +145,7 @@ class OpenPreset(QUndoCommand):
class RenamePreset(QUndoCommand):
def __init__(self, parent, path, oldName, newName):
super().__init__('Rename preset')
super().__init__('rename preset')
self.parent = parent
self.path = path
self.oldName = oldName
@ -167,7 +167,7 @@ class DeletePreset(QUndoCommand):
)
self.store = self.parent.core.getPreset(self.path)
self.presetName = self.store['preset']
super().__init__('Delete %s preset (%s)' % (self.presetName, compName))
super().__init__('delete %s preset (%s)' % (self.presetName, compName))
self.loadedPresets = [
i for i, comp in enumerate(self.parent.core.selectedComponents)
if self.presetName == str(comp.currentPreset)

View File

@ -100,6 +100,42 @@ class MainWindow(QtWidgets.QMainWindow):
self.window.installEventFilter(self)
componentList = self.window.listWidget_componentList
style = window.pushButton_undo.style()
undoButton = window.pushButton_undo
undoButton.setIcon(
style.standardIcon(QtWidgets.QStyle.SP_FileDialogBack)
)
undoButton.clicked.connect(self.undoStack.undo)
undoButton.setEnabled(False)
self.undoStack.cleanChanged.connect(
lambda change: undoButton.setEnabled(self.undoStack.count())
)
self.undoMenu = QMenu()
self.undoMenu.addAction(
self.undoStack.createUndoAction(self)
)
self.undoMenu.addAction(
self.undoStack.createRedoAction(self)
)
action = self.undoMenu.addAction('Show History...')
action.triggered.connect(
lambda _: self.showUndoStack()
)
undoButton.setMenu(self.undoMenu)
style = window.pushButton_listMoveUp.style()
window.pushButton_listMoveUp.setIcon(
style.standardIcon(QtWidgets.QStyle.SP_ArrowUp)
)
style = window.pushButton_listMoveDown.style()
window.pushButton_listMoveDown.setIcon(
style.standardIcon(QtWidgets.QStyle.SP_ArrowDown)
)
style = window.pushButton_removeComponent.style()
window.pushButton_removeComponent.setIcon(
style.standardIcon(QtWidgets.QStyle.SP_DialogDiscardButton)
)
if sys.platform == 'darwin':
log.debug(
'Darwin detected: showing progress label below progress bar')

View File

@ -110,6 +110,13 @@
<property name="sizeConstraint">
<enum>QLayout::SetMinimumSize</enum>
</property>
<item>
<widget class="QPushButton" name="pushButton_undo">
<property name="text">
<string>Undo</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_6">
<property name="orientation">