Skip to content

Commit

Permalink
Record mechanism on CueSettingsPanel
Browse files Browse the repository at this point in the history
Add record mechanism with apply button

A signal as been added in lisp/cues/cue.py so the setting panel
can be notified when changes are done by SettingsDialog
  • Loading branch information
Yinameah committed Apr 19, 2017
1 parent 93a23eb commit 8737f76
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 14 deletions.
6 changes: 6 additions & 0 deletions lisp/cues/cue.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,8 @@ def __init__(self, id=None):

self.changed('next_action').connect(self.__next_action_changed)

self.property_updated = Signal()

def execute(self, action=CueAction.Default):
"""Execute the specified action, if supported.
Expand Down Expand Up @@ -520,3 +522,7 @@ def __next_action_changed(self, next_action):
self.end.disconnect(self.next.emit)
if next_action == CueNextAction.AutoFollow:
self.end.connect(self.next.emit)

def update_properties(self, properties):
super().update_properties(properties)
self.property_updated.emit()
1 change: 0 additions & 1 deletion lisp/layouts/list_layout/layout.py
Original file line number Diff line number Diff line change
Expand Up @@ -441,7 +441,6 @@ def __selection_changed(self):
cue = self.model_adapter.item(index.row())
self.cueSettingsPanel.display_cue_settings(cue)


def __cue_added(self, cue):
cue.next.connect(self.__cue_next, Connection.QtQueued)

Expand Down
64 changes: 51 additions & 13 deletions lisp/ui/settings/cue_settings_panel.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
And a custom widget to display and save the Cue Settings
"""

from collections import OrderedDict
from copy import deepcopy

from PyQt5.QtCore import Qt, pyqtSignal
Expand All @@ -34,10 +33,13 @@
QHBoxLayout, QScrollArea, QLineEdit, QSizePolicy

from lisp.core.util import greatest_common_superclass
from lisp.core.singleton import QSingleton
from lisp.core.signal import Connection
from lisp.cues.cue import Cue
from lisp.layouts.cue_layout import CueLayout
from lisp.ui.settings.cue_settings import CueSettingsRegistry
from lisp.ui.settings.settings_page import CueSettingsPage
from lisp.cues.cue_actions import UpdateCueAction, UpdateCuesAction
from lisp.core.actions_handler import MainActionsHandler
from lisp.ui.ui_utils import translate
from lisp.ui.widgets import QFoldableTab

Expand Down Expand Up @@ -182,14 +184,16 @@ def lazy_init(self):
self.open_settings_panel()


class CueSettingsPanel(QWidget):
class CueSettingsPanel(QWidget, metaclass=QSingleton):

apply_button_clicked = pyqtSignal(object)
"""emitted when apply button is clicked (list of cues to update)"""

def __init__(self, splitter):
super().__init__()

print(self)

self.splitter = splitter

self.setMaximumHeight(350)
Expand All @@ -209,15 +213,10 @@ def __init__(self, splitter):

self.layout().addWidget(self.scrollArea)

self._cues_to_update = []

# TODO : Start here to record settings
#self.splitter.apply_button_clicked.connect(
# lambda: self.apply_button_clicked(self._cues_to_update))
# keep trace of tabs with 'type(SettingWidget)':('QFoldableTab', 'SettingWidget')
self._current_displayed_cues = None
self.splitter.apply_button_clicked.connect(self.save_cues_settings)

# FIXME : is orderedDict still needed ?
self.settings_widgets = OrderedDict()
self.settings_widgets = {}

def sk(widget):
# Sort-Key function
Expand All @@ -244,12 +243,32 @@ def sk(widget):

self.scrollArea.setWidget(self.scrollWidget)

# TODO : this should be called also when an Undo in MainActionHandler is done, otherwise values don't get updated
def display_cue_settings(self, cues=None):
"""
Retrieve cues settings and display them in relevant settings pages in Settings Panel
:param cues : List of cues or None
"""
# Disconnect previous property_updated signal
if self._current_displayed_cues is not None:
if type(self._current_displayed_cues) is list:
for cue in self._current_displayed_cues:
cue.property_updated.disconnect(
self.on_cue_properties_updated)
else:
self._current_displayed_cues.property_updated.disconnect(
self.on_cue_properties_updated)

self._current_displayed_cues = cues

# Connect new ones
if self._current_displayed_cues is not None:
if type(self._current_displayed_cues) is list:
for cue in self._current_displayed_cues:
cue.property_updated.connect(
self.on_cue_properties_updated, mode=Connection.QtQueued)
else:
self._current_displayed_cues.property_updated.connect(
self.on_cue_properties_updated, mode=Connection.QtQueued)

# Hide everything
for tab in self.settings_widgets.values():
Expand Down Expand Up @@ -279,7 +298,6 @@ def display_cue_settings(self, cues=None):
name_to_display = translate('CueSettingsPanel',
'Multiple selection : ') + str([cue.name for cue in cues])


# Display currently edited cue
self.splitter.handle.display_cue_name(name_to_display)

Expand All @@ -302,3 +320,23 @@ def display_cue_settings(self, cues=None):
settings_widget.load_settings(cue_properties)
tab.show()

def on_cue_properties_updated(self):
#print(f'on a chopé un update pour {self._current_displayed_cues}')
self.display_cue_settings(self._current_displayed_cues)
print(f"display called from on_cue_properties_updated for {self._current_displayed_cues}")

def save_cues_settings(self):
aggregated_settings = {}
for tab in self.settings_widgets.values():
if tab.isVisible():
settings = tab.currentWidget().get_settings()
aggregated_settings = {**aggregated_settings, **settings}

if type(self._current_displayed_cues) is list:
action = UpdateCuesAction(aggregated_settings, self._current_displayed_cues)
MainActionsHandler.do_action(action)
else:
action = UpdateCueAction(aggregated_settings, self._current_displayed_cues)
MainActionsHandler.do_action(action)


0 comments on commit 8737f76

Please sign in to comment.