Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 49 additions & 4 deletions lisp/plugins/action_cues/collection_cue.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@

from PyQt5.QtCore import Qt, QT_TRANSLATE_NOOP
from PyQt5.QtWidgets import (
QWidget,
QVBoxLayout,
QHBoxLayout,
QSizePolicy,
QDialogButtonBox,
QDialog,
Expand All @@ -26,6 +28,7 @@
QTableView,
QGroupBox,
QPushButton,
QCheckBox,
)

from lisp.application import Application
Expand All @@ -42,24 +45,50 @@
class CollectionCue(Cue):
Name = QT_TRANSLATE_NOOP("CueName", "Collection Cue")
Category = QT_TRANSLATE_NOOP("CueCategory", "Action cues")
CueActions = (CueAction.Default, CueAction.Start, CueAction.Stop)

targets = Property(default=[])
tracking = Property(default=False)

def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.name = translate("CueName", self.Name)
self.ended_cues_count = 0

def __start__(self, fade=False):
for target_id, action in self.targets:
cue = self.app.cue_model.get(target_id)
if cue is not self:
if self.tracking:
cue.stopped.connect(self.mark_as_done)
cue.error.connect(self.mark_as_done)
cue.interrupted.connect(self.mark_as_done)
cue.end.connect(self.mark_as_done)
cue.execute(action=CueAction[action])

return False
return self.tracking

def __stop__(self, fade=False):
for target_id, action in self.targets:
target_cue = self.app.cue_model.get(target_id)
target_cue.end.disconnect(self.mark_as_done)
target_cue.stopped.disconnect(self.mark_as_done)
target_cue.interrupted.disconnect(self.mark_as_done)
target_cue.error.disconnect(self.mark_as_done)
target_cue.stop()
self.ended_cues_count = 0

return True

def mark_as_done(self, cue):
self.ended_cues_count += 1
if self.ended_cues_count == len(self.targets):
self.ended_cues_count = 0
self._ended()
Comment on lines +71 to +87
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we don't stop tracking the cue when we "mark (it) as done", if the cue is started again, the counting will be off


class CollectionCueSettings(SettingsPage):
Name = QT_TRANSLATE_NOOP("SettingsPageName", "Edit Collection")
Tracking = QT_TRANSLATE_NOOP("CollectionTracking", "Collection tracking")
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that "Tracking mode" could be a better description for the option


def __init__(self, **kwargs):
super().__init__(**kwargs)
Expand All @@ -82,12 +111,20 @@ def __init__(self, **kwargs):
self.collectionView.setAlternatingRowColors(True)
self.collectionGroup.layout().addWidget(self.collectionView)

self.bottomBarGroup = QWidget(self)
self.bottomBarGroup.setLayout(QHBoxLayout())
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
self.bottomBarGroup.setLayout(QHBoxLayout())
self.bottomBarGroup.setLayout(QHBoxLayout())
self.bottomBarGroup.layout().setContentsMargins(0, 0, 0, 0)

We can remove the margins of the inner layout

self.collectionGroup.layout().addWidget(self.bottomBarGroup)

# Collection tracking option
self.trackingCheckBox = QCheckBox(self.Tracking)
self.bottomBarGroup.layout().addWidget(self.trackingCheckBox)

# Buttons
self.dialogButtons = QDialogButtonBox(self.collectionGroup)
self.dialogButtons.setSizePolicy(
QSizePolicy.Minimum, QSizePolicy.Minimum
)
self.collectionGroup.layout().addWidget(self.dialogButtons)
self.bottomBarGroup.layout().addWidget(self.dialogButtons)

self.addButton = QPushButton(self.dialogButtons)
self.dialogButtons.addButton(
Expand All @@ -109,6 +146,7 @@ def retranslateUi(self):
)
self.addButton.setText(translate("CollectionCue", "Add"))
self.delButton.setText(translate("CollectionCue", "Remove"))
self.trackingCheckBox.setText(translate("CollectionTracking", "Collection tracking"))

def enableCheck(self, enabled):
self.setGroupEnabled(self.collectionGroup, enabled)
Expand All @@ -119,13 +157,18 @@ def loadSettings(self, settings):
if target is not None:
self._addCue(target, CueAction(action))

self.trackingCheckBox.setChecked(settings["tracking"])

def getSettings(self):
if self.isGroupEnabled(self.collectionGroup):
targets = []
for target_id, action in self.collectionModel.rows:
targets.append((target_id, action.value))

return {"targets": targets}
return {
"targets": targets,
"tracking": self.trackingCheckBox.isChecked()
}

return {}

Expand All @@ -140,8 +183,10 @@ def _showAddCueDialog(self):

def _removeCurrentCue(self):
row = self.collectionView.currentIndex().row()
cueId = self.collectionModel.rows[row][0]
if row == -1:
Comment thread
FrancescoCeruti marked this conversation as resolved.
return

cueId = self.collectionModel.rows[row][0]
self.collectionModel.removeRow(row)
self.cueDialog.add_cue(Application().cue_model.get(cueId))

Expand Down