Skip to content

Commit

Permalink
Add a couple of signals to make handling the loading of session confi…
Browse files Browse the repository at this point in the history
…g easier
  • Loading branch information
s0600204 committed Apr 30, 2019
1 parent 3868119 commit b986e2d
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 3 deletions.
4 changes: 4 additions & 0 deletions lisp/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
class Application(metaclass=Singleton):
def __init__(self, app_conf):
self.session_created = Signal()
self.session_initialised = Signal()
self.session_before_finalize = Signal()

self.__conf = app_conf
Expand Down Expand Up @@ -142,6 +143,7 @@ def __new_session_dialog(self):
self.__load_from_file(dialog.sessionPath)
else:
self.__new_session(dialog.selected())
self.session_initialised.emit(self.__session)
else:
if self.__session is None:
# If the user close the dialog, and no layout exists
Expand Down Expand Up @@ -215,6 +217,8 @@ def __load_from_file(self, session_file):
for plugin_name, plugin_config in session_dict['session']['plugins'].items():
self.__session.set_plugin_session_config(plugin_name, plugin_config)

self.session_initialised.emit(self.__session)

# Load cues
for cues_dict in session_dict.get("cues", {}):
cue_type = cues_dict.pop("_type_", "Undefined")
Expand Down
29 changes: 26 additions & 3 deletions lisp/core/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ def __init__(self, app):
""":type app: lisp.application.Application"""
self.__app = app

app.session_created.connect(self._on_session_init)
app.session_created.connect(self._on_session_created)
app.session_initialised.connect(self._on_session_initialised)

@property
def app(self):
Expand All @@ -47,6 +48,28 @@ def app(self):
def finalize(self):
"""Called when the application is getting closed."""

def _on_session_init(self):
"""Called each time a session is initialised (eg. when a session is created or opened)."""
def _on_session_created(self):
"""Called immediately after a session is created.
In the case of a file load, this gets called before the session
properties and cues are restored.
"""
self.SessionConfig = PluginSessionConfig(self)
self.SessionConfig.changed.connect(self._on_session_config_altered)
self.SessionConfig.updated.connect(self._on_session_config_altered)

def _on_session_initialised(self, _):
"""Called once a session is fully initialised.
For new sessions, there is not much difference between this and `app.session_created`
For loaded sessions, this is called *after* the various showfile properties have
been set, but *before* the cues are restored.
"""
pass

def _on_session_config_altered(self, _):
"""Called whenever the session config is changed or updated in any way."""
pass


0 comments on commit b986e2d

Please sign in to comment.