Skip to content

Commit

Permalink
Setting Panel in Cart Layout
Browse files Browse the repository at this point in the history
Simple implementation of CueSettingPanel in CartLayout
with a new "intermediate" class for minimal modification

+ dicsconnect cue modification signal when modification comes from
the panel itself
  • Loading branch information
Yinameah committed Apr 20, 2017
1 parent c90bee8 commit 83b6e48
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 16 deletions.
2 changes: 2 additions & 0 deletions lisp/layouts/cart_layout/cue_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ class CueWidget(QWidget):
context_menu_request = pyqtSignal(object, QPoint)
edit_request = pyqtSignal(object)
cue_executed = pyqtSignal(object)
cue_selected = pyqtSignal()

def __init__(self, cue, **kwargs):
super().__init__(**kwargs)
Expand Down Expand Up @@ -285,6 +286,7 @@ def _clicked(self, event):
self.edit_request.emit(self.cue)
elif event.modifiers() == Qt.ControlModifier:
self.selected = not self.selected
self.cue_selected.emit()
else:
self.cue_executed.emit(self.cue)
self.cue.execute()
Expand Down
61 changes: 59 additions & 2 deletions lisp/layouts/cart_layout/layout.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

from PyQt5.QtCore import Qt, QT_TRANSLATE_NOOP
from PyQt5.QtWidgets import QTabWidget, QAction, QInputDialog, qApp, \
QMessageBox
QMessageBox, QWidget, QVBoxLayout

from lisp.core.configuration import config
from lisp.core.signal import Connection
Expand All @@ -37,12 +37,14 @@
from lisp.ui.settings.pages.cue_appearance import Appearance
from lisp.ui.settings.pages.cue_general import CueGeneralSettings
from lisp.ui.settings.pages.media_cue_settings import MediaCueSettings
from lisp.ui.settings.cue_settings_panel import CueSettingsPanel, CueSettingsPanelSplitter
from lisp.ui.ui_utils import translate

AppSettings.register_settings_widget(CartLayoutSettings)


class CartLayout(QTabWidget, CueLayout):
class CartLayout(QWidget, CueLayout):

NAME = 'Cart Layout'
DESCRIPTION = translate('LayoutDescription',
'Organize cues in grid like pages')
Expand All @@ -56,6 +58,49 @@ class CartLayout(QTabWidget, CueLayout):
'To copy cues drag them while pressing SHIFT')
]

def __init__(self, cue_model, **kwargs):
super().__init__(cue_model=cue_model)

self.setLayout(QVBoxLayout())

self.splitter = CueSettingsPanelSplitter()
self.layout().addWidget(self.splitter)

self.cart_layout_pages = CartLayoutPages(cue_model, **kwargs)
self.splitter.addWidget(self.cart_layout_pages)
self.splitter.addWidget(CueSettingsPanel(self.splitter))

self.splitter.lazy_init()
CueSettingsPanel().display_cue_settings(None)

def finalize(self):
self.cart_layout_pages.finalize()

@CueLayout.model_adapter.getter
def model_adapter(self):
return self.cart_layout_pages.model_adapter

def edit_selected_cues(self):
self.cart_layout_pages.edit_selected_cues()

def select_all(self, cue_class=Cue):
self.cart_layout_pages.select_all(cue_class)

def deselect_all(self, cue_class=Cue):
self.cart_layout_pages.deselect_all(cue_class)

def invert_selection(self):
self.cart_layout_pages.invert_selection()

def get_context_cue(self):
self.cart_layout_pages.get_context_cue()

def get_selected_cues(self, cue_class=Cue):
self.cart_layout_pages.get_selected_cues()


class CartLayoutPages(QTabWidget, CueLayout):

def __init__(self, cue_model, **kwargs):
super().__init__(cue_model=cue_model, **kwargs)
self.tabBar().setObjectName('CartTabBar')
Expand Down Expand Up @@ -218,15 +263,25 @@ def select_all(self, cue_class=Cue):
for widget in self.widgets():
if isinstance(widget.cue, cue_class):
widget.selected = True
self.__selection_changed()

def deselect_all(self, cue_class=Cue):
for widget in self.widgets():
if isinstance(widget.cue, cue_class):
widget.selected = False
self.__selection_changed()

def invert_selection(self):
for widget in self.widgets():
widget.selected = not widget.selected
self.__selection_changed()

def __selection_changed(self):
sel = self.get_selected_cues()
if sel:
CueSettingsPanel().display_cue_settings(sel)
else:
CueSettingsPanel().display_cue_settings(None)

def contextMenuEvent(self, event):
# For some reason the currentWidget geometry does not include the
Expand Down Expand Up @@ -411,6 +466,7 @@ def __cue_added(self, cue):

widget = CueWidget(cue)
widget.cue_executed.connect(self.cue_executed.emit)
widget.cue_selected.connect(self.__selection_changed)
widget.context_menu_request.connect(self._on_context_menu)
widget.edit_request.connect(self.edit_cue)
widget.set_accurate_timing(self._accurate_timing)
Expand All @@ -435,6 +491,7 @@ def __cue_removed(self, cue):
widget = self.__pages[page].take_widget(row, column)

widget.cue_executed.disconnect()
widget.cue_selected.disconnect()
widget.context_menu_request.disconnect()
widget.edit_request.disconnect()

Expand Down
34 changes: 20 additions & 14 deletions lisp/ui/settings/cue_settings_panel.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ def on_unfold(self):
self.splitter().panel_opened.emit()

def adjust_height(self):
pref_height = self.splitter().widget(1).prefered_height()
pref_height = self.splitter().widget(1).preferred_height()
# Take margins into account
pref_height += 10
cues_zone, panel_zone = self.splitter().sizes()
Expand Down Expand Up @@ -323,21 +323,27 @@ def on_cue_properties_updated(self):
print(f"display called from on_cue_properties_updated for {self._current_displayed_cues}")

def save_cues_settings(self):
print(f'start saving cues for {self._current_displayed_cues}')
aggregated_settings = {}
for tab in self.settings_widgets.values():
if tab.isVisible():
settings = tab.currentWidget().get_settings()
aggregated_settings = {**aggregated_settings, **settings}
if self._current_displayed_cues is not None:
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)
if type(self._current_displayed_cues) is list:
self._current_displayed_cues.property_updated.disconnect(self.on_cue_properties_updated)
action = UpdateCuesAction(aggregated_settings, self._current_displayed_cues)
MainActionsHandler.do_action(action)
self._current_displayed_cues.property_updated.connect(
self.on_cue_properties_updated, mode=Connection.QtQueued)
else:
self._current_displayed_cues.property_updated.disconnect(self.on_cue_properties_updated)
action = UpdateCueAction(aggregated_settings, self._current_displayed_cues)
MainActionsHandler.do_action(action)
self._current_displayed_cues.property_updated.connect(
self.on_cue_properties_updated, mode=Connection.QtQueued)

def prefered_height(self):
def preferred_height(self):
"""
Return prefered height based on custom hints given by QFoldableTab
:return: int
Expand Down

0 comments on commit 83b6e48

Please sign in to comment.