From 5e3f148957c370094f67003bee50e143c52a0b8e Mon Sep 17 00:00:00 2001 From: Tristan Rowley Date: Sat, 29 Feb 2020 14:58:19 +0000 Subject: [PATCH] plugins are notified of exiting so they can save config etc --- actions.py | 1 + data_centre/data.py | 1 - data_centre/plugin_collection.py | 17 +++++++---------- plugins/ShaderLoopRecordPlugin.py | 5 +++++ plugins/ShaderQuickPresetPlugin.py | 4 ++++ 5 files changed, 17 insertions(+), 11 deletions(-) diff --git a/actions.py b/actions.py index 0e17948..50d4d31 100644 --- a/actions.py +++ b/actions.py @@ -729,6 +729,7 @@ class Actions(object): def quit_the_program(self): self.data._update_json(self.data.SETTINGS_JSON, self.data.settings) + self.data.plugins.quit_plugins() self.video_driver.exit_all_players() self.exit_openframeworks() self.exit_osc_server('','') diff --git a/data_centre/data.py b/data_centre/data.py index 38d221d..0dce385 100644 --- a/data_centre/data.py +++ b/data_centre/data.py @@ -111,7 +111,6 @@ class Data(object): def initialise_plugins(self): #initialise plugin manager self.plugins = plugin_collection.PluginCollection("plugins", self.message_handler, self) - self.plugins.apply_all_plugins_on_value(5) def load_midi_mapping_for_device(self, device_name): # check if custom config file exists on disk for this device name diff --git a/data_centre/plugin_collection.py b/data_centre/plugin_collection.py index 9f8485f..a0e304f 100644 --- a/data_centre/plugin_collection.py +++ b/data_centre/plugin_collection.py @@ -15,6 +15,9 @@ class Plugin(object): self.description = 'UNKNOWN' self.pc = plugin_collection + def quit_plugin(self): + print("quitting " + type(self).__name__) + class MidiFeedbackPlugin(Plugin): """Base class for MIDI feedback plugins """ @@ -476,6 +479,10 @@ class PluginCollection(object): print("Looking for plugins under package %s" % self.plugin_package) self.walk_package(self.plugin_package) + def quit_plugins(self): + # tell each plugin to quit + for plugin in self.get_plugins(): + plugin.quit_plugin() def get_plugins(self, clazz = None): if clazz: @@ -483,16 +490,6 @@ class PluginCollection(object): else: return [c for c in self.plugins if not c.disabled] - def apply_all_plugins_on_value(self, argument): - """Apply all of the plugins on the argument supplied to this function - """ - print() - print('Applying all plugins on value %s:' %argument) - for plugin in self.plugins: - #print(" Applying %s on value %s yields value %s" % (plugin.description, argument, plugin.perform_operation(argument))) - pass - - def walk_package(self, package): """Recursively walk the supplied package to retrieve all plugins """ diff --git a/plugins/ShaderLoopRecordPlugin.py b/plugins/ShaderLoopRecordPlugin.py index 45c6c43..fc3cf29 100644 --- a/plugins/ShaderLoopRecordPlugin.py +++ b/plugins/ShaderLoopRecordPlugin.py @@ -45,6 +45,11 @@ class ShaderLoopRecordPlugin(ActionsPlugin,SequencePlugin,DisplayPlugin): def save_presets(self): self.pc.update_json(self.PRESET_FILE_NAME, self.frames) + def quit_plugin(self): + super().quit_plugin() + self.save_presets() + + # DisplayPlugin methods def get_display_modes(self): return ['LOOPREC','NAV_LPRC'] diff --git a/plugins/ShaderQuickPresetPlugin.py b/plugins/ShaderQuickPresetPlugin.py index 3da91fc..ce31a6e 100644 --- a/plugins/ShaderQuickPresetPlugin.py +++ b/plugins/ShaderQuickPresetPlugin.py @@ -25,6 +25,10 @@ class ShaderQuickPresetPlugin(ActionsPlugin): #,SequencePlugin): def save_presets(self): self.pc.update_json(self.PRESET_FILE_NAME, self.presets) + def quit_plugin(self): + super().quit_plugin() + self.save_presets() + @property def parserlist(self): return [